출력 숫자 적용될 때 연산자는 모두

도전

<and 로 구성된 입력 문자열 (또는 배열)이 주어지면 >다음과 같은 정수 시퀀스 (배열 또는 문자열)를 출력합니다.

  • 출력에서 연속적인 숫자 사이에 순서대로 적용될 때 연산자는 모두 정확합니다.
  • 모든 정수는 양수 (1 이상)
  • 정수의 합은 수학적으로 가능한 한 작습니다

선택한 언어에서 “보다 큼”및 “보다 작음”과 일치하도록 입력이 달라질 수 있습니다.

대체 출력으로 출력의 숫자 합계를 지정하십시오. 답변 제목에서 해결하려는 버전을 명시하십시오.

일반적인 제외 및 규칙이 적용되며 가장 작은 바이트가 이깁니다.

입력 문자열이 도움이된다면 언어에서 정수 오버플로가 발생하지 않는다고 가정 할 수 있습니다.

  • >제공 2 1되는 금액을3
  • >>>제공 4 3 2 1되는 금액을10
  • ><제공 2 1 2되는 금액을5
  • 제공 1되는 금액을1
  • >>>>>>>>>제공 10 9 8 7 6 5 4 3 2 1되는 금액을55
  • >><<>><>>>제공 3 2 1 2 3 2 1 4 3 2 1되는 금액을24
  • ><>><>><>제공 2 1 3 2 1 3 2 1 2 1되는 금액을18
  • <<<<>제공 1 2 3 4 5 1되는 금액을16
  • <<<<><<>제공 1 2 3 4 5 1 2 3 1되는 금액을22
  • >><<제공 3 2 1 2 3되는 금액을11


답변

젤리 , 19 바이트

0;+×¥@\
=”<µCṚÇṚ»Ç‘

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

각 번호의 값이 최대 (>그것의 바로 오른쪽에 ,<그것의 바로 왼쪽에 ) + 1 .


아니면 …

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


답변

> <> , 40 38 바이트

1v!rnr~<oa
?\i:0(?^3%\+$
{/?:-{:}-1/1:

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

적절한 언어. 참고로 ><>2,1,2,1을 산출합니다.

작동 방식 :

1v   Initialise the stack as 1 and enter loop
 \i:0(?^  If we're out of input, go to the first line
        3%\ Otherwise mod the input by 3, yielding 0 for < and 2 for >
        -1/Subtract 1 to get -1 and 1 respectively
    -{:}   Copy the previous number and subtract the above from it

 /?:    If the number is not 0, repeat the loop

?\        \+$  Otherwise:
                Increment each number until we reach the original 0
{/        /1:   And enter the first loop again

      ~<    When we're out of input, pop the extra -1 from EOF
   rnr      Output the first number
1v!         Push a 1
        oa  Print a newline and repeat, popping the extra 1 each time


답변

파이썬 3, 93 바이트

k=0
for r in input().split('<'):p=len(r);print(max(k,p)+1,*range(p,0,-1),end=' ');k=1+(p<1)*k

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

스크램블되지 않은

# offset, will be explained later
k = 0
for run in input().split('<'):
    # p = length of sequence of '>'s, which will produce p+1 decreasing integers
    p = len(run)
    # will print:
    # p+1 p p-1 ... 1    or    k+1 p p-1 ... 1
    print(max(k, p) + 1, *range(p, 0, -1), end=' ')
    # offset of the next sequence: (i.e. -1 + the minimal value of the first integer)
    k = 1 + (k if p > 0 else 0)


답변

하스켈 , 119 바이트

n%">"=r[1..n]
n%"<"=[1..n]
n%(c:b)|c==b!!0=(n+1)%b|a:s<-2%b,e:z<-r$n%[c]=r z++last(max:[min|c>'<'])a e:s
r=reverse
(2%)

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

설명

여기서 아이디어는 >s 또는 <s 의 런 을 가지며 각각이 오름차순 및 내림차순 범위에 매핑된다는 것입니다. 따라서 group문자열을 연속 문자 그룹으로 나누는 데 사용 합니다. 우리의 임무는 그런 다음 적절한 방식으로 이들을 함께 스티치하는 것입니다.

<>예를 들어 두리스트를 더 큰 끝 값을 사용하여 연결하고 싶을 때

<<<<<<>>

나뉘어져있다

<<<<<<  >>

범위에 매핑

[1,2,3,4,5,6,7] [3,2,1]

그런 다음 스티치 할 때 3더 작기 때문에 떨어 집니다 ( 3보다 크지 않습니다 7).

 [1,2,3,4,5,6,7,2,1]

우리가 ><반대로 할 때 더 큰 가치를 떨어 뜨립니다.

실제 코드는 연산자를 만들어이를 달성합니다 %. 에 대한 정의 %는 매우 복잡하지만 기본적으로 왼쪽에서 오른쪽으로 연속 문자 수를 추적합니다. 왼쪽에있는 연산자의 가치가 있습니다. 캐릭터가 바뀌는 곳에 도달하면 앞에서 설명한대로 스티칭을 수행합니다.


답변

레티 나 0.8.2 , 36 바이트


1
{`\b(1+)>\1
1$&
}`(1+)<\1\b
$&1
1

온라인으로 사용해보십시오! 링크에는 테스트 사례가 포함됩니다. 설명:


1

1s 전, 사이 및 뒤에 s를 삽입 <하고> 의.

{`\b(1+)>\1
1$&
}`(1+)<\1\b
$&1

모든 비교가 만족 될 때까지 정수를 반복적으로 증가시킵니다.

1

정수를 합하고 십진수로 변환하십시오.


답변

Java 10, 198181 바이트

s->{var p=s.split("(?<=(.))(?!\\1)");int l=p.length,L[]=new int[l],i=l,r=0,a,b;for(;i-->0;r+=a*-~a/2-(i<l-1?p[i].charAt(0)<61?a<(b=L[i+1])?a:b:1:0))a=L[i]=p[i].length()+1;return r;}

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

설명:

s->{                      // Method with String parameter and integer return-type
  var p=s.split("(?<=(.))(?!\\1)");
                          //  Split the String into parts
                          //  (i.e. ">><<>><>>>" becomes [>>, <<, >>, <, >>>])
  int l=p.length,         //  Get the amount of parts
      L[]=new int[l],     //  Create an integer-array of the same size
      i=l,                //  Index-integer, starting at this size
      r=0,                //  Result-integer, starting at 0
      a,b;                //  Two temp integers to reduce the byte-count
  for(;i-->0;             //  Loop downwards over the array; range: (`l`,0]
      ;r+=                //    After every iteration: increase the result with:
          a*-~a/2         //     The triangle number of the current item
        -(i<l-1?          //     If it's not the last item:
           p[i].charAt(0)<61?
                          //      And the order of the current and previous is "<>":
            a<(b=L[i+1])? //       If the current item in `L` is smaller than the previous:
             a            //        Subtract the current item
            :             //       Else (the current is equal or larger than the previous):
             b            //        Subtract the previous item
           :              //      Else (the order of the two parts is "><" instead):
            1             //       Subtract 1
          :               //     Else (it's the last item in `L`):
           0))            //      Leave the result `r` unchanged
    a=L[i]=               //   Set both `a` and the current item in `L` to:
     p[i].length()+1;     //    The length of the part + 1
  return r;}              //  Return the result


답변

하스켈 , 87 바이트

r=reverse
s#c=(+1).length.takeWhile(==c)<$>scanr(:)[]s
f s=zipWith max(s#'>')$r$r s#'<'

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

내 젤리 답변의 포트.