10
\$\begingroup\$

A Bingo card is five columns of five squares each, with the middle square designated "FREE". Numbers cannot duplicate.

The five columns are populated with the following range of numbers:

  • B:1-15
  • I:16-30
  • N:31-45
  • G:46-60
  • O:61-75

In as few characters as possible, output a string that can be interpreted as a randomized Bingo card. For example:

1,2,3,4,5,16,17,18,19,20,31,32,33,34,35,46,47,48,49,50,61,62,63,64,65

This example is not randomized so that I can show that column 1 is populated with 1,2,3,4,5. Also note that the free space has not been given any special treatment because the front-end that interprets this string will skip it.

Another example would be:

1,16,31,46,61,2,17,32,47,62...

In this example, the output is by row instead of by column.

A third example might be:

01020304051617181920313233343546474849506162636465

This is the same output as the 1st example except in fixed length.

\$\endgroup\$
2
  • \$\begingroup\$ Am I the only one who has never heard of Bingo but instead only of Bullshit Bingo? \$\endgroup\$
    – Joey
    May 20 '11 at 18:54
  • \$\begingroup\$ Yes! That's it! My idea is to come up with a list of 75 or more words and populate the card with SELECT * FROM List ORDER BY NEWID() \$\endgroup\$ May 20 '11 at 23:29
2
\$\begingroup\$

PHP, 86

for($o=[];25>$i=count($o);){$n=rand(1,15)+($i-$i%5)*3;$o[$n]=$n;}echo implode(",",$o);
\$\endgroup\$
3
  • \$\begingroup\$ Welcome to PPCG, nice first answer c: \$\endgroup\$
    – Rod
    Oct 26 '16 at 10:28
  • \$\begingroup\$ Thanks, I just noticed a bit too late that this question is 5 years old... xD Not sure if it matters though \$\endgroup\$
    – chocochaos
    Oct 26 '16 at 10:31
  • \$\begingroup\$ join is an alias for ìmplode and you can put the assigment in the after loop. This will shorten your idea to for($o=[];25>$i=count($o);$o[$n]=$n)$n=rand(1,15)+($i-$i%5)*3;echo join(",",$o); \$\endgroup\$ Oct 26 '16 at 15:09
1
\$\begingroup\$

Ruby 1.9, 48 characters

$><<(0..4).map{|i|[*1..75][15*i,15].sample 5}*?,
\$\endgroup\$
1
\$\begingroup\$

Windows PowerShell, 51 54

I'm not sure whether I understood your task correctly, though.

(0..4|%{($x=15*$_+1)..($x+14)|random -c 5})-join','

Sample outputs:

5,9,1,7,13,26,18,23,17,22,37,33,34,41,44,50,53,59,60,58,73,72,64,69,66
14,10,13,5,1,24,29,26,17,30,34,33,43,41,38,59,50,60,49,56,71,61,72,70,68
3,11,4,5,13,27,16,25,26,22,43,34,42,32,38,51,52,49,58,54,61,70,73,71,62
1,9,13,12,4,23,25,20,26,22,40,33,35,44,37,55,47,52,59,53,74,70,75,64,69
8,6,7,1,9,16,21,23,18,17,35,41,37,38,34,60,50,57,51,59,66,75,73,74,71
11,6,13,4,1,29,27,24,22,18,40,35,41,32,43,51,54,57,58,53,74,71,69,66,64
\$\endgroup\$
1
\$\begingroup\$

PHP 106

<?$z=1;for($i=0;$i<5;$i++){for($j=0;$j<rand(1,5);$j++){$o[]=rand($z,$z+15);}$z+=15;}echo implode(",", $o);

I'm not sure I understood correctly the problem... Can you provide a more detailed explanation?

\$\endgroup\$
1
  • \$\begingroup\$ The output is incorrect. You always need to output all 25 squares :) \$\endgroup\$
    – chocochaos
    Oct 26 '16 at 10:07
1
\$\begingroup\$

R, 63 51 50 49 45 bytes

Thanks to Billywob for ongoing suggestions and encouraging my competitive streak.

cat(sapply(split(n<-1:75,cut(n,5)),sample,5))

5 14 15 3 1 20 30 28 18 27 32 45 42 43 41 49 54 50 56 47 68 66 64 73 71

\$\endgroup\$
6
  • \$\begingroup\$ The vectorized approach I tried is a bit shorter.cat(sapply(list(15,16:30,31:45,46:60,61:75),sample,5)) Edit: never mind the printing, added cat instead \$\endgroup\$
    – Billywob
    Oct 26 '16 at 11:29
  • \$\begingroup\$ @Billywob Thanks, that's a great answer! I have since found one that's even shorter. (Not vectorized, unfortunately.) \$\endgroup\$
    – rturnbull
    Oct 26 '16 at 11:40
  • 1
    \$\begingroup\$ Turns you can do even better: cat(sapply(split(1:75,ceiling(1:75/15)),sample,5)). Works by splitting the vector 1:75 into a list where each element is a vector of length 15 instead of using list() to pass objects to sapply. \$\endgroup\$
    – Billywob
    Oct 26 '16 at 11:49
  • \$\begingroup\$ Very nice! I had your solution posted for a few seconds, but then I figured out how to outgolf you by a single byte. \$\endgroup\$
    – rturnbull
    Oct 26 '16 at 12:03
  • \$\begingroup\$ Hah! Even better. But I don't think you need the labels = FALSE option for cut. Because all that matters is that there are 5 repeating factors passed to the split function, regardless of names. \$\endgroup\$
    – Billywob
    Oct 26 '16 at 12:08
0
\$\begingroup\$

Clojure - 52 chars

(map #(take 5(shuffle %))(partition 15(range 1 76)))

Example output (note that it provides the separate rows as sub-lists):

((4 1 12 10 2) (25 23 21 16 27) (39 33 45 44 43) (48 53 59 54 47) (73 71 61 64 63))
\$\endgroup\$
0
\$\begingroup\$

Python 2, 84 bytes

from random import*
print sum([sample(range(1+i*15,16+i*15),5)for i in range(5)],[])

If the output as list if lists is okay there is a 75 bytes solution:

from random import*
print[sample(range(1+i*15,16+i*15),5)for i in range(5)]
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.