Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,3 +1,5 @@
|
|||
using Printf
|
||||
|
||||
println(" X | 1 2 3 4 5 6 7 8 9 10 11 12")
|
||||
println("---+------------------------------------------------")
|
||||
|
||||
|
|
|
|||
33
Task/Multiplication-tables/Prolog/multiplication-tables.pro
Normal file
33
Task/Multiplication-tables/Prolog/multiplication-tables.pro
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
make_table(S,E) :-
|
||||
print_header(S,E),
|
||||
make_table_rows(S,E),
|
||||
fail.
|
||||
make_table(_,_).
|
||||
|
||||
print_header(S,E) :-
|
||||
nl,
|
||||
write(' '),
|
||||
forall(between(S,E,X), print_num(X)),
|
||||
nl,
|
||||
Sp is E * 4 + 2,
|
||||
write(' '),
|
||||
forall(between(1,Sp,_), write('-')).
|
||||
|
||||
make_table_rows(S,E) :-
|
||||
between(S,E,N),
|
||||
nl,
|
||||
print_num(N), write(': '),
|
||||
between(S,E,N2),
|
||||
X is N * N2,
|
||||
print_row_item(N,N2,X).
|
||||
|
||||
print_row_item(N, N2, _) :-
|
||||
N2 < N,
|
||||
write(' ').
|
||||
print_row_item(N, N2, X) :-
|
||||
N2 >= N,
|
||||
print_num(X).
|
||||
|
||||
print_num(X) :- X < 10, format(' ~p', X).
|
||||
print_num(X) :- between(10,99,X), format(' ~p', X).
|
||||
print_num(X) :- X > 99, format(' ~p', X).
|
||||
Loading…
Add table
Add a link
Reference in a new issue