Skip to content

Instantly share code, notes, and snippets.

@ochaochaocha3
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ochaochaocha3/b58af9faaae98789583c to your computer and use it in GitHub Desktop.
Save ochaochaocha3/b58af9faaae98789583c to your computer and use it in GitHub Desktop.
Erlang で家計簿の穴埋め
-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