Skip to content

Instantly share code, notes, and snippets.

@freddiefujiwara
Created January 12, 2012 23:54
Show Gist options
  • Select an option

  • Save freddiefujiwara/1603899 to your computer and use it in GitHub Desktop.

Select an option

Save freddiefujiwara/1603899 to your computer and use it in GitHub Desktop.
coin
var c1=3,c5=2,c10=1,c50=3,c100=0,c500=2,A=620;
var total = 0,i=0;
for(i = 0 ; i < c500 && (A-500) >= 0 ; i ++,total++){A-=500}
console.log("500円"+i+"枚");
for(i = 0 ; i < c100 && (A-100) >= 0 ; i ++,total++){A-=100}
console.log("100円"+i+"枚");
for(i = 0 ; i < c50 && (A-50) >= 0 ; i ++,total++){A-=50}
console.log("50円"+i+"枚");
for(i = 0 ; i < c10 && (A-10) >= 0 ; i ++,total++){A-=10}
console.log("10円"+i+"枚");
for(i = 0 ; i < c5 && (A-5) >= 0 ; i ++,total++){A-=5}
console.log("5円"+i+"枚");
for(i = 0 ; i < c1 && (A-1) >= 0 ; i ++,total++){A-=1}
console.log("1円"+i+"枚");
console.log("合計"+total+"枚");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment