Last active
December 27, 2015 18:54
-
-
Save anna-is-cute/1bdf8aa4c5543787dc16 to your computer and use it in GitHub Desktop.
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
import java.util.Random | |
class Roll { | |
private val random = Random() | |
fun roll(n: Int = 1, d: Int = 6): String { | |
val res = (1..n).map { this@Roll.random.nextInt(d) + 1 } | |
return "${res.joinToString()} = ${res.sum()}" | |
} | |
fun roll(input: String): String { | |
val (n, d) = input.split("d").map { it.toInt() } | |
return roll(n = n, d = d) | |
} | |
} |
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
from random import randrange | |
def roll(n=1, d=6): | |
if type(n) == str: | |
return roll(*[int(x) for x in n.split('d')]) | |
res = [randrange(1, d + 1) for i in range(n)] | |
return '{} = {}'.format(', '.join([str(x) for x in res]), sum(res)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment