+ 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..

20th Jan 2018, 12:42 PM
Aliuakbar
Aliuakbar - avatar
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
20th Jan 2018, 1:00 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 10
Your example does not make sense should 3 not rather be 3:1 0 0 0 then 4 4:1 0 0 1
20th Jan 2018, 12:50 PM
Louis
Louis - avatar
25th Jan 2018, 12:21 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 9
Enter amount of cards when asked https://code.sololearn.com/c5hEV3XP5c28
20th Jan 2018, 1:25 PM
Louis
Louis - avatar
+ 9
Python : n cards --> int(n**0.5) face-up https://code.sololearn.com/cQijKOtyB2Fe/#py
21st Jan 2018, 5:37 PM
Cépagrave
Cépagrave - avatar
+ 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
20th Jan 2018, 4:31 PM
Oma Falk
Oma Falk - avatar
+ 6
Here is my answer with interpretation https://code.sololearn.com/cABg86JUA0zU
22nd Jan 2018, 11:28 AM
Oma Falk
Oma Falk - avatar
+ 5
https://code.sololearn.com/cRlgXTs0tEw6/?ref=app
20th Jan 2018, 1:39 PM
code learner
code learner - avatar
+ 4
0:0000 1:1111 2:1010 3:1000 4:1001 it should be like this!
20th Jan 2018, 1:34 PM
code learner
code learner - avatar
+ 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
20th Jan 2018, 5:18 PM
code learner
code learner - avatar
+ 3
What input should be given by user ? Just number of cards or cards and flips?
20th Jan 2018, 5:19 PM
code learner
code learner - avatar
+ 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]
20th Jan 2018, 12:43 PM
Aliuakbar
Aliuakbar - avatar
+ 2
@code learner user input is deck size
20th Jan 2018, 8:23 PM
Aliuakbar
Aliuakbar - avatar
+ 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
23rd Jan 2018, 3:05 PM
István Ócsai
István Ócsai - avatar