Comment detail

ピラミッドを作る (Nested Flatten)
erl -noshell -eval 'pyramid:pyramid(4), halt().'
のように実行.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
-module(pyramid).
-export([pyramid/1]).

pyramid(N) ->
        pyramid(N, 1).

pyramid(Max, Row) when Max < Row ->
        ok;
pyramid(Max, Row) ->
        write(" ", Max - Row),
        write("*", Row * 2 - 1),
        io:put_chars("\n"),
        pyramid(Max, Row + 1).

write(_String, 0) ->
        ok;
write(String, Repeat) ->
        io:put_chars(String),
        write(String, Repeat - 1).

Index

Feed

Other

Link

Pathtraq

loading...