コードを使用したクッキング


24

あなたはシェフであり、スパイスを使った料理が大好きですが、最近は、使用頻度に基づいてスパイスを整理することが好きになっています。しかし、最後にスパイスを使用したときに書き留める時間はありません。単に、あなたはスパイスを交換して動かします、そして、これはトリックをするようです。

しかし、もちろんあなたはシェフであり、それはあなたがいくつかの料理人を持っていることを意味します。あなたは彼らにあなたのスパイスとの婚約の簡単なルールを伝えることにします。

  1. 最近スパイスを使用した場合は、スパイスラックで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
私はシェフでこれをかなりやりましたが、最終的には疲れすぎました!できれば50バウンティをあげます。
-geokavel

5
ここだ要旨ミキシングボウルへの入力を取得するには。残りは非常に困難ですが、適切な人に実行可能です!
-geokavel

回答:


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ある1バイトのために。
H.PWiz

8

Haskell、48バイト

foldl(?) は、2つのリスト引数を取り、同じ要素(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少なくとも2つの要素がある場合?、2番目の要素がに等しいかどうかを確認しn、等しい場合は最初の2つの要素を切り替えます。等しくない場合、?最初の要素を固定し、残りを再帰します。
    • s要素が最大で1つある場合、?変更せずに返します。

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.

-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

いくつかの冗長な単語を削除することによって、あなたはできる32のバイト保存
ジョナサン・アラン

@geokavel昨日追加されました。
ジョナサンアラン

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

JavaScript、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)
  • 2つのリストは文字列の配列です

出力:

  • list_of_spicesはインプレースで変更されます。




4

Java 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)));})

2つの入力を次のように取ります ArrayList<String>バイトを節約するために新しいを返す代わりに、受け取り、最初のリストを変更します。

@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

Javaは、Javaをからかったすべての人々に復gettingしています。
-geokavel

2

05AB1E20 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. IFがcあるList<string>の代わりに、string[]あなたが直接使用することができますc.IndexOf。3. c所定の場所で変更されているため、返却する必要はありません。
raznagul


1

Mathematica、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}
]

{塩、胡pepper、パプリカ、クミン、オレガノ}


私はMathematicaの専門家ではありませんが、おそらくスペースを削除してバイトを節約できます。
パジョンク

@pajonkはそれらなしで既にカウントされていますが、ここでも削除する必要があります、ありがとう。
クバ

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.