40
\$\begingroup\$

enter image description here

Given one of the following inputs:

Sweet Onion Chicken Teriyaki
Oven Roasted Chicken
Turkey Breast
Italian BMT
Tuna
Black Forest Ham
Meatball Marinara
output a number from 1-7 (or 0-6) representing the day of the week that you get that deal, starting with Monday as the lowest number. Input can be all lowercase or uppercase if preferred (i.e "italian bmt"). No internet allowed.

\$\endgroup\$
10
  • 8
    \$\begingroup\$ Don't really see how this Kolmogorov complexity. The text is the input...numbers are the output. \$\endgroup\$
    – geokavel
    Sep 5, 2017 at 15:45
  • 5
    \$\begingroup\$ Also does Sunday say "Meatball Marinara" or "Meatball Marina Ra"? \$\endgroup\$ Sep 5, 2017 at 16:09
  • 17
    \$\begingroup\$ I'm pretty sure it's supposed to be Marinara but the keming in the image is pretty awful... \$\endgroup\$ Sep 5, 2017 at 16:14
  • 6
    \$\begingroup\$ If it's useful to anyone: the number of a's plus the number of e's in each input is [5,4,3,2,1,3,6] respectively. \$\endgroup\$
    – geokavel
    Sep 5, 2017 at 18:14
  • 23
    \$\begingroup\$ When you use sudo. \$\endgroup\$
    – jpmc26
    Sep 5, 2017 at 19:10

28 Answers 28

88
+50
\$\begingroup\$

Python 2, 38 30 28 bytes

lambda S:`6793**164`[len(S)]

Try it online!

Unfortunately still one byte longer than the best Python 2 answer thus far; though not using the enklact-approach.

Now one byte shorter than i cri everytim's answer!

How does it work?

After a lot of brute force, I found an expression that results in a number which has just the right digits.
I noticed that looking at only one specific digit of the given string's lengths required 3 bytes (%10). So I wrote another Python program (Pastebin link) to further search for numbers who directly map the input strings' lengths to the day of the week.

The magic number looks like this: 6793**164 = 28714733692312345620167113260575862840674216760386883406587492336415023761043044176257567032312859371641211117824224067391750766520256112063756278010050204239810862527958109285342869876264808102743173594017101607983288521836082497514383184553444755034407847810524083812459571382103831904835921560285915349760536969265992879312869538914200854305957428078269094250817029486005437991820466986793657301214564264748923199288698278615871481529585816783654841131577178922192383679718074693535597651237893794976519274268917335387876260270630339777501802739852278932279775510324916969726203688466311848240746465178859847331248655567344801 (a number with an impressive 629 decimal digits)

And as you can see, the number provides the necessary mapping from [28, 20, 13, 11, 4, 16, 17] to [0, 1, 2, 3, 4, 5, 6] (Python strings are 0-indexed):

2871 4 733692 3 1 2 34 5 6 20 1 6711326 0 5758628406742167603868834... [4]^ [11]^ [13]^ [16]^ ^[17] ^[20] ^[28]

My program also found other expressions which yield numbers with the required property, though they take more bytes to represent (29 instead of 28): 19439**540, 34052**726, 39311**604, 44873**182, 67930**164 and 78579**469. (Those are all the expressions found by the linked program; its execution took several hours.)

Alternative function that requires 28 bytes: lambda S:`7954<<850`[len(S)]
Alternative function that requires 29 bytes: lambda S:`9699<<2291`[len(S)]
Alternative function that requires 30 bytes: lambda S:`853<<4390`[len(S)+9]
Alternative function that requires 31 bytes: lambda S:`1052<<3330`[len(S)+8]

How does it work? How did I generate that number? (30 byte answer)

The 30 byte answer was lambda S:`3879**41`[len(S)%10].

Looking at the input string's lengths [28, 20, 13, 11, 4, 16, 17], I noticed that all last digits in base ten differ, resulting in the list [8, 0, 3, 1, 4, 6, 7]. So I only needed a mapping from that list to the list of all seven days of the week, [0, 1, 2, 3, 4, 5, 6].

My first approach simply used a string to perform the mapping: lambda S:"13*24*560"[len(S)%10], though the string required eleven bytes ("13*24*560").
So I wrote a Python program (Pastebin link) to test for arithmetic expressions which result in an integer with matching digits, hoping to further golf the program. What I came up with thus far is `3879**41` (only ten bytes, the only and thereby smallest expression my program finds).

Of course, there are many different possible expressions one could try; I just got lucky that there was one in the form a**b with a reasonably small result that fit my need.

Just for anyone curious, 3879**41 = 1372495608710279938309112732193682350992788476725725221643007306215781514348937145528919415861895033279220952836384201346579163035594383625990271079 = 1.372... * 10**147.

Another valid function I found whilst searching for alternative expressions that unfortunately requires 32 bytes: lambda S:`7**416`[len(S)%10+290]

\$\endgroup\$
8
  • 1
    \$\begingroup\$ How did you generate that number? :o \$\endgroup\$ Sep 5, 2017 at 18:57
  • 11
    \$\begingroup\$ @icrieverytim Brute force. \$\endgroup\$ Sep 5, 2017 at 19:34
  • \$\begingroup\$ -9114**28 is a smaller integer* that also works (*in absolute terms not just because it is negative -- 111 digits rather than 629). Does not save on bytes though. \$\endgroup\$ Sep 7, 2017 at 17:01
  • 4
    \$\begingroup\$ Every once in a while I check the PCG questions in HNQ, and am usually disappointed to find golfing languages are the top three spots. Today i was not disappointed. Thank you! \$\endgroup\$
    – Sidney
    Sep 7, 2017 at 19:01
  • 4
    \$\begingroup\$ @icrieverytim ಠ_ಠ that's just the same number but halved with a shift factor of one more ಠ_ಠ :P \$\endgroup\$
    – hyper-neutrino
    Sep 25, 2017 at 14:15
58
\$\begingroup\$

Python 2, 29 bytes

lambda s:'enklact'.find(s[3])

Try it online!

Explanation

The magic string, enklact, was found by looking for the first column with unique letters.

The first column goes SOTITBM which is not useful 'cause it contains duplicates. The second and third ones also don't work because they are wvutule and eeranaa respectively. The fourth column, however works as it has all unique letters.

lambda s:'enklact'.find(s[3])

lambda s:                      # declare a function that takes a single paramater s
                  .find(    )  # find the index of the first instance of...
                        s[3]   # the fourth (0-indexing) character of s...
         'enklact'             # in the magic string
\$\endgroup\$
0
21
\$\begingroup\$

Python, 26 bytes

lambda S:1923136>>len(S)&7

Try it online!

With a debt of thanks (for my second straight code-golf try) to Jonathan Frech's answer -- I wouldn't have thought to use the string length instead of a distinguishing letter!

This code derives from my experience with De Bruijn Sequences and programming for chess.

In chess, you often work with several 64-bit integers, where each bit indicates something is true or false about the corresponding square on the chessboard, such as "there is a white piece here" or "this square contains a pawn".

It is therefore useful to be able to quickly convert 2**n to n quickly and cheaply. In C and C++, the quickest way to do this is to multiply by a 64-bit De Bruijn sequence -- equivalent to shifting by n bits -- then right-shift 58 (to put the first six bits last -- make sure you're using an unsigned int or you'll get 1s half the time) and look up this 0..63 number in a table that gives you the corresponding n which is in the same range, but rarely the same number.

This is kind of related. Instead of changing from 2**n to n, however, we want to change from n to some other 3-bit number. So, we hide our 3-bit numbers in a magic 31-bit number (a 28-bit shift requires bits 28-30, with numbering starting at 0.)

I generated the number needed by just seeing what values had to fall where (trying both 0..6 and 1..7 as the output sets). Fortunately, the overlapping values (14, 16, and 17) happen to work out! And since the first tri-bit is 000 and the next is 001, we don't need the leftmost 7 bits, resulting in fewer digits -> fewer bytes of source.

The required number is 000xxxx001110101011xxxx100xxxx, where the x's can be 1 or 0 and it doesn't affect the result for these particular subs -- I set them to 0 just to minimize the number, but changing any of the last 8 xs shouldn't affect the source code's length. Setting all the xs to 0, and leaving off the start, gives 1923136 in decimal (or 1D5840 in hex, but then you need the 0x prefix -- shame!) The &7 at the end just masks the last 3 bits, you could also use %8, but then you'd need parentheses due to python's operator precedence rules.

tl;dr: 1923136 encodes each of the three-bit combinations from 0 to 6 in exactly the right spots that these sandwich names happen to fall in place, and then it's a matter of taking the last three bits after a right shift.

\$\endgroup\$
1
  • \$\begingroup\$ Quite similar to my bit mask approach, but even better. \$\endgroup\$ Dec 7, 2017 at 22:06
12
\$\begingroup\$

Jelly, 10 bytes

What's with all this "enklact" business?

⁽ṃXị“Ð$¥»i

A monadic link taking a list of characters and returning the Monday=1 day of the week.

Try it online! or see the test-suite

How?

⁽ṃXị“Ð$¥»i - Link: list of characters, sandwichName  e.g. "Tuna"
⁽ṃX        - base 250 literal                             -7761
   ị       - index into sandwichName (1-indexed & modular) 'n'
    “Ð$¥»  - dictionary word                               "retinal"
         i - index of                                           5
\$\endgroup\$
3
  • \$\begingroup\$ How did you find the -7761/retinal combo? \$\endgroup\$
    – Emigna
    Sep 6, 2017 at 8:20
  • 3
    \$\begingroup\$ Wrote a loop that ran through creating "words" and seeing if they existed in the dictionary. "retinal" was the only one between -32249 and 32250 (the range of ⁽...) \$\endgroup\$ Sep 6, 2017 at 8:23
  • \$\begingroup\$ ...slight mistake - the range of ⁽.. is actually [-31349,32250]-[-99,999] (there are also other numbers one may represent with three or less bytes like 7!! or ȷ76) \$\endgroup\$ Sep 7, 2017 at 17:24
9
\$\begingroup\$

C (gcc), 72 71 56 46 41 39 bytes

f(char*s){s=index(s="enklact",s[3])-s;}

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ i;char x[]="enklact"; is shorter than i,x[]={101,110,107,108,97,99,116};. \$\endgroup\$ Sep 5, 2017 at 15:54
  • \$\begingroup\$ Was about to post that to: char*x="enklact" is even shorter: Try it online! \$\endgroup\$
    – scottinet
    Sep 5, 2017 at 15:56
  • \$\begingroup\$ Also, you can remove i=0. \$\endgroup\$ Sep 5, 2017 at 15:59
  • \$\begingroup\$ Even shorter version using index: Try it online! \$\endgroup\$
    – scottinet
    Sep 5, 2017 at 16:01
  • \$\begingroup\$ @scottinet Nice! I've never used index() before. Thanks \$\endgroup\$
    – cleblanc
    Sep 5, 2017 at 16:04
7
\$\begingroup\$

MATL, 16 15 bytes

O5OHlO7KI6vjYm)

Try it online! Or verify all test cases.

Explanation

O5OHlO7KI6 % Push numbers 0, 5, 0, 2, 1, 0, 7, 4, 3, 6
v          % Concatenate all numbers into a column vector
j          % Push input as a string
Ym         % Mean (of ASCII codes)
)          % Index into the column vector (modular, 1-based, with implicit rounding)
           % Implicit display
\$\endgroup\$
5
\$\begingroup\$

Jelly, 11 bytes

4ị“-ƭɼoṚ0»i

Try it online!

Explanation:

4ị“-ƭɼoṚ0»i
4ị          4th element of z
  “-ƭɼoṚ0»i First index in "enklactate"
\$\endgroup\$
7
  • 3
    \$\begingroup\$ @Mr.Xcoder unless I use enklactate instead of enklact for my string, in which case it brings it down to 11 ;) \$\endgroup\$ Sep 5, 2017 at 15:58
  • 6
    \$\begingroup\$ Oh, for fudge's sakes, why is enklactate in Jelly's dictionary? \$\endgroup\$ Sep 5, 2017 at 16:00
  • 3
    \$\begingroup\$ @icrieverytim It's not, enk is a string and lactate is a word. EDIT: just confirmed, enklactate isn't in the dictionary. \$\endgroup\$ Sep 5, 2017 at 16:00
  • 1
    \$\begingroup\$ @icrieverytim I think it's just lactate. \$\endgroup\$
    – Mr. Xcoder
    Sep 5, 2017 at 16:00
  • 2
    \$\begingroup\$ Aw maaan, I wanted to find a way to mock Jelly's dictionary... Maybe next time. :P \$\endgroup\$ Sep 5, 2017 at 16:03
5
\$\begingroup\$

Perl 5, 24 bytes

23 bytes code + 1 for -p.

/[Svrl\s](?!a)/;$_="@+"

-4 bytes thanks to @nwellnhof!

Try it online!

\$\endgroup\$
0
5
\$\begingroup\$

I thought I would post a couple of other alternatives

Javascript 38 bytes

a=s=>(271474896&7<<s.Length)>>s.Length

Explanation: Bit-mask rocks?

Javascript 27 bytes

s=>"240350671"[s.length%10]
\$\endgroup\$
8
  • \$\begingroup\$ the 2nd alternative is 29 bytes long forgot a= \$\endgroup\$ Sep 7, 2017 at 14:18
  • \$\begingroup\$ Why is the a= part needed? Look at Shaggy's answer. \$\endgroup\$
    – geokavel
    Sep 7, 2017 at 14:19
  • 1
    \$\begingroup\$ @BrunoCosta On this site, we don't require you to name your functions. Anonymous ones work, so you don't need the a=. \$\endgroup\$
    – Riker
    Sep 7, 2017 at 14:20
  • 1
    \$\begingroup\$ @BrunoCosta tha'ts cool, it's really up to you. You can also just not count it in the header byte count, and include it in the snippet for ease of testing. \$\endgroup\$
    – Riker
    Sep 8, 2017 at 2:39
  • 1
    \$\begingroup\$ @MichaelBoger Unfofrtantly I don't think it can because the minimum amount of code to make that work I believe it's something along the lines of a=s=>{b=s.Length;return(271474896&7<<b)>>b} \$\endgroup\$ Dec 7, 2017 at 21:43
3
\$\begingroup\$

Japt, 12 bytes

0-indexed, takes input in lowercase.

`kÇXsm`bUg#

Test it


Explanation

Implicit input of lowercase string U

`kÇXsm`

The compressed string kotinsm.

bUg#

Get the first index (b) of the character at index (g) 26 (#) in U. (Yay, index wrapping!)

Implicit output of integer result.


Alternative

Same as the above (and everyone else!), just using the characters at index 3 instead, allowing for title case input.

`klact`bUg3

Test it

\$\endgroup\$
3
  • \$\begingroup\$ Where'd the en go? :P \$\endgroup\$ Sep 5, 2017 at 15:52
  • 1
    \$\begingroup\$ @icrieverytim: that's a compressed string; en is compressed to an unprintable. \$\endgroup\$
    – Shaggy
    Sep 5, 2017 at 15:53
  • 7
    \$\begingroup\$ I think I see a bUg in your code. \$\endgroup\$
    – shenles
    Sep 5, 2017 at 19:03
3
\$\begingroup\$

05AB1E, 11 bytes

Saved 1 byte thanks to Erik the Outgolfer and 1 byte thanks to Magic Octopus Urn.

.•ΛΓ2º•I3èk

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ "enklact" -> ’enkl†¼’ \$\endgroup\$ Sep 5, 2017 at 16:04
  • \$\begingroup\$ ’enkl†¼’ -> .•ΛΓ2º• \$\endgroup\$ Sep 6, 2017 at 14:14
  • \$\begingroup\$ @MagicOctopusUrn Oh thanks \$\endgroup\$
    – Mr. Xcoder
    Sep 6, 2017 at 14:16
  • \$\begingroup\$ @Mr.Xcoder this is how I got that. \$\endgroup\$ Sep 6, 2017 at 15:55
  • \$\begingroup\$ @MagicOctopusUrn Will keep in the archive, thanks :p \$\endgroup\$
    – Mr. Xcoder
    Sep 6, 2017 at 15:56
3
\$\begingroup\$

JavaScript (ES6), 25 bytes

0-indexed.

s=>"enklact".search(s[3])

Test it

o.innerText=(f=
s=>"enklact".search(s[3])
)(i.value);oninput=_=>o.innerText=f(i.value)
<select id=i><option selected value="Sweet Onion Chicken Teriyaki">Sweet Onion Chicken Teriyaki</option><option value="Oven Roasted Chicken">Oven Roasted Chicken</option><option value="Turkey Breast">Turkey Breast</option><option value="Italian BMT">Italian BMT</option><option value="Tuna">Tuna</option><option value="Black Forest Ham">Black Forest Ham</option><option value="Meatball Marinara">Meatball Marinara</option></select><pre id=o>

\$\endgroup\$
4
  • 1
    \$\begingroup\$ This is 25 bytes! \$\endgroup\$
    – geokavel
    Sep 7, 2017 at 14:26
  • \$\begingroup\$ Thanks, @geokavel. Don't know where I got those extra 3 bytes from; even counting f= would only make it 27. \$\endgroup\$
    – Shaggy
    Sep 7, 2017 at 14:31
  • \$\begingroup\$ simple and effective solution. +1 :) \$\endgroup\$
    – Brian H.
    Dec 7, 2017 at 11:13
  • \$\begingroup\$ @Shaggy Maybe your third extra byte was a trailing newline. \$\endgroup\$
    – Sam Howard
    Dec 7, 2017 at 21:31
3
\$\begingroup\$

GolfScript, 12 bytes

{+}*93&(5?7%

Try it online!

Maps the inputs (via the sum of their code points) to 0 to 6.

Explanation

Found with a GolfScript snippet brute force tool I wrote a while ago...

{+}*  # Sum all code points.
93&   # ... AND 93.
(     # Decrement.
5?    # ... raised to the fifth power.
7%    # ... modulo 7.

Here is how this transforms each of the inputs to the desired result:

                                 {+}*   93&     (            5?   7%
Sweet Onion Chicken Teriyaki     2658    64    63     992436543    0
Oven Roasted Chicken             1887    93    92    6590815232    1
Turkey Breast                    1285     5     4          1024    2
Italian BMT                       965    69    68    1453933568    3
Tuna                              408    24    23       6436343    4
Black Forest Ham                 1446     4     3           243    5
Meatball Marinara                1645    77    76    2535525376    6
\$\endgroup\$
2
\$\begingroup\$

Excel, 28 bytes

Using the enklact method:

=FIND(MID(A1,4,1),"enklact")
\$\endgroup\$
1
  • \$\begingroup\$ You can drop 2 bytes by converting this to Google Sheets and dropping the ") \$\endgroup\$ Mar 1, 2018 at 20:48
2
\$\begingroup\$

Perl 6, 22 bytes

tr/enklact/^6/.comb[3]

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ perl 2017.07 accepts tr/enklact/^6/.comb[3] which would be 22 bytes, but tio.run apparently does not have it yet. \$\endgroup\$
    – Massa
    Sep 5, 2017 at 18:29
  • \$\begingroup\$ (tio.run runs perl6 v2017.6) \$\endgroup\$
    – Massa
    Sep 5, 2017 at 18:38
  • 1
    \$\begingroup\$ As long as an interpreter exists that can run the 22 byte version, it's valid. \$\endgroup\$
    – Shaggy
    Sep 6, 2017 at 13:18
2
\$\begingroup\$

CJam, 11 bytes

l1b93&(5#7%

Try it online!

A port of my GolfScript answer. It costs 1 byte to read the input explicitly, but we save two when summing the code points.

\$\endgroup\$
2
\$\begingroup\$

Husk, 10 bytes

%7^5←n93ṁc

Try it online!

Another port of my GolfScript answer. I'm sure eventually I'll find a language that can sum the code points for a single byte...

Husk (post-challenge update), 9 bytes

%7^5←n93Σ

Try it online!

Now, Σ does sum code points directly. Since this was added per a request after I answered this challenge, I'm not going to use it as my primary score though.

\$\endgroup\$
1
\$\begingroup\$

Pyth, 13 bytes

x"enklact"@w3

Verify all the test cases.

Alternative:

x."atÖÅû"@w3

3 can be substituted by any of the following values: [3, 4, 11, 13, 21, 24, 25, 26]

\$\endgroup\$
1
\$\begingroup\$

Pyke, 12 bytes

3@"enklact"@

Try it here!

\$\endgroup\$
1
\$\begingroup\$

Proton, 23 bytes

s=>'enklact'.find(s[3])

Try it online!

:P

\$\endgroup\$
1
\$\begingroup\$

Perl 5, 43 + 1 (-p) = 44 bytes

for$i(S,O,TUR,I,TUN,B,M){$"++;$_=$"if/^$i/}

Try it online!

Requires the first three characters of input to be upper case.

\$\endgroup\$
2
  • \$\begingroup\$ It has to be all uppercase, all lowercase, or regular. \$\endgroup\$
    – geokavel
    Sep 5, 2017 at 21:41
  • \$\begingroup\$ Call it all uppercase, then. Anything beyond the first three characters is ignored. \$\endgroup\$
    – Xcali
    Sep 5, 2017 at 21:52
1
\$\begingroup\$

Java 8, 26 bytes

Credit to @icrieverytim

Takes input as a char[]

s->"enklact".indexOf(s[3])
\$\endgroup\$
2
  • \$\begingroup\$ You can do s->"enklact".indexOf(s[3]) if you specify that you take input as a char array. \$\endgroup\$
    – shooqie
    Sep 5, 2017 at 17:17
  • \$\begingroup\$ Is that okay? I've a few answers that can be shortened like that \$\endgroup\$ Sep 5, 2017 at 17:30
1
\$\begingroup\$

Haskell, 36 bytes

-9 bytes thanks to H.PWiz.

f s=length$fst$span(/=s!!3)"enklact"

Try it online!

Alternate solution, 45 bytes

This uses the indexOf function in Data.List as elemIndex.

import Data.List
(`elemIndex`"enklact").(!!3)

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ 37 bytes \$\endgroup\$
    – H.PWiz
    Oct 28, 2017 at 21:51
  • \$\begingroup\$ @H.PWiz Oh, neat abuse of break. Thanks! \$\endgroup\$ Oct 28, 2017 at 22:00
  • 1
    \$\begingroup\$ 36 \$\endgroup\$
    – H.PWiz
    Oct 28, 2017 at 22:03
  • \$\begingroup\$ @H.PWiz Haha, how'd I miss that. XD \$\endgroup\$ Oct 28, 2017 at 22:05
1
\$\begingroup\$

C++, 119 118 77 76 73 bytes

-41 bytes thanks to Peter Cordes
-1 byte thanks to Zacharý
-3 bytes thanks to Michael Boger

At the string index 3, character for every sandwich is different

#include<string>
int s(char*p){return std::string("enklact").find(p[3]);}
std::initializer_list<char*> t{
    "Sweet Onion Chicken Teriyaki",
    "Oven Roasted Chicken",
    "Turkey Breast",
    "Italian BMT",
    "Tuna",
    "Black Forest Ham",
    "Meatball Marinara"
};

for (auto& a : t) {
    std::cout << s(a);
}

Golfing with std::string, that was obvious ofc... what was i thinking...

\$\endgroup\$
4
  • 1
    \$\begingroup\$ std::find in a string literal (or maybe a std::string) seems like the obvious way to go. Basically the same idea as index or strchr that the C answers are using, in a data structure where the 0-5 is implicit from the position. \$\endgroup\$ Sep 8, 2017 at 4:30
  • \$\begingroup\$ You can remove the newline inbetween lines 2 and 3. \$\endgroup\$
    – Adalynn
    Oct 22, 2017 at 21:06
  • \$\begingroup\$ You don't need a variable to store enklact. std::string("enklact").find(p[3]) works fine. This brings it down 3 characters. \$\endgroup\$
    – Sam Howard
    Dec 6, 2017 at 23:41
  • \$\begingroup\$ You CAN pass string literals to your function (g++ only raises a warning) so the memcpy stuff isn't needed. \$\endgroup\$
    – Sam Howard
    Dec 6, 2017 at 23:42
0
\$\begingroup\$

C# (.NET Core), 289 bytes

using System;class c{delegate int s(string r);static void Main(){s y=x=>{if(x[0]==83)return 1;if(x[0]==79)return 2;if (x[0]==84&x[2]=='r')return 3;if(x[0]==73)return 4;if(x[0]==84)return 5;if(x[0] ==66)return 6;if(x[0]==77)return 7;return 0;};Console.Write(y.Invoke(Console.ReadLine()));}}

Run online

\$\endgroup\$
0
\$\begingroup\$

Golfscript, 13 bytes

Try it online!

'enklact'\3=?

Takes the 4th character (which, for each, will be unique) and looks it up in the string "enklact".

Alternatively:

'nklact'\3=?)

This takes advantage of the fact that Golfscript's ? function returns -1 if the element searched for is not found (which, for Monday, it will not). If this were allowed, the solution could be reduced by 1 byte.

\$\endgroup\$
0
\$\begingroup\$

Dyalog APL, 13 bytes

'enklact'⍳4⌷⍞

Try it online!

\$\endgroup\$
0
\$\begingroup\$

K (oK), 13 bytes

Solution:

"enklact"?*3_

Try it online!

Examples:

> "enklact"?*3_"Black Forest Ham"
5
> "enklact"?*3_"Turkey Breast"
2

Explanation:

Interpretted right-to-left, pull out the 4th element from the input and return the zero-index location in the "enklact" list:

"enklact"?*3_  / the solution
           3_  / 3 drop, 3_"Turkey Breast" => "key Breast" 
          *    / first, *"key Breast" => "k"
         ?     / lookup right in left
"enklact"      / list to lookup element in
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.