Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
16
Task/Factorial/Mercury/factorial-1.mercury
Normal file
16
Task/Factorial/Mercury/factorial-1.mercury
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
:- module factorial.
|
||||
|
||||
:- interface.
|
||||
:- import_module integer.
|
||||
|
||||
:- func factorial(integer) = integer.
|
||||
|
||||
:- implementation.
|
||||
|
||||
:- pragma memo(factorial/1).
|
||||
|
||||
factorial(N) =
|
||||
( N =< integer(0)
|
||||
-> integer(1)
|
||||
; factorial(N - integer(1)) * N
|
||||
).
|
||||
18
Task/Factorial/Mercury/factorial-2.mercury
Normal file
18
Task/Factorial/Mercury/factorial-2.mercury
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
:- module test_factorial.
|
||||
:- interface.
|
||||
:- import_module io.
|
||||
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
:- import_module factorial.
|
||||
:- import_module char, integer, list, string.
|
||||
|
||||
main(!IO) :-
|
||||
command_line_arguments(Args, !IO),
|
||||
filter(is_all_digits, Args, CleanArgs),
|
||||
Arg1 = list.det_index0(CleanArgs, 0),
|
||||
Number = integer.det_from_string(Arg1),
|
||||
Result = factorial(Number),
|
||||
Fmt = integer.to_string,
|
||||
io.format("factorial(%s) = %s\n", [s(Fmt(Number)), s(Fmt(Result))], !IO).
|
||||
1
Task/Factorial/Mercury/factorial-3.mercury
Normal file
1
Task/Factorial/Mercury/factorial-3.mercury
Normal file
|
|
@ -0,0 +1 @@
|
|||
factorial(100) = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
|
||||
Loading…
Add table
Add a link
Reference in a new issue