Skip to content

Instantly share code, notes, and snippets.

@A-gambit
Created October 18, 2015 20:37
Show Gist options
  • 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.

Revisions

  1. A-gambit created this gist Oct 18, 2015.
    17 changes: 17 additions & 0 deletions gistfile1.txt
    Original 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())
    }