Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View 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
).

View 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).

View file

@ -0,0 +1 @@
factorial(100) = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000