Last active
September 20, 2017 08:11
-
-
Save shiv4nsh/ebeff9c67fafb0572061ec0b5a3cddb1 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
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