Hi
I have just started out on my F# adventure, and what a ride (I have 10-12 years of professional C# programming experience)
I have challenged myself to solve as many problems as I can in project euler using F# and trying to stay true to the functional paradigme. But now I am stuck at problem 18 link
So here is my problem, this is my first search tree in F#, but nodes share leafs. Which isn’t the case for all the examples I can find.
I think it is ok easy describe the union. My take:
type Tree =
| Node of int * Tree * Tree
| Empty
I have two questions:
-
How do I populate a tree, when using immutable data and shared leafs like in the link? Should I create an id for each node, and put them in a set / look-up, and try to get them from there before creating the node?
-
Furthermore, I need to do a lot of calculations from bottom-up (The current solution I am working with). If I just made a recursive algoritme, that went from the top, and just tried every route, I would have had no (or little) problem implementing it.
But adding the largest leaf to the node, requires a mutable data structure? Or how do I solve this the most “pure” functional way?
Perhaps I just need the correct terms to search for. Or should I just throw the data into a good old-fashioned 2D array?
I would prefer as little help as possible, but just enough so I am no longer stuck…