+ 7
[Challenge] Flipping Cards
You get a deck of cards with n cards. Then you turn every card, every second, every third, every fourth and so on until you turn the n-th card. The question is how many cards are then face-up? I give you an example of a deck with 4 cards. 0 represents hidden and 1 means open 0: 0 0 0 0 1: 1 1 1 1 2: 1 0 1 0 3: 1 0 0 0 4: 1 0 0 1 So the answer for n = 4 would be two. I now challenge you to write a code to solve this puzzle for a general n. You can also solve it mathematicaly annd you will get a much easier..
14 Antworten
+ 25
0)0000
1)1111
2)1010 //every 2nd
3)1000 //every 3rd
4)1001 //every 4th
//hope it makes sense to you ☺
//& by following it , here is my try
https://code.sololearn.com/cE8KuXITKBmx/?ref=app
+ 10
Your example does not make sense
should 3 not rather be
3:1 0 0 0
then 4
4:1 0 0 1
+ 9
Enter amount of cards when asked
https://code.sololearn.com/c5hEV3XP5c28
+ 9
Python :
n cards --> int(n**0.5) face-up
https://code.sololearn.com/cQijKOtyB2Fe/#py
+ 6
hmmmmm
column c is flipped if it is n times row r
So 0 or 1 gives answer, if the count of devisors up to n id odd or even.
So far my first thoughts.
Could be wrong
+ 6
Here is my answer with interpretation
https://code.sololearn.com/cABg86JUA0zU
+ 5
https://code.sololearn.com/cRlgXTs0tEw6/?ref=app
+ 4
0:0000
1:1111
2:1010
3:1000
4:1001
it should be like this!
+ 3
how do we decide number of flips? is it deck size+1?
i.e. In example given above deck is of 4 cards and cards are flipped 5 times
+ 3
What input should be given by user ?
Just number of cards or cards and flips?
+ 2
.. and faster code.
I will update this post in 24 hours with my solution and explanations plus a mathematical proof.
Good luck!
[Post character limitations]
+ 2
@code learner user input is deck size
+ 2
I think the easy way is to determine the suare root of the number of cards, but I made a nice little code for further development, for example find out the face-up cards turn-by-turn.
https://code.sololearn.com/cLhAFc6dBj6A/#java