When do I get my sandwich?

37

9

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.

geokavel

Posted 2017-09-05T15:28:03.183

Reputation: 6 352

8Don't really see how this Kolmogorov complexity. The text is the input...numbers are the output. – geokavel – 2017-09-05T15:45:15.007

Fixed inputs and outputs are considered [tag:kolmogorov-complexity] by some people. – Erik the Outgolfer – 2017-09-05T15:45:45.247

5Also does Sunday say "Meatball Marinara" or "Meatball Marina Ra"? – Erik the Outgolfer – 2017-09-05T16:09:06.447

17

I'm pretty sure it's supposed to be Marinara but the keming in the image is pretty awful...

– totallyhuman – 2017-09-05T16:14:03.070

1@i cri everytim do you mean kerning? – Restioson – 2017-09-05T18:05:55.380

2@Restioson Yes, that was an intentional typo. :P – totallyhuman – 2017-09-05T18:07:24.317

6If 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. – geokavel – 2017-09-05T18:14:55.690

22When you use sudo. – jpmc26 – 2017-09-05T19:10:32.957

4

@jpmc26 That doesn't work, and in fact, might be dangerous.

– JiK – 2017-09-07T19:36:43.047

3How am I seeing this question? I have ad-blocker turned on. – None – 2017-09-08T11:56:04.417

Answers

85

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]

Jonathan Frech

Posted 2017-09-05T15:28:03.183

Reputation: 6 681

1How did you generate that number? :o – totallyhuman – 2017-09-05T18:57:29.783

10@icrieverytim Brute force. – Jonathan Frech – 2017-09-05T19:34:46.633

-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. – Jonathan Allan – 2017-09-07T17:01:37.290

4Every 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! – Sidney – 2017-09-07T19:01:15.533

Now comes a magic number solution to all questions – Matthew Roh – 2017-09-12T23:08:26.317

@Nobody Well, if you have the computational power, sure! – Jonathan Frech – 2017-09-13T02:32:54.497

7954<<850 also works. – totallyhuman – 2017-09-22T21:30:05.547

@icrieverytim 7954<<850 is already listed as an alternative function. – Jonathan Frech – 2017-09-22T21:33:11.750

Whoops, wrong number. 3977<<851 – totallyhuman – 2017-09-22T22:05:25.133

4@icrieverytim ಠ_ಠ that's just the same number but halved with a shift factor of one more ಠ_ಠ :P – HyperNeutrino – 2017-09-25T14:15:16.783

50

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

totallyhuman

Posted 2017-09-05T15:28:03.183

Reputation: 15 378

19

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.

Michael Boger

Posted 2017-09-05T15:28:03.183

Reputation: 323

Quite similar to my bit mask approach, but even better. – Bruno Costa – 2017-12-07T22:06:10.200

12

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

Jonathan Allan

Posted 2017-09-05T15:28:03.183

Reputation: 67 804

How did you find the -7761/retinal combo? – Emigna – 2017-09-06T08:20:54.287

3Wrote 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 ⁽...) – Jonathan Allan – 2017-09-06T08:23:06.393

...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) – Jonathan Allan – 2017-09-07T17:24:17.650

9

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

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

Try it online!

cleblanc

Posted 2017-09-05T15:28:03.183

Reputation: 3 360

i;char x[]="enklact"; is shorter than i,x[]={101,110,107,108,97,99,116};. – Jonathan Frech – 2017-09-05T15:54:17.987

Was about to post that to: char*x="enklact" is even shorter: Try it online!

– scottinet – 2017-09-05T15:56:53.053

Also, you can remove i=0. – Jonathan Frech – 2017-09-05T15:59:18.553

Even shorter version using index: Try it online!

– scottinet – 2017-09-05T16:01:12.287

@scottinet Nice! I've never used index() before. Thanks – cleblanc – 2017-09-05T16:04:21.553

It's old, deprecated and POSIX only, but it's also 1 byte shorter than strchr :-) – scottinet – 2017-09-05T16:57:49.183

7

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

Luis Mendo

Posted 2017-09-05T15:28:03.183

Reputation: 87 464

5

Perl 5, 24 bytes

23 bytes code + 1 for -p.

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

-4 bytes thanks to @nwellnhof!

Try it online!

Dom Hastings

Posted 2017-09-05T15:28:03.183

Reputation: 16 415

5

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]

Bruno Costa

Posted 2017-09-05T15:28:03.183

Reputation: 151

the 2nd alternative is 29 bytes long forgot a= – Bruno Costa – 2017-09-07T14:18:13.890

Why is the a= part needed? Look at Shaggy's answer.

– geokavel – 2017-09-07T14:19:47.620

1@BrunoCosta On this site, we don't require you to name your functions. Anonymous ones work, so you don't need the a=. – Rɪᴋᴇʀ – 2017-09-07T14:20:35.850

@Riker Yeah I read that some time ago in meta but I like the fact that you are able to paste it into console and test it without modifications. – Bruno Costa – 2017-09-07T14:22:47.983

1@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. – Rɪᴋᴇʀ – 2017-09-08T02:39:55.783

Can that first alternative be reduced by assigning s.Length to a variable? I don't know JS that well, but I'd think this should work. – Michael Boger – 2017-12-07T21:37:53.780

1@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} – Bruno Costa – 2017-12-07T21:43:34.220

a=s=>(271474896&7<<(l=s.length))>>l – totallyhuman – 2017-12-31T21:49:46.913

4

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"

Erik the Outgolfer

Posted 2017-09-05T15:28:03.183

Reputation: 38 134

Yeah, compressed strings makes it 13 bytes, sadly – Mr. Xcoder – 2017-09-05T15:57:30.003

2@Mr.Xcoder unless I use enklactate instead of enklact for my string, in which case it brings it down to 11 ;) – Erik the Outgolfer – 2017-09-05T15:58:38.337

5Oh, for fudge's sakes, why is enklactate in Jelly's dictionary? – totallyhuman – 2017-09-05T16:00:03.863

3@icrieverytim It's not, enk is a string and lactate is a word. EDIT: just confirmed, enklactate isn't in the dictionary. – Erik the Outgolfer – 2017-09-05T16:00:35.777

1@icrieverytim I think it's just lactate. – Mr. Xcoder – 2017-09-05T16:00:42.987

2Aw maaan, I wanted to find a way to mock Jelly's dictionary... Maybe next time. :P – totallyhuman – 2017-09-05T16:03:37.607

1Every time I see a frustratingly short PCG answer written in Jelly, it makes me jelly. – Pharap – 2017-09-06T08:39:39.080

3

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

Shaggy

Posted 2017-09-05T15:28:03.183

Reputation: 24 623

Where'd the en go? :P – totallyhuman – 2017-09-05T15:52:33.947

1@icrieverytim: that's a compressed string; en is compressed to an unprintable. – Shaggy – 2017-09-05T15:53:36.153

7I think I see a bUg in your code. – shenles – 2017-09-05T19:03:20.013

3

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!

Mr. Xcoder

Posted 2017-09-05T15:28:03.183

Reputation: 39 774

"enklact" -> ’enkl†¼’ – Erik the Outgolfer – 2017-09-05T16:04:32.453

’enkl†¼’ -> .•ΛΓ2º• – Magic Octopus Urn – 2017-09-06T14:14:54.083

@MagicOctopusUrn Oh thanks – Mr. Xcoder – 2017-09-06T14:16:50.483

@Mr.Xcoder this is how I got that.

– Magic Octopus Urn – 2017-09-06T15:55:05.467

@MagicOctopusUrn Will keep in the archive, thanks :p – Mr. Xcoder – 2017-09-06T15:56:13.937

3

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>

Shaggy

Posted 2017-09-05T15:28:03.183

Reputation: 24 623

1

This is 25 bytes!

– geokavel – 2017-09-07T14:26:26.210

Thanks, @geokavel. Don't know where I got those extra 3 bytes from; even counting f= would only make it 27. – Shaggy – 2017-09-07T14:31:56.160

simple and effective solution. +1 :) – Brian H. – 2017-12-07T11:13:22.173

@Shaggy Maybe your third extra byte was a trailing newline. – Michael Boger – 2017-12-07T21:31:01.573

3

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

Martin Ender

Posted 2017-09-05T15:28:03.183

Reputation: 184 808

2

Perl 6, 22 bytes

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

Try it online!

Massa

Posted 2017-09-05T15:28:03.183

Reputation: 189

perl 2017.07 accepts tr/enklact/^6/.comb[3] which would be 22 bytes, but tio.run apparently does not have it yet. – Massa – 2017-09-05T18:29:49.537

(tio.run runs perl6 v2017.6) – Massa – 2017-09-05T18:38:22.033

1As long as an interpreter exists that can run the 22 byte version, it's valid. – Shaggy – 2017-09-06T13:18:41.450

2

Excel, 28 bytes

Using the enklact method:

=FIND(MID(A1,4,1),"enklact")

Wernisch

Posted 2017-09-05T15:28:03.183

Reputation: 2 534

You can drop 2 bytes by converting this to Google Sheets and dropping the ") – Taylor Scott – 2018-03-01T20:48:55.037

2

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.

Martin Ender

Posted 2017-09-05T15:28:03.183

Reputation: 184 808

2

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.

Martin Ender

Posted 2017-09-05T15:28:03.183

Reputation: 184 808

1

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]

Mr. Xcoder

Posted 2017-09-05T15:28:03.183

Reputation: 39 774

1

Java 8, 26 bytes

Credit to @icrieverytim

Takes input as a char[]

s->"enklact".indexOf(s[3])

Roberto Graham

Posted 2017-09-05T15:28:03.183

Reputation: 1 305

You can do s->"enklact".indexOf(s[3]) if you specify that you take input as a char array. – shooqie – 2017-09-05T17:17:49.077

Is that okay? I've a few answers that can be shortened like that – Roberto Graham – 2017-09-05T17:30:38.143

1

Pyke, 12 bytes

3@"enklact"@

Try it here!

Mr. Xcoder

Posted 2017-09-05T15:28:03.183

Reputation: 39 774

1

Proton, 23 bytes

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

Try it online!

:P

totallyhuman

Posted 2017-09-05T15:28:03.183

Reputation: 15 378

1

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.

Xcali

Posted 2017-09-05T15:28:03.183

Reputation: 7 671

It has to be all uppercase, all lowercase, or regular. – geokavel – 2017-09-05T21:41:39.067

Call it all uppercase, then. Anything beyond the first three characters is ignored. – Xcali – 2017-09-05T21:52:36.170

1

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...

HatsuPointerKun

Posted 2017-09-05T15:28:03.183

Reputation: 1 891

1std::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. – Peter Cordes – 2017-09-08T04:30:30.360

You can remove the newline inbetween lines 2 and 3. – Zacharý – 2017-10-22T21:06:12.317

You don't need a variable to store enklact. std::string("enklact").find(p[3]) works fine. This brings it down 3 characters. – Michael Boger – 2017-12-06T23:41:59.310

You CAN pass string literals to your function (g++ only raises a warning) so the memcpy stuff isn't needed. – Michael Boger – 2017-12-06T23:42:04.620

1

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!

totallyhuman

Posted 2017-09-05T15:28:03.183

Reputation: 15 378

137 bytes – H.PWiz – 2017-10-28T21:51:51.110

@H.PWiz Oh, neat abuse of break. Thanks! – totallyhuman – 2017-10-28T22:00:43.173

136 – H.PWiz – 2017-10-28T22:03:43.890

@H.PWiz Haha, how'd I miss that. XD – totallyhuman – 2017-10-28T22:05:24.970

0

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

snorepion

Posted 2017-09-05T15:28:03.183

Reputation: 43

0

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.

Josiah Winslow

Posted 2017-09-05T15:28:03.183

Reputation: 725

0

Dyalog APL, 13 bytes

'enklact'⍳4⌷⍞

Try it online!

Zacharý

Posted 2017-09-05T15:28:03.183

Reputation: 5 710

0

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

streetster

Posted 2017-09-05T15:28:03.183

Reputation: 3 635