Created
January 13, 2016 13:00
-
-
Save alsotang/d18096230d087e2ea742 to your computer and use it in GitHub Desktop.
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
| var _ = require('lodash') | |
| var base = 10000; | |
| function win() { | |
| return ~~(Math.random() * 10000 % 2) | |
| } | |
| function bet(num) { | |
| var isWin = win() | |
| if (isWin) { | |
| return num * 0.9 | |
| } else { | |
| return 0; | |
| } | |
| } | |
| function bet2(num) { | |
| base -= num | |
| if (base <= 0) { | |
| console.log('输完了') | |
| process.exit(0) | |
| } | |
| console.log('下注:', num, ',余额:', base) | |
| var winNum = bet(num) | |
| if (!winNum) { | |
| num *= 3 | |
| bet2(num) | |
| } else { | |
| base += num + winNum | |
| } | |
| } | |
| _.range(1000).forEach(function () { | |
| bet2(1) | |
| }) | |
| console.log('base', base) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment