14
0
The game of Sevens is played as follows: n
players sit in a circle, and start counting up from 1, passing to the left (or from player A
to player B
).
When a number p
that has a 7
in it OR is divisible by 7
is reached, then the player who spoke the number p-1
, after the next player says p
, must say p+1
and the order of people speaking reverses. For example, if player B
speaks 6
, player C
says 7
, B
says 8
, and player A
says 9
.
Note: For those who want to play in real life, if a person forgets a number (or in the version where sevens
are not said, accidentally says a seven
), they are eliminated from the circle, but we will omit this detail from this challenge.
The challenge itself is to print which numbers each player should say in a perfect game of Sevens up to an input m
for an input n
players.
As an example, where five people, A
, B
, C
, D
, and E
, are to play till they reach 30
. They play in this manner
A: 1 6 8 13 15 19 23 30
B: 2 7* 12 16 18 24
C: 3 11 17* 25
D: 4 10 21* 26 28*
E: 5 9 14* 20 22 27*29
where sevens
are marked with *
. Note that at 27
and 28
, we're reversing twice, and play continues "as normal" from D
to E
.
Please note that the output does not have to be in the above format. I simply printed it that way for some clarity.
Rules
The input is two integers in any order,
m
representing the last number to say,n
representing the number of players.The output can be several arrays or several strings, one for each player. If you use strings, you do not have to use separators (though, if you could add some in your code tests, we would appreciate the readability). If you can actually print them in a circle somehow, that is acceptable as well, and it would be pretty cool too.
The output does not have to designate which players are which (it's fairly obvious that the first player is the one who says
1
), though if the output isn't sorted for whatever reason, you should make clear which player is speaking which set of numbers. Omitting players who do not say anything is also allowed if you make it clear which players are speaking. I will add some more examples of possible outputs below.This is code golf, so the smallest number of bytes wins.
As always, if the problem is unclear, please let me know. Good luck and good golfing!
Examples
>>> sevens_string(30, 5, " ")
'1 6 8 13 15 19 23 30'
'2 7 12 16 18 24'
'3 11 17 25'
'4 10 21 26 28'
'5 9 14 20 22 27 29'
>>> sevens_string(42, 5)
'16813151923303539'
'27121618243140'
'31117253241'
'410212628333742'
'591420222729343638'
>>> sevens_array(20, 3)
[1, 4, 7, 10, 13, 15, 19]
[2, 5, 9, 12, 16, 18]
[3, 6, 8, 11, 14, 17, 20]
>>> sevens_array(18, 10)
[1, 13, 15]
[2, 12, 16, 18]
[3, 11, 17]
[4, 10]
[5, 9]
[6, 8]
[7]
[]
[]
[14]
I think a more useful output for purposes of visualizing the game play would be a list of players in order of play. (E.g. with 4 players and a max of 15, that'd be
1 2 3 4 1 2 3 2 1 4 3 2 1 4 1
.) I'm not saying that's better or worse in terms of he challenge: just that it'd be more useful in the real world. – msh210 – 2016-05-22T06:50:46.320Can we display the result as a matrix and pad with zeroes? – Dennis – 2016-05-22T07:16:22.090
@Dennis Empty arrays should be kept. The result may be a zero-padded matrix. – Sherlock9 – 2016-05-23T04:41:29.920