logoalt Hacker News

meindnochyesterday at 4:39 PM2 repliesview on HN

Any problem can be solved by a sufficient number of nested for loops.

(if you have enough time)


Replies

6510today at 5:28 AM

One level of nested for loop for each type of coin. (Run them until i*coin is larger than the input)

Populate a 2d lookup array. $7,50 becomes arr[750] = [7,1,0,0,0,0] which represents [7x100,1x50,0x25,0x10,0x5,0x1]

With each loop check if the array entry exists, if so check if that number of coins is larger. [7,1,0... is better than [7,0,2...] because 8 is a better solution than 9!

scotty79yesterday at 10:41 PM

And a stack.