18
\$\begingroup\$

Write the shortest program that prints, in order, a complete list of iPhone iterations, according to this site:

iPhone
iPhone 3G
iPhone 3GS
iPhone 4
iPhone 4S
iPhone 5
iPhone 5c
iPhone 5s
iPhone 6
iPhone 6 Plus
iPhone 6s
iPhone 6s Plus
iPhone SE
iPhone 7
iPhone 7 Plus
iPhone 8
iPhone 8 Plus
iPhone X
iPhone XR
iPhone XS
iPhone XS Max
iPhone 11
iPhone 11 Pro
iPhone 11 Pro Max

Output should be printed exactly as specified, though trailing newlines are allowed (as well as additional whitespace at the end of each line).

This is code golf, so the shortest answer in bytes, per language, wins.

\$\endgroup\$
  • \$\begingroup\$ Note that this is about 87 bytes using naive compression. \$\endgroup\$ – FryAmTheEggman Mar 8 at 3:17
  • \$\begingroup\$ Possible duplicate of We're no strangers to code golf, you know the rules, and so do I \$\endgroup\$ – pppery Mar 8 at 15:58
  • \$\begingroup\$ @pppery I would say it's just different enough not to be a dupe. \$\endgroup\$ – Redwolf Programs Mar 8 at 16:02
  • 1
    \$\begingroup\$ I disagree; the fact that only one answer beats Bubblegum is evidence that the text doesn't have enough structure for specialized compression algorithms to beat generic ones. \$\endgroup\$ – pppery Mar 8 at 16:04
  • 1
    \$\begingroup\$ @pppery I admit the answers can't be as interesting as I though, but that's not necessarily grounds for closing/duping, right? \$\endgroup\$ – Redwolf Programs Mar 8 at 16:07

21 Answers 21

11
\$\begingroup\$

Canvas, 77 76 73 bytes

¶+∔iF╴qV1┼#│»lN↶:╋KARV/+├6<∔ZK@≠≡Ze3h}s×⁴*⁵GZX─?ep┼Q‟-s{iPhone ×|∙ Plus╋]

Try it here!

-3G-3GS-4-4S-5-5c-5s-6-6|-6s-6s|-SE-7-7|-8-8|-X-XR-XS-XS Max-11-11 Pro-11 Pro Max compressed, split on -, | replaced with ' Plus', and 'iPhone ' prepended.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Wow, this beats the Bubblegum solution! \$\endgroup\$ – PkmnQ Mar 11 at 4:20
8
\$\begingroup\$

Zsh, 107 105 bytes

-2 bytes due to leniency on trailing spaces

print -l iPhone\ {,{3G,4}{,S},5{,c,s},6{,s}{,\ Plus},SE,{7,8}{,\ Plus},X{,R,S,S\ Max},11{,\ Pro{,\ Max}}}

Try it online! Try it online!

A long brace expansion. Bash/sh need printf %s\\n instead for 4 extra bytes.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Not necessarily. I just came up with a Bash answer that's the same size (but it uses less strict output rules). \$\endgroup\$ – S.S. Anne Mar 8 at 22:17
  • 1
    \$\begingroup\$ Ah, the "as well as additional whitespace at the end of each line" wasn't allowed when I posted. \$\endgroup\$ – GammaFunction Mar 8 at 23:51
7
\$\begingroup\$

JavaScript (ES6),  137 136  135 bytes

_=>"iPhone3G9GS39S33c9s3303s9s01SE3903301X1XR1XS1XS Max22 Pro2 Pro Max".replace(/\d/g,n=>[" Plus",k=`
iPhone `,k+11,k+i][n]||k+i++,i=3)

Try it online!

How?

The numeric version is stored in a counter \$i\$ initialized to \$3\$.

Below are the digits used for the compression:

  • \$0\$: " Plus"
  • \$1\$: "\n" + "iPhone "
  • \$2\$: "\n" + "iPhone 11"
  • \$3\$: "\n" + "iPhone " + \$i\$
  • \$9\$: same as \$3\$, but \$i\$ is incremented afterwards

Resulting in:

"iPhone"    --> "iPhone"
"3G"        --> "iPhone 3G"
"9GS"       --> "iPhone 3GS" (i++)
"3"         --> "iPhone 4"
"9S"        --> "iPhone 4S" (i++)
"3"         --> "iPhone 5"
"3c"        --> "iPhone 5c"
"9s"        --> "iPhone 5s" (i++)
"3"         --> "iPhone 6"
"30"        --> "iPhone 6 Plus"
"3s"        --> "iPhone 6s"
"9s0"       --> "iPhone 6s Plus" (i++)
"1SE"       --> "iPhone SE"
"3"         --> "iPhone 7"
"90"        --> "iPhone 7 Plus" (i++)
"3"         --> "iPhone 8"
"30"        --> "iPhone 8 Plus"
"1X"        --> "iPhone X"
"1XR"       --> "iPhone XR"
"1XS"       --> "iPhone XS"
"1XS Max"   --> "iPhone XS Max"
"2"         --> "iPhone 11"
"2 Pro"     --> "iPhone 11 Pro"
"2 Pro Max" --> "iPhone 11 Pro Max"
|improve this answer|||||
\$\endgroup\$
4
\$\begingroup\$

///, 108 bytes

Naive compression, simply replacing # with \niPhone. (Further compression does not work by the way.)

/#/
iPhone //@/ Plus/iPhone#3G#3GS#4#4S#5#5c#5s#6#6@#6s#6s@#SE#7#7@#8#8@#X#XR#XS#XS Max#11#11 Pro#11 Pro Max

Try it online!

///, 103 bytes

This works only if preceding newlines are allowed.

/#/
iPhone //@/ Plus/##3G#3GS#4#4S#5#5c#5s#6#6@#6s#6s@#SE#7#7@#8#8@#X#XR#XS#XS Max#11#11 Pro#11 Pro Max

Try it online!

|improve this answer|||||
\$\endgroup\$
4
\$\begingroup\$

Python3, 123 bytes

Not too fancy but the smallest I could get

print('iPhone,3G,3GS,4,4S,5,5c,6,6 Plus,SE,7,7 Plus,8,8 Plus,X,XR,XS,XS Max,11,11 Pro,11 Pro Max'.replace(',','\niPhone '))

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ -1 Byte \$\endgroup\$ – wilkben Mar 9 at 14:10
  • 1
    \$\begingroup\$ You don't have iPhone 5s, iPhone 6s or iPhone 6s Plus. \$\endgroup\$ – IMP1 Mar 10 at 10:03
  • 1
    \$\begingroup\$ And 6s and 6s Plus are missing as well. \$\endgroup\$ – Ismael Miguel Mar 10 at 10:05
4
\$\begingroup\$

05AB1E, 82 bytes

Just ties the new Bubblegum solution!

”3G3GS44S55c5s66‰´6s6s‰´SE77‰´88‰´XXRXSXSî£1111ˆ×11ˆ×•ΛΩ&°ŽäÞнã•0šTª£'i”ƒ¿ ”«ì»

Try it online!

(Solution by Kevin Crujissen)

So many unknown operations...but I get it from analysis.

This pushes everything at the start. Concatenated.

Then it makes a list by pushing a big number, turning it into a list and prepending 0, and appending 10.

["0", "2", "3", "1", "2", "1", "2", "2", "1", "6", "2", "7", "2", "1", "6", "1", "6", "1", "2", "2", "6", "2", "6", 10]

Then, using £, it splits the big concatenated mess into a list of strings.

Finally, it pushes "iPhone", prepends it to everything in the list, and separates the list with newlines.

Original Solution, 178 bytes

'i”ƒ¿”«D… 3G«D'S«.ÀD.Á„ 4«D'S«.ÀD.Á„ 5«Ð'c«s's«.ÀD.Á„ 6«D" Plus"D.Á«sDŠ's«D.À«.ÀD.Á… SE«.ÀD.Á„ 7«D" Plus"D.Á«.À.ÀD.Á„ 8«DŠs«.ÀD.Á„ X«Ð'R«s'S«D" Max"D.Á«.À.ÀD.Á… 11«DŠ" Pro"«DŠs«»

Try it online!

Explanation

First, I push the string "iPhone" by using 'i”ƒ¿”«.

I duplicate that, and push " 3G", and concatenate them to get "iPhone 3G".

After that, I use .ÀD.Á to get "iPhone" at the top of the stack, etc.

When I get to iPhone 6, I put " Plus" at the bottom of the stack and save it for iPhone 6S Plus.

I don't save it for iPhone 7 and 8 Plus, because I'm not sure if it will golf off some bytes, and I'd already spent enough time figuring it out.

I did save " Max" though, and I'm pretty sure now that saving " Plus" would've shaved off more bytes. However, now that the program is already completed, it's unclear how I do that.

At the end, I concatenate the whole stack together with newline delimiters, and implicit output happens.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ 84B. \$\endgroup\$ – petStorm Mar 8 at 7:59
  • 3
    \$\begingroup\$ 80 \$\endgroup\$ – Expired Data Mar 8 at 15:11
  • \$\begingroup\$ This is missing iPhone 6s and iPhone 6s Plus, as are all the suggested edits (the 178 is fine) :( \$\endgroup\$ – Jonathan Allan Mar 9 at 0:11
  • \$\begingroup\$ @ExpiredData This is missing iPhone 6s & Plus (as well as mine). Quick fix of 89 bytes \$\endgroup\$ – petStorm Mar 9 at 0:35
  • 1
    \$\begingroup\$ @ExpiredData Your 85-byter is missing the leading iPhone (and I'm not sure leading newlines are allowed either). Here an easy fix that's still 85 bytes, though. PS: If your 85-byter would have worked, you could have dropped the ) to join the stack directly. \$\endgroup\$ – Kevin Cruijssen Mar 9 at 14:51
3
\$\begingroup\$

Bubblegum, 82 bytes

00000000: cb0c c8c8 cf4b e582 500a c6ee 0856 308c  .....K..P....V0.
00000010: 6902 67c0 854c e18c 6438 ab18 c632 8333  i.g..L..d8...2.3
00000020: 1402 724a 11c2 482c 1489 6057 18cb 1cce  ..rJ..H,..`W....
00000030: 4051 6001 67a0 0847 c019 4170 5630 82a5  @Q`.g..G..ApV0..
00000040: e09b 5801 e319 1a22 580a 0145 f9a8 3c90  ..X...."X..E..<.
00000050: 4a00                                     J.

Try it online!

Bubblegum, 87 bytes

Written by @FryAmTheEggman, so I don't take credit for this.

00000000: e001 0700 4f5d 0034 9409 072b 9ed9 334a  ....O].4...+..3J
00000010: 2d4f 957c 30d4 5ae8 8bc7 1c12 f267 7c2c  -O.|0.Z......g|,
00000020: 47df 6d0b 6d45 b174 dcab 2da7 e97a ed9f  G.m.mE.t..-..z..
00000030: e772 808d f6c6 d93e c423 2b3c 378e 0a13  .r.....>.#+<7...
00000040: c57b 7a72 436d a362 6818 88d0 a495 4466  .{zrCm.bh.....Df
00000050: e336 dcfb ac00 00                        .6.....

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ 82 bytes, generated with zopfli. \$\endgroup\$ – ovs Mar 8 at 16:51
3
\$\begingroup\$

Jelly, 83 bytes

“Ø^ÞṠṠẠ'Ḣߥ»=⁶œṗ;11;“RcGEs436X578 ”µ“ƈ`¿øÐ⁽ḞÆCḊḋɲÑF×GÇz ⁸¦MƊ‘ד£¿Þ瑦5ŻṃµṚ“®Ɲ,»,K)Y

Try it online!

How?

Uses eighteen non-"iPhone " parts and constructs each line from a big-endian number in base eighteen, then prefixes each with "iPhone " and joins with newline characters.

The parts used are (comma separated):
Max, Plus, Pro, ,S,R,c,G,E,X,s,3,4,5,6,7,8,11

The mapping to the eighteen digits was chosen so that:

  1. the space character is a zero - allowing a single byte prepend-zero to make the first line
  2. no two digit "numbers" are greater than 255 - allowing encoding with code-page indices
  3. the three digit "numbers" (S,G,3; Plus,s,6; Max,S,X; and Max, Pro,11) are all exact multiples of five (and less than 1275) - allowing encoding with code-page indices, with post multiplication to acquire their full value
  4. the three words are adjacent and do not occupy digit one - allowing compression with a split-before spaces application

One such (1-indexed) ordering is:
S, Max, Plus, Pro,11,R,c,G,E,s,4,3,6,X,5,7,8,

As such the code works like so:

“...»=⁶œṗ;11;“...”µ“...‘ד£¿Þ瑦5ŻṃµṚ“®Ɲ,»,K)Y - Main Link: no arguments
“...»                                          - string = "S"+" Max"+" Plus"+" Pro"
      ⁶                                        - space character
     =                                         - equals? (vectorises)
       œṗ                                      - partition before truthy indices
         ;11                                   - concatenate 11
             “...”                             - list of characters "RcGEs436X578 "
            ;                                  - concatenate
                                               - giving our "digits" [1,2,...,17,0]
                  µ                            - start a new monadic chain
                   “...‘                       - list of code-page indices = [156, 96, 11, 29, 15, 141, 195, 13, 67, 193, 233, 163, 16, 70, 17, 71, 14, 122, 32, 136, 5, 77, 145]
                               ¦               - sparse application...
                                               - ...to indices:
                         “£¿Þç‘                -   code-page indices = [2, 11, 20, 23]
                        ×       5              - ...do: multiply by five -> [156, 480, 11, 29, 15, 141, 195, 13, 67, 193, 1165, 163, 16, 70, 17, 71, 14, 122, 32, 680, 5, 77, 725]
                                 Ż             - prepend a zero
                                  ṃ            - base-decompress (convert to base-18 using the "digits")
                                               -   e.g. 680 -> [2, 1, 14] -> [" Max",'S','X']
                                   µ        )  - for each:
                                    Ṛ          -   reverse it (e.g. [" Max",'S','X'] -> ['X','S'," Max"])
                                     “®Ɲ,»     -   string = "iPhone"
                                          ,    -   pair
                                           K   -   join with a space character
                                             Y - join with newline characters
                                               - implicit, smashing print
|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Keg, 129 127 bytes

‘1⊙‘®p`iPhone `:&
⑻3G
⑻3GS
⑻4
⑻4S
⑻5
⑻5c
⑻5s
⑻6
⑻6 ©p
⑻6s
⑻6s ©p
⑻SE
⑻7
⑻7 ©p
⑻8
⑻8 ©p
⑻X
⑻XR
⑻XS
⑻XS Max
⑻11
⑻11 Pro
⑻11 “∂⬭q≥

Try it online!

How's that for a submission! Simply using the register and a little bit of string compression + variables gives a kind of competitive answer.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Retina 0.8.2, 91 bytes


¶3G¶3GS¶4¶4S¶5¶5c¶5s¶6=¶6s=¶SE¶7=¶8=¶X¶XR¶XS!¶11¶11 Pro!
%(`^
iPhone 
!
¶$` Max
=
¶$` Plus

Try it online! Includes additional whitespace on the first line Explanation:


¶3G¶3GS¶4¶4S¶5¶5c¶5s¶6=¶6s=¶SE¶7=¶8=¶X¶XR¶XS!¶11¶11 Pro!

Insert the names of the models, but without iPhone, Max or Plus, which get added later.

%(`

Operate on each line individually.

^
iPhone 

Prefix iPhone to the line.

!
¶$` Max

If the line has a !, then duplicate it and append Max to the duplicate.

=
¶$` Plus

If the line has a =, then duplicate it and append Plus to the duplicate.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Bash, 109 bytes

printf %s\\n iPhone\ {,{3G,4}{,S},5{,c,s},6{,s}{,\ Plus},SE,{7,8}{,\ Plus},X{,R,S,S\ Max},11{,\ Pro{,\ Max}}}

Similar to the Zsh solution but some slight changes and some output leniency.

Try it online!

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Swift, 152 bytes

",3G,3GS,4,4S,5,5c,5s,6,6 Plus,6s,6s Plus,SE,7,7 Plus,8,8 Plus,X,XR,XS,XS Max,11,11 Pro,11 Pro Max".split(separator: ",").forEach{print("iPhone \($0)")}

Being related to iPhones, this needs an answer in Swift. Unfortunately Swift is woooordy. The most boring route is the shortest :/

Try it online

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Perl 5, 118 114 bytes

$_="3G3GS44S55c5s66-6s6s-SE77-88-XXRXSXS Max99Pro9Pro Max";s/-/ Plus/g;s/^|(\d|X|SE)/\niPhone $1/g;s/9/11 /g;print

Try it online!

This code is rather simple: in the string $_, it replaces "-" with " Plus". Then it cuts the string at every digit, "X" or "SE" and prefixes the matching part with a line break and "iPhone ". Finally, it replaces "9" by "11 ".

Attempting to replace " Max" or " Pro" with shorter symbols would not bring any benefits because the substitution would cost more characters.

Thanks to Weizel who allowed me to save 4 bytes by replacing the first "iPhone" in the string.

I assumed that the final newline was not necessary.

Note: I accidentally created two user accounts: user92654 and user92655. The former was the author of this answer but is probably lost forever. The latter has my correct name.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Last line is not required to end with a newline (-: \$\endgroup\$ – Redwolf Programs Mar 8 at 16:29
  • \$\begingroup\$ Add line beggining sarch in this substitution s/^|(\d|X|SE)/\niPhone $1/g. It allows to cut 'iPhone' in the main string and saves 4 bytes. \$\endgroup\$ – Weizel Mar 14 at 17:14
1
\$\begingroup\$

Stax, 100 bytes

Yay, I (finally) beat Zsh!

┌W○εRKW>◙≡D↨u^╬=Θs╜i^░δ#(\D╘i╗◄⌠╜`┌!║Æ♂∞╦J╘^╙üÜ°¢╠╣⌂ƒ♣↨←Bµ☻òK$▲,0fε▄PÉ↔ΓÅ▲s2îùvπ↑╛!╢╠♣=·F┴²C6µób└╢íf

Run and debug it

Explanation

  1. Repace all A's in the compressed string with "".
  2. Surround it with ".
  3. Evaluate the string.
  4. Wrap the output in a list.
  5. Map every item with a preceding iPhone. Print with a newline.
|improve this answer|||||
\$\endgroup\$
1
\$\begingroup\$

R, 175 178 bytes

cat(paste('iPhone',c('','3G','3GS','4','4S','5','5c','5s','6','6 Plus','6s','6s Plus','SE','7','7 Plus','8','8 Plus','X','XR','XS','XS Max','11','11 Pro','11 Pro Max')),sep='\n')

Try it online!

Manual is shorter than this programmatic take:

R, 231 bytes

r=rep;b='';m='Plus';cat(paste("iPhone",paste0(r(c(b,3:6,'SE',7:8,'X',11),c(1,2,2,3,3,1,2,2,4,3)),c(b,'G','GS',b,'S',b,'c','s',b,'s','s',r(b,6),'R','S','S',r(b,3))),c(r(b,9),m,b,m,b,b,m,b,m,r(b,3),'Max',b,'Pro','Pro Max')),sep='\n')

Try it online!

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ First answer doesn't seem to include the original iPhone? \$\endgroup\$ – Neil Mar 8 at 19:47
  • \$\begingroup\$ @Neil whoops, fixed thanks \$\endgroup\$ – John Mar 8 at 19:49
  • \$\begingroup\$ write and rbind save 3 bytes: Try it online! I may come back and tinker with the numerals a little more; I do think it can be shortened somehow. \$\endgroup\$ – Giuseppe Mar 9 at 21:41
  • \$\begingroup\$ note that write is just a wrapper to cat so it can sometimes be shorter if you know the options :-) \$\endgroup\$ – Giuseppe Mar 9 at 21:42
1
\$\begingroup\$

Ruby, 129 bytes

$><<"iPhone:3G:3GS:4:4S:5:5c:5s:6:6 Plus:6s:6s Plus:SE:7:7 Plus:8:8 Plus:X:XR:XS:XS Max:11:11 Pro:11 Pro Max".gsub(?:,"
iPhone ")

Try it online!

Uses the fact that strings can have newlines in (one byte), rather than \n (two bytes). Otherwise this is a simple replacement of a single-character string into iPhone

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

C (gcc), 162 bytes

f(i,n){n="3G3GS44S55c5s66 Plus6s6s PlusSE77 Plus88 plusXXRXSXS Max1111 Pro11 Pro Max";for(i=24;i--;)printf("iPhone %s\n",n+=strlen(n++));}

-1 byte thanks to Neil!
-45 bytes thanks to dzaima!

Try it online!

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Batch, 156 Bytes

@ECHO(iPhone&For %%A In (3G 3GS 4 4S 5 5c 5s 6 6s "6 Plus" "6s Plus" SE 7 "7 Plus" 8 "8 Plus" X XR XS "XS Max" 11 "11 Pro" "11 Pro Max")do @Echo(iPhone %%~A

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

C# (Visual C# Interactive Compiler), 123 bytes

Write("iPhone,3G,3GS,4,4S,5,5c,6,6 Plus,SE,7,7 Plus,8,8 Plus,X,XR,XS,XS Max,11,11 Pro,11 Pro Max".Replace(",","\niPhone "))

Try it online!

C# (Visual C# Interactive Compiler), 131 chars, 154 bytes

foreach(var x in"ȔДȥ͖˶ଇ˷೷աଈ	ଉ\0΀Ƞਠࡼၼ")WriteLine($"iPhone {x%16-1:0;X;.}"+" GS Max Pro Maxs PluscSER".Substring(x/16%32,x>>9));

Though it isn't the shortest, I invested quite a lot of effort and it would be a shame to just toss it all away.

Note: There is a null byte in the string, but I can't copy-paste it so it's represented by \0 in the code.

Try it online!

|improve this answer|||||
\$\endgroup\$
  • 5
    \$\begingroup\$ I think you could use Write instead of WriteLine. If a trailing newline is needed, a \n i still shorter than WriteLine \$\endgroup\$ – Stephan Bauer Mar 9 at 8:33
0
\$\begingroup\$

T-SQL, 145 bytes:

SELECT'iPhone '+value
FROM string_split(' -3G-3GS-4-4S-5-5c-5s-6-6 Plus-6s-6s Plus-SE-7-7 Plus-8-8 Plus-X-XR-XS-XS Max-11-11 Pro-11 Pro Max','-')

I did find a shorter version using a simple string replacement (128 bytes), but it's not quite as interesting, and it's not clear whether the preceding line break is allowed:

PRINT REPLACE('223G23GS2424S2525c25s2626 Plus26s26s Plus2SE2727 Plus2828 Plus2X2XR2XS2XS Max211211 Pro211 Pro Max',2,'
iPhone ')

I used the numeral (2) as the replacement character so I don't have to include another set of quotes.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Pyth, 103 bytes

j"
iPhone "[kk"3G""3GS"4"4S"5"5s""5c"6+6J" Plus"="6s"+GJ"SE"7+7J8+8~J" Max"\X"XR"K"XS"+KJ11="11 Pro"+bJ

Today I learned about the ~.

Try it online!

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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