Erlang 학습

703 단어
너는 빠른 정렬에 두 줄의 코드만 필요하다고 생각하니?
코드:
-module(mysort).
-compile(export_all).
qsort([])->[];
qsort([P|T])->qsort([X||X<-T, X<P])++[P]++qsort([X||X<-T,X>=P]).

아마 이것이 Erlang일 것이다. 80%의 시간을 생각하고 20%의 시간을 우아한 코드를 쓴다.
같은 PE의 이 문제 Problem1은 세 줄 코드로 완성할 수 있습니다.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000.
sum35(N)->sum([X||X<-lists:seq(1,N-1), ((X rem 3)==0) or ((X rem 5)==0)]).
sum([])->0;
sum([H|T])->H+sum(T).

관중 여러분 즐겁게 놀아요!
더 많은 내용은 www.daidongsheng을 방문하세요.com

좋은 웹페이지 즐겨찾기