31ph4n70m

Maximum_of_array.erl

Nov 28th, 2019
719
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. % erlang solution to codeabbey challenge 15
  2. -module(prog).
  3. -export([min/1, max/1, main/0]).
  4.  
  5. min([]) ->
  6.     {error, empty_list};
  7.  
  8. min([H|T]) ->
  9.     min1(H, T).
  10.  
  11. min1(M, [H|T]) when M < H ->
  12.     min1(M, T);
  13. min1(M, [H|T]) when M >= H ->
  14.     min1(H, T);
  15. min1(M, []) ->
  16.     M.
  17.  
  18. max([]) ->
  19.     {error, empty_list};
  20.  
  21. max([H|T]) ->
  22.     max1(H, T).
  23.  
  24. max1(M, [H|T]) when M >= H ->
  25.     max1(M, T);
  26. max1(M, [H|T]) when M < H ->
  27.     max1(H, [H|T]);
  28. max1(M, []) ->
  29.     M.
  30.  
  31. main() ->
  32.     Nums = [-66696, 5605, -72801, 8738, 28820, -29567, 14343, -36741, 48223, -70036, 30901, -79402, -69324, 37159, -53593, 73305, -13098, -76755, 20214, -74605, 33371, 39657, -32462, -65933, 10918, -27814, 950, -66811, 74234, -57134, 79525, -72461, 28471, -73275, 16276, -22708, -22843, -49380, 20550, -54619, -39417, -28549, -54022, -28741, -71389, -27615, -35436, -4487, -24370, 64778, 908, -70999, 24435, 48446, -56933, -44647, -59367, 24017, -31458, -65132, 46883, -31933, -57594, -4646, -25209, 38682, 52645, 31948, 69301, -6804, 57328, -50115, 44647, -76693, 1144, 53257, -24309, 45707, -31229, 31320, 30486, 49678, 40321, -25079, 18124, 63388, 10274, 38757, 7405, 58815, 53624, -25711, -53117, 76030, 49642, 1674, 34712, 22288, -46378, 24014, -64516, -69049, 53898, 60130, -65742, -24958, 33388, -10052, -59250, -77841, -58731, 51235, 51836, 61590, -53843, -10039, 44978, 36430, -51281, -27617, 15246, -77657, 26671, 42128, 78372, -3686, -36198, 33085, -61397, -2576, -22901, -45914, 8375, -49003, -65783, 22632, 6039, 47604, -67419, 26788, 49763, -46150, -1976, 21600, -64560, 24181, -68438, 60417, -19388, -39720, -47199, 75857, -37378, 59472, 37986, -39005, -24213, -78211, 74079, -5611, -787, -28822, 28475, -72412, 2175, 42691, 30220, -71786, 10296, 42801, 35002, -19941, 76650, -46973, -78340, -67909, 57207, -66779, 72507, -42180, -26500, -54691, -46323, 16121, -75219, 71663, 57116, -19433, 73451, 51195, 54956, -7336, -57626, 3431, 252, 24548, -33877, -49528, 32762, 56419, 73272, -12236, -43521, 69923, 20791, -41862, -77986, -2001, -28642, 74521, 35818, 24857, -60169, 69495, -39021, -55388, 61158, -61905, 5179, 54610, 69290, -19865, -32726, -68336, 63566, 47525, 36212, -50311, 77997, -11026, -73892, 71270, 56738, -37413, 61194, -2471, 724, 63208, 75528, 52081, 57730, 31346, -3061, 77560, 20841, 37918, -57828, 2000, 56012, 27350, -23390, 45303, -72514, 23883, 56967, 71051, -8591, 13179, -59260, -10593, -77847, -53152, -19323, 58891, -10566, -38129, -23579, 70158, -54921, -28051, 42240, -77191, -76705, -40821, -79630, 24136, 77096, -57459, -53864, 53109, 49891, 2746, 18413, 57376, -53370, -4620, 48427, 18038, -71441, 69167, -72554, -69288, -63985, -11878, 69602, 5449, 29993, -33977, -4392, 55072],
  33.     Maxnum = max(Nums),
  34.     Minnum = min(Nums),
  35.     Resp = integer_to_list(Maxnum) ++ " " ++ integer_to_list(Minnum),
  36.     erlang:display(Resp).
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×