Very good puzzle. Really had to work on some recursive programming.
HOWEVER. I do think this belongs in the medium or hard puzzle.
This is a bit more tricky than usual āeasyā puzzles for some languages indeed
I improved on the best published solution by externalizing the functions, and using the new ES2020 nullish coalescing operator, check my solution.
did the same
Thank you!
I had the same issue, and after reading your comment i realized I made the same mistake.
Thanks again!
hi OverCoder,
set a level recursivity to not exceed and store the cell value.
int cellOperation(int indexCell, long level = 0)
{
bool isRef;
int arg1, arg2;
if (value[indexCell] != INT_MIN) return value[indexCell];
arg1 = getValue(args1[indexCell], isRef);
if (isRef)
arg1 = cellOperation(arg1, ++level);
if (operations[indexCell] == "VALUE")
{
if (level >= 10)
value[indexCell] = arg1;
return arg1;
}
arg2 = getValue(args2[indexCell], isRef);
if (isRef)
arg2 = cellOperation(arg2, ++level);
if (operations[indexCell] == "ADD")
{
if (level >= 10)
value[indexCell] = arg1 + arg2;
return arg1 + arg2;
}
if (operations[indexCell] == "SUB")
return arg1 - arg2;
if (operations[indexCell] == "MULT")
return arg1 * arg2;
return 0;
}
};
evaluate func helped me remove 20 lines of code and pass the āaccounting is hard 1ā test.
thanks.
->SUB $3 $3
itās a special case
Hi all.
Itās a win to me
Coded in C, with recursionā¦
at begginning i was thinking to resolve basics cells such as NoRef or Substract to Zeroā¦
But at the end, we have to solve it by recursionā¦and all with the same method to prevent side effectā¦
Iām an embedded softwafe engineer. In my domain, recursion is strictly forbidden (like i work with 8ko ram ^^).
i understand principle of recursion, but itās not easy to āsee where it goā¦ā
Thank all for comments; tips⦠on this thread
That -0 killed me too lol!
All in all I first tried it in Java and got too distracted I think.
A few month later my second attempt was using typescript AND I wanted to try to break it down into small functions (functional programming). That MIGHT have helped me keep it simple and it is oh so simple indeed (once you got the hang to recursion n stuff ;D)!
Iām coding this puzzle using Python.
Iām programming for fun and discovering recursion.
Iāve hit a roadblock in test 08. I donāt have a working test after this one.
I guess Iāll have to use try, except. Is this correct? If so, Iām not sure how to use it⦠Do you have any advice to help me?
Thanks in advance for your answers.
There are usually multiple ways to solve a puzzle. My solution doesnāt contain try/except, but I guess itās possible to use them in a working solution.
Itās difficult to comment further on your preliminary guess. Itās better if you actually write some code to test your theory, or at least a more detailed write-up of your theoretical approach for others to comment on.
Has anyone whoās completed this in python got any tips on getting the last three problems? No matter what I try it always fails due to my codes recursion depth being too much for it.
You may try adding a line of code to increase the maximum recursion depth, but there seem to be just one or two published Python solutions (out of the dozens published) which do so.
You may want to read/search this thread to get some hints on how else you may optimise your code.
I did kind of use recursion, but then in a while loop, and not in a function, so I think that is how I avoided the recursion-depth problem. I did have some time-out problems though. My final (successful) approach was to recursively start with a not-reference value, use that value to solve cells referring to that value, and to take any of those fully solved cells as next not-reference value.
I just tried changing the recursion limit and that led me to finding out that my code just isnāt optimized enough so it just times out. Iāll have to try some solutions to further optimize the code and see if that helps otherwise maybe try a new approach.
For those struggling with test cases 11-12 (accounting is hard 1 and 2):
Read the description carefully. It says VALUE can (not must) have a constant value. It can be something like āVALUE $2 _ā as well as āVALUE 2 _ā .
For test cases 11-12 you need to support āVALUE $i _ā and for test case 13 you need memoisation.