Solved: Recognize the painful fact that if you can't do this in 10 minutes, you can't really program.

problem

(Begin quote) 400: Name: Anonymous @ teary eyes. (Gifu Castle): 2011/10/15 (Sat) 18: 51: 50.10 ID: eMBuD7fo0 I picked it up from a certain place. "If you can't do this in 10 minutes, be aware of the painful fact that you can't really program."

Create a function that returns the distributed cards as an array given the number of people and the cards. The cards are dealt in order from the front of the given character string, the number of cards dealt is equal, and the remainder is ignored. (End of citation) http://qiita.com/hisui@github/items/b47c411437d60440a605

Answer

I couldn't understand the problem clearly, but it looks like this: It took about 5 minutes.

def card_distributer(number, cards):
  card_list = [ [] for i in range(number) ]
  while ( len(cards) // number ) > 0:
    for i in range(number):
      card_list[i].append(cards.pop(0))
  return card_list

print card_distributer(3,['SA', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'SJ', 'SQ', 'SK'])

output

[ ['SA', 'S4', 'S7', 'S10'], ['S2', 'S5', 'S8', 'SJ'], ['S3', 'S6', 'S9', 'SQ'] ]

Recommended Posts

Solved: Recognize the painful fact that if you can't do this in 10 minutes, you can't really program.
What to do if you can't use the trash in Lubuntu 18.04.
If you feel that you can't find the Object Inspector in recent Spyder
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you can't log in as root
What to do if you can't find PDO in Laravel or CakePHP
What to do if you can't use scikit grid search in Python
What to do if you can't install with pip in babun environment
If you guys in the scope kitchen can do it with a margin ~ ♪
Solution to the problem that you can't activate by putting conda in pyenv