Skip to content

Instantly share code, notes, and snippets.

@mrorigo
Created October 10, 2021 08:32
Show Gist options
  • Save mrorigo/a81e903605cba49984b8adbb22e00f3a to your computer and use it in GitHub Desktop.
Save mrorigo/a81e903605cba49984b8adbb22e00f3a to your computer and use it in GitHub Desktop.
Double Cola problem in Erlang
%% Double Cola problem in Erlang
%% https://codeforces.com/problemset/problem/82/A
-module(main).
-export([start/1]).
start(N) ->
io:fwrite(
cola(N-1, [ {"Sheldon", 1},
{"Leonard", 1},
{"Penny", 1},
{"Rajesh", 1},
{"Howard", 1}]) ++ "\n").
cola(N, [{Name, Count} | TheRest]) when N-Count >= 0 ->
cola(N-Count, TheRest ++ [{Name, Count * 2}]);
cola(N, [{Name, Count} | _]) when N-Count < 0 ->
Name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment