Last active
August 29, 2015 14:24
-
-
Save mfn/3518f593c62fa6bb12e4 to your computer and use it in GitHub Desktop.
#camp404 "poker chip" code challenge: enter a number, tell the number the minimum number of chips required to represent them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- challenge description: | |
- a given set of infinite poker chips in theses sizes: 500, 100, 50, 25, 10, 5, 2, 1 | |
- enter a number | |
- tell the user the minimum number of chips necessary to represent the value | |
--> | |
<!-- initial 91 char solution ; thx to @neuling for the inspiration and @johannesnagl saving me one extra char --> | |
<p onclick="i=prompt();for(a of[500,100,50,25,10,5,2,1])if(e=~~(i/a))alert(e+' '+a,i%=a)">. | |
<!-- since it wasn't specified that spitting out 0 chips would be prohibited, another solution --> | |
<!-- 84 chars --> | |
<p onclick="i=prompt();for(a of[500,100,50,25,10,5,2,1])alert(~~(i/a)+'x'+a),i%=a">. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tricks used:
Math.floor
with~~
,
can be used to separte satements but they're still kind of compounded together hence no need for{
and}
for thefor
bodyInterestingly, I used
alert(foo ,bar)
before:alert
ignoresbar
but it is executed which gave me the calculation