math in today's comics
04-30-2017, 05:13 PM (This post was last modified: 04-30-2017 05:17 PM by pier4r.)
Post: #5
 pier4r Senior Member Posts: 2,224 Joined: Nov 2014
RE: math in today's comics
Don, your list of "started threads" is a gold mine of puzzles useful as programming challenges. I will read and solve the ones that I think I can solve, one day or another. Thanks for sharing.

Anyway I included the test partially as #16 challenge for processing list. My solution is not fast (or better, in the best case is very fast, in the worst, is eternal) but I like it.

For the factorial, a sharp 506w will do it.

Code:
 # userRPL   shuffleListHelp "input: L2: a list L1: numbers of shuffles (affecting single elements) output: L1: shuffled list remarks: to work properly the number of shuffles should not be low, like the number of elements should do it"      shuffleList   @ TODO: consider something like this http://www.hpmuseum.org/forum/thread-2889.html   @       the point is that one receives a list, it is not creating it from the start.   @ TODO: consider analyze the results to suggest a proper number of shuffles or to   @       implement a better algorithm.   \<<     @program that receives a list in input, and shuffles the elements     @returning the shuffled list in output on the stack          @arguments on the stack.     @ 2: list     @ 1: number of random elements to shuffle around          0     \->     @external inputs     inputList     noShuffles     @local var     numEl     \<<       @explode the list on the stack       inputList OBJ\->       @save the num of elements       'numEl' STO              @roll randomily the elements in the list       1 noShuffles       START         numEl RAND * 1 + IP         ROLL       NEXT              @build the list back       numEl       \->LIST     \>>   \>> c16vaV1     \<<       { 0 8 8 2 }  @mult117       { 1 3 4 }    @primeN       { 6 4 0 9 }  @intCubed       0 @iterations       0 @stoFlags       \->       mult117       primeN       intCubed       iterations       stoFlags       \<<         RCLF 'stoFlags' STO         @-3 SF                @ multiple117         @ I could compute multiples of 117 until I get the right digits         @ but I need to convert a number in digits then.         @ so let's try with permutations. I could write a function         @ to return all the permutations of a list, but so far I put it         @ in the todo. So we do random permutations (shuffle) of a list.         @ it will eventually hit the mark.         WHILE           mult117 { 1000 100 10 1 } *           \GSLIST           117 MOD 0 \=/         REPEAT           mult117 8 shuffleList           'mult117' STO           1 'iterations' STO+         END                  iterations         mult117                      0 'iterations' STO         WHILE           primeN { 100 10 1 } *           \GSLIST           ISPRIME? NOT         REPEAT           primeN 8 shuffleList           'primeN' STO           1 'iterations' STO+         END                  iterations         primeN                  0 'iterations' STO         WHILE           intCubed { 1000 100 10 1 } *           \GSLIST           3 XROOT             @now we have the cube root of the value           FP 0 \=/             @continue until the cube root is not returning an integer.         REPEAT           intCubed 8 shuffleList           'intCubed' STO           1 'iterations' STO+         END                  iterations         intCubed                  stoFlags STOF       \>>     \>>

Code:
 @spoilers 2808 117 MOD 0 == 431 isprime? 4096 3 XROOT

Wikis are great, Contribute :)
 « Next Oldest | Next Newest »

 Messages In This Thread math in today's comics - Don Shepherd - 04-30-2017, 02:18 PM RE: math in today's comics - rprosperi - 04-30-2017, 03:46 PM RE: math in today's comics - Don Shepherd - 04-30-2017, 04:58 PM RE: math in today's comics - rprosperi - 04-30-2017, 07:48 PM RE: math in today's comics - Don Shepherd - 04-30-2017, 09:07 PM RE: math in today's comics - rprosperi - 05-01-2017, 02:31 AM RE: math in today's comics - Don Shepherd - 05-01-2017, 12:43 PM RE: math in today's comics - BobVA - 04-30-2017, 04:54 PM RE: math in today's comics - pier4r - 04-30-2017 05:13 PM

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