home
>
Project Euler
>
ForNext
Shut the fuck up and write some code
Problem 15
格子経路
2×2 のマス目の左上からスタートした場合, 引き返しなしで右下にいくルートは 6 つある.
では, 20×20 のマス目ではいくつのルートがあるか.
Lattice paths
Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 20×20 grid?
考え方
n個のものからr個を取り出す取り出し方は
VBScript
JScript
Perl
PHP
Python
Ruby
PowerShell
Scala
更新日 : 2013.01.30
scala> (21 to 40).product / (1 to 20).product res0: Int = 0 scala> (BigInt(21) to 40).product / (BigInt(1) to 20).product res1: scala.math.BigInt = 137846528820
F#
更新日 : 2013.01.30
> ([21..40] |> List.reduce(*)) / ([1..20] |> List.reduce(*)) - ;; val it : int = 0 > ([21I..40I] |> List.reduce(*)) / ([1I..20I] |> List.reduce(*)) - ;; val it : System.Numerics.BigInteger = 137846528820I