📎 Webclip
Elixir Christmas Tree Puzzle
The page sets a short Elixir coding challenge: print a Christmas tree with a 9-row triangle of 0 characters, a * at the top, and an H trunk at the bottom. The star and trunk must line up with the tree, and the full output is 11 rows high.
Reading notes#
- The triangle has to be properly indented so each row stays centered above the next.
- The top
*and bottomHare separate rows aligned with the tree. - The shortest solution wins, though creative versions can receive an honourable mention.
- Submissions were requested as GitHub issue comments, together with a Twitter handle.
- The article then presents several submitted solutions and explains how they work.
- The winning solution uses an anonymous function and the Erlang
:string.centre/2function. - One solution uses
io.format/2andio_lib.format/2to build the rows. - Other solutions rely on lists, comprehensions,
List.duplicate/2,IO.puts, or string functions such asString.rjust/2andString.duplicate/2. - The bonus section shows more decorative versions, including a colored tree with flashing lights.
