Created
October 19, 2021 16:13
-
-
Save wmoralesdev/1f1ff31d6060e415f64d6da3dec11407 to your computer and use it in GitHub Desktop.
This file contains 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
ejercicio3:- | |
open('lista_numeros.txt', read, Valores), | |
llenar_lista(Valores, L), | |
close(Valores), | |
conteo(L, P, N), | |
open('total_cont.txt', write, Total), | |
write(Total, P), | |
write(Total, '\n'), | |
write(Total, N), | |
close(Total), | |
nl. | |
llenar_lista(Valores, L):- | |
read(Valores, X), | |
( | |
\==(X, end_of_file), | |
llenar_lista(Valores, L2), | |
=(L, [X|L2]) | |
; | |
==(X, end_of_file), | |
=(L, []) | |
), | |
!. | |
conteo([], 0, 0). | |
conteo([X|L], P, N):- | |
conteo(L, P2, N2), | |
( | |
>(X, 0) -> | |
P is P2 + 1, | |
N is N2 | |
; | |
<(X, 0) -> | |
P is P2, | |
N is N2 + 1 | |
; | |
P is P2, | |
N is N2 | |
). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment