Last active
August 29, 2015 14:15
-
-
Save ochaochaocha3/b58af9faaae98789583c to your computer and use it in GitHub Desktop.
Erlang で家計簿の穴埋め
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
-module(lunch). | |
-export([calc/0]). | |
calc() -> | |
NDays = 7, | |
TotalInThePeriod = 2290, | |
Menus = [{set, 370}, {curry, 350}, {udon, 300}], | |
Seq = lists:seq(0, NDays), | |
Amounts = [[X, Y, Z] || | |
X <- Seq, Y <- Seq, Z <- Seq, X + Y + Z =:= NDays], | |
Breakdowns = lists:map( | |
fun(Amount) -> | |
lists:zip(Menus, Amount) | |
end, | |
Amounts), | |
lists:filter( | |
fun(Breakdown) -> | |
Total = lists:foldl( | |
fun({{_, Price}, N}, Acc) -> | |
N * Price + Acc | |
end, | |
0, Breakdown), | |
Total =:= TotalInThePeriod | |
end, | |
Breakdowns). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment