Created
May 25, 2015 12:12
-
-
Save langrenfengzi/e67f7fd50cb2d392b43d to your computer and use it in GitHub Desktop.
How much did you spend on subway in a month in BeiJing
This file contains 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
function monthlyCost(price){ | |
var sum = 0; | |
var n = 23; | |
var d08,d05; | |
d08 = price * 0.8; | |
d05 = price * 0.5; | |
for(var i=0;i<n*2;i++){ | |
sum += price; | |
if(sum>=100 && price > d08){ | |
price = d08; | |
console.info((i/2)+" day 80%"); | |
}else if(sum >= 150 && price > d05){ | |
price = d05; | |
console.info((i/2)+" day 50%"); | |
} | |
} | |
console.info("one month cost " + sum); | |
} |
Now it's monthlyCost(7), about 232. :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try monthlyCost(6), about 207.