Код:
List = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163,
167, 173, 179, 181, 191, 193, 197, 199] &
take_result (List, Result)
take_result ([], "error") :-
!
;
take_result ([Numb | Tail], Result) :-
Result = compute list ([Product, Numb, Elmt]) where
(
m:lst.member (Tail, Elmt) &
Product == Numb * Elmt &
Product >= 1000 &
Product <= 9999 &
Sum == Numb + Elmt &
get_mult_digits (Product, Dig_Prod) &
get_mult_digits (Sum, Dig_Sum) &
CowsBulls == Product - Sum - ?(Dig_Prod * Dig_Sum) / 2 &
CowsBulls >= 1000 &
CowsBulls <= 9999 &
compare_cows (Product, CowsBulls, Cows) &
Cows = 4
) &
Result <> [] &
!
;
take_result ([Numb | Tail], Result) :-
take_result (Tail, Result)
;
get_mult_digits (Number, Res) :-
Num_str = to_str (Number) &
Res = compute product (Digit) where
(
m:type.enum_nbr (1, ?:str.length (Num_str), Pos) &
Digit_str = :str.sub (Num_str, Pos, 1) &
Digit = to_integer (Digit_str)
)
;
compare_cows (Product, CowsBulls, Cows) :-
get_number_as_list (Product, Prod_ls) &
get_number_as_list (CowsBulls, Cows_ls) &
Cows = compute number where
(
m:lst.member (Cows_ls, [Digit, Pos1]) &
t:lst.member (Prod_ls, [Digit, Pos2]) &
Pos1 <> Pos2
)
;
get_number_as_list (Number, Numb_ls) :-
Numb_str = to_str (Number) &
Numb_ls = compute list ([Digit, Pos]) where
(
m:type.enum_nbr (1, ?:str.length (Numb_str), Pos) &
Digit_str = :str.sub (Numb_str, Pos, 1) &
Digit = to_integer (Digit_str)
)
;
И задачка в задачката - на какъв език е писано това