Mistři v programování na #hovnokod

Ruby #277

N = 5
$mas = (1..N).to_a
$c = 0
 
def generate(l = 0)
    if l == N-1
        for i in 0..N-1 do
            print("#{$mas[i]} ")
        end
        $c += 1; print("\n")
    else
        for i in l..N-1 do
            t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
            generate(l+1)
            t = $mas[l]; $mas[l] = $mas[i]; $mas[i] = t;
        end
    end
    return $c
end
 
p generate(0);

HovnoKod,