Post Reply 
Little explorations with HP calculators (no Prime)
12-27-2018, 03:22 PM
Post: #318
RE: Little explorations with HP calculators (no Prime)
To explore this, I put together a couple of helper apps.

The first simply creates a randomized list of 1s (blue balls) and 0s (white balls):
Code:
Balls
\<<
   @ create a list containing 100 blue
   @ and 40 white balls
   @ (1 = blue, 0 = white)
   1. 100. LMRPT
   0. 40. LMRPT
   +

   @ randomize the list
   LSHUF
\>>

"Balls" creates a randomized list of 100 1s and 40 0s in about 0.1s.

To see how many contiguous runs of 50 blue/20 white "balls" there were in a list, I created this routine:
Code:
AnnaBerta
\<<
   @ result list
   { }

   @ check all contiguous groups of 70
   1. 71. FOR x

      @ extract 70 balls starting from position x
      OVER x DUP 69. + SUB

      @ count the white balls
      0. LCNT

      @ if 20, add x to result list
      20. SAME
      { x + }
      IFT
   NEXT
\>>

"AnnaBerta" takes the list created by "Balls" and checks each contiguous subgroup of 70 elements for the proper mixture of blue/white elements. I assumed that no wrap-around is appropriate for contiguous groups, so I only check starting positions of 1-71.

The smallest result I recall seeing was 1, ie. a single contiguous group in the target list. The largest would be 71, since it's possible to come up with an ordered list where all contiguous subgroups meet the criteria. I've yet to see that in random testing, though. Smile

Execution time of "AnnaBerta" varies depending on the number of found starting points. A list with only 1 "match" completes in about 2.4s, and the opposite extreme (71 matches) completes in about 3.1s.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little explorations with HP calculators (no Prime) - DavidM - 12-27-2018 03:22 PM



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