가장 적은 숫자로 가장 큰 숫자를 출력하십시오.


37

양의 정수가 비어 있지 않은 목록이 주어지면 가장 적은 숫자를 가진 숫자 집합에서 가장 큰 숫자를 출력하십시오.

입력 목록은 특정 순서가 아니며 반복되는 값을 포함 할 수 있습니다.

예 :

[1] -> 1
[9] -> 9
[1729] -> 1729
[1, 1] -> 1
[34, 3] -> 3
[38, 39] -> 39
[409, 12, 13] -> 13
[11, 11, 11, 1] -> 1
[11, 11, 11, 11] -> 11
[78, 99, 620, 1] -> 1
[78, 99, 620, 10] -> 99
[78, 99, 620, 100] -> 99
[1, 5, 9, 12, 63, 102] -> 9
[3451, 29820, 2983, 1223, 1337] -> 3451
[738, 2383, 281, 938, 212, 1010] -> 938

바이트 단위의 가장 짧은 코드가 이깁니다.


입력 번호가 별도의 줄에있을 수 있습니까?
seshoumara

@seshoumara 합리적으로 들립니다.
Calvin 's Hobbies

답변:


13

Pyth, 7 3 6 바이트

eS.ml`

테스트 스위트

설명:

e      Still grab the last element
 S      Still sort
  .ml`   But prefilter the list for those with the (m)inimum length.

7 바이트 솔루션 :

eSh.gl`

테스트 스위트

설명:

   .g   Group items in (implicit) input by:
     l  The length of
      ` their representation
  h     Get those with the shortest length
 S      Sort the resulting list
e       and grab the last (i.e. largest) element

6

파이썬 2, 48 42 바이트

@Dennis 덕분에 -6 바이트 ( min대신 사용 sorted)

lambda l:min(l,key=lambda x:(len(`x`),-x))

모든 테스트 사례는 아이디어가 있습니다

목록의 최소값을 (길이,-값)


1
min대신 작동해야합니다 sorted.
Dennis

@Dennis, oh jeez-감사합니다! 아마도 자신을 게시 할만 큼 충분히 다를 수 있습니다.
Jonathan Allan

스와핑 sorted()[0]을 위해 min? 나는 원래 코드의 사소한 수정을 고려합니다.
Dennis

len(`x`)+1./x길이 도 같습니다. 당신이 필요 너무 나쁘다 1..
xnor

글쎄, 그것은 내가 생각해 낸 것보다 짧습니다. 잘 했어!
mbomb007

6

젤리 , 7 바이트

DL,NµÞḢ

TryItOnline 에서 테스트
하거나 TryItOnline 에서 모든 테스트 사례 보기

어떻게?

DL,NµÞḢ - Main link takes one argument, the list, e.g. [738, 2383, 281, 938, 212, 1010]
D       - convert to decimal, e.g. [[7,3,8],[2,3,8,3],[2,8,1],[9,3,8],[2,1,2],[1,0,1,0]]
 L      - length, e.g. [3,4,3,3,3,4]
   N    - negate, e.g [-738, -2383, -281, -938, -212, -1010]
  ,     - pair, e.g. [[3,-738],[4,-2383],[3,-281],[3,-938],[3,-212],[4,-1010]]
    µ   - make a monadic chain
     Þ  - sort the input by that monadic function, e.g [938,738,281,212,2383,1010]
          (the lists in the example are not created, but we sort over the values shown)
      Ḣ - pop and return the first element, e.g. 938

1
종류의 큰 사용!
마일

@miles 당신의 길은 여전히 ​​영감을 받았습니다 :)
Jonathan Allan

5

05AB1E , 5 바이트

암호:

({é¬(

설명:

(      # Negate the list, e.g. [22, 33, 4] -> [-22, -33, -4]
 {     # Sort, e.g. [-22, -33, -4] -> [-33, -22, -4]
  é    # Sort by length, e.g. [-33, -22, -4] -> [-4, -22, -33]
   ¬   # Get the first element.
    (  # And negate that.

CP-1252 인코딩을 사용합니다 . 온라인으로 사용해보십시오!



4

MATL , 14 바이트

10&YlktX<=G*X>

온라인으로 사용해보십시오!

설명:

  &Yl           % Log
10              % Base 10
     kt         % Floor and duplicate
       X<       % Find the smallest element
         =      % Filter out elements that do not equal the smallest element
          G     % Push the input again
           *    % Multiply (this sets numbers that do not have the fewest digits to 0)
            X>  % And take the maximum

4

망막 ,24 16 바이트

오 ^`
O $ #`
$ .0
G1`

온라인으로 사용해보십시오! 또는 모든 테스트 사례를 실행하십시오 .

Martin 덕분에 8 바이트가 절약되었습니다!

모든 테스트는 약간 오래된 버전의 코드를 사용하고 있지만 알고리즘은 동일합니다. 시간이 더 가까워지면 더 가깝게 업데이트하겠습니다.

후행 줄 바꿈이 중요합니다. 숫자를 역 숫자로 정렬 한 다음 자릿수로 정렬합니다. 이렇게하면 첫 번째 위치에서 가장 적은 숫자로 가장 큰 숫자가 남으므로 나머지 숫자 만 삭제할 수 있습니다.


입력 줄 바꿈을 분리하면 두 정렬 단계에서 정규 표현식을 생략 G1`하고 마지막 단계에 사용할 수 있습니다 .
Martin Ender

또한 첫 번째 단계는 필요하지 않습니다 #. 주어진 정수 길이에 대한 상대 순서 만 신경 쓰고 한 길이 내에서 사전 식의 숫자 정렬이 정확합니다.
Martin Ender

@MartinEnder 감사합니다! 두 가지 팁을 모두 추가했습니다. 나는 제안한다 \w+방법 나는 테스트 스위트를 만들만큼 투쟁에 필요하지 않을 것이라고, 정렬의 기본값으로)
FryAmTheEggman

: 여기 당신에게 더 골프에 대한 아이디어를 제공하는 경우에, 또 다른 16 retina.tryitonline.net/...
마틴 청산

4

Mathematica, 33 31 바이트

Max@MinimalBy[#,IntegerLength]&

MinimalBy는에 따라 가장 작은 점수 IntegerLength, 즉 가장 작은 자릿수를 가진 원래 입력 목록의 모든 요소를 ​​선택합니다 . Max는 가장 큰 것을 출력합니다.

2 바이트를 찾아서 저장 한 Martin Ender에게 감사드립니다. :)


4

펄 6 , 18 바이트

*.min:{.chars,-$_}

설명:

*\        # Whatever lambda
.min:     # find the minimum using

{         # bare block lambda with implicit parameter 「$_」

  .chars, # number of characters first ( implicit method call on 「$_」 )
  -$_     # then negative of the value in case of a tie
}

용법:

say [738, 2383, 281, 938, 212, 1010].&( *.min:{.chars,-$_} ); # 938

my &code = *.min:{.chars,-$_}

say code [78, 99, 620, 10]; # 99

3

젤리 , 8 바이트

DL€İMị¹Ṁ

온라인으로 사용해보십시오! 또는 모든 테스트 사례를 확인하십시오.

설명

DL€İMị¹Ṁ  Input: list A
D         Convert each integer to a list of base 10 digits
 L€       Get the length of each list (number of digits of each)
   İ      Take the reciprocal of each
    M     Get the indices of the maximal values
      ¹   Get A
     ị    Select the values at those indices from A
       Ṁ  Find the maximum and return

이 8 바이트는 어떻습니까? 이 모든 문자가 ASCII에 적합합니까?
Federico Poloni

1
@FedericoPoloni 예, 다른 코드 페이지에도 불구하고 적합 합니다.
Outgolfer Erik

3

자바 스크립트 (ES6), 51

l=>l.sort((a,b)=>(a+l).length-(b+l).length||b-a)[0]

테스트

f=l=>l.sort((a,b)=>(a+l).length-(b+l).length||b-a)[0]

;[
 [[1], 1]
,[[9], 9]
,[[1729], 1729]
,[[1, 1], 1]
,[[34, 3], 3]
,[[38, 39], 39]
,[[409, 12, 13], 13]
,[[11, 11, 11, 1], 1]
,[[11, 11, 11, 11], 11]
,[[78, 99, 620, 1], 1]
,[[78, 99, 620, 10], 99]
,[[78, 99, 620, 100], 99]
,[[1, 5, 9, 12, 63, 102], 9]
,[[3451, 29820, 2983, 1223, 1337], 3451]
,[[738, 2383, 281, 938, 212, 1010], 938]
].forEach(([l,x])=>{
  var r=f(l)
  console.log(r==x?'OK':'KO',l+' -> '+r)
})  


3

J, 21 14 바이트

마일과 (간접적으로) 조나단 덕분에 7 바이트를 절약했습니다!

{.@/:#@":"0,.-

이것은 4 개의 체인입니다 :

{.@/: (#@":"0 ,. -)

입력을 살펴 봅시다 10 27 232 1000. 내부 포크는 세 개의 타인으로 구성됩니다. #@":"0크기를 계산하고 ,.각 크기를 부정 ( -) 멤버와 연결합니다. input의 10 27 232 1000경우 다음과 같이 남습니다.

   (#@":"0 ,. -) 10 27 232 1000
2   _10
2   _27
3  _232
4 _1000

이제 우리는 {.@/:외부 타인으로 있습니다. {.이진 정렬 ( /:) 보다 먼저 monadic입니다 ( ). 즉, 우리는 dyadic 결과의 첫 번째 요소를 취할 것 /:입니다. 이것은 왼쪽 인수에 따라 오른쪽 인수를 정렬하여 입력을 제공합니다.

   (/: #@":"0 ,. -) 10 27 232 1000
27 10 232 1000

그런 다음 사용 {.하면 해당 목록의 첫 번째 요소가 제공 되며 다음 과 같이 완료됩니다.

   ({.@/: #@":"0 ,. -) 10 27 232 1000
27

구 버전

>./@(#~]=<./@])#@":"0

여전히 개선 작업 중입니다. 나는 그것을 30에서 골프로 떨어 뜨렸다. 그리고 나는 이것으로 충분하다고 생각한다. 먼저 기본 부분으로 나누겠습니다.

   size =: #@":"0
   max =: >./
   min =: <./
   over =: @
   right =: ]
   left =: [
   selectMin =: #~ right = min over right

   f =: max over selectMin size
   f 3 4 5
5
   f 3 4 53
4
   f 343 42 53
53

작동 방식은 다음과 같습니다.

>./@(#~ ] = <./@]) #@":"0

이것은 모나 딕 열차이지만이 부분은 갈고리입니다. 동사 >./@(#~ ] = <./@])는 메인 체인에 대한 입력으로 왼쪽 인수와 오른쪽 인수로 정의 된 크기 #@":"0로 호출됩니다. 이는 길이 ( #) 이상 ( @) 기본 형식 ( ":), 즉 숫자 스트링 화로 계산되며 , 이는 입력 ( "0) 의 0- 셀 (즉, 멤버)에 적용됩니다 .

input 예제를 살펴 보겠습니다 409 12 13.

   (#@":"0) 409 12 13
3 2 2

이제 내부 동사에 대해 >./@(#~ ] = <./@]). 내부의 >./@(...)최대 값 ( >./) 을 효과적으로 의미하는 것처럼 보입니다 . 내부에 관해서는,이 5 열과 동등한 4 열입니다 :@(...)

[ #~ ] = <./@]

[원래 인수를 ]참조하고 크기 배열을 나타냅니다. 409 12 133 2 2각각이 예이다. 이 경우 올바른 타인 <./@]은 최소 크기를 계산합니다 2. 이 경우 ] = <./@]최소값과 동일한 값의 부울 배열입니다 0 1 1. 마지막으로 [ #~ ...오른쪽 인수 마스크에 따라 왼쪽 인수에서 값을 가져옵니다. 이는 해당하는 요소 0가 삭제되고 1유지됨 을 의미합니다 . 그래서 우리는로 남았습니다 12 13. 마지막으로 위의 내용에 따라 최대 값을 가져 와서 올바른 결과를 얻었 13습니다.


일부 셔플 링과 훅은 바이트를 절약 할 수 있습니다 >./@#~[:(=<./)#@":"0.
마일

@miles XD 방금 설명을 작성했습니다. 아 잘,이 아름다움을 보도록하겠습니다 ...
Conor O'Brien

Jonathan은 더 나은 방법을 찾았습니다. 우리는 J, 그 14 바이트로 변환하는 경우 {.@/:#@":"0,.-만 입력 목록으로 형성되어야한다
마일

@ 마일리지 "목록 모양"? 당신은 400 12 13?
Conor O'Brien

2

자바 스크립트 (ES6), 62 바이트

var solution =

a=>a.map(n=>(l=`${n}`.length)>a?l>a+1|n<r?0:r=n:(a=l-1,r=n))|r

;document.write('<pre>' + `
[1] -> 1
[9] -> 9
[1729] -> 1729
[1, 1] -> 1
[34, 3] -> 3
[38, 39] -> 39
[409, 12, 13] -> 13
[11, 11, 11, 1] -> 1
[11, 11, 11, 11] -> 11
[78, 99, 620, 1] -> 1
[78, 99, 620, 10] -> 99
[78, 99, 620, 100] -> 99
[1, 5, 9, 12, 63, 102] -> 9
[3451, 29820, 2983, 1223, 1337] -> 3451
[738, 2383, 281, 938, 212, 1010] -> 938
`.split('\n').slice(1, -1).map(c =>
  c + ', result: ' + solution(eval(c.slice(0, c.indexOf('->'))))
).join('\n'))


2

dc, 54 바이트

?dZsL0sN[dsNdZsL]su[dlN<u]sU[dZlL=UdZlL>ukz0<R]dsRxlNp

설명:

?dZsL0sN                  # read input, initialize L (length) and N (number)
[dsNdZsL]su               # macro (function) 'u' updates the values of L and N
[dlN<u]sU                 # macro 'U' calls 'u' if N < curr_nr
[dZlL=U dZlL>ukz0<R]dsR   # macro 'R' is a loop that calls 'U' if L == curr_nr_len
                          #or 'u' if L > curr_nr_len
xlNp                      # the main: call 'R' and print N at the end

실행 예 : 'input.txt'는 질문의 진술에 모든 테스트 사례를 포함합니다.

while read list;do echo "$list -> "$(dc -f program.dc <<< $list);done < input.txt

산출:

1 -> 1
9 -> 9
1729 -> 1729
1 1 -> 1
34 3 -> 3
38 39 -> 39
409 12 13 -> 13
11 11 11 1 -> 1
11 11 11 11 -> 11
78 99 620 1 -> 1
78 99 620 10 -> 99
78 99 620 100 -> 99
1 5 9 12 63 102 -> 9
3451 29820 2983 1223 1337 -> 3451
738 2383 281 938 212 1010 -> 938

2

자바 7, 112104 바이트

int c(int[]a){int i=a[0],j;for(int b:a)i=(j=(i+"").length()-(b+"").length())>0?b:b>i&j==0?b:i;return i;}

@ Barteks2x 덕분에 여러 바이트를 절약하는 다른 접근법 .

언 골프 및 테스트 사례 :

여기에서 시도하십시오.

class M{
  static int c(int[] a){
    int i = a[0],
        j;
    for(int b : a){
      i = (j = (i+"").length() - (b+"").length()) > 0
           ? b
           : b > i & j == 0
              ? b
              : i;
    }
    return i;
  }

  public static void main(String[] a){
    System.out.println(c(new int[]{ 1 }));
    System.out.println(c(new int[]{ 9 }));
    System.out.println(c(new int[]{ 1729 }));
    System.out.println(c(new int[]{ 1, 1 }));
    System.out.println(c(new int[]{ 34, 3 }));
    System.out.println(c(new int[]{ 409, 12, 13 }));
    System.out.println(c(new int[]{ 11, 11, 11, 1 }));
    System.out.println(c(new int[]{ 11, 11, 11, 11 }));
    System.out.println(c(new int[]{ 78, 99, 620, 1 }));
    System.out.println(c(new int[]{ 78, 99, 620, 100 }));
    System.out.println(c(new int[]{ 1, 5, 9, 12, 63, 102 }));
    System.out.println(c(new int[]{ 3451, 29820, 2983, 1223, 1337 }));
    System.out.println(c(new int[]{ 738, 2383, 281, 938, 212, 1010 }));
  }
}

산출:

1
9
1729
1
3
13
1
11
1
99
9
3451
938

1
더 짧은 버전 : int c (int [] a) {int i = a [0], j; for (int b : a) i = (j = (i + ""). length ()-(b + ""). length ())> 0? b : b> i & j == 0? b : i; return i;}
barteks2x

@ Barteks2x 감사합니다. 편집했습니다.
Kevin Cruijssen

2

bash, awk, 정렬 53 바이트

set `awk '{print $0,length($0)}'|sort -rnk2n`;echo $1

stdin에서 입력을 읽습니다 (한 줄에 하나씩).

bash and sort, 58 57 바이트

set `sort -n`;while((${#2}==${#1}));do shift;done;echo $1


마지막 샘플에서 작동하지 않습니다. 938 대신 2383을주었습니다
Archemar

@Archemar 죄송합니다, 질문을 잘못 읽고, 이제 수정되었습니다
Emmanuel

while와 사이의 공백을 제거 할 수 있습니다 ((.
seshoumara

1

자바 스크립트 ES6, 80 77 70 바이트

a=>Math.max(...a.filter(l=>l.length==Math.min(...a.map(i=>i.length))))

나는 올바른 방향으로 가고 있기를 바랍니다.


당신은 대체 할 수 a.map(i=>i.length).sort((a,b)=>a-b)[0]와 함께 Math.min(...a.map(i=>i.length))?
user81655

@ user81655 응, 할 수있어. 나는 그 편집을했다고 생각했지만 분명히하지 않았다
Downgoat

당신은 또한 당신이 재사용 할 수 있도록 최소값을 무시하려고 시도 할 수 있습니다 Math.max: a=>(m=Math.max)(...a.filter(l=>l.length==-m(...a.map(i=>-i.length))))비록 1 바이트 만 저장하는 것 같습니다.
user81655

다른 바이트의 경우 테스트를 통과하지 않은 값을 반환 filter하는로 대체 할 수 있습니다 .map0a=>(m=Math.max)(...a.map(l=>l.length+m(...a.map(i=>-i.length))?0:l))
user81655

1

Brachylog , 16 바이트

or:@]feL:la#=,Lh

온라인으로 사용해보십시오!

설명

or                 Sort the list in descending order.
  :@]f             Find all suffixes of the list.
      eL           Take one suffix L of the list.
        :la        Apply length to all numbers in that suffix.
           #=,     All lengths must be equal.
              Lh   Output is the first element of L.

1

하스켈, 39 바이트

snd.maximum.map((0-).length.show>>=(,))

이것은 작동하지 않으며 선호 34합니다 2.
xnor

오 감사. 다시 생각해야 ..
Damien

이제 더 잘 작동합니다!
Damien

1

자바 스크립트 (ES6), 57 54 53 바이트

l=>l.sort((a,b)=>(s=a=>1/a+`${a}`.length)(a)-s(b))[0]

레코드의 경우 이전 버전은 수학 중심이지만 1 바이트 더 큽니다.

l=>l.sort((a,b)=>(s=a=>1/a-~Math.log10(a))(a)-s(b))[0]

테스트 사례

let f =
l=>l.sort((a,b)=>(s=a=>1/a+`${a}`.length)(a)-s(b))[0]

console.log(f([1]));                              //  -> 1
console.log(f([9]));                              //  -> 9
console.log(f([1729]));                           //  -> 1729
console.log(f([1, 1]));                           //  -> 1
console.log(f([34, 3]));                          //  -> 3
console.log(f([38, 39]));                         //  -> 39
console.log(f([409, 12, 13]));                    //  -> 13
console.log(f([11, 11, 11, 1]));                  //  -> 1
console.log(f([11, 11, 11, 11]));                 //  -> 11
console.log(f([78, 99, 620, 1]));                 //  -> 1
console.log(f([78, 99, 620, 10]));                //  -> 99
console.log(f([78, 99, 620, 100]));               //  -> 99
console.log(f([1, 5, 9, 12, 63, 102]));           //  -> 9
console.log(f([3451, 29820, 2983, 1223, 1337]));  //  -> 3451
console.log(f([738, 2383, 281, 938, 212, 1010])); //  -> 938


1

MATL , 11 바이트

tV48\&XS0))

입력은 다음과 같은 열 벡터 ( ;구분자로 사용)입니다.

[78; 99; 620; 100]

온라인으로 사용해보십시오! 또는 모든 테스트 사례를 확인하십시오 .

설명

입력 [78; 99; 620; 100]을 예로 들어 봅시다 .

t      % Input column vector implicitly. Duplicate
       %   STACK: [78; 99; 620; 100], [78; 99; 620; 100]
V      % Convert to string. Each number is a row, left-padded with spaces
       %   STACK: [78; 99; 620; 100], [' 78'; ' 99'; '620'; '100']
48\    % Modulo 48. This transforms each digit into the corresponding number,
       % and space into 32. Thus space becomes the largest "digit"
       %   STACK: [78; 99; 620; 100], [32 7 8; 32 9 9; 6 2 0; 1 0 0]
&XS    % Sort rows in lexicographical order, and push the indices of the sorting
       %   STACK: [78; 99; 620; 100], [4; 3; 1; 2]
0)     % Get last value
       %   STACK: [78; 99; 620; 100], 2
)      % Index
       %   STACK: 99
       % Implicitly display

1
설명에서 스택 상태를 보는 것이 좋습니다!
flawr

1

펄, 38 37 바이트

에 +1 포함 -a

STDIN에 입력하십시오 :

perl -M5.010 maxmin.pl <<< "3451 29820 2983 1223 1337"

maxmin.pl:

#!/usr/bin/perl -a
\$G[99-y///c][$_]for@F;say$#{$G[-1]}

가장 큰 숫자로 메모리를 선형으로 사용하므로 너무 큰 숫자로 시도하지 마십시오. 이 결함이없는 솔루션은 38 바이트입니다.

#!/usr/bin/perl -p
$.++until$\=(sort/\b\S{$.}\b/g)[-1]}{

이 모든 것들이 매우 어색하고 전혀 기분이 좋지 않습니다 ...


1

R, 72 41 36 바이트

새로운 접근 방식으로 함수를 다시 작성했습니다. @bouncyball의 제안 덕분에 5 바이트가 골프를 쳤다.

n=nchar(i<-scan());max(i[n==min(n)])

설명 :

        i<-scan()       # Read input from stdin
n=nchar(         );     # Count the number of characters in each number in i
max(             )      # Return the maximum of the set where
    i[n==min(n)]        # the number of characters is the minimum number of characters.

function(i){while(1){if(length(o<-i[nchar(i)==T]))return(max(o));T=T+1}}

들여 쓰기 / 설명 :

function(i){               # Take an input i
  while(1){                # Do the following continuously:
    if(length(
        o<-i[nchar(i)==T]) # Define o to be the subset of i with numbers of length T,
      )                    # where T is 1 (a built-in!).
                           # We take the length of this subset (its size), and then pass
                           # it to if(). Thanks to weak typing, this numeric is converted
                           # to a logical value. When this occurs, zero evaluates to FALSE
                           # and any non-zero number evaluates to TRUE. Therefore, the if()
                           # is TRUE iff the subset is not empty.
      return(max(o));      # If it's true, then we just return the largest element of the
                           # subset, breaking out of our loop.
    T=T+1                  # Otherwise, increment our counter and continue.
  }
}


1
다음을 정의하지 않고 4 바이트를 절약하십시오 function.i=scan();n=nchar(i);max(i[n==min(n)])
bouncyball

@bouncyball 감사합니다! 그리고 1 바이트가 더 절약되었습니다 n=nchar(i<-scan()).
rturnbull

1

Bash + coreutils, 58 바이트

d=`sort -n`;egrep ^.{`sed q<<<"$d"|wc -L`}$<<<"$d"|tail -1

입력 형식은 한 줄에 하나의 값입니다. 골프 제안을 환영합니다.

설명:

d=`sort -n`                             #save the list in ascending numerical order
egrep ^.{                    }$<<<"$d"  #print only list lines having as many chars
         `sed q<<<"$d"|wc -L`                 #as the first sorted line does
|tail -1                                #and then get the last one (the answer)

+1 감사합니다. sed q=head -1
Emmanuel

1

파이썬 2-41 바이트

lambda l:max((-len(`x`),x) for x in l)[1]

0

파이썬 2, 58 바이트

def F(x):l={len(`i`):i for i in sorted(x)};print l[min(l)]

0

파이썬 3, 56 바이트

lambda a:sorted(sorted(a),key=lambda x:-len(str(x)))[-1]

람다에서 람다를 사용합니다!

파이썬 2, 53 바이트

s=lambda a:sorted(sorted(a),key=lambda x:-len(`x`))[-1]

동일하지만 백틱으로


0

, 11 바이트

(SNgSK-#_v)

입력을 명령 행 인수로 사용합니다. 온라인으로 사용해보십시오!

S정형 K연산자를 사용하여 처음으로 ! Python과 마찬가지로 sorted()iterable의 각 항목에 적용되는 함수와 정렬 키로 사용 된 결과를 가져옵니다. 이 프로그램의 작동 방식은 다음과 같습니다.

 SNg         List of cmdline args, sorted numerically in increasing order
    SK       Sort with key function...
      -#_    ... negative length(x), thus putting the shortest numbers at the end but not
               affecting the relative ordering among numbers with the same length
(        v)  Get the last element (index -1) and auto-print

0

클로저, 63 바이트

(reduce #(if(=(quot %1 10)(quot %2 10))(max %1 %2) %1)(sort x)) 

에서와 같이 :

(reduce #(if(=(quot %1 10)(quot %2 10))(max %1 %2) %1)(sort[3 7 121 11 8 2 10 9]))
=> 9

작게 만드는 방법이 있다고 확신하지만.


당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.