aher

APL routines for US Bingo

Apr 13th, 2013
162
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. The function is run by entering it's name:
  27.  
  28. AplPickEm
  29.  
  30. It produces output like the following:
  31.  
  32. B I N G O
  33. 6 18 42 48 75
  34. 7 19 41 52 67
  35. 8 24 X 55 66
  36. 9 29 34 51 72
  37. 4 28 33 59 68
  38.  
  39. B I N G O
  40. 3 26 38 47 73
  41. 2 20 39 60 74
  42. 10 25 X 46 71
  43. 1 16 37 53 70
  44. 14 22 44 54 65
  45.  
  46. B I N G O
  47. 5 27 36 57 69
  48. 11 17 40 50 64
  49. 15 21 X 49 61
  50. 13 23 35 58 62
  51. 12 30 45 56 63
  52.  
  53. Here is the code to draw the numbers 1-75 at random...
  54.  
  55. ⍝ One-time initialization of global variables
  56. ∇ Init
  57. N ← 0,15×⍳5
  58. L ← 'BINGO'
  59. ⍝ Map numbers 1-75 to letters 'BINGO'
  60. MAP←((⍳75)∘.≥1+5↑N)^(⍳75)∘.≤1↓N
  61.  
  62. ⍝ Shuffle the deck of Bingo calling cards
  63. ∇ Shuffle
  64. DECK ← 75?75
  65.  
  66. ⍝ Draw the next Bingo calling card from the deck
  67. ∇ Draw;C
  68. ⍝ Pick a calling card C from the deck
  69. C ← 1↑DECK
  70. DECK ← 1↓DECK
  71. ⍝ Map C to letters 'BINGO'
  72. C ← ((,MAP[C;]) / L), ' ', C
  73. ⍝ Call the result
  74. C
  75.  
  76. ⍝ Play a game until someone shouts "BINGO!"
  77. Init
  78. Shuffle
  79. Draw
  80. B 10
  81. Draw
  82. G 57
  83. Draw
  84. N 36
  85. ...
  86.  
  87. ⍝ Finally, the code to compute the number of all possible Bingo cards
  88. f←{(!⍵)×⍵!15}
  89. (f 4)×(f 5)*4
  90.  
  91. 5.524464741E26
Advertisement
Add Comment
Please, Sign In to add comment