Created
April 24, 2012 01:43
-
-
Save udzura/2475376 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(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])). |
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
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