코드로 요리


24

당신은 요리사이고 향신료로 요리하는 것을 좋아하지만 최근에는 향신료를 얼마나 자주 사용하는지에 따라 향신료를 정리하는 것을 좋아했습니다. 그러나 향신료를 마지막으로 사용했을 때 기록 할 시간이 없습니다. 간단히, 향신료를 바꾸고 움직여서 트릭을 수행하는 것처럼 보입니다.

그러나 물론 당신은 요리사이고 그것은 당신과 함께 요리사를 가지고 있다는 것을 의미합니다. 당신은 그들에게 당신의 향신료와의 간단한 교전 규칙을 말하기로 결정합니다.

  1. 최근에 향신료를 사용한 경우 향신료 랙에서 향신료를 위로 올리십시오.

  2. []빈 운동 목록과 같이 향신료를 전혀 사용하지 않은 경우 향신료 목록은 영향을받지 않습니다.

  3. 스파이스 홀더에 스파이스를 넣을 수 있지만 사용하는 경우 반드시 옮기십시오.

  4. 목록은 무엇이든 포함 할 수 있습니다. 그러나 이것들은 우리가 작업하는 향신료이기 때문입니다. 향료의 이름을 사용하는 것이 좋습니다.

  5. 향신료는 독특해야합니다. 같은 향신료가 너무 많으면 국물을 망칠 수 있습니다.

일반적인 코드 골프 규칙이 적용됩니다.

오레가노가 반복해서 사용되는 예.

pepper  pepper  pepper  pepper  oregano
paprika paprika paprika oregano pepper
salt    salt    oregano paprika paprika
cumin   oregano salt    salt    salt
oregano cumin   cumin   cumin   cumin

태스크

향신료 목록과 사용 된 향신료 목록을 입력 한 다음 최종 목록을 출력하십시오.

입력

[pepper, paprika, salt, cumin, oregano], [oregano, cumin, cumin, salt, salt, salt]

산출

[salt, pepper, paprika, cumin, oregano]

이것이 어떻게 보이는가

pepper  pepper  pepper  pepper  pepper  pepper  salt
paprika paprika paprika paprika paprika salt    pepper
salt    salt    salt    cumin   salt    paprika paprika
cumin   oregano cumin   salt    cumin   cumin   cumin
oregano cumin   oregano oregano oregano oregano oregano

입력

[pepper, paprika, salt, cumin, oregano], [salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, salt, oregano]

산출

[salt, pepper, paprika, oregano, cumin]

향신료 목록에있는 항목이 독특합니까?
tsh

네, 고유 것이다
tisaconundrum

31
나는 이것을 Chef 에서 꽤 많이 얻었 지만 결국 너무 피곤합니다! 그들이 할 수 있다면 누군가에게 50 현상금을 줄 것입니다.
geokavel

5
다음 은 믹싱 보울에 투입 되는 요점 입니다. 나머지는 매우 어려울 수 있지만 올바른 사람에게는 가능합니다!
geokavel

1
@geokavel 도전 수락
NieDzejkob

답변:


4

껍질 , 15 14 바이트

Fλṁ↔`C⁰tMo→=¢⁰

입력은 문자열 목록입니다 (다른 종류의 목록에서도 작동). 온라인으로 사용해보십시오!

H.PWiz 덕분에 -1 바이트

설명

Fλṁ↔`C⁰tMo→=¢⁰  Implicit inputs (two lists).
F               Fold second input using the first as initial value
 λ              with this anonymous function:
                 Arguments x (list of spices) and s (used spice).
                 For example, x=["a","b","c","d"] and s="c".
            ¢⁰   Repeat x infinitely: ["a","b","c","d","a","b","c","d"..
        M        For each item,
           =     test equality to s: [0,0,1,0,0,0,1,0..
         o→      and increment: [1,1,2,1,1,1,2,1..
       t         Drop first element: [1,2,1,1,1,2,1..
    `C⁰          Cut x to these lengths: [["a"],["b","c"],["d"]]
  ṁ↔             Reverse each slice and concatenate: ["a","c","b","d"]

x그렇지 않으면 최상위 향신료를 사용할 때 목록이 마지막 요소를 잃을 수 있으므로 무한 반복해야합니다 . 후행 1을 추가하는 것으로 충분하지만 반복에는 더 적은 바이트가 필요합니다. 더 좋은 방법은 첫 번째 요소를 삭제하는 대신 목록을 회전하는 것이지만 Husk에는 기본 제공 요소가 없습니다.


Σm한 바이트에 대한.
H.PWiz

8

하스켈 , 48 바이트

foldl(?)는 두 개의 목록 인수를 사용하고 동일한 ( Eq-comparable) 유형 의 모든 요소가 포함 된 목록을 반환하는 익명 함수 입니다.

로 사용하십시오 foldl(?)["pepper", "paprika", "salt", "cumin", "oregano"]["oregano", "cumin", "cumin", "salt", "salt", "salt"].

foldl(?)
(x:y:r)?n|y==n=y:x:r|s<-y:r=x:s?n
s?n=s

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

  • foldl(?) s m(스파이스 랙) 목록으로 시작 하고 연산자를 사용하여 순서대로 s각 요소 (스파이스)와 결합합니다 .m?
  • s?nn스파이스 랙 의 스파이스 를 사용하고 s결과 스파이스 랙을 반환합니다.
    • s요소가 두 개 이상인 경우 두 번째 요소 ?가 같은지 확인하고, 두 번째 요소 가 같은 n경우 첫 두 요소를 전환합니다. 같지 않으면 ?첫 번째 요소는 고정 된 상태로 유지하고 나머지 요소는 되풀이됩니다.
    • 경우 s최대 하나 개의 요소가, ?이 변경되지 반환합니다.

7

요리사 , 875 843 바이트

S.

Ingredients.
1 g T
0 g Z
J
I

Method.
Put Z into mixing bowl.Take I from refrigerator.B I.Put I into mixing bowl.Take I from refrigerator.B until bed.Take I from refrigerator.V I.Put Z into 2nd mixing bowl.N T.Fold J into mixing bowl.Put J into mixing bowl.Remove I.Fold T into mixing bowl.Put J into 2nd mixing bowl.N until ned.Fold T into mixing bowl.Put T into mixing bowl.Fold J into 2nd mixing bowl.Put J into mixing bowl.C T.Stir for 1 minute.Put Z into mixing bowl.Fold T into mixing bowl.C until ced.Fold T into 2nd mixing bowl.G T.Put T into mixing bowl.Fold T into 2nd mixing bowl.G until ged.Put I into mixing bowl.Fold T into mixing bowl.Take I from refrigerator.V until ved.Fold T into mixing bowl.L T.Put T into 2nd mixing bowl.Fold T into mixing bowl.L until led.Pour contents of 2nd mixing bowl into baking dish.

Serves 1.

작동하지 않을 곳 을 제거 하여 Jonathan Allan 에게 -32 바이트 감사합니다 the.

Chef에는 문자열 유형이 없으므로 성분은 양의 정수입니다. 0은 사용 된 재료에서 시작 목록을 분리하고 사용 된 재료 목록을 종료하는 데 사용됩니다. 예제는 TIO 링크를 참조하십시오.

의사 코드 설명 :

A, B: stack
T, J, IN: int
T = 1
A.push(0) // used as the marker for the bottom of the stack
IN = input() // input the first list
while(IN):
    A.push(IN)
    IN = input()
IN = input() // for each used ingredient
while(IN):
    B.push(0)
    while(T): // move all ingredients up to and including the one we are moving right now to the second stack
        T = A.peek() - IN
        B.push(A.pop())
    A.push(B.pop())
    if(A.peekUnderTop() != 0):
        A.swapTopTwoItems()
    T = B.pop() // move the ingredients from the second stack back to the first
    while(T):
        A.push(T)
        T = B.pop()
    T = IN // to make it non-zero for next iteration
    IN = input(0
print(A.inverted())

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


대박! 이 언어는 TIO에 모두 사용 되었습니까?
geokavel


@geokavel 어제 추가되었습니다.
Jonathan Allan

1
@geokavel 서빙하기 전에 믹싱 보울의 내용물을 베이킹 접시에 부었습니까?
NieDzejkob

1
@NieDzejkob Did you pour the contents of the mixing bowl into the baking dish before serving?: P 롤 (P도 매우 이상한 질문을 당신이 저를 요구하는 경우에 요리 :)이 완전히되지 여기에 요리 SE와 갈 것 주석 같은 소리
HyperNeutrino

6

자바 스크립트, 61 바이트

a=>b=>b.map(v=>(p=a.indexOf(v))&&a.splice(p-1,2,a[p],a[p-1]))

입력 형식 :

  • f (list_of_spices) (list_of_what_spices_got_used)
  • 두 목록은 문자열의 배열입니다

산출:

  • list_of_spices가 현재 위치에서 수정되었습니다.




4

자바 8, 87 86 76 바이트

a->b->b.forEach(x->{int i=a.indexOf(x);a.set(i,a.set(i>0?i-1:i,a.get(i)));})

ArrayList<String>바이트를 저장하기 위해 새 입력 을 리턴하는 대신 두 개의 입력을 사용 하고 첫 번째 List를 수정합니다.

@Nevay 덕분에 -10 바이트 .

설명:

여기에서 시도하십시오.

a->b->{                  // Method with two ArrayList<String> parameters and no return-type
  b.forEach(x->{         //  Loop over the second input-List
    int i=a.indexOf(x);  //   Get the index of the current item in the first input-List
    a.set(i,a.set(       //    Swap items:
      i>0?               //     If the current item is not the top item yet:
       i-1               //      Use the item above it
      :                  //     Else:
       i,                //      Use itself
         a.get(i)));     //     And swap it with the current item
  })                     //  End of loop
                         // End of method (implicit / single-line body)

1
77 바이트 :a->b->b.forEach(x->{int i=a.indexOf(x);a.set(i,a.set(i>0?i-1:i,a.get(i)));});
Nevay

자바는 그것을 재미있게 만든 모든 사람들에게 복수하고 있습니다.
geokavel

2

05AB1E , 20 18 바이트

vDyk>Ig‚£`U`2(@)X«

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

설명

v                    # for each used spice
 D                   # duplicate current spice order
  yk                 # get the index of the current spice
    >                # increment
     Ig‚             # pair with the number of unique spices
        £            # split the spice list into pieces of these sizes
         `           # split as 2 separate lists to stack
          U          # store the list of spices below the current one in X
           `         # push the current spice and all above separately to stack
            2(@      # swap the second item to the top of the stack
               )     # wrap in a list
                X«   # append the rest of the spices


2

C #을 125 117 81 79 바이트

(c,n)=>{foreach(var i in n){var j=c.IndexOf(i);if(j!=0){c[j]=c[--j];c[j]=i;}}};

.NET Fiddle에서 사용해보십시오

raznagul 덕분에 36 바이트로 골프


에 대한 네임 스페이스가 누락되어 있으므로 대답은 117 바이트입니다 Array.IndexOf. 그러나 답을 더 짧게 만드는 몇 가지 방법이 있습니다. 1. foreach-loop 대신 -loop를 사용하십시오 for. 2. 경우 cA는 List<string>대신 string[]직접 사용할 수 있습니다 c.IndexOf. 3. c수정 된 대로 반품 할 필요가 없습니다.
raznagul


1

매스 매 티카, 52 바이트

그러나 그것은 나의 첫 번째 게시물이므로 잘못 계산되면 친절하십시오 :)

Keys@Sort@Merge[{PositionIndex@#,-Counts@#2},Total]&

그리고 예 :

Keys@Sort@Merge[{PositionIndex@#, -Counts@#2}, Total] &[
    {pepper, paprika, salt, cumin, oregano}
  , {oregano, cumin, cumin, salt, salt, salt}
]

{소금, 후추, 파프리카, 커민, 오레가노}


나는 Mathematica 전문가가 아니지만 바이트를 절약하기 위해 공백을 제거 할 수 있습니다.
pajonk

@pajonk은 이미 그것들없이 계산되었지만 여기에서도 제거해야했습니다. 감사합니다.
Kuba

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