Created
October 18, 2015 20:37
-
-
Save A-gambit/b71f651e866b95f2ef23 to your computer and use it in GitHub Desktop.
Revisions
-
A-gambit created this gist
Oct 18, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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()) }