Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,26 +1,32 @@
|
|||
:- module fizzbuzz.
|
||||
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- import_module int, string, bool.
|
||||
|
||||
:- func fizz(int) = bool.
|
||||
:- func buzz(int) = bool.
|
||||
fizz(N) = ( if N mod 3 = 0 then yes else no ).
|
||||
|
||||
:- func buzz(int) = bool.
|
||||
buzz(N) = ( if N mod 5 = 0 then yes else no ).
|
||||
|
||||
:- pred fizzbuzz(int::in, bool::in, bool::in, string::out) is det.
|
||||
% 3? 5?
|
||||
fizzbuzz(_, yes, yes, "FizzBuzz").
|
||||
fizzbuzz(_, yes, no, "Fizz").
|
||||
fizzbuzz(_, no, yes, "Buzz").
|
||||
fizzbuzz(N, no, no, S) :- S = from_int(N).
|
||||
% N 3? 5?
|
||||
:- func fizzbuzz(int, bool, bool) = string.
|
||||
fizzbuzz(_, yes, yes) = "FizzBuzz".
|
||||
fizzbuzz(_, yes, no) = "Fizz".
|
||||
fizzbuzz(_, no, yes) = "Buzz".
|
||||
fizzbuzz(N, no, no) = from_int(N).
|
||||
|
||||
main(!IO) :- main(1, 100, !IO).
|
||||
|
||||
:- pred main(int::in, int::in, io::di, io::uo) is det.
|
||||
main(N, To, !IO) :-
|
||||
io.write_string(S, !IO), io.nl(!IO),
|
||||
fizzbuzz(N, fizz(N), buzz(N), S),
|
||||
( if N < To then main(N + 1, To, !IO) else !:IO = !.IO ).
|
||||
io.write_string(fizzbuzz(N, fizz(N), buzz(N)), !IO), io.nl(!IO),
|
||||
( N < To -> main(N + 1, To, !IO)
|
||||
; !:IO = !.IO ).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue