Last active
September 11, 2017 22:59
-
-
Save fellipecaetano/993d03166f725ec714c044e28a9ac65e to your computer and use it in GitHub Desktop.
MC346 - P1 (2016S1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% questão 2 | |
numero(L) :- numero(L, []). | |
numero --> inteiro. | |
numero --> inteiro, ['.']. | |
numero --> inteiro, ['.'], inteiro. | |
inteiro --> digito. | |
inteiro --> digito, inteiro. | |
digito --> ['0']. | |
digito --> ['1']. | |
%%% questão 3 | |
passos(1, 0) :- !. | |
passos(N, P) :- | |
0 =:= N mod 2, | |
N1 is N/2, | |
passos(N1, P1), | |
P is P1 + 1, | |
!. | |
passos(N, P) :- | |
0 \= N mod 2, | |
N1 is 3*N + 1, | |
passos(N1, P1), | |
P is P1 + 1, | |
!. | |
%%% questão 4 | |
series([], _, []) :- !. | |
series([H|T], A, S) :- | |
serie(N, AI, AF) = H, | |
AI =< A, | |
AF >= A, | |
series(T, A, S1), | |
S = [N|S1]. | |
series([H|T], A, S) :- | |
serie(_, AI, _) = H, | |
A < AI, | |
series(T, A, S). | |
series([H|T], A, S) :- | |
serie(_, _, AF) = H, | |
A > AF, | |
series(T, A, S). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment