Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
int_words( N , _ ) :- \+ integer(N), !, fail. int_words( N , [negative|Ws] ) :- N < 0, X is abs(N), number_phrase(X,Ws). int_words( N , Ws ) :- N >= 0, number_phrase(N,Ws). number_phrase(N,Ws) :- groups(N,[],Gs), length(Gs,P), groups_to_words(Gs,P,Ws). groups_to_words( [G] , _ , Ws ) :- group_name(G,Ws,[]). groups_to_words( [G|Gs] , P , Ws ) :- period(P,Sfx), group_name(G,Ws,[Sfx|W1]), P1 is P-1, groups_to_words(Gs,P1,W1). group_name( 0 , Ws , Ws ) :- !. group_name( N , Ws , W1 ) :- div_rem(N,100,Q,R), hundreds(Q,Ws,W0), tens_and_ones(R,W0,W1). hundreds( 0 , Ws , Ws ). hundreds( N , [W,hundred|W0] , W0 ) :- N > 0, special(N,W). tens_and_ones( N , [W|Ws] , Ws ) :- special(N,W), !. tens_and_ones( N , [W1-W2|Ws] , Ws ) :- Ones is N rem 10, Tens is N - Ones, special(Tens,W1), special(Ones,W2). groups( 0 , Gs , Gs ) . groups( N , Ts , Gs ) :- N > 0, div_rem(N,1000,Q,R), groups(Q,[R|Ts],Gs). div_rem(X,Y,Q,R) :- Q is X div Y, R is X rem Y. period( 2, thousand ). period( 3, million ). period( 4, billion ). period( 5, trillion ). period( 6, quadrillion ). period( 7, quintillion ). period( 8, sextillion ). special( 0, zero ). special( 1, one ). special( 2, two ). special( 3, three ). special( 4, four ). special( 5, five ). special( 6, six ). special( 7, seven ). special( 8, eight ). special( 9, nine ). special( 10, ten ). special( 11, eleven ). special( 12, twelve ). special( 13, thirteen ). special( 14, fourteeen ). special( 15, fifteen ). special( 16, sixteen ). special( 17, seventeen ). special( 18, eighteen ). special( 19, nineteen ). special( 20, twenty ). special( 30, thirty ). special( 40, forty ). special( 50, fifty ). special( 60, sixty ). special( 70, seventy ). special( 80, eighty ). special( 90, ninety ).