Verfasst: Samstag 2. Mai 2009, 12:06
wie wärs mit ner lösung in prolog?
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
#!/usr/bin/env escript
-mode(compile).
header(TITLE, W, H) ->
io:format("~s~n", [TITLE]),
io:format("~w ~w~n", [W, H]).
row(0, _) ->
io:format("~n");
row(N, BIT) ->
io:format("~w", [BIT]),
BIT1 = BIT bxor 1,
row(N-1, BIT1).
rows(_, 0, _) ->
void;
rows(W, H, BIT) ->
row(W, BIT),
BIT1 = BIT bxor 1,
rows(W, H-1, BIT1).
checkered_flag(TITLE, W, H) ->
header(TITLE, W, H),
rows(W, H, 0).
main([]) ->
checkered_flag("P1", 30, 20).
Code: Alles auswählen
println "P 1\n20 10"
for (i in 0..9) {
for (j in 0..20) {
if ((i % 2) ^ (j % 2)) {
print "1 "
}
else {
print "0 "
}
}
println ""
}