Skip to content

Instantly share code, notes, and snippets.

@dubistdu
Last active March 20, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubistdu/6f6440f71e0c36e480d23505669002a4 to your computer and use it in GitHub Desktop.
Save dubistdu/6f6440f71e0c36e480d23505669002a4 to your computer and use it in GitHub Desktop.
Code war simple fun #165
n [100a, 50a, 20a]
50 [0,1,0], 70 [0,1,1], 90 [0,1,2], 110 [0,1,3], 130 [0,1,4], 210 [1,1,3], 230[1,1,4], 250 [2,1.0]
if n%20 == 10 [?, 1, ?]
Integer rounds up decimal places to floor
Use integer so I don't have to worry about cases like 1.7. \n
For example, (1.0 - 1.9) all equals to 1
Number of $100 bills
subtract 50 from total first since 1 $50 will always be there. 50 does not ever get used more than once
divide n-50 by 100 and you will get # of 100 bills
Number of $20s
When n < 100
(n-50)/100 => Returns 0
If the math is done in float it will return something else which will result in different number
But in my case
which leaves (n - 50) to be divided by 20 => number of $20 bills
When n > 100
(n-50)/100 will return at least 1.
Then it will have to be multiplied by 100 to get the number of 100 bills to be subtracted from (n-50)
and then to be divided by 20 to get # of 20$ bills
Same goes for the case for n%20 == 0
```
if n%20 == 10
[(n-50)/100, 1, (n-50-(n-50)/100*100)/20]
elsif n%20 == 0
[ n/100,0,(n-(n/100)*100)/20]
end
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment