From 59108d0ef219401e8c2222e49961dfd427d110cd Mon Sep 17 00:00:00 2001 From: sasagawa888 Date: Thu, 24 Oct 2024 15:16:50 +0900 Subject: [PATCH] Fixed get get0 --- builtin.c | 7 +------ tests/bug.pl | 29 ++++++++++++++++++++++++++++- tests/iitaka.pl | 7 +++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/builtin.c b/builtin.c index c2bcc9f..be4f416 100644 --- a/builtin.c +++ b/builtin.c @@ -691,9 +691,6 @@ int b_get0(int arglist, int rest) else c = getc(GET_PORT(arg1)); - if (c == EOL) { - c = getc(GET_PORT(arg1)); - } if(c==EOF) return(NO); @@ -736,12 +733,10 @@ int b_get(int arglist, int rest) else c = getc(GET_PORT(arg1)); - if (c == EOL) - c = getc(GET_PORT(arg1)); if(c==EOF) return(NO); - + i = (int) c; if (c == EOL) goto exit; diff --git a/tests/bug.pl b/tests/bug.pl index c050559..7e4aa07 100644 --- a/tests/bug.pl +++ b/tests/bug.pl @@ -1,3 +1,30 @@ +% 9-queens program - +test16 :- between(1,16,X),test1,fail. + +test :- queen([1,2,3,4,5,6,7,8,9],X),write(X),nl,fail. +test1 :- queen([1,2,3,4,5,6,7,8,9],X),fail. + +queen(Data, Out) :- + queen_2(Data, [], Out). + +queen_2([], _, []). +queen_2([H|T], History, [Q|M]) :- + qdelete(Q, H, T, L1), + nodiag(History, Q, 1), + queen_2(L1, [Q|History], M). + + +qdelete(A, A, L, L). +qdelete(X, A, [H|T], [A|R]) :- + qdelete(X, H, T, R). + + +nodiag([], _, _). +nodiag([N|L], B, D) :- + D =\= N - B, + D =\= B - N, + D1 is D + 1, + nodiag(L, B, D1). + \ No newline at end of file diff --git a/tests/iitaka.pl b/tests/iitaka.pl index 6e8150b..83fc4fa 100644 --- a/tests/iitaka.pl +++ b/tests/iitaka.pl @@ -135,4 +135,11 @@ repeat, while_do(get0(H,C),put(C)), close(H),!. + +copy_file(File_nameX,File_nameY):- + open(H1,File_nameX,r), + create(H2,File_nameY), + repeat, + while_do(get0(H1,C),put(H2,C)), + close(H1),close(H2),!.