Oreo? No... Lollipop, maybe?

46

3

Since 2009, Android's version code names have been confectionery-themed. Android 1.5 is Cupcake, Android 1.6 is Donut, Android 2.0 is Eclair, etc.. In fact, the version names are alphabetical!

C -> Cupcake
D -> Donut
E -> Eclair
F -> Froyo
G -> Gingerbread
H -> Honeycomb
I -> Ice Cream Sandwich
J -> Jellybean
K -> Kitkat
L -> Lollipop
M -> Marshmallow
N -> Nougat
O -> Oreo

In order:

Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwich, Jellybean, Kitkat, Lollipop, Marshmallow, Nougat, Oreo

Challenge

Write a program/function that takes a letter from C to O and outputs its respective Android version code name.

Specifications

  • Standard I/O rules apply.
  • Standard loopholes are forbidden.
  • You can choose to either support lowercase input or uppercase input or even both.
  • The output may be in title case (Cupcake) or completely lower case (eclair). Ice cream sandwich may be capitalized however you like. (I didn't expect it to cause so much confusion...)
  • This challenge is not about finding the shortest approach in all languages, rather, it is about finding the shortest approach in each language.
  • Your code will be scored in bytes, usually in the encoding UTF-8, unless specified otherwise.
  • Built-in functions (Mathematica might have one :P) that compute this sequence are allowed but including a solution that doesn't rely on a built-in is encouraged.
  • Explanations, even for "practical" languages, are encouraged.

Test cases

These are uppercase and title case.

Input   Output

F       Froyo
I       Ice Cream Sandwich
J       Jellybean
N       Nougat
G       Gingerbread
L       Lollipop

In a few better formats:

F, I, J, N, G, L
f, i, j, n, g, l

F I J N G L
f i j n g l

totallyhuman

Posted 2017-08-22T17:17:10.157

Reputation: 15 378

@WheatWizard That's much harder though – Mr. Xcoder – 2017-08-22T17:23:53.023

8@Mr.Xcoder Are you saying its not a dupe because its easier? This is a dupe precisely because it is an easier version of an existing question. We've already done this type of question to death and this one provides absolutely nothing new or interesting to the genre. – Post Rock Garf Hunter – 2017-08-22T17:30:53.593

2@WheatWizard I think the former is a better dupe, since the latter is restricted source. – Mr. Xcoder – 2017-08-22T17:57:09.290

9It might be a dupe of some other challenge. But Help me recognize my monster is asking for string to symbol conversion (which leads to hash-based solutions). This one is asking for symbol to string. – Arnauld – 2017-08-22T18:02:09.667

2

FYI, It should be Jelly Bean, with a space. https://en.wikipedia.org/wiki/Android_Jelly_Bean

– mbomb007 – 2017-08-22T19:04:41.307

1Darn, I lost the chance of incrementing everybody's byte count by 1. – totallyhuman – 2017-08-22T19:08:12.363

1If you want to be correct on the versions, you should probably just update it and tell people to change their answers. – mbomb007 – 2017-08-22T19:08:53.910

No, that's a little too annoying, don't you think? – totallyhuman – 2017-08-22T19:09:33.880

@totallyhuman you can do what I did on the nun challenge and update each one individually :P – MD XF – 2017-08-22T19:36:21.160

Should it be Ice Cream Sandwich or Ice cream sandwich? The initial code block suggests the former but the test cases suggest the latter. The current winning answer requires Ice cream sandwich, but The output may be in title case (Cupcake) or completely lower case (eclair)..... Ice cream sandwich is not in title case. – MD XF – 2017-08-22T19:38:01.037

Ice Cream Sandwich is title case. And, again, all of those are fine. – totallyhuman – 2017-08-22T19:40:07.470

In Ice cream sandwich the c and s are not capitalized. – MD XF – 2017-08-22T19:40:30.197

Ah, I see my mistake. Updated. :) – totallyhuman – 2017-08-22T19:42:49.963

6*coughs* – Magic Octopus Urn – 2017-08-22T20:15:33.960

5@MagicOctopusUrn Yeah, I saw that, too. Unfortunately, it doesn't include MARSHMALLOW and later. – mbomb007 – 2017-08-22T20:49:50.293

2Closely related – AdmBorkBork – 2017-08-23T19:24:49.080

Note: Cupcake wasn't the first confectionary themed codename: Android 1.1 had the internal codename "Petit four" which is a small bite-sized confectionery, pastry or biscuit. – thomasrutter – 2017-08-25T00:13:21.737

Answers

14

Charcoal, 73 bytes

θ§⪪”%↖↙1¬¢/vy⁵⸿ψJPP±≔S×5Jρνξ–Gu ◧;Yx³F▶ψ;εB↥:P¹N﹪J$α✂χ✳⦄⟲*±¶Sp:ς↘V◧◧”x℅θ

Try it online! I/O is in lower case. Based on this verbose version. Explanation:

                Implicitly print:
θ               Input character
                Implicitly print:
   ”...”        Long compressed string "oneycombx...xingerbread"
  ⪪            Split on
        x       The string "x"
 §              Circularly indexed by
          ℅     Character code of
           θ    Input character

Neil

Posted 2017-08-22T17:17:10.157

Reputation: 95 035

4I... What? How. – Magic Octopus Urn – 2017-08-22T20:13:03.613

@MagicOctopusUrn Sorry I was too busy to add an explanation at the time. Hope this one suffices. – Neil – 2017-08-22T20:24:21.857

1Oh wow, I didn't know it did compressed strings! – Magic Octopus Urn – 2017-08-22T20:24:55.923

How Charcoal beats SOGL here is just unbelievable. – Erik the Outgolfer – 2017-08-23T09:41:19.603

Jelly's still beating it :joy: https://codegolf.stackexchange.com/a/140092/73675

– Hugo H – 2017-08-23T17:39:18.783

@Neil you can just remove the comma in the verbose version :P

– ASCII-only – 2017-08-23T23:20:43.303

14

Bash + Core Utils 131 128 122 117 bytes.

The script is encoded as Base64 because it contains special (weird) characters.

Accepts the Android codename letter only in lowercase as its first positional parameter. Returns the full codename also in lowercase.

CiPBUeICicG5tJ8W5a0Pc/hYuw7hkNMSIYkAPjARkdgFrdbh3NJgTmB4gRPiiQDJAaOyBH4ki14C
QDeKRNQJ8IJYER411DAnx0SO4CAKYmFzZTMyICQwfHRyICdBLVo0NwonICdhLXoKICd8Z3JlcCBe
JDEK

Explaination:

#�Q��������s�X����!�>0�������`N`x������~$�^@7�D�    ��X5�0'�D�� 
base32 $0|tr 'A-Z47
' 'a-z
 '|grep ^$1
  • The first two lines are the binary blob with the data (see a the end of the answer for more information). The first line is empty, to avoid problems with Bash, as otherwise it may think that is being fed with a binary file.
  • base32 $0 encodes the script contents with Base32, with the default line wrapping of 76 characters.
  • tr 'A-Z47\n' 'a-z\n ' (note that the \n is written as a literal newline) will lowercase the input and replace 4, 7 and \n by \n, space and space respectively.
  • grep ^$1 will output the lines matching the string provided as first argument to the script.

Binary data

This octet stream was forged so it doesn't contain newlines and when it's decoded with Base32 as per RFC 4648, the resulting string is the list of Android codenames (using 4 as item delimiter and 7 to replace the space character). Among its peculiarities, it begins with a newline character and a hash (#) so it behaves as a comment and, therefore, isn't executed by the interpreter.

Also, the default line wrapping to 76 characters of this Base32 implementation helped me a byte, as I reordered the items to use the line break as one of the Ice cream sandwich spaces.


Also, and going a bit off-topic, I think that Google shouldn't indirectly advertise commercial products in the Android codenames.

Helio

Posted 2017-08-22T17:17:10.157

Reputation: 240

2Nice, this is a really cool answer! Welcome to the site :) – James – 2017-08-23T17:22:06.987

Another Bash answer: https://codegolf.stackexchange.com/a/140147/41835

– Helio – 2017-08-23T20:48:05.007

1This version is buggy, at least on my system (bash 4.4.12, coreutils 8.27). For f, it outputs two lines: one with froyo and another with mysterious fgeyltmuzteibno. – MarSoft – 2017-08-24T12:40:48.133

1@MarSoft: Thanks! Fixed. The pity is that now I need a byte more. – Helio – 2017-08-24T12:58:39.983

@MarSoft: Solved! Now with the same bytes! – Helio – 2017-08-24T15:59:15.203

11

Python 3, 139 bytes

lambda x:x+'upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo'.split(",")[ord(x)-67]

Try it online!

Mr. Xcoder

Posted 2017-08-22T17:17:10.157

Reputation: 39 774

11

Jelly, 57 bytes

Oị“¡ȥọ⁴ḷæĿɱ}#n#i®ÞSỊ3ƙɼıjṁ)-⁵g7ḥjC?4ƘẠʂ+ḋ¤⁺jṣð£?v»Ḳ¤F⁾! y

Try it online!

-5 thanks to Jonathan Allan.

Erik the Outgolfer

Posted 2017-08-22T17:17:10.157

Reputation: 38 134

Save four bytes by using a placeholder for the spaces in "ice cream sandwich" and using spaces for splitting, for example: Oị“¡ḟ¤Y7bh%XO€ḥıṣẎṄṢ°ḊḞİỌĿż0Y⁷ẠỵƈƭV>tÐNY_LɠðṅẒọX?v»Ḳ¤F⁾! y – Jonathan Allan – 2017-08-24T14:00:55.720

...actually make that five bytes (I had used "lair" when "clair" is in the dictionary): Oị“¡ȥọ⁴ḷæĿɱ}#n#i®ÞSỊ3ƙɼıjṁ)-⁵g7ḥjC?4ƘẠʂ+ḋ¤⁺jṣð£?v»Ḳ¤F⁾! y – Jonathan Allan – 2017-08-24T14:10:18.027

@JonathanAllan thanks...wait why would I need the F? oh it's because I get input as a string not char – Erik the Outgolfer – 2017-08-24T14:28:09.013

11

Bash + Core Utils (Grep): 132 130 Bytes

Simple as could be

grep ^$1<<<'Cupcake
Donut
Eclair
Froyo
Gingerbread
Honeycomb
Ice Cream Sandwich
Jellybean
Kitkat
Lollipop
Marshmallow
Nougat
Oreo'

markasoftware

Posted 2017-08-22T17:17:10.157

Reputation: 346

1Input via dd is clever, but could you save as a script and use $1 instead? – Dom Hastings – 2017-08-23T05:35:55.843

8

C++, 206 201 198 bytes

Thanks to @sergiol for helping to save 3 bytes!

#import<cstdio>
void f(int l){char*w[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};printf("%c%s",l,w[l-67]);}

Try it online!

C, 173 bytes

f(l){char*w[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};printf("%c%s",l,w[l-67]);}

Well, it started as C++, but now it's also valid C, and some bytes can be saved by compiling it as C.

Try it online!

Steadybox

Posted 2017-08-22T17:17:10.157

Reputation: 15 798

@sergiol Thanks! I was able to save three bytes with that after a bit of golfing. – Steadybox – 2017-08-23T01:55:36.757

4#import in c++? what am I missing here? – Abhinav Gauniyal – 2017-08-23T05:17:57.217

@AbhinavGauniyal: IIRC I think some compiling warning advised me also to add #import <cstdio> because the lack of #include <stdio.h>; or may be I am wrong – sergiol – 2017-08-23T08:04:17.507

@AbhinavGauniyal It's not standard C++, but at least GCC and MSVC have it. – Steadybox – 2017-08-23T13:24:35.677

7

JavaScript (ES6), 137 136 bytes

Saved 1 byte thanks to Neil

c=>'CupcakeDonutEclairFroyoGingerbreadHoneycombIce Cream SandwichJellybeanKitkatLollipopMarshmallowNougatOreo'.match(c+'([a-z]| .)+')[0]

Demo

let f =

c=>'CupcakeDonutEclairFroyoGingerbreadHoneycombIce Cream SandwichJellybeanKitkatLollipopMarshmallowNougatOreo'.match(c+'([a-z]| .)+')[0]

;[...'CDEFGHIJKLMNO'].map(c => console.log(c, '->', f(c)))

Arnauld

Posted 2017-08-22T17:17:10.157

Reputation: 111 334

can't you include the space in the character range, probably with \s? haven't used much JS Regex – michi7x7 – 2017-08-22T18:26:53.593

1@michi7x7 Hes need the match to stop at an uppercase letter except in the case of Ice Cream Sandwich, although ([a-z]| .)+ (saving 1 byte) would work even with Ice Cream Sandwich in the middle of the string (it would start failing when code names reached S though). – Neil – 2017-08-22T18:35:45.833

@Neil well, [a-z\s]+ doesn't match uppercase letters. I just don't know if you can do that in JS – michi7x7 – 2017-08-22T18:39:46.610

@michi7x7 So how would it work with Ice Cream Sandwich? – Neil – 2017-08-22T18:54:27.090

2Use Ice cream sandwich, like in the test case (although this is not Title Case) – michi7x7 – 2017-08-22T19:03:47.817

@michi7x7 Ah, yes. I didn't notice it was allowed. Thanks! – Arnauld – 2017-08-22T19:29:52.033

@michi7x7 Ah, I see proper case is allowed too so yes [ a-z]+ would work in that case. – Neil – 2017-08-23T09:47:49.567

5

Japt, 81 79 bytes

Contains a few characters that won't display here.

U+`Æ+tfÆ÷¯kef©fclairfê $ßdfey¬mbf­ ×Äm ÑØrfÁKÞ fkfo¥ipopfÂâÚaow`qf gUc

Test it

  • 2 bytes saved thanks to Oliver.

Explanation

Implicit input of uppercase character string U.

A compressed string (everything between the backticks) of the names, separated with an f and without their first letter is split (q) into an array on f.

Within that array we get the element at the index (g) of Us character code. (Yay, index wrapping!)

We append that to U and implicitly output the resulting string.

Shaggy

Posted 2017-08-22T17:17:10.157

Reputation: 24 623

@Oliver: Oh, nice, thanks :) On my phone, walking down the street so definitely wouldn't have gotten that for a while (if at all). – Shaggy – 2017-08-22T18:10:27.533

5

Excel VBA, 137 134 132 Bytes

Anonymous VBE immediate window function that takes input as expected type Variant\String and length 1 holding a capital letter from cell [A1] and outputs to the VBE immediate window function

?[A1]Split("upcake onut clair royo ingerbread oneycomb ce cream sandwich ellybean itkat ollipop arshmallow ougat reo")(Asc([A1])-67)

-5 Bytes for changing the spaces in ce cream sandwich from (char 32) to  (char 160) `` (char 127) and removing comma delimiter in the Split function

Taylor Scott

Posted 2017-08-22T17:17:10.157

Reputation: 6 709

4

SOGL V0.12, 81 bytes

]&ŗ√‰fō¶č▓'▼$»3↕█γb└a}⅟∑─b¹¦Æ:↕┘∞½Σ#gī±⅔≡≥\3Qy-7todΥ7ā‼D←εPρρ:¬c‰ƨ}f沑θ╔@ŗz,WHHw

Try it Here!

Explanation:

...‘            push "cupcake donut eclair froyo gingerbread honeycomb ice_cream_sandwich jellybean kitkat lollipop marshmallow nougat oreo"
    θ           split on spaces
     ╔@ŗ        replace underscores with spaces
        z,W     find the inputs index in the lowercase alphabet
           HH   decrease by 2
             w  get that item from the array

Now there is a shorter 80 byte version, but I added the +2/-2 built-ins because of this challenge :p

The compressed string is split like "cup","cake"," donut eclair fro","yo gingerbread honeycomb ice","_","cream","_","sandwich jelly","bean kit","kat loll","i","pop marsh","mallow"," nougat oreo" for maximum usage of english words (many weren't in SOGLs dictionary), right now I can't find any improvements.

dzaima

Posted 2017-08-22T17:17:10.157

Reputation: 19 048

4

><>, 181 bytes

!vi:od5*-0$6a*@p!
v<
 v"upcake"
 v"onut"
 v"clair"
 v"royo"
 v"ingerbread"
 v"oneycomb"
 v"ce Cream Sandwich"
 v"ellybean"
 v"itkat"
 v"ollipop"
 v"arshmallow"
 v"ougat"
 v"reo"
o<>

Try it online!

This works by self-modifying the program to place a < in front of the correct name to print, the position of which is determined by the value of the inputted letter.

Business Cat

Posted 2017-08-22T17:17:10.157

Reputation: 8 927

3

Dyalog APL, 158 143 131 bytes

1 byte saved thanks to @Zacharý

12 bytes saved thanks to @Gil

{⍵,(⎕A⍳⍵)⊃','(1↓¨=⊂⊢)',,,upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo'}

Try it online!

How?

',,,upcake...' - list of words

','(1↓¨=⊂⊢) - split by ','

(⎕A⍳⍵)⊃ - take from the place of the argument in the alphabet

⍵, - and append to the letter

Uriel

Posted 2017-08-22T17:17:10.157

Reputation: 11 708

Why did you describe as flatten? – Zacharý – 2017-08-22T19:08:39.650

Also, {⍵,∊⍬⍬'upcake' 'onut' 'clair' 'royo' 'ingerbread' 'oneycomb' 'ce cream sandwich' 'ellybean' 'itkat' 'ollipop' 'arshmallow' 'ougat' 'reo'[⎕A⍳⍵]} works for 1 less byte! – Zacharý – 2017-08-22T19:10:22.697

@Zacharý because it is... "mix". nice one! why ∊ and not ↑? – Uriel – 2017-08-22T19:27:23.377

Because is flatten as well, but actually flatten and not "mix". ↑(1 2)(3 4) is NOT flat, while ∊(1 2)(3 4) is. – Zacharý – 2017-08-22T20:21:19.450

@Zacharý OP changed that... AGAIN. – Uriel – 2017-08-22T20:34:33.187

Use a single string for all and partition it to save another 12 bytes: {⍵,(⎕A⍳⍵)⊃','(1↓¨=⊂⊢)',,,upcake,onut,.... – Gil – 2017-08-22T22:14:44.543

Do as Gil said, that is amazing. – Zacharý – 2017-08-22T22:24:34.833

@Gil nice one! I tried with regex before but it was too long. – Uriel – 2017-08-22T22:32:40.030

Too tired to think clearly now, but another option is to skip separators and only use an initial capital letter for each version and partition it that way (you might find a way to shorten the expression further): 'ABCupcakeDonutEclair..'∘{⍺/⍨(+\⍺∊⎕A)∊⎕A⍳⍵}'D' – Gil – 2017-08-22T22:48:07.270

@Gil I think I have an even shorter solution, but I'm afk til tomorrow, so I'll test it when I get to the ws – Uriel – 2017-08-22T23:36:31.837

Yeah, going off of Gil's comment, {⍵/⍨(+\⍵∊⎕A)∊⎕A⍳⍞}'...' should save 1 more byte than Gil's suggestion. – Zacharý – 2017-08-23T18:38:23.813

Outgolfed – Zacharý – 2017-08-23T19:10:52.763

Outgolf Zacharý with Gil's suggestion: (⎕A⍳⍞)⊃'ABCup…Oreo'(∊⊂⊣)⎕A

– Adám – 2017-08-23T19:36:27.800

I could steal that solution, but considering I was inspired by "I think I have an even shorter solution," so I won't do the whole percent mess again (Answers going between me and Cowsquack, which ended up with like 4 APL answers). – Zacharý – 2017-08-23T20:11:51.637

3

C (gcc), 195 192 190 bytes

-2 bytes thanks to @Quentin

*V[]={"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo"};main(c,v)char**v;{printf("%c%s",c,V[(c=*v[1])-67]);}

Try it online!

cleblanc

Posted 2017-08-22T17:17:10.157

Reputation: 3 360

3

Tcl, 158 bytes

proc A s {puts $s[lindex {upcake onut clair royo ingerbread oneycomb "ce Cream Sandwich" ellybean itkat ollipop arshmallow ougat reo} [expr [scan $s %c]-67]]}

Try it online!

sergiol

Posted 2017-08-22T17:17:10.157

Reputation: 3 055

2Tcl! You don't see too many Tcl solutions on here. It's a shame. – Silvio Mayolo – 2017-08-23T03:14:04.450

3

EXCEL, 154 bytes

=A1&CHOOSE(CODE(A1)-66,"upcake","onut","clair","royo","ingerbread","oneycomb","ce Cream Sandwich","ellybean","itkat","ollipop","arshmallow","ougat","reo")

Wernisch

Posted 2017-08-22T17:17:10.157

Reputation: 2 534

I've never thought of using excel in this way. Perfect. Now do it with WORD – tisaconundrum – 2017-08-24T00:11:53.377

@tisaconundrum - we do not speak of that accursed thing; Even VBA could not save it – Taylor Scott – 2017-10-10T15:57:03.107

2

Pyth, 117 116 bytes

Port of my Python answer.

+Q@c"upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"\,a67C

Try it here! or Check out the Test Suite

Pyth, 99 bytes (70 characters)

-15 bytes thanks to @insert_name_here!

+Q@c." y|çEC#nZÙ¦Y;åê½9{ü/ãѪ#¤
ØìjX\"¦Hó¤Ê#§T£®úåâ«B'3£zÞz~Уë"\,a67C

Try it here!

Mr. Xcoder

Posted 2017-08-22T17:17:10.157

Reputation: 39 774

You could save 15 bytes by using compressed strings (though the answer would have to contain unprintable characters then).

– insert_name_here – 2017-08-23T18:36:57.777

@insert_name_here Thanks. – Mr. Xcoder – 2017-08-23T18:38:17.373

2

Gaia, 110 bytes

:c“reo“upcake“onut“clair“royo“ingerbread“oneycomb“ce Cream Sandwich“ellybean“itkat“ollipop“arshmallow“ougat”=+

Try it online!

Explanation

:          Push two copies of the input
 c         Get the codepoint of the top one
  “...”    Push the list of version names without their first letters
       =   Modularly index the code point into the list
        +  Append to the input

Business Cat

Posted 2017-08-22T17:17:10.157

Reputation: 8 927

2

Cubically, 1047 852 830 bytes

Functions sure help golf large programs...

⇒+552
⇒+551
⇒+553
⇒+55
⇒/1+52
⇒/1+53
~@7+4f5=?{:5+53@:4/1f1@:5+51@:5+2/1f4@:5+3/1f2@:2/1f2@}
+5f5=?{:3/1f1@:2/1f1@:5+53@:5+3/1f1@}
+51f5=?{:5+51@+1@:5+2/1f4@:5+1/1+551@+1@}
+52f5=?{:5+1/1f1@:3/1f1@:4/1f3@:3/1f1@}
+53f5=?{:5+1/1f2@:2/1f1@:4/1f2@:2/1f2@:5+1/1f1@:5+3/1f4@:5+1/1f1@:2/1f2@:5+2/1f4@:1/1f2@}
+53=?{:3/1f1@:2/1f1@-1@:4/1f3@:5+51@:3/1f1@:1/1f1@:5+3/1f4@}
+1f6=?{:5+51@:2/1f2@:5/1+3@:4/1+52@:5+1/1f1@:2/1f2@:5+2/1+55@:1/1f1@:5/1+3@:2/1+54@:5+2/1f4@6:2/1f1@6:1/1f2@6:2/1f3@6:5+1/1f2@6:5+51@6:5/1f2@6}
+2f6=?{:2/1f2@:5+52@@:4/1f3@:5+3/1f4@:2/1f2@:5+2/1f4@:2/1f1@}
+3f6=?{:5+1/1f2@:5+3/1f1@-1@:5+2/1f4@:5+3/1f1@}
+4f6=?{:3/1f1@:5+52@@:5+1/1f2@:4/1f1@:3/1f1@:4/1f1@}
+5f6=?{:5+2/1f4@:5+1/1f1@:5+2/1f1@:5/1f2@:1/1f1@:5+2/1f4@:5+52@@:3/1f1@:2/1f3}
+51f6=?{:3/1f1@:5+53@:4/1f2@:5+2/1f4@:5+3/1f1@}
+52f6=?{:5+1/1f1@:2/1f2@:3/1f1@}

Try it online! This is 830 bytes in Cubically's SBCS.

  • ~ reads input, @ prints it. (This breaks when the input is invalid.)
  • Each of the +.../...+...=7?6{...} compares the input to each ASCII value (C, D, E, F, etc) and executes the code within {...} if they are equal.
  • Each code block ({...}) prints the rest of the name (the first character is already printed).

Thanks to TehPers' ASCII to Cubically translator which was very helpful.

MD XF

Posted 2017-08-22T17:17:10.157

Reputation: 11 605

1That's 1060 bytes – Conor O'Brien – 2017-08-24T22:32:33.703

2

Haskell, 145 bytes

f c=takeWhile(/=succ c)$dropWhile(/=c)"CupcakeDonutEclairFroyoGingerbreadHoneycombIce Cream SandwichJellybeanKitkatLollipopMarshmallowNougatOreo"

Leif Willerts

Posted 2017-08-22T17:17:10.157

Reputation: 1 060

3takeWhile can be fst.span and dropWhile accordingly snd.span. – Laikoni – 2017-08-22T22:29:43.703

2

Java (OpenJDK 8), 128 bytes

c->c+"upcake#onut#clair#royo#ingerbread#oneycomb#ce Cream Sandwich#ellybean#itkat#ollipop#arshmallow#ougat#reo".split("#")[c-67]

Try it online!


Using regexes, 149 bytes

s->"CupcakeDonutEclairFroyoGingerbreadHoneycombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreo".replaceAll(".*?("+s+"[a-z ]+).*","$1")

Try it online!

  • 4 bytes saved on the regex solution thanks to Kevin Cruijssen!

Olivier Grégoire

Posted 2017-08-22T17:17:10.157

Reputation: 10 647

1Was about to post the same .split answer (only with different delimiter) when I read the challenge and couldn't find a Java answer (until I went to the second page of answers), so +1. As for the regex answer, ([a-z]| .)+ can be [a-z ]+, since you are allowed to output "Ice cream sandwich" ("The output may be in title case (Cupcake) or completely lower case (eclair). Ice cream sandwich may be capitalized however you like. (I didn't expect it to cause so much confusion...)") – Kevin Cruijssen – 2017-10-11T11:52:56.417

2

Ruby, 127 bytes

->c{c+%w[upcake onut clair royo ingerbread oneycomb ce\ Cream\ Sandwich ellybean itkat ollipop arshmallow ougat reo][c.ord-67]}

Takes uppercase input. Try it online!

daniero

Posted 2017-08-22T17:17:10.157

Reputation: 17 193

1

V, 125 bytes

Ccupcake
donut
eclair
froyo
gingerbread
honeycomb
ice cream sandwich
jellybean
kitkat
lollipop
marshmallow
nougat
oreoÇ^"/d

Try it online!

James

Posted 2017-08-22T17:17:10.157

Reputation: 54 537

1

Recursiva, 130 119 118 bytes

+aYQ'upcake!onut!clair!royo!ingerbread!oneycomb!ce cream sandwich!ellybean!itkat!ollipop!arshmallow!ougat!reo''!'-Oa99

Try it online!

officialaimm

Posted 2017-08-22T17:17:10.157

Reputation: 2 739

1

Pyke, 117 bytes

Port of my Python answer.

"upcake,onut,clair,royo,ingerbread,oneycomb,ce cream sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"\,cQ.o67-@+

Try it here!

Encoded as hex codes, the new technique of golfing in Pyke, it would be 116 bytes:

22 75 70 63 61 6B 65 2C 6F 6E 75 74 2C 63 6C 61 69 72 2C 72 6F 79 6F 2C 69 6E 67 65 72 62 72 65 61 64 2C 6F 6E 65 79 63 6F 6D 62 2C 63 65 20 63 72 65 61 6D 20 73 61 6E 64 77 69 63 68 2C 65 6C 6C 79 62 65 61 6E 2C 69 74 6B 61 74 2C 6F 6C 6C 69 70 6F 70 2C 61 72 73 68 6D 61 6C 6C 6F 77 2C 6F 75 67 61 74 2C 72 65 6F 22 5C 2C 63 51 EF 36 37 2D 40 2B

(Paste in and check Use hex encoding?).

Mr. Xcoder

Posted 2017-08-22T17:17:10.157

Reputation: 39 774

1Pyke needs an "Android releases" builtin right? – Erik the Outgolfer – 2017-08-22T18:00:32.667

1@EriktheOutgolfer It has Pokemons, so why not? – Mr. Xcoder – 2017-08-22T18:01:22.123

1

R, 131, 126, 123, 112, 178 bytes

grep(paste0('^',scan(,'')),c("Cupcake","Donut","Eclair","Froyo","Gingerbread","Honeycomb","Ice Cream Sandwich","Jellybean","Kitkat","Lollipop","Marshmallow","Nougat","Oreo"),v=T)

Thanks for @Mark for saving 5 + 8 + 3 bytes

AndriusZ

Posted 2017-08-22T17:17:10.157

Reputation: 219

1

C#, 147 136 129 bytes


Data

  • Input Char c The first letter of the version name
  • Output String The full name of the version

Golfed

// Requires the input to be uppercase.
// This is the one counting for the challange
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-67];

// Optional. Requires the input to be lowercase.
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-99];

// Optional. Works with both uppercase and lowercase with the additional cost of 10 bytes.
c=>c+"upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo".Split(',')[c-(c<99?67:99)];

Ungolfed

c =>
    c + "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - 67 ];

Ungolfed readable

// Takes a char 
c =>
    // Appends the input letter to...
    c + 

    // ... the name in the resulting index of the subtraction of the char with 67 ('C'), or with 99 ('c') for the lowercase version
    "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - 67 ];

// Takes a char 
c => 
    // Appends the input letter to...
    c + 

    // ... the name in the resulting index of the subtraction of the char with 67 ('C') if the char is uppercase ( 'C' == 67, 'O' == 79 )
    //    or with 99 ('c') if the char is lowercase ( 'c' == 99, 'o' == 111 )
    "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
        .Split( ',' )[ c - ( c < 99 ? 67 : 99 ) ];

Full code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestBench {
    public static class Program {
        private static Func<Char, String> f = c =>
            c + "upcake,onut,clair,royo,ingerbread,oneycomb,ce Cream Sandwich,ellybean,itkat,ollipop,arshmallow,ougat,reo"
                .Split( ',' )[ c - 67 ];

        static void Main( string[] args ) {
            List<Char>
                testCases = new List<Char>() {
                    'C',
                    'D',
                    'E',
                    'F',
                    'G',
                    'H',
                    'I',
                    'J',
                    'K',
                    'L',
                    'M',
                    'N',
                    'O',
                };

            foreach(Char testCase in testCases) {
                Console.WriteLine($" Input: {testCase}\nOutput: {f(testCase)}\n");
            }

            Console.ReadLine();
        }
    }
}

Releases

  • v1.0 - 147 bytes - Initial solution.
  • v1.1 - -11 bytes - Borrowed Olivier Grégoire's idea.
  • v1.2 - - 7 bytes - Changed the function input from explicit to implicit.

Notes

  • None

auhmaan

Posted 2017-08-22T17:17:10.157

Reputation: 906

Could you save anything by removing the first letter from each name and appending the string you retrieve from the array to the input character? – Shaggy – 2017-08-23T08:52:09.350

(char c) can just be c – LiefdeWen – 2017-08-23T10:40:50.067

1

R, 169 155 bytes

sub(paste0(".*(",scan(,""),"[^A-Z]+).*"),"\\1","CupcakeDonutEclairFroyoGingerbreadHoneycombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreo")

Sven Hohenstein

Posted 2017-08-22T17:17:10.157

Reputation: 2 464

1

Dyalog APL, 125 bytes

{⍵/⍨⍞=⎕A[+\⍵∊⎕A]}'ABCupcakeDonutEclairFroyoGingerbreadHonecombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreo'

Try it online!

How?

  • ⍵∊⎕A (the long string) with 1 for capital letters, 0 for lowercase/spaces.
  • +\ Group (returning numbers) ⍵ by capital letters.
  • ⎕A[...] The capital letter signified by a number
  • ⍵/⍨⍞= The group signified by that number
  • {...}'...' Set to the long string

Zacharý

Posted 2017-08-22T17:17:10.157

Reputation: 5 710

Clever approach. – Adám – 2017-08-23T19:41:15.767

1

C (gcc), 168 bytes

main(){puts(memchr("Cupcake\0Donut\0Eclair\0Froyo\0Gingerbread\0Honeycomb\0Ice cream sandwich\0Jellybean\0Kitkat\0Lollipop\0Marshmallow\0Nougat\0Oreo",getchar(),117));}

Try it online!

Cole Cameron

Posted 2017-08-22T17:17:10.157

Reputation: 1 013

1

PowerShell, 136 134 bytes

param($c)$c+('upcake0onut0clair0royo0ingerbread0oneycomb0ce cream sandwich0ellybean0itkat0ollipop0arshmallow0ougat0reo'-split0)[$c-99]

Try it online!

Takes a [char] input character, in lowercase, and outputs in lowercase.

-2 thanks to AdmBorkBork's suggestion to -split0 instead of -split','.

TessellatingHeckler

Posted 2017-08-22T17:17:10.157

Reputation: 2 412

You could use 0 as a separator and then -split0 to save the quotes. – AdmBorkBork – 2017-08-29T14:40:12.087

@AdmBorkBork good suggestion, thanks! – TessellatingHeckler – 2017-08-29T17:22:40.780

0

C#, 271 characters

var i="Cupcake|Donut|Eclair|Froyo|Gingerbread|Honeycomb|Ice cream sandwich|Jellybean|Kitkat|Lollipop|Marshmallow|Nougat|Oreo";var s=i.Split('|');int b;var c=new char[12];for(b=0;b<12;b++){c[b]=s[b][0];}for(b=0;b<12;b++){if(Console.Read().ToString()[0]==c[b])return s[b];}

Accepts one character from the console input stream, then returns the correct version number. Please tell me if I've done anything wrong or omitted something that should be here, this is my first time golfing.

snorepion

Posted 2017-08-22T17:17:10.157

Reputation: 43

2This is a good first submission, but it looks to be halfway between a function and a full program. Try using arrow notation (x=>...) to define a function and using x instead of Console.Read(). – Andrew – 2017-08-23T01:05:47.140

0

SimpleTemplate, 183 bytes

This just simply checks if the first letter of the word is the same or not.
Nothing super fancy.

{@setl"Cupcake","Donut","Eclair","Froyo","Gingerbread","Honeycomb","Ice Cream Sandwich","Jellybean","Kitkat","Lollipop","Marshmallow","Nougat","Oreo"}{@eachl}{@ifargv.0 is_.0}{@echo_}

Ungolded:

{@// array with all the names}
{@set list "Cupcake", "Donut", "Eclair", "Froyo", "Gingerbread", "Honeycomb", "Ice Cream Sandwich", "Jellybean", "Kitkat", "Lollipop", "Marshmallow", "Nougat", "Oreo"}
{@each list as name}
    {@if argv.0 is name.0} {@// name.0 -> first character}
        {@echo name}
    {@/}
{@/}

Try it on http://sandbox.onlinephpfunctions.com/code/002cfd9c5a84546dac3a656f6011b998ccfe33af

Ismael Miguel

Posted 2017-08-22T17:17:10.157

Reputation: 6 797

0

Cinnamon Gum, 118 bytes

Hexdump:

0000000: 6c0d cac9 1183 300c 05d0 5638 fd26 74cc  l.....0...V8.&t.
0000010: bed7 2084 020e b2c5 0818 c6dd 87eb 9b77  .. ............w
0000020: 80ac 93f0 a874 44e7 655d e804 15e3 1474  .....tD.e].....t
0000030: c637 bc3a 5dd0 a7d2 6bb4 a1dc d115 8317  .7.:]...k.......
0000040: ade2 b9a5 1b92 6823 bbe7 66e6 d26d 4906  ......h#..f..mI.
0000050: bae3 a766 b555 2ef4 c098 9691 177a c2dc  ...f.U.......z..
0000060: 2c4d 3ed1 0b99 631e 329b f946 6f14 5ffb  ,M>...c.2..Fo._.
0000070: 7d7c e0a1 fe07                           }|....

Try it online!

totallyhuman

Posted 2017-08-22T17:17:10.157

Reputation: 15 378

0

PHP, 133+1 bytes

<?=$argn,[upcake,onut,clair,royo,ingerbread,oneycomb,"ce Cream Sandwich",ellybean,itkat,ollipop,arshmallow,ougat,reo][ord($argn)-67];

no TiO this time. Run as pipe with -nR.

Titus

Posted 2017-08-22T17:17:10.157

Reputation: 13 814

0

SQL, 2017, 206 bytes

Assuming a function/procedure would have to be created otherwise you can't take input.

CREATE PROCEDURE X(@x VARCHAR)AS SELECT*FROM STRING_SPLIT('Cupcake,Donut,Eclair,Froyo,Gingerbread,Honeycomb,Ice cream sandwich,Jellybean,Kitkat,Lollipop,Marshmallow,Nougat,Oreo',',') WHERE value like @x+'%'

Cannot find a place to show this version online so there's a "slightly" more version-friendly submission

SQL, 244 bytes

CREATE PROCEDURE Y(@y VARCHAR,@x VARCHAR(999)='CupcakeDonutEclairFroyoGingerbreadHoneycombIce cream sandwichJellybeanKitkatLollipopMarshmallowNougatOreoP')AS SELECT STUFF(STUFF(@x,CHARINDEX(CHAR(ASCII(@y)+1),@x),999,''),1,CHARINDEX(@y,@x)-1,'')

Things to note, this is on a case-sensitive database therefore the delimiter could be the capital letter.

Explanation

Database is case-sensitive
Inner STUFF - removes everything from the the next capital letter in alphabet
Outer STUFF - removes everything before the input capital letter

SQL Fiddle worked example, not able to show a case sensitive database online so changed to a comma delimited list that works the same.

PreQL

Posted 2017-08-22T17:17:10.157

Reputation: 1