aher

APL routines for US Bingo

Apr 13th, 2013
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. APL routines for US Bingo
  2.  
  3. The following is a niladic function called AplPickEm
  4. used to randomly generate a strip of three 5x5 US Bingo
  5. cards with all 75 numbers.
  6.  
  7. This was tested using Dyalog APL 12.1.
  8.  
  9. N.B. The index origin ⎕IO is 1
  10.  
  11. ∇ AplPickEm;X;A;B;C
  12. ⍝ APL program to randomly generate three 75-ball Bingo cards
  13. X←75 ⍴ X←⍉5 15 ⍴ (15?15),(15+15?15),(30+15?15),(45+15?15),60+15?15
  14. A← 6 5 ⍴ 'BINGO', 25 ↑ X
  15. A[4;3]← 'X' ⍝ Blot-out the "FREE" space
  16. A ⍝ Print first card
  17. ⎕←⍳0 ⍝ Newline
  18. B← 6 5 ⍴ 'BINGO', 25 ↑ 25 ↓ X
  19. B[4;3]← 'X'
  20. B
  21. ⎕←⍳0 ⍝ Newline
  22. C← 6 5 ⍴ 'BINGO', 50 ↓ X
  23. C[4;3]← 'X'
  24. C
  25. ∇
  26.  
  27. The function is run by entering it's name:
  28.  
  29. AplPickEm
  30.  
  31. It produces output like the following:
  32.  
  33. B I N G O
  34. 6 18 42 48 75
  35. 7 19 41 52 67
  36. 8 24 X 55 66
  37. 9 29 34 51 72
  38. 4 28 33 59 68
  39.  
  40. B I N G O
  41. 3 26 38 47 73
  42. 2 20 39 60 74
  43. 10 25 X 46 71
  44. 1 16 37 53 70
  45. 14 22 44 54 65
  46.  
  47. B I N G O
  48. 5 27 36 57 69
  49. 11 17 40 50 64
  50. 15 21 X 49 61
  51. 13 23 35 58 62
  52. 12 30 45 56 63
  53.  
  54. Here is the code to draw the numbers 1-75 at random...
  55.  
  56. ⍝ One-time initialization of global variables
  57. ∇ Init
  58. N ← 0,15×⍳5
  59. L ← 'BINGO'
  60. ⍝ Map numbers 1-75 to letters 'BINGO'
  61. MAP←((⍳75)∘.≥1+5↑N)^(⍳75)∘.≤1↓N
  62. ∇
  63.  
  64. ⍝ Shuffle the deck of Bingo calling cards
  65. ∇ Shuffle
  66. DECK ← 75?75
  67. ∇
  68.  
  69. ⍝ Draw the next Bingo calling card from the deck
  70. ∇ Draw;C
  71. ⍝ Pick a calling card C from the deck
  72. C ← 1↑DECK
  73. DECK ← 1↓DECK
  74. ⍝ Map C to letters 'BINGO'
  75. C ← ((,MAP[C;]) / L), ' ', C
  76. ⍝ Call the result
  77. C
  78. ∇
  79.  
  80. ⍝ Play a game until someone shouts "BINGO!"
  81. Init
  82. Shuffle
  83. Draw
  84. B 10
  85. Draw
  86. G 57
  87. Draw
  88. N 36
  89. ...
  90.  
  91. ⍝ Finally, the code to compute the number of all possible Bingo cards
  92. f←{(!⍵)×⍵!15}
  93. (f 4)×(f 5)*4
  94.  
  95. 5.524464741E26
Advertisement
Add Comment
Please, Sign In to add comment