Skip to content

Instantly share code, notes, and snippets.

@shiv4nsh
Last active September 20, 2017 08:11
Show Gist options
  • Save shiv4nsh/ebeff9c67fafb0572061ec0b5a3cddb1 to your computer and use it in GitHub Desktop.
Save shiv4nsh/ebeff9c67fafb0572061ec0b5a3cddb1 to your computer and use it in GitHub Desktop.
object CakeBonusQuestion {
type Set = Int=>Boolean
val BOUND_VALUE=1000
private def forall(set:Set, predicate:(Int=>Boolean)):Boolean={
def containsValue(set:Set,element:Int)=set(element)
def isNotInConjecture(value:Int):Boolean =containsValue(set, value) && !predicate(value)
def iterate(value: Int): Boolean = {
if (value > BOUND_VALUE) true
else if (isNotInConjecture(value)) false
else iterate(value + 1)
}
iterate(-BOUND_VALUE)
}
def main(args: Array[String]) {
val resultTrue = forall((a:Int)=> a % 4 == 0, (a:Int)=> a % 2 == 0)
println(resultTrue)
val resultFalse = forall( (a:Int)=> a % 2 == 0, (a:Int)=> a % 4 == 0)
println(resultFalse)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment