Skip to content

Instantly share code, notes, and snippets.

@mfn
Last active August 29, 2015 14:24
Show Gist options
  • Save mfn/3518f593c62fa6bb12e4 to your computer and use it in GitHub Desktop.
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
<!-- 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">.
@mfn
Copy link
Author

mfn commented Jul 11, 2015

Tricks used:

  • Replaced Math.floor with ~~
  • a comma , can be used to separte satements but they're still kind of compounded together hence no need for { and } for the for body
    Interestingly, I used alert(foo ,bar) before: alert ignores bar but it is executed which gave me the calculation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment