Skip to content

Instantly share code, notes, and snippets.

@udzura
Created April 24, 2012 01:43
Show Gist options
  • Save udzura/2475376 to your computer and use it in GitHub Desktop.
Save udzura/2475376 to your computer and use it in GitHub Desktop.
最大値を返す@Erlang
-module(ore).
-export([max/1]).
max([]) -> null;
max([H|[]]) -> H;
max([H, S|[]]) when H > S -> H;
max([_, S|[]]) -> S;
max([H, S|T]) -> max(H, max([S|T])).
List = [random:uniform(100) || _ <- lists:seq(1, 100)].
% [45,73,95,51,32,60,92,67,48,60,15,21,70,16,56,22,46,43,1,57,
% 48,41,31,6,58,99,34,19,21|...]
l(ore).
% {module,ore}
ore:max([]).
% null
ore:max([1]).
% 1
ore:max(List).
% 99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment