Olaf Klischat wrote: > Stefan Mahlitz <stefan / mahlitz-net.de> writes: > >>Why use a Hash? > > Efficiency. Array#include? runs in linear time (i.e. the running time > is proportional to the size of the array because all elements have to > be tested sequentially), while Hash#[] runs in constant time (i.e. the > running time is independent of the size of the hash). So the > array-based solution will scale very badly for large numbers. I knew that after the benchmarks. ;) To ask the same question in another way: How would someone not being aware of the advantages a Hash-lookup gives (compared to Array-lookup) choose to implement the problem with a Hash? It is not obvious for inexperienced programmers. Well, I remembered after seeing the first solution with Hash (it has been a long time since I wrote the last program). Stefan Mahlitz