Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Created October 18, 2015 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save A-gambit/b71f651e866b95f2ef23 to your computer and use it in GitHub Desktop.
Save A-gambit/b71f651e866b95f2ef23 to your computer and use it in GitHub Desktop.
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