#47 楼 @recurlamlisp 你看明白 minikanren 的实现了么?
#!/usr/bin/swipl -q -g main -f
:- use_module(library(clpfd)).
:- use_module(library(aggregate)).
coins([C50, C20, C10, C5, C1]) :-
Vars = [C50, C20, C10, C5, C1],
Vars ins 0 .. sup,
50*C50 + 20*C20 + 10*C10 + 5*C5 + C1 #= 87,
labeling([], Vars).
main :-
aggregate_all(count, coins(_), Count),
io:format("~w~n", [Count]),
halt.
#38 楼 @recurlamlisp 你总得说一下题目是什么吧
#!/usr/bin/swipl -q -g main -f
:- use_module(library(simplex)).
coins -->
constraint(integral(c(100))),
constraint(integral(c(50))),
constraint(integral(c(20))),
constraint(integral(c(5))),
constraint([c(100)] >= 0),
constraint([c(50)] >= 0),
constraint([c(20)] >= 0),
constraint([c(5)] >= 0),
constraint([c(100)] =< 1),
constraint([c(50)] =< 1),
constraint([c(20)] =< 3),
constraint([c(5)] =< 1),
constraint([100*c(100), 50*c(50), 20*c(20), 5*c(5)] = 160),
minimize([c(100), c(50), c(20), c(5)]).
main :-
gen_state(S0),
coins(S0, S),
variable_value(S, c(100), C100),
variable_value(S, c(50), C50),
variable_value(S, c(20), C20),
variable_value(S, c(5), C5),
io:format("~w*100 ~w*50 ~w*20 ~w*5~n", [C100, C50, C20, C5]),
halt.
Prolog
#!/usr/bin/swipl -q -g main -f
:- use_module(library(simplex)).
coins -->
constraint(integral(c(10))),
constraint(integral(c(7))),
constraint(integral(c(1))),
constraint([c(10)] >= 0),
constraint([c(7)] >= 0),
constraint([c(1)] >= 0),
constraint([10*c(10), 7*c(7), 1*c(1)] = 14),
minimize([c(10), c(7), c(1)]).
main :-
gen_state(S0),
coins(S0, S),
variable_value(S, c(10), C10),
variable_value(S, c(7), C7),
variable_value(S, c(1), C1),
io:format("~w*10 ~w*7 ~w*1~n", [C10, C7, C1]),
halt.
Prolog 无压力
#!/usr/bin/swipl -q -g main -f
:- use_module(library(simplex)).
coins -->
constraint(integral(c(50))),
constraint(integral(c(30))),
constraint(integral(c(1))),
constraint([c(50)] >= 0),
constraint([c(30)] >= 0),
constraint([c(1)] >= 0),
constraint([50*c(50), 30*c(30), 1*c(1)] = 60),
minimize([c(50), c(30), c(1)]).
main :-
gen_state(S0),
coins(S0, S),
variable_value(S, c(50), C50),
variable_value(S, c(30), C30),
variable_value(S, c(1), C1),
io:format("~w*50 ~w*30 ~w*1~n", [C50, C30, C1]),
halt.
必须 Prolog 啊,输入一遍题目就可以了
#!/usr/bin/swipl -q -g main -f
:- use_module(library(simplex)).
coins -->
constraint(integral(c(50))),
constraint(integral(c(20))),
constraint(integral(c(10))),
constraint(integral(c(5))),
constraint(integral(c(1))),
constraint([c(50)] >= 0),
constraint([c(20)] >= 0),
constraint([c(10)] >= 0),
constraint([c(5)] >= 0),
constraint([c(1)] >= 0),
constraint([50*c(50), 20*c(20), 10*c(10), 5*c(5), 1*c(1)] = 87),
minimize([c(50), c(20), c(10), c(5), c(1)]).
main :-
gen_state(S0),
coins(S0, S),
variable_value(S, c(50), C50),
variable_value(S, c(20), C20),
variable_value(S, c(10), C10),
variable_value(S, c(5), C5),
variable_value(S, c(1), C1),
io:format("~w*50 ~w*20 ~w*10 ~w*5 ~w*1~n", [C50, C20, C10, C5, C1]),
halt.
cdecl to rescue
owk -> AWK
感觉不对,没猜错的话,某博彩公司打算开展东亚业务,但这公司在 glassdoor 上才 1 分 (当然也只有 1 次评分),楼主就是东亚业务 Manager?