Post Reply 
Little explorations with HP calculators (no Prime)
03-28-2017, 11:07 AM (This post was last modified: 03-28-2017 05:39 PM by pier4r.)
Post: #53
RE: Little explorations with the HP calculators
Quote:brilliant.org (this site is very nice on certain topics, other topics are a bit, well, low profile still)

[Image: gewiGNI.png]

On this I have at first no useful direction whatsoever. Anyway since the intention is to burn the 50g somehow, I will try with a trial and error approach in the range of possible values (knowing that the diameter cannot be smaller than, say, 10, and bigger than 10 * sqrt(2) ) until I fit the mentioned form.

edit, the minvalue 10 is a tad too much, since the diameter is included in the radius of the big circle. So the maxvalue is 10 actually.

Ok wrote the program, not so nice but it is the first iteration. Its output are all the possible "valid" length of the diameter, given that the diameter is expected to be greater or equal to 7 and smaller or equal to 10, plus the value of a b and c. The problem is, to deremine the right value if the right value is there (there could be the case that a is large, while sqrt(b) and c have a small difference, this is not captured by the program.
Code:

@ problem:
@ take a circle of radius 10. Take a quarter of it.
@ Inscribe the biggest circle in it.
@ the diameter of the inscribed circle can be written in the form:
@ a*(sqrt(b)-c) . a,b,c are integers, b is square free.
@ We need to find the value of floor( a^2*b^2*c^2 / (a+b+c) )
@ but this program is mainly to find the 3 single values

@ Addition1: due to changes in parts of the program, may be that variables are unused.
@ they stay until the program is stable.

\<<
  7 @ minDValue
    @ because the diameter is longer than half the diagonal of a square of side 10.
  10 @maxDValue
    @ because the diameter is smaller than the radius
  1 @a
  2 @b
  1 @c
  0 @result
  10 @uFstopComputation
     @handy for boolean variables
  11 @uFisResultValid
  12 @uFcanIncrementA
  13 @uFcanIncrementB
  14 @uFcanIncrementC
  15 @uFexitLoop
  16 @uFbSquareFree
  20 @uFdebug
  10000 @maxIterations (debug)
  0 @iterations (debug)
  0 @sF3
  0 @sF105
  \->
  minDValue @starting the search from here as diameter
  maxDValue @stopping the search here as diameter
  a
  b
  c
  result
  uFstopComputation
  uFisResultValid
  uFcanIncrementA
  uFcanIncrementB
  uFcanIncrementC
  uFexitLoop
  uFbSquareFree
  uFdebug
  maxIterations
  iterations
  sF3
  sF105
  \<<
    @system flag set, then restored at the end
    -3 FS? 'sF3' STO
    -105 FS? 'sF105' STO
    -3 SF
    -105 SF
    
    uFdebug SF
  
    uFstopComputation CF
      @we stop the computation if the flag is set
    uFcanIncrementA SF
      @we can increment a
    uFcanIncrementB SF
    uFcanIncrementC SF
    

    WHILE 
      uFstopComputation FC?
      
      iterations maxIterations \<=
      uFdebug FS?
      AND
      
      AND
    REPEAT
      b \v/ 
        @sqrt b
      c -
      a *
      'result' STO
      
      IF
        result  minDValue \>=
        result  maxDValue \<=
        AND
      THEN
      
        IF
          b 1 >
        THEN
          @ testing the square free
          uFbSquareFree SF
          
          2 @ start
          b \v/ FLOOR @end
          FOR testN
            IF
              b testN 2 ^ \>=
              @ no need to go further when the testN is bigger than b
            THEN
              IF
                b testN 2 ^ MOD
                0 ==
                @ if no remainder for the division
              THEN
                uFbSquareFree CF @ no square free
                @uFisResultValid CF
                  @result not valid
                
                @ugly break
                b 'testN' STO
              END
            ELSE
              @ugly break
              b 'testN' STO
            END
          NEXT
        END
        
        IF
          uFbSquareFree FS?
        THEN
          @ the result should be fine, post it
          @ for further checks in packed list that are compact
          result  a b  c 
          4 \->LIST
        END
      END
      
      IF
        result  maxDValue \<=
      THEN
        @ as long as the result is under the max value.
        IF
          b \v/ c \>=
            @ otherwise the sqrt(b) -c is negative
        THEN
          1 'c' STO+
        ELSE
          @if c cannot be incremented, time for b
          1 'b' STO+
          1 'c' STO @reset c
        END
      ELSE
        IF
          a b <
        THEN
          @the program incremented b (in the case also c)
          @ until the value grew too much, time to increment a
          1 'a' STO+
          @ reset the rest
          2 'b' STO 
          1 'c' STO
        ELSE
          @a > b
          IF
            b == 2
            c == 1
          THEN
            @ we are in the case that
            @ with default b and c values, a is already too big.
            @ stop sim.
            uFstopComputation SF
          END
        END
      END
      
      IF
        uFdebug FS?
      THEN
        1 'iterations' STO+
        @ a b c 3 \->LIST
      END
    END
    
    IF
      uFdebug FS?
    THEN
      iterations
      "iter" \->TAG
    END
    
    @system flag restored
    IF
      sF3
    THEN
      -3 SF
    END
    
    IF
      sF105
    THEN
      -105 SF
    END
  \>>
\>>

Wikis are great, Contribute :)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with the HP calculators - pier4r - 03-28-2017 11:07 AM



User(s) browsing this thread: 3 Guest(s)