Last active
August 21, 2022 10:23
-
-
Save esehara/6486846 to your computer and use it in GitHub Desktop.
Prolog de Kakeibo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% it is fiction!! | |
accounts(給料, 200000). | |
accounts(家賃, 60000). | |
accounts(借金, 10000). | |
% vim: set syntax=prolog: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
income(給料). | |
expense(家賃). | |
expense(借金). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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