[Community Puzzle] Bulgarian solitaire

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Hey everyone,

I started this puzzle a bit earlier, i think i have the correct logic but after some re thinking and changing container types and algorythms i still have the “Process has timed out. This may mean that your solution is not optimized enough to handle some cases.” message for the “Large Piles” and “Many Piles” tests

I do this puzzle in c++, i use multiset as container for my “piles” so i don’t have to sort everytime, a vector to store each pile turn, i use std::move at the only place i “add” something but even then, when i try the test cases i find it takes too much time … anyone willing to help ? dunno if i should post my code here or else.

You don’t need to store all the piles from all the steps. Just regenerate the next one and keep two states. Hint: Think of Achilles and the tortoise contest when the track they’re running on has a cycle: will they ever be on the same spot?

I still can’t figure out how to do it with your clue.
I didnt know the story about Achilles & the tortoise (or forgot it), after reading it all i can understand it’s about not looking the problem correct way.
I understand that storing everything isn’t the solution, but your solution of storing only 1 line i can’t figure out how u succeed on loops larger than 1.
I though about checking if a state of pile is in a “loopable state” before storing but i can’t figure out if it’s a thing or not. i read about triangle numbers but … still can’t figure out how to progress on this problem sadly

Well, i succeed the puzzle, now looking at the result of the other people … i feel like i didnt understand the math clearly enough T_T but well, i passed it ^^"

Not one line. Two lines. “Achiles” and the tortoise start at the same state of the game but you always increase Achiles by two updates and the tortoise by one. When they meet again it has to be somewhere on the cycle, keep one stationary, move the other and count how many steps are needed until they collide again and that gives you the cycle length.

For “empty pile” test, as enter i have 7,7,421. result wanted is 1
as i understand i need create turn like that :
turn 0 : 7 7 421
turn 1: 6 6 420 3
turn 2: 5 5 419 2 4
turn 2: 4 4 418 1 3 5

i already more than 1 loop . so i misunderstand how do turn or misundertand the enter number.
( i’m french so answer as french is possible).

nvm, i finally understand you don’t ned print number of loop, but the size of the loop