Very good puzzle. Really had to work on some recursive programming.
HOWEVER. I do think this belongs in the medium or hard puzzle.

2 Likes

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!
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 (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ā¦ā

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?

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 _ā .

1 Like

For test cases 11-12 you need to support āVALUE \$i _ā and for test case 13 you need memoisation.

1 Like