RosettaCodeData/Task/Babbage-problem/Prolog/babbage-problem-1.pro

14 lines
328 B
Prolog
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
:- use_module(library(clpfd)).
babbage_(B, B, Sq) :-
2026-02-01 16:33:20 -08:00
B * B #= Sq,
number_chars(Sq, R),
append(_, ['2','6','9','6','9','6'], R).
2023-07-01 11:58:00 -04:00
babbage_(B, R, Sq) :-
2026-02-01 16:33:20 -08:00
N #= B + 1,
babbage_(N, R, Sq).
2023-07-01 11:58:00 -04:00
babbage :-
2026-02-01 16:33:20 -08:00
once(babbage_(1, Num, Square)),
format('lowest number is ~p which squared becomes ~p~n', [Num, Square]).