Skip to content

Instantly share code, notes, and snippets.

@matlockx
Last active August 29, 2015 14:02
Show Gist options
  • Save matlockx/3777482e252d1d9dcb80 to your computer and use it in GitHub Desktop.
Save matlockx/3777482e252d1d9dcb80 to your computer and use it in GitHub Desktop.
getSymbols
#!/bin/sh
exec scala "$0" "$@" -feature
!#
// Execute:
// ./RandomSymbol numberOfSymbolIds numberOfSymbolsOnCard
object RandomSymbol {
def main(args: Array[String]) {
val symbolIdList = 1 to args(0).toInt toList
val loose = symbolIdList.combinations(args(1).toInt).toList
val win = symbolIdList.combinations(args(1).toInt - 3).toList
def shuffle(list : List[_]) = util.Random.shuffle(list)
def getSymbols(list : List[List[Int]]) : List[Int] = {
list(util.Random.nextInt(list.size))
}
var again = true
while(again){
val winNumber = util.Random.nextInt(symbolIdList.size)
val win = symbolIdList.filter(_ != winNumber).combinations(args(1).toInt - 3).toList
println("WinNumber: " + winNumber)
println("Win: " + shuffle(getSymbols(win).map(v => v.toString) ++ List(winNumber, winNumber, winNumber) ))
println("Loose: " + shuffle(getSymbols(loose).map(v => v.toString)))
print("Again? (y/n) ")
again = (readLine) == "y"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment