ビンゴの結果を整形表示
Posted feedbacks - Prolog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | shuffle([], []).
shuffle(X, [R|Y]) :- length(X, XL), N is random(XL),
nth0(N, X, R), select(R, X, X1), shuffle(X1, Y).
write_row(L, W) :- write_row(L, W, W).
write_row( [], _, _) :- nl.
write_row([X|L], W, Tab) :- format('~t~d~*|', [X, Tab]),
Tab1 is Tab + W + 1, write_row(L, W, Tab1).
write_bingo(W, X, S) :-
length(X, N), N > 10,
nth0(10, X, XE), append(XL, [XE|XR], X),
nth0(10, S, SE), append(SL, [SE|SR], S),
write_row(XL, W), write_row(SL, W), nl,
write_bingo(W, [XE|XR], [SE|SR]).
write_bingo(W, X, S) :- write_row(X, W), write_row(S, W).
bingo(N) :- findall(X, between(1, N, X), L), shuffle(L, S),
atom_number(A, N), atom_length(A, T), write_bingo(T, L, S).
|


raynstard
#3403()
Rating1/1=1.00
「重複無し乱数」で作ったbingo関数の結果を下のように「何番目の乱数か」とセットにして10個ずつ折り返して表示するコードを書いてください。
[ reply ]