Created
October 18, 2015 20:37
-
-
Save A-gambit/b71f651e866b95f2ef23 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 Count { | |
def count(i: Int, array: List[Int], max: Int):Int = | |
if (array.length == max) | |
1 | |
else if (i > 4 && !(array contains (i - 3)) && (array contains (i - 1))) | |
0 | |
else | |
List(i - 2, i - 1, i + 1, i + 2).foldLeft(0)((res: Int, x: Int) => | |
if (!(array contains (x)) && x <= max && x >= 2) res + count(x, array :+ x, max) | |
else res | |
) | |
def main(args: Array[String]): Unit = | |
for (ln <- io.Source.stdin.getLines) | |
return printf(count(1, List(1), ln.toInt).toString()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment