[Community Puzzle] Christmas Tree


Send your feedback or ask for help here!

Created by @igreactive,validated by @AgathokakologicalBit,@kugan49 and @tutubalin.
If you have any issues, feel free to ping them.

The problem says:

At the moment of writing it I know it’s possible to solve it in JVM languages and Python.

What an advice!

Why not directly tell us in what languages it is “impossible” (or very difficult) to have it solved (because these “poor” languages do not have BigInt support).

Having to deal with bigints adds nothing to the quality of the puzzle. Without the big test cases, this would have been an ok-ish easy elementary school math puzzle (not much to do with coding though). With bigints, there is an additional ‘practice using a library’ aspect, not particularly interesting.
What might be slightly more interesting: is it solvable with int64 only?

I solved it using gmp in c++, which is always fun since you have to be sneaky about it.

Solved it with BigInt in JS and BigInteger in C#.
Imo the math part of the puzzle is ok, fairly easy but still requires some thought.
Fighting the numerical limits oth is just a chore :expressionless:

1 Like

Thought a puzzle with ‘just few lines of calculations’ in Python would be easy to translate in other languages to increase my count.

I couldn’t have been more wrong.

Even inside the JVM family there are differences, the exact same formulas/types work in Kotlin and Groovy but not Scala for example :upside_down_face:

The main problem is not the big integers but the float errors, even when casting BigDecimal everywhere it’s a pain to make it work.

1 Like

Solve it in lua using long int (signed int64). Not very clean (you must manage overflow , checking if the value becomes negative), but it can be done.

In another hand, I don’t understand why using so large number but to create artificial difficulty.


Work in java too. (use long but to compute the square root)

In fact one validator is more difficult to pass.
For passing it, I must not do the computation with u*(u-1)/2, I must do the division by 2 on the even number and then multiply the two numbers … :rofl:


My solution in Pacal with UInt64 works fine with all samples but fails in “Tricky tree validator” :frowning:
Any idea to help me understand my mistake ?

Both input numbers in that validator are smaller than 10. You may create some custom cases to test your code.