JuliaでProject Euler(15)

Problem 15

https://projecteuler.net/problem=15

DPで解く。

function e015(N)
    a = zeros(Int, N+1, N+1)
    a[1,1] = 1
    for x in 2:N+1
        a[1,x] = 1
    end
    for y in 2:N+1
        a[y,1] = 1
    end
    for y in 2:N+1
        for x in 2:N+1
            a[y,x] = a[y,x-1] + a[y-1,x]
        end
    end
    
    return a[N+1,N+1]
end

N = parse(Int, ARGS[1])
println(e015(N))

Juliaでは、配列の配列だけでなく多次元配列が使える。
アクセス方法は上の通り。