Last active
August 29, 2015 13:59
-
-
Save DeepSky8/10740649 to your computer and use it in GitHub Desktop.
There must be an easier, non-compiler-breaking way
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
def wager(bet: Int, heads: Int, total: Int, flip: Int): (Boolean, Int, Int) = { | |
if(total > 1000) = heads match { | |
case 0 => (false, 1, total-bet) | |
case 1 => (false, 0, total-bet) | |
} else { | |
if(heads == flip) { | |
(true, heads, total+bet) | |
} else = heads match { | |
case 0 => (false, 1, total-bet) | |
case 1 => (false, 0, total-bet) | |
} | |
} | |
} | |
//edit | |
//new solution | |
def wager(bet: Int, heads: Int, total: Int, flip: Int): (Boolean, Int, Int) = { | |
if(total > 1000) { | |
(false, switch(heads), total - bet) | |
} else { | |
if(heads == flip) { | |
(true, heads, total+bet) | |
} else { | |
(false, switch(heads), total-bet) | |
} | |
} | |
} | |
def switch(head: Int): Int = head match { | |
case 0 => 1 | |
case 1 => 0 | |
} | |
// edit | |
// more newer solution | |
def wager(bet: Int, heads: Boolean, total: Int, flip: Int): (Boolean, Boolean, Int) = { | |
if(total > 1000) { | |
(false, !(heads), total - bet) | |
} else { | |
if(heads == flip) { | |
(true, heads, total+bet) | |
} else { | |
(false, !(heads), total-bet) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment