# [Community Puzzle] Christmas Tree

https://www.codingame.com/training/medium/christmas-tree

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.

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

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

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.

3 Likes

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 âŚ

4 Likes

My solution in Pacal with UInt64 works fine with all samples but fails in âTricky tree validatorâ
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.