Skip to content

Instantly share code, notes, and snippets.

Created May 30, 2014 13:39
Show Gist options
  • Save anonymous/5f3533e88cf944def929 to your computer and use it in GitHub Desktop.
Save anonymous/5f3533e88cf944def929 to your computer and use it in GitHub Desktop.
object DeceitfulWarSC {
println("Welcome to the Scala worksheet")
def countNaomi(naomi:List[Double], ken:List[Double], count:Int):Int = {
if ( naomi == Nil) count
else if( naomi.head < ken.head ) countNaomi( naomi.tail, ken.tail, count)
else countNaomi( naomi.tail, ken diff List(ken.last), count + 1)
}
def countNaomiDeceitful(naomi:List[Double], ken:List[Double], count:Int):Int = {
if ( naomi == Nil) count
else if( naomi.head > ken.head ) countNaomi( naomi.tail, ken.tail, count + 1)
else countNaomi( naomi diff List(naomi.last), ken.tail, count)
}
val naomi = "0.186 0.389 0.907 0.832 0.959 0.557 0.300 0.992 0.899".split(" ").map(_.toDouble).toList.sorted.reverse
val ken = "0.916 0.728 0.271 0.520 0.700 0.521 0.215 0.341 0.458".split(" ").map(_.toDouble).toList.sorted.reverse
countNaomiDeceitful(naomi, ken.reverse, 0)
countNaomi(naomi, ken, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment