Exercise Help - Say

Could someone please give me a hint on how to best come up with a solution for the “Say” exercise.

I have been stuck on it for a few weeks, because I can’t figure out a way to do it that doesn’t involve a messy solution using a lot of conditionals for every single index of the number.

Here are some pointers that you can hopefully use to help solving it

  • Identify unique values that you need : in normal number, pretty much every other number no matter how big or small is made up from digit 0 to 9. This problem operate on the same principle
  • Try to break the big number in smaller chunks, you can see this in every day life with how people write out big number with separator, you can apply the same logic here. Once you manage so solve the smallest chunk then you pretty much solve the whole thing.
  • Leverage actual value of number to be use as index in array or key in dictionary to access words. (hint of what data structure you should consider using)

Also, there is nothing wrong with a messy solution with a lot of conditionals, the goal is to solve the exercise first and foremost. Focus on solving it first before thinking about making it looks good.

1 Like

My solution in Clojure is quite messy, likely due to the Lisp-style nesting that can quickly get out of hand. This is while using a specific algorithm from a book. It’s probably my messiest solution ever.

So if you are stuck for few weeks, you should also consider looking for an algorithm on the internet.

1 Like