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