Skip to content

Instantly share code, notes, and snippets.

@esehara esehara/accounts.pl
Last active Dec 22, 2015

Embed
What would you like to do?
Prolog de Kakeibo
% it is fiction!!
accounts(給料, 200000).
accounts(家賃, 60000).
accounts(借金, 10000).
% vim: set syntax=prolog:
income(給料).
expense(家賃).
expense(借金).
#!swipl -q -g main -s
:- use_module(library(apply)).
:- use_module(library(lists)).
:- include(category).
:- include(accounts).
:- include(tools).
main :-
print('
==================================
Logical Kakeibo
==================================
\n'),
account_list(INCOMES, EXPENSES),
costs(INCOMES, INCOME),
costs(EXPENSES, EXPENSE),
format("収入 ~f円\n", INCOME),
format("出費 ~f円\n", EXPENSE),
format("残り ~f円\n", INCOME - EXPENSE),
halt.
% vim: set syntax=prolog:
isincome((KIND, _)) :- income(KIND).
getcost((_, COST), COST).
costs(ACCOUNTLIST, COST) :-
maplist(getcost, ACCOUNTLIST, COSTS),
sumlist(COSTS, COST).
account_list(INCOMES, EXPENSES) :-
findall((X, Y), accounts(X, Y), ACCOUNTS),
partition(isincome, ACCOUNTS, INCOMES, EXPENSES).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.