title: The Curious Case of Steve Ballmer

text:
# Question
Title: The Curious Case of Steve Ballmer
Steve Ballmer is the ex-CEO of Microsoft, and in a recent article, claimed that he "still does not know what he did wrong with mobile".

As CodeProject's newsletter pointed out, "That article's title could be ended at so many spots and still be accurate".

Given no input, output the following:

```
Steve Ballmer still does not know.
Steve Ballmer still does not know what he did.
Steve Ballmer still does not know what he did wrong.
Steve Ballmer still does not know what he did wrong with mobile.

```

This must be outputted exactly as shown, and must be the only output of your program. You may include a single trailing newline.

This is so fewest bytes **in each language** wins

# Answer
# Python 3, ~~100~~ ~~99~~ ~~99~~ 97 bytes

-1 byte thanks to ovs
-1 byte thanks to Jonathan Allan
-1 byte thanks to Dennis

```
for i in b'!-3?':print('Steve Ballmer still does not know what he did wrong with mobile'[:i]+'.')

```

Try it online!
> 28 votes

# Answer
# 05AB1E, ~~50~~ ~~49~~ ~~45~~ 44 bytes

4 bytes saved with inspiration from Kevin's Java answer

```
„€Ž†©'–Ñ…€À€½ƒ§“mer„â‚à€–ƒ€“”™¸ïß”[Žì'.«=¨ð«

```

Try it online!

**Explanation**

```
„€Ž†©                                         # push "with mobile"
     '–Ñ                                      # push "wrong"
        …€À€½ƒ§                               # push "what he did"
               “mer„â‚à€–ƒ€“                  # push "mer still does not know"
                            ”™¸ïß”            # push "Steve Ball"
                                  [Ž          # loop until stack is empty
                                    ì         # prepend the top string to the 2nd top string
                                     '.«      # append a dot
                                        =     # print without popping
                                         ¨    # remove the dot
                                          ð«  # append a space

```
> 19 votes

# Answer
## Haskell, 96 bytes

```
(++".\n")=<<scanl(++)"Steve Ballmer still does not know"[" what he did"," wrong"," with mobile"]

```

Try it online!

`scanl` is like `foldl` (or reduce as it is called in other languages) except it returns a list of all intermediate results instead of just the final one. Each intermediate result is appended with `".\n"` and all of them are concatenated into a single string.
> 17 votes

# Answer
## Retina, ~~82~~ 75 bytes

*Thanks to Neil for saving 7 bytes.*

Byte count assumes ISO 8859-1 encoding.

```

Steve Ballmer still does not know what he did wrong with mobile.
 w
.¶$`$&

```

Try it online!

### Explanation

```

Steve Ballmer still does not know what he did wrong with mobile.

```

Initialise the working string to the full headline.

```
 w
.¶$`$&

```

As pointed out by Neil, all three truncations are made before a word starting with `w`, and there are no other words starting with `w`. So we match a space followed by a `w` to find the truncation points. At these points, we insert the following:

* , a period and a linefeed to truncate the sentence and begin a new one.
* `$``, the entire string in front of the match, so that the next sentence starts over from the beginning.
* `$&`, the space and `w` again, so that they're also part of the next sentence.

We don't need to match the `mobile` explicitly, because that will simply be what's left over on the third match.
> 16 votes

# Answer
# ///, 88 bytes

*8 bytes saved by @MartinEnder!*

```
/1/Steve Ballmer still does not know//2/1 what he did//3/2 wrong/1.
2.
3.
3 with mobile.

```

Try it online!
> 9 votes

# Answer
# PHP, 104 95 94 bytes

```
<?=$a="Steve Ballmer still does not know",$a=".
$a what he did",$a.=" wrong",$a?> with mobile.

```
> 9 votes

# Answer
# Java 8, ~~127~~ 126 bytes

```
()->{String t="Steve Ballmer still does not know",d=".\n";return t+d+(t+=" what he did")+d+(t+=" wrong")+d+t+" with mobile.";}

```

-1 byte thanks to *@KonstantinCh*.

Try it here.
> 7 votes

# Answer
# 05AB1E, 46 bytes

```
”™¸ïßme”“r„â‚à€–ƒ€“«…€À€½ƒ§'–Ñ„€Ž†©).pvyðý'.«»

```

Try it online!
> 7 votes

# Answer
# C (gcc), 112 bytes

```
f(){printf("%.33s.\n%1$.45s.\n%1$s.\n%1$s with mobile.","Steve Ballmer still does not know what he did wrong");}

```

Try it online!
> 7 votes

# Answer
# Jelly, ~~52~~ 46 bytes

```
“ṬċḌ)⁹œḃṣ⁷Ṅḋ%W3Œƭ;ḷẓ“£Ṿ⁴'Þḣ~ẉ“¥Ị)“Ṡ8gÐ/»;\p”.Y

```

Credits for `ṬċḌ)⁹œḃṣ⁷Ṅḋ%W3Œƭ;ḷẓ` go to @EriktheOutgolfer, who used it in his answer.

Try it online!

### How it works

The lion share of the work is done by Jelly's dictionary compression here.

```
ṬċḌ)⁹œḃṣ⁷Ṅḋ%W3Œƭ;ḷẓ

```

encodes

```
Steve| Ball|mer| still| do|es| no|t| know

```

there `|` indicates boundaries between words that where fetched from the dictionary and strings that were encoded character by character (`mer`, `es`, and `t`).

Similarly, `£Ṿ⁴'Þḣ~ẉ` encodes `what| he| did` (surprisingly, `he` does *not* come from the dictionary), `¥Ị)` encodes `wrong`, and `Ṡ8gÐ/` encodes `with| mobile`.

```
“ṬċḌ)⁹œḃṣ⁷Ṅḋ%W3Œƭ;ḷẓ“£Ṿ⁴'Þḣ~ẉ“¥Ị)“Ṡ8gÐ/»

```

thus yields the string array

```
“Steve Ballmer still does not know“ what he did“ wrong“ with mobile”

```

`;\` cumulatively reduces by concatenation, building the phrases on each line.

Finally, `p”.` computes the Cartesian product of these phrases and the dot character, and `Y` separates the resulting sentences by linefeeds.
> 6 votes

# Answer
# JavaScript (ES6), 102 bytes

```
_=>(s="Steve Ballmer still does not know")+`.
${s+=" what he did"}.
${s+=" wrong"}.
${s} with mobile.`

```

---

## Try it

```
o.innerText=(
_=>(s="Steve Ballmer still does not know")+`.
${s+=" what he did"}.
${s+=" wrong"}.
${s} with mobile.`
)()
```

```
<pre id=o>
```
> 6 votes

# Answer
# Retina, ~~95~~ 86 bytes

```
:`
Steve Ballmer still does not know.
:`.$
 what he did.
:`.$
 wrong.
.$
 with mobile.

```

Try it online! Edit: Saved 9 bytes by switching from outputting parts of the whole string to building up the string in pieces. The `:`` is needed on the first three stages to make them output.
> 5 votes

# Answer
# C (gcc), ~~124~~ 122 bytes

```
#define A"Steve Ballmer still does not know"
#define B".\n"A" what he did"
f(){puts(A B B" wrong"B" wrong with mobile.");}

```

Try it online!
> 5 votes

# Answer
# C#, ~~158~~ ~~128~~ ~~120~~ 114 bytes

```
()=>{var s="Steve Ballmer still does not know";return s+$@".
{s+=" what he did"}.
{s+=" wrong"}.
 with mobile.";};

```

*Saved 30 bytes thanks to @KevinCruijssen.*
*Saved 6 bytes thanks to @Shaggy.*

---

Version using sub-stringing for 120 bytes:

```
s=n=>"Steve Ballmer still does not know what he did wrong with mobile".Substring(0,n)+".\n";()=>s(33)+s(45)+s(51)+s(63);

```

Version borrowed from @KevinCruijssen for 128 bytes:

```
()=>{string t="Steve Ballmer still does not know",d=".\n";return t+d+(t+=" what he did")+d+(t+=" wrong")+d+t+" with mobile"+d;};

```

Version using looping for 158 bytes:

```
()=>{var r="";for(int i=0;++i<5;)r+=$"Steve Ballmer still does not know{(i>1?$" what he did{(i>2?$" wrong{(i>3?" with mobile":"")}":"")}":"")}.\n";return r;};

```

Simple approach using ternary statements to in a loop to append the new parts onto the string each time.
> 4 votes

# Answer
# Bash, ~~111~~ ~~109~~ 107 bytes

```
a=(Steve Ballmer still does not know "what he did" wrong with\ mobile)
for i in {6..9};{ echo ${a[@]::i}.;}

```

Try it online!
> 3 votes

# Answer
# Japt, ~~70~~ ~~68~~ ~~65~~ ~~61~~ ~~60~~ 59 bytes

Contains a few characters that won't display here; follow the link below to see the full code.

```
`Sve Ba¥´r Ð]l º not know
 Ø  ¹d
 Ùg
 ØP ¶ßè`£'.iP±X}R

```

Try it online

* ~~3~~ 4 bytes saved thanks to ETH, plus another 4 with some prompting.

---

## Explanation

Everything between the 2 backticks is a compressed string of the following:

```
Steve Ballmer still does not know
 what he did
 wrong
 with mobile

```

```
`...`             :Decompress the string.
     £       }R   :Map over the each line X in the string
         P±X      :   Append X to P (initially the empty string)
      '.i         :   Prepend that to the string "."

```
> 3 votes

# Answer
# Fission, ~~299~~ ~~291~~ 269 bytes

```
MN"."                             ]              ]        ]
                                  W$]            W$$]     W$$$]
R"Steve Ballmer still does not know"%[" what he did"%[" wrong"%[" with mobile.";
                                    [W              [W        [W

```

Try it online!

Finally a 2D language I understand!

### Explanation

Program spawns an atom with 1 mass and 0 energy (a `1:0` atom)at the `R` on line 3, and begins moving to the right.

`"Steve Ballmer still does not know"` prints each character.

`%` moves the atom up if it has 0 energy, or decrements it's energy and moves it down.

`]` moves the atom to the left, `$` increments the atom's energy, `W` moves the atom up.

Once the atom is on the top row, it moves to the left, until it reaches `"."`, which prints a period, `N`, which prints a newline, and finally `M`, which moves the atom down to the `R` again, which subsequently moves the atom to the right.

Each loop the atom's energy is one higher, meaning it will pass through one more `%`. After the 4th loop it reaches the `;` at the end of the third line, which destroys the atom. The program terminates once all atoms are destroyed.
> 3 votes

# Answer
# Vim, 79 keystrokes

```
iSteve Ballmer still does not know.<CR><C-x><C-l><Backspace> what he did.<CR><C-x><C-l><Backspace> wrong.<CR><C-x><C-l><Left> with mobile

```

`<C-x><C-l>` auto-completes with the previous line. Alternatively you can replace every occurrence of `<CR><C-x><C-l>` with `<Esc>o<C-a>`
> 3 votes

# Answer
# CJam, 79 bytes

```
4{)"Steve Ballmer still does not know
hat he did
rong
ith mobile"N/<" w"*'.+N}%

```

Try it online!
> 3 votes

# Answer
# Ruby, 94 bytes

```
"!-3Z".bytes{|i|puts"Steve Ballmer still does not know what he did wrong with mobile"[0,i]+?.}

```

Iterates through the 4 characters in the first string, converting each to its ascii value `n` and outputting the first `n` characters of the second string each time. It really does not matter what the last character of the first string is, so long as its ascii value is equal or greater than the length of the second string.
> 3 votes

# Answer
# Nim, 100 bytes

```
for i in " ,2>":echo "Steve Ballmer still does not know what he did wrong with mobile"[0..i.int],"."

```

here the same in more readable code:

```
const str = "Steve Ballmer still does not know what he did wrong with mobile"

for i in [32, 44, 50, 62]:
  echo(str[0..i], ".")

```

The language has string slicing and inclusive upper bounds. The rest should explain itself if you know programming.
> 3 votes

# Answer
# PHP, 116 Bytes

```
for(;$i<4;)echo"Steve Ballmer still does not know",["",$t=" what he did",$t.=" wrong","$t with mobile"][+$i++],".

```

";

Try it online!
> 2 votes

# Answer
# SOGL, 42 bytes

```
⁹⁴<>‘υG‘Γω/w¹‘O‛Æw▓½0H(æ█◄K∆2Ξgh‘4{Tļ.@+;+

```

Explanation:

```
..‘                    push "with mobile"
   ..‘                 push "wrong"
      ..‘              push "what he did"
         ..‘           push "Steve Ballmer still does not know"
            4{         4 times do
              T          output, not popping the top of stack
               ļ.        output "."
                 @+      append a space to the top thing in stack
                   ;+    reverse add (adding the next part to the top thing in stack)

```
> 2 votes

# Answer
# Jelly, 49 bytes

```
“ṬċḌ)⁹œḃṣ⁷Ṅḋ%W3Œƭ;ḷẓ“¡=~Ṃ©N|ȯ“¡ṭṂ“CṬṀWỌ»ḣJK;¥€”.Y

```

Try it online!
> 2 votes

# Answer
# Go, ~~140~~ 127 bytes

```
import."fmt"
func f(){for _,i:=range"!-3?"{Println("Steve Ballmer still does not know what he did wrong with mobile"[:i]+".")}}

```

Try it online!
> 2 votes

# Answer
# Sed, 96

```
s/^/Steve Ballmer still does not know./p
s/\./ what he did./p
s/\./ wrong./p
s/\./ with mobile./

```

Try it online.

Implicit newline input given, as per this meta-question.
> 2 votes

# Answer
# Bash, ~~92~~ 91 bytes

```
printf 'Steve Ballmer still does not %s.
' know{,' what he did'{,\ wrong{,\ with\ mobile}}}

```

Try it online!
> 2 votes

# Answer
JavaScript (ES6, no browser dependencies) 154 Bytes

```
(s='Steve Ballmer still does not know what he did wrong with mobile.')=>{
  let l=s.slice.bind(s)
  return `${l(0,33).\n${l(0,45)}.\n${l(0,51)}.\n${s}`
}

```

The other ES6 solution requires (and doesn't account for) the use of html and html element APIs.
> 2 votes

# Answer
# C (gcc), ~~113~~ 112 bytes

-1 bytes thanks to ceilingcat.

```
f(c){for(c=0;write(1,"Steve Ballmer still does not know what he did wrong with mobile","!-3?"[c++]);puts("."));}

```

Try it online!
> 2 votes

# Answer
# APL (Dyalog Unicode), 81 bytesSBCS

```
↑1⌽¨,\'.Steve Ballmer still does not know' ' what he did' ' wrong' ' with mobile'

```

Try it online!

One the very right, we have a list of strings.

`,\` cumulative concatenation

`1⌽¨` cyclically rotate each one step left (puts the periods at the ends)

mix the list of strings into a character matrix
> 2 votes

# Answer
# Charcoal, ~~71~~ 69 bytes

```
Ａ⟦⟧βＦ⪪”↓/‘ZQ≔'Ｗε}÷＆’/↗∧μ~⎇²~ηρπ‖¢β\`σuσＩ⌀δ#″:§▶¬QγγＱＺ–” w⁺⪫⊞Ｏβι w¦.¶

```

Try it online! Link is to verbose version of code, with some separators omitted because deverbosifier can't do it automatically. This is basically a port of @KevinCruijssen's answer.
> 1 votes

# Answer
# Mathematica, ~~108~~ 104 bytes

```
"Steve Ballmer still does not know what he did wrong with mobile"~StringTake~#~Print~"."&/@{33,45,51,63}

```

Try it online!

*-4 bytes from Martin*
> 1 votes

# Answer
# \>\<\>, 135 bytes

```
".wonk ton seod llits remllaB evetS"\
l?!\o99+2*1./"h tahw  "32p10pao     \
52p\".did e"/"   "53p33p
  /\".gnorw"/
1p/\".elibom htiw;"3

```

This basically goes through the string, prints then replaces the fullstop and conditionals with spaces to keep moving along the code.

It may be best to visualise it using the below \>\<\> pond link;

\>\<\> pond!

Try it online!
> 1 votes

# Answer
# Powershell, 101 bytes

```
0..3|%{-join("Steve Ballmer still does not know"," what he did"," wrong"," with mobile")[0..$_]+"."}

```
> 1 votes

# Answer
## \>\<\>, 126 bytes

```
 \"elibom htiw \"10p";"15p
  "gnorw  "10p
  "did eh tahw \"11p
 \"wonk ton seod llits remllaB evetS\"12p04.
  l?!vo
oo00.>a"."

```
> 1 votes

# Answer
# Octave, 126 bytes

Two approaches, same length:

```
printf('%s.\n',(s={'Steve Ballmer still does not know',' what he did',' wrong',' with mobile'}){1},[s{1:2}],[s{1:3}],[s{1:4}])

```

Try it online!

```
s={'Steve Ballmer still does not know',' what he did',' wrong',' with mobile'};printf('%s.\n',s{1},[s{1:2}],[s{1:3}],[s{1:4}])

```

Try it online!

I could make it 21 bytes shorter, if I steal Rod's approach, but that's no fun.

```
for i=[33,45,51,63],disp(['Steve Ballmer still does not know what he did wrong with mobile'(1:i),46]),end

```
> 1 votes

# Answer
# MATLAB / Octave - 120 bytes

```
a=[];s={'Steve Ballmer still does not know',' what he did',' wrong',' with mobile'};for i=s,a=[a i{1}];disp([a '.']);end

```

Logic is to start off with an empty string, then we have a cell array that contains the base string as the first element followed by the additions for the other elements. Note that each additional component has a space prepended. We then iterate through the cell array, and at each iteration we concatenate with a component and display the string to the user adding a period at the end.

We get:

```
>> a=[];s={'Steve Ballmer still does not know',' what he did',' wrong',' with mobile'};for i=s,a=[a i{1}];disp([a '.']);end
Steve Ballmer still does not know.
Steve Ballmer still does not know what he did.
Steve Ballmer still does not know what he did wrong.
Steve Ballmer still does not know what he did wrong with mobile.

```

# Try it online!

http://www.tutorialspoint.com/execute\_octave\_online.php?PID=0Bw\_CjBb95KQMRGZoWFJ1Z3NaNTQ
> 1 votes

# Answer
# Perl 6, 90 bytes

```
"$_.".say for [\,] 'Steve Ballmer still does not know','what he did','wrong','with mobile'

```
> 1 votes

# Answer
**Perl**, 98 bytes

```
for('Steve Ballmer still does not know',' what he did',' wrong',' with mobile'){$s.=$_;say "$s."}

```

(Run via perl -M5.10.1 ... so that "say" will be recognized)
> 1 votes

# Answer
# Retina, 82 bytes

```

ABCC with mobile.
C
B wrong
B
.¶A what he did
A
Steve Ballmer still does not know

```

Try it online!
> 1 votes

# Answer
# Rust, 145 bytes

```
||{for i in b"!-3?"{println!("{}.",&"Steve Ballmer still does not know what he did wrong with mobile".to_owned().get(..*i as usize).unwrap());}};

```

Inspired by this solution.

Try it online!
> 1 votes

# Answer
# Julia 0.6, 99 bytes

Generate the 4 desired strings with `cumprod` (`*` is string concatenation). Tack on a period with a broadcasted string concatenation `.*` and print all elements in the list with a broadcasted call `println.`.

```
println.(cumprod(["Steve Balmer still does not know"," what he did"," wrong"," with mobile"]).*".")

```

Try it online!
> 1 votes

# Answer
# Unix TMG, 145 bytes

```
p:parse(b)b:=(1){<Steve Ballmer still does not know>$1<.>*}=(1){1({< what he did>$1})}=(1){1({< wrong>$1})}={3({})2({})1({})1({< with mobile>})};

```

With some white spaces:

```
p:parse(b)
b:=(1){<Steve Ballmer still does not know>$1<.>*}
  =(1){1({< what he did>$1})}
  =(1){1({< wrong>$1})}
  ={3({}) 2({}) 1({}) 1({< with mobile>})};

```
> 1 votes

# Answer
# 05AB1E, 43 bytes

```
”™¸ïßmer”“„â‚à€–ƒ€“…€À€½ƒ§'–Ñ„€Ž†©)η¦ðý'.«»

```

Try it online!
> 1 votes

# Answer
# Deadfish~, 1507 bytes

```
{{i}dd}iiic{iii}iiic{d}dddddc{ii}dddc{dd}iiic{{d}iii}ic{iii}iiiic{iii}ic{i}iccic{d}iic{i}iiic{{d}ii}ddc{{i}dd}iiicic{d}dciiicc{{d}iii}ddddddc{{i}ddd}ddc{i}ic{d}c{i}iiiic{{d}ii}dddc{{i}dd}ddciciiiiic{{d}ii}ddddc{{i}ddd}iiiiiciiicic{i}ddc{{d}iii}dddc{ddd}ddddddc{{i}ddd}iiic{iii}iiic{d}dddddc{ii}dddc{dd}iiic{{d}iii}ic{iii}iiiic{iii}ic{i}iccic{d}iic{i}iiic{{d}ii}ddc{{i}dd}iiicic{d}dciiicc{{d}iii}ddddddc{{i}ddd}ddc{i}ic{d}c{i}iiiic{{d}ii}dddc{{i}dd}ddciciiiiic{{d}ii}ddddc{{i}ddd}iiiiiciiicic{i}ddc{{d}i}iiic{{i}d}dddc{d}dddddc{d}iiic{ii}dc{{d}ii}ddddc{{i}ddd}iicdddc{{d}iii}ic{{i}ddd}ddciiiiicdddddc{ddddd}ddddc{ddd}ddddddc{{i}ddd}iiic{iii}iiic{d}dddddc{ii}dddc{dd}iiic{{d}iii}ic{iii}iiiic{iii}ic{i}iccic{d}iic{i}iiic{{d}ii}ddc{{i}dd}iiicic{d}dciiicc{{d}iii}ddddddc{{i}ddd}ddc{i}ic{d}c{i}iiiic{{d}ii}dddc{{i}dd}ddciciiiiic{{d}ii}ddddc{{i}ddd}iiiiiciiicic{i}ddc{{d}i}iiic{{i}d}dddc{d}dddddc{d}iiic{ii}dc{{d}ii}ddddc{{i}ddd}iicdddc{{d}iii}ic{{i}ddd}ddciiiiicdddddc{{d}iii}iic{{i}d}dddcdddddcdddcdc{d}iiic{dddddd}iiic{ddd}ddddddc{{i}ddd}iiic{iii}iiic{d}dddddc{ii}dddc{dd}iiic{{d}iii}ic{iii}iiiic{iii}ic{i}iccic{d}iic{i}iiic{{d}ii}ddc{{i}dd}iiicic{d}dciiicc{{d}iii}ddddddc{{i}ddd}ddc{i}ic{d}c{i}iiiic{{d}ii}dddc{{i}dd}ddciciiiiic{{d}ii}ddddc{{i}ddd}iiiiiciiicic{i}ddc{{d}i}iiic{{i}d}dddc{d}dddddc{d}iiic{ii}dc{{d}ii}ddddc{{i}ddd}iicdddc{{d}iii}ic{{i}ddd}ddciiiiicdddddc{{d}iii}iic{{i}d}dddcdddddcdddcdc{d}iiic{{d}iii}dc{{i}d}dddc{d}ddddc{i}ic{d}ddc{{d}iii}ddc{{i}dd}dddciic{d}dddc{i}dddciiic{d}iiic{ddddd}dddddc

```

Try it online!
> 1 votes

# Answer
# Stax, ~~38~~ 37 bytes

```
¥úσÆ}≡ër↑←â .M)↨\7╒°1╕J°Y¥₧iC+F.ifd┼$

```

Run and debug it
> 1 votes

# Answer
# Braingolf, ~~139~~ 108 bytes

```
"Steve Ballmer still does not know
."VRMM!&@v!&@R" what he did"!&@v!&@R" wrong"!&@v!&@R " with mobile"&@v&@R

```
> 0 votes

# Answer
## QBIC, 95 bytes

```
?@Steve Ballmer still does not know`+@.`?A+@ what he did`+B?A+C+@ wrong`+B?A+C+D+@ with mobile.

```

This makes every part of the output into a separate string literal, where 'A$' holds `Steve Ballmer still does not know`, and then repeatedly prints 'A$', followed by 'B$' (a period) or the next literal.

Chopping the original string into substrings takes just a byte more (96 bytes):

```
?B,34|+@.`?_sB,46|+A?_sB,52|+A?@Steve Ballmer still does not know what he did wrong with mobile.

```

Here, 'B$' holds the entire thing, and parts of it are subsequently shown using substring ('\_s...|\`). Note that 'A$' now holds the period. This allows the full sentence to be moved to the end of the program, so we can drop the closing backtick.
> 0 votes

# Answer
# Tcl, 115 bytes

```
puts [set S "Steve Ballmer still does not know"].\n[set h "$S what he did"].\n[set w $h\ wrong].\n$w\ with\ mobile.

```

Try it online!
> 0 votes

# Answer
## REXX, 123 bytes

```
s='Steve Ballmer still does not know what he did wrong with mobile'
w=6 9 10 12
do i=1 to 4
say subword(s,1,word(w,i)).
end

```
> 0 votes

# Answer
# MSX-BASIC, 123 bytes

```
1s$="Steve Ballmer still does not know what he did wrong with mobile":forx=1to4:readl:?left$(s$,l);".":next:data33,45,51,64

```
> 0 votes

# Answer
# Clojure(script), 122 bytes

```
(print(apply str(interpose"\n"(reductions str"Steve Ballmer still does not know"[" what he did"" wrong"" with mobile"]))))

```
> 0 votes

# Answer
# Pyth - 98

```
K." w!ZÑ`±§ÑÔæý^àV;KæM×ü1A_4ÿ"J" what he did"A," wrong"" with mobile"=N\.+KN++KJNs[KJGN)s[KJGHN

```

The first string is a packed string
> 0 votes

# Answer
# Fission 2, ~~109~~ 107 bytes

```
R"Steve Ballmer still does not know"J2~~$$" what he did"J1~$" wrong"J0" with mobile."*
/0C+$$J1C+$$J2C@"."N

```

Try it online!

I was a little annoyed at the amount of whitespace in the previous Fission answer, so I decided to see if I could make it smaller.
> 0 votes

# Answer
# GolfScript, 82 bytes

```
4,{"Steve Ballmer still does not know
 what he did
 wrong
 with mobile"n/\)<"."n}/

```

This can be considered "19 bytes" since that's the actual code.

`4,{"nnn"s/\)<"."n}/` are all the excess characters that actually make the code itself.

Try it online!

Very happy with this. Splits along newlines, then adds the next element one at a time with a period until everything is printed. Lovely.

Explanation!

```
First of all, we have to acknowledge the string.
It's split along newlines right where we want the breaks to be.
This will be important.

For the explanation, our string is S.

4,{Sn/\)<"."n}/
4,              #Make an array [0 1 2 3]
  {          }/ #For each of those elements...
   Sn/          #Take our string and split it along newlines
      \         #Move our number-element to the front of the stack
       )        #Increase it by 1
        <       #Look at a number of parts of the split string eq. to that num
         "."    #Put a period after
            n   #Newline
                #Implicit "print the stack" at the end of creation. No quotes.

```
> 0 votes

# Answer
# Python 3, 97 bytes

```
["Steve Ballmer still does not know what he did wrong with mobile"[:i]+"."for i in [33,45,51,63]]

```

Try it online!
> 0 votes

# Answer
# Vyxal `oj`, ~~124~~ ~~58~~ 50 bytes

```
`æ⁽ æ∴Ǐ₇ ⟑∵ ƛ∪ λ† ¬λ λ⟨ he ¬ṙ ↔Ẏ λ» ∨⁺`»→⇩d»₆τẎ\.+

```

Try it Online!
> 0 votes

---
Tags: code-golf, string, kolmogorov-complexity
---


title: Old Spanish alphabetical order

text:
# Question
Title: Old Spanish alphabetical order
Before 1994, Spanish dictionaries used alphabetical order with a peculiarity: digraphs `ll` and `ch` were considered as if they were single letters. `ch` immediately followed `c` , and `ll` immediately followed `l`. Adding the letter `ñ`, which follows `n` in Spanish, the order was then:

```
a, b, c, ch, d, e, f, g, h, i, j, k, l, ll, m, n, ñ, o, p, q, r, s, t, u, v, w, x, y, z

```

Since 1994 `ll` and `ch` are considered as groups of two letters (`l`,`l` and `c`,`h` respectively), and thus alphabetical order is the same as in English, with the exception of the letter `ñ`.

The old order was definitely more *interesting*.

## The challenge

Input a list of zero or more words and output the list sorted according to the old Spanish alphabetical order. Sorting is between words (not between letters within a word). That is, words are atomic, and the output will contain the same words in a possibly different order.

To simplify, we will not consider letter `ñ`, or accented vowels `á`, `é`, `í`, `ó`, `ú`, or uppercase letters. Each word will be a sequence of one or more characters taken from the inclusive range from ASCII 97 (`a`) through ASCII 122 (`z`).

If there are more than two `l` letters in a row, they should be grouped left to right. That is, `lll` is `ll` and then `l` (not `l` and then `ll`).

Input format can be: words separated by spaces, by newlines, or any convenient character. Words may be surrounded by quotation marks or not, at your choice. A list or array of words is also acceptable. Any reasonable format is valid; just state it in your answer.

In a similar way, output will be any reasonable format (not necessarily the same as the input).

Code golf, shortest wins.

## Test cases

In the following examples words are separated by spaces. First line is input, second is output:

```
llama coche luego cocina caldo callar calma
caldo calma callar cocina coche luego llama

cuchara cuchillo cubiertos cuco cueva
cubiertos cuco cuchara cuchillo cueva

```

"Words" can be single letters too:

```
b c a ch ll m l n
a b c ch l ll m n

```

or unlikely combinations (remember the rule that `l`'s are grouped left to right):

```
lll llc llz llll lllz
llc lll lllz llll llz

```

An empty input should give an empty output:

```

```

Of course, this order can be applied to other languages as well:

```
chiaro diventare cucchiaio
cucchiaio chiaro diventare

all alternative almond at ally a amber
a almond alternative all ally amber at

```

# Answer
# Pyth, ~~14~~ 13 bytes

**Update:** saw this got accepted and noticed a trivial 1 byte golf. Whoops.

```
:D"ll|ch|."1Q

```

Try it online. Test suite.

For each word, find all non-overlapping matches for the regex `ll|ch|.`. This splits the word into the "letters". Then, just sort the words by the splitted lists.
> 10 votes

# Answer
# Vyxal `a`, 15 bytes

```
µ‛ch‛c~V‛ll‛l~V

```

Takes input as words separated by newlines, outputs a list.
Try it Online!

```
µ‛ch‛c~V‛ll‛l~V    # Full program
µ                  # Sort (implicit) input by key:
       V           # Replace...
 ‛ch               # `ch`...
    ‛c~            # with `c~`
              V    # Replace...
        ‛ll        # `ll`...
           ‛l~     # with `l~`

```
> 6 votes

# Answer
# PowerShell, ~~46~~ ~~44~~ ~~51~~ 50 bytes

```
$args|sort @{e={$_-replace'(?=ch|ll)(.).','$1Α'}}

```

The `Α` character is the Greek letter alpha which in comes after all Latin letters in PowerShell's default sort order (at least on my machine, I'm not sure if it's different in other locales). It's counted as 2 bytes in UTF8 encoding.

Example usage, assuming this string is saved in a file named `es-sort.ps1`:

```
> es-sort.ps1 'lzego' 'luego' 'llama'

luego
lzego
llama

```
> 4 votes

# Answer
# Mathematica, 81 bytes

```
StringReplace[Sort@StringReplace[#,"ch"->"cZ","ll"->"lZ"],"cZ"->"ch","lZ"->"ll"]&

```

Same approach as TimmyD's answer.
> 2 votes

# Answer
# Jelly, ~~16~~ ~~15~~ 12 bytes

```
eƬ“ch“ll”µƝÞ

```

Try it online!

Previous 12-byter sorted leading digraphs incorrectly, since the index took precedence over the actual character data.

```
           Þ    Sort the input by:
         µƝ     for each pair of adjacent characters as a list,
 Ƭ              apply while unique (collecting all results):
e               is it an element of
  “ch“ll”       ['ch', 'll']?

```

`eƬ2ƤÞ“ch“ll”` also works for 12 bytes, doing precisely the same thing.
> 2 votes

# Answer
# 05AB1E, 15 bytes

```
Σ„ch„c~:„ll„l~:

```

I/O as a list of strings.

Very straight-forward approach, but I'm unable to find anything shorter (thus far).

Try it online or verify all test cases.

**Explanation:**

```
Σ         # Sort the (implicit) input-list of strings by:
 „ch„c~:  #  Replace all "ch" with "c~"
 „ll„l~:  #  Replace all "ll" with "l~"
          #  (and then sort it by default lexicographical order)
          # (after which the sorted list is output implicitly)

```
> 2 votes

# Answer
# Python 2, ~~128~~ 116 bytes

```
lambda p:map(''.join,sorted([{'!':'ll','?':'ch'}.get(c,c)for c in w.replace('ll','!').replace('ch','?')]for w in p))

```

I still feel like there's definitely room for improvement here.
> 1 votes

# Answer
# Javascript, 95 bytes

```
s=>s.map(a=>a.replace(/ll|ch/g,m=>m[0]+'~')).sort().map(a=>a.replace(/.~/g,m=>m>'d'?'ll':'ch'))

```
> 1 votes

# Answer
# Perl, 40 bytes

Includes +1 for `-p`

Run with the list of words on STDIN:

```
perl -p spanisort.pl <<< "llama coche luego cocina caldo callar calma"

```

`spanisort.pl`

```
s/ll|ch|./\u$&/g;$_="\L@{[sort split]}"

```
> 1 votes

# Answer
# Ruby, 42 bytes

```
->a{a.sort_by{_1.gsub(/ll|ch/){$&[0]+?|}}}

```

Attempt This Online!
> 1 votes

---
Tags: code-golf, string, sorting
---


title: Yes, of course I'm an adult!

text:
# Question
Title: Yes, of course I'm an adult!
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.
In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.

## Input:

Your program/function accepts a positive integer or decimal.

## Output:

* Is the input an integer `>= 18`? Simply print the input.
* Is the input an integer `0-17`? Print `18`.
* Is the input a decimal `>= 1.4`? Simply print the input.
* Is the input a decimal `0.0-1.4`? Print `1.4`.

# Challenge rules:

* Assume the input will always be in the range of `0-122` (oldest woman ever was 122) or `0.0-2.72` (tallest man ever was 2.72).
* You are allowed to take the input as a String, object, or anything else you prefer.
* The decimal inputs will never have more than three decimal places after the decimal point.
* `2` or `2.` both aren't valid outputs for `2.0`. You are free to output `2.00` or `2.000` instead of `2.0` however.
Just like the input the output will never have more than three decimal places after the point.

## General rules:

* This is , so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
* Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
* Default Loopholes are forbidden.
* If possible, please add a link with a test for your code.
* Also, please add an explanation if necessary.

## Test cases:

```
0      ->  18
1      ->  18
2      ->  18
12     ->  18
18     ->  18
43     ->  43
115    ->  115
122    ->  122

0.0    ->  1.4
1.04   ->  1.4
1.225  ->  1.4
1.399  ->  1.4
1.4    ->  1.4
1.74   ->  1.74
2.0    ->  2.0
2.72   ->  2.72

```

# Answer
> 4 votes
# Convex, 9 bytes

```
_1ÛI1.4?»

```

Try it online!

# Answer
> 43 votes
# Python 2.7, 34 bytes

```
lambda x:max(x,[18,1.4]['.'in`x`])

```

# Answer
> 15 votes
# 05AB1E, ~~13~~ 11 bytes

Uses CP-1252 encoding.

```
ÐîQ18*14T/M

```

**Explanation**

```
Ð             # triplicate input
 î            # round up
  Q           # check for equality
   18*        # multiply 18 by this (18 if input is int, else 0)
      14T/    # push 14 / 10
          M   # take max of stack (input and 1.4 or 18)

```

Try it online

# Answer
> 15 votes
# JavaScript (ES6), 27 ~~31~~

Input taken as a string. To check if the input value has decimals, it's appended to itself: if there is no decimal point the result is still a valid number, else it's not. To recognize a valid number (including 0), I use division as in javascript `1/n` is numeric and not 0 for any numeric `n` (eventually the value is `Infinity` for `n==0`), else it's `NaN`

```
x=>x<(y=1/(x+x)?18:1.4)?y:x

```

**Test**

```
f=
x=>x<(y=1/(x+x)?18:1.4)?y:x

;[
 ['0', '18' ],['1', '18' ],['2', '18' ],['12', '18' ],['18', '18' ],['43', '43' ],['115', '115'], ['122', '122' ]
,['0.0', '1.4'],['1.0', '1.4'],['1.04', '1.4'],['1.225', '1.4'],['1.399', '1.4'],['1.4', '1.4'],['1.74', '1.74'],['2.0', '2.0'],['2.72', '2.72']
].forEach(t=>{
  var i=t[0],k=t[1],r=f(i)
  console.log(i,k,r,k==r?'OK':'KO')
})
```

*My prev (wrong) solution:*

Taking input as a number, you can use remainder operator `%` to check if the number is integer.

```
x=>x<(y=x%1?1.4:18)?y:x

```

or

```
x=>Math.max(x,x%1?1.4:18)

```

But this does not work as the challenge request to discriminate between, say, `2` and `2.0` and that's the same number. So it's not possibile to get the input as a number

# Answer
> 8 votes
# Java 8, ~~90~~ ~~61~~ 57 bytes

```
i->(i+"").contains(".")?(float)i<1.4?1.4:i:(int)i<18?18:i

```

-4 bytes returning `Object` instead of `String`; and some additional bytes converting Java 7 to 8.
-4 byte taking the input as `Object` instead of `String` as well.

**Explanation:**

Try it here.

```
i->                      // Method with Object as both parameter and return-type
  (i+"").contains(".")?  //  If the input as String contains a dot:
   (float)i<1.4?         //   If the input is a float below 1.4:
    1.4                  //    Return double 1.4
   :                     //   Else:
    i                    //    Return the input-float as is
  :(int)i<18?            //  Else if the input is an integer below 18:
   18                    //   Return integer 18
  :                      //  Else:
   i                     //   Return the input-integer as is

```

# Answer
> 7 votes
# PHP, 40 Bytes

modified by @user59178 Thank You

```
<?=max(is_int(0+$i=$argv[1])?18:1.4,$i);

```

PHP, 42 Bytes first Version

```
<?=max(strpos($i=$argv[1],".")?1.4:18,$i);

```

# Answer
> 7 votes
# Pyth, 14 bytes

```
eS,@,18h.4}\.`

```

Try it online.

# Answer
> 6 votes
# Perl, ~~29~~ 27 bytes

Includes +2 for `-lp`

Give input on STDIN

```
adult.pl <<< 1.24

```

`adult.pl`:

```
#!/usr/bin/perl -lp
$_>($a=/\./?1.4:18)or*_=a

```

If you don't mind an extra newline if you really were a full adult then leaving out the `l` option for 26 bytes works too

# Answer
> 6 votes
## EXCEL: ~~26~~ ~~31~~ 29 Bytes

```
=MAX(A1;IF(MOD(A1;1);1,4;18))

```

Formula can go anywhere except A1, the input cell.

Fixed errors, and replaced with Emigna's suggestion.

Thanks to Alexandru for saving me some bytes using truths

# Answer
> 5 votes
# Brachylog, 14 bytes

```
#$:18ot|:1.4ot

```

Try it online!

### Explanation

```
    #$             Input is an integer
      :18o         Sort the list [Input, 18]
          t        Take the last element
|              Or
    :1.4o          Sort the list [Input, 1.4]
         t         Take the last element

```

# Answer
> 5 votes
# GNU sed, 40 + 1 = 41 bytes

(score +1 for use of `-r` flag to interpreter)

```
s/^.$|^1[^9]$/18/
/^0|1\.[0-3]/s/.*/1.4/

```

### Annotated:

```
#!/bin/sed -rf

# First, anything that's a single digit or is '1' followed by a
# digit other than '9' is replaced with '18'.
s/^.$|^1[^9]$/18/

# Now, any line beginning with '0' or containing '1.0' to '1.3' is
# replaced with '1.4'.
/^0|1\.[0-3]/s/.*/1.4/

```

We take advantage of the constraints on input, so don't have to test the start of string when we see '1.' - we know there's only one digit before the decimal point.

### Test result:

```
$ ./94832.sed <<END
> 0
> 1
> 2
> 12
> 18
> 43
> 122
>
> 0.0
> 1.04
> 1.225
> 1.399
> 1.4
> 1.74
> 2.0
> 2.72
> END
18
18
18
18
18
43
122

1.4
1.4
1.4
1.4
1.4
1.74
2.0
2.72

```

# Answer
> 5 votes
## Haskell, 50 bytes

```
x#y=show$max x$read y
f s|elem '.'s=1.4#s|1<2=18#s

```

Usage example: `f "1.0"` -\> `"1.6"`.

Haskell's strict type requires usage of strings as input and output. Howevers, `read`, `max` and `show` are polymorphic and handle all numeric types.

# Answer
> 5 votes
# Java, ~~79~~ 70 bytes

```
int f(int x){return x<18?18:x;}
float f(float x){return x<1.4?1.4f:x;}

```

Defines two methods with overloading, which use the conditional operator.

Call it like `f(5)` or `f(1.4f)`.

# Answer
> 4 votes
# CJam, ~~18~~ 14 bytes

Saved 4 bytes thanks to Martin Ender.

```
q~_`'.&1.4I?e>

```

Online interpreter

# Answer
> 4 votes
# IBM/Lotus Notes Formula Language, ~~58~~ 49 bytes

```
@If(@Like(@Text(a);"%.%");@If(a<1.4;1.4;a);@If(a<18;18;a))

```

Computed field formula where a is an editable numeric field.

**EDIT**

```
@If(@Like(@Text(a);"%.%");@Max(1.4;a);@Max(18;a))

```

Alternative inspired by @Mego

# Answer
> 4 votes
# Jelly, ~~16 15 13~~ 12 bytes

-1 thanks to caird coinheringaahing (take input as a string).

```
ċ”.ị1.4,18»V

```

**TryItOnline**
Or see all test cases, also at **TryItOnline**

How?

```
ċ”.ị1.4,18»V - Main link: string, S
 ”.          - '.' character
ċ            - count (occurrences of '.' in S)
    1.4,18   - pair literals 1.4 and 18:  [1.4,  18]
   ị         - index into (1-indexed)
           V - evaluate (S) as Jelly code
          »  - maximum

```

# Answer
> 4 votes
## Actually, 16 bytes

```
;:.7τ9τ($'.íuIkM

```

Try it online!

Explanation:

```
;:.7τ9τ($'.íuIkM
;                 dupe input
 :.7τ             1.4 (.7*2) - note that :1.4 is the same length, but an additional delimiter would be needed to separate it from the following 1
     9τ           18 (9*2)
       ($'.íu     1-based index of "." in string representation of input, 0 if not found
             I    1.4 if input contains a "." else 18
              kM  maximum of remaining values on stack

```

# Answer
> 4 votes
# AWK - 29 bytes

```
($0<c=$0~/\./?1.4:18){$0=c}1

```

Usage:

```
awk '{c=$0~/\./?1.4:18}($0<c){$0=c}1' <<< number

```

Testing was performed with `gawk` on RHEL 6. I tried with all the test cases, unfortunately I don't have `AWK` on the machine that has internet access, so copy-paste is not possible.

Is there a more compact way to do this in `AWK`?

# Answer
> 4 votes
# C#, 58 bytes

```
x=>x is int?(int)x>17?x:18:(float)x<1.4?"1.4":$"{x:.0##}";

```

No crazy string parsing needed for C#. Input is expected to be an `int` or `float` (unfortunately C# can't cast a `double` to `float` if the `double` is in an `object`). Output will be either `int` or `string` in an `object`.

(almost missed the at least 1 decimal requirement, added that now)

Ungolfed:

```
/*Func<object, object> Lambda = */ x =>
    x is int // if parameter is an int
        ? (int)x > 17 // check if x is at least 18
            ? x // at least 18 so return x
            : 18 // less than 18 so return 18
        : (float)x < 1.4 // x is float, check if at least 1.4
            ? "1.4" // less than 1.4 so return 1.4
            : $"{x:.0##"} // at least 1.4 so return x and ensure at least 1 decimal place
;

```

Alternate implementation which is also 58 bytes.

```
x=>x is int?(int)x>17?x:18:$"{((float)x<1.4?1.4:x):.0##}";

```

# Answer
> 4 votes
## Emacs Lisp, 37 bytes

```
(lambda(x)(max(if(floatp x)1.4 18)x))

```

Guesses from the "datatype" whether the integer or float version should be used. (`floatp` returns `t` for `1.0`, but not for `1.`) The parameter is a number as integer or float, i.e. it should satisfy `numberp`.

# Answer
> 4 votes
# Haskell, 49 bytes

```
x#y=show.max x.fst<$>reads y;f s=head$18#s++1.4#s

```

Basically, this first attempts to read the input as an integer and then as a double if that fails. Then proceeds to compare it to the respective comparison baseline.

# Answer
> 3 votes
# C#, 69 bytes

```
s=>s.Contains(".")?float.Parse(s)<1.4?"1.4":s:int.Parse(s)<18?"18":s;

```

**Try it online!**

Full program with test cases:

```
using System;

namespace YesImAnAdult
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string,string>f= s=>s.Contains(".")?float.Parse(s)<1.4?"1.4":s:int.Parse(s)<18?"18":s;

            Console.WriteLine(f("0"));  //18
            Console.WriteLine(f("1"));  //18
            Console.WriteLine(f("2"));  //18
            Console.WriteLine(f("12")); //18
            Console.WriteLine(f("18")); //18
            Console.WriteLine(f("43")); //43
            Console.WriteLine(f("122"));    //122

            Console.WriteLine(f("0.0"));    //1.4
            Console.WriteLine(f("1.04"));   //1.4
            Console.WriteLine(f("1.225"));  //1.4
            Console.WriteLine(f("1.399"));  //1.4
            Console.WriteLine(f("1.4"));    //1.4
            Console.WriteLine(f("1.74"));   //1.74
            Console.WriteLine(f("2.0"));    //2.0
            Console.WriteLine(f("2.72"));   //2.72
        }
    }
}

```

A pretty straightforward solution. Note that on some systems float.Parse() might return incorrect results. Pass *CultureInfo.InvariantCulture* as the second argument according to this answer.

# Answer
> 3 votes
# ~~Dyalog APL, 14 bytes~~ Rendered invalid by further specifications

`⎕IO←0` which is default on many systems. Takes string as argument.

```
⍎⌈18 1.4⊃⍨'.'∘∊

```

`⍎⌈` max of the evaluated argument and

`18 1.4⊃⍨` {18,1.4} selected by

`'.'∘∊` whether the argument contains a period

# Answer
> 3 votes
# C++, 68 bytes

```
int A(int a){return a<18?18:a;}float A(float h){return h<1.4?1.4:h;}

```

This answer is actually 2 functions with the same name, and the compiler works out for me which to call, so it acts as one function without me having to take in one input and decide which it is. Since input on the floating point is guaranteed to be of the same precision as the output, I can return it safely without having to truncate it either.

***Ungolfed + tests***

```
#include <iostream>

int A(int a)
{
   return a < 18 ? 18 : a;
}

float A(float h)
{
   return h < 1.4 ? 1.4 : h;
}

int main()
{
  std::cout << 0 << " " << A(0) << "\n";
  std::cout << 19 << " " << A(19) << "\n";
  std::cout << 1.1 << " " << A(1.1f) << "\n";
  std::cout << 2.2 << " " << A(2.2f) << "\n";
}

```

# Answer
> 3 votes
# C, ~~119~~ ~~111~~ ~~105~~ 100

```
m;f(char*s){float atof(),l=atof(s);for(m=s;*s&&*s++!=46;);puts(*s?l<1.4?"1.4":m:atoi(m)>18?m:"18");}

```

Tested with

```
main(c,v)char**v;{
    f("0");
    f("1");
    f("2");
    f("12");
    f("18");
    f("44");
    f("115");
    f("122");
    f("0.0");
    f("1.04");
    f("1.225");
    f("1.339");
    f("1.4");
    f("1.74");
    f("2.0");
    f("2.72");
}

```

Output

```
18
18
18
12
18
44
115
122
1.4
1.4
1.4
1.4
1.4
1.74
2.0
2.72

```

# Answer
> 3 votes
## C, 50 bytes:

```
#define A(x)(x/2+(x+1)/2-x?x<1.4?1.4:x:x<18?18:x)

```

The byte count includes the newline at the end of the macro definition.

Test:

```
#define A(x)(x/2+(x+1)/2-x?x<1.4?1.4:x:x<18?18:x)
#include <assert.h>
int main() {
  assert(A(0) == 18);
  assert(A(1) == 18);
  assert(A(2) == 18);
  assert(A(12) == 18);
  assert(A(18) == 18);
  assert(A(43) == 43);
  assert(A(115) == 115);
  assert(A(122) == 122);
  assert(A(0.0) == 1.4);
  assert(A(1.04) == 1.4);
  assert(A(1.225) == 1.4);
  assert(A(1.399) == 1.4);
  assert(A(1.4) == 1.4);
  assert(A(1.74) == 1.74);
  assert(A(2.0) == 2.0);
  assert(A(2.72) == 2.72);
}

```

# Answer
> 3 votes
# C#, 71 bytes

```
object A(object i){return i is int?(int)i>18?i:18:(double)i>1.4?i:1.4;}

```

try it here

# Answer
> 3 votes
# Vyxal , ~~13~~ 12 bytes

```
₌⌊±[18|1.4]∴

```

Try it Online!

Takes input as string.

# Answer
> 2 votes
# C#, 95 Bytes

Golfed:

```
string y(string p){int a;return int.TryParse(p,out a)?a>17?p:"18":double.Parse(p)<1.4?"1.4":p;}

```

Ungolfed:

```
class YesOfCourseImAnAdult
  {
    public string y(string p)
    {
      int a;
      return int.TryParse(p, out a) ? a > 17 ? p : "18"
       : double.Parse(p) < 1.4 ? "1.4" : p;
    }
  }

```

Test cases:

```
var codeGolf = new YesOfCourseImAnAdult();
Console.WriteLine(codeGolf.y("0"));
Console.WriteLine(codeGolf.y("1"));
Console.WriteLine(codeGolf.y("2"));
Console.WriteLine(codeGolf.y("12"));
Console.WriteLine(codeGolf.y("18"));
Console.WriteLine(codeGolf.y("43"));
Console.WriteLine(codeGolf.y("122"));

Console.WriteLine(codeGolf.y("0.0"));
Console.WriteLine(codeGolf.y("1.04"));
Console.WriteLine(codeGolf.y("1.225"));
Console.WriteLine(codeGolf.y("1.399"));
Console.WriteLine(codeGolf.y("1.4"));
Console.WriteLine(codeGolf.y("1.74"));
Console.WriteLine(codeGolf.y("2.0"));
Console.WriteLine(codeGolf.y("2.72"));

```

Output:

```
18
18
18
18
18
43
122

1.4
1.4
1.4
1.4
1.4
1.74
2.0
2.72

```

# Answer
> 2 votes
# Python 2, 49 bytes

```
lambda a:(a,1.4)[a<1.4]if"."in`a`else(a,18)[a<18]

```

# Answer
> 2 votes
## Batch, 102 bytes

```
@set/ps=
@if %s:.=%==%s% (if %s% lss 18 set s=18)else if %s:~0,1%%s:~2,1% lss 14 set s=1.4
@echo %s%

```

First determines whether the input is an integer by checking whether deleting all `.`s has any effect on the string. If it is then the value is readily compared against 18, otherwise the first and third characters are combined into a number which is compared against 14.

# Answer
> 2 votes
# PHP, ~~36~~ ~~35~~ 34 bytes

```
echo max($a=$argn,$a[1]&p?1.4:18);

```

Checks whether the character in the second position is a digit (binary `and` with `p`). If so, use 18 as the minimum, otherwise 1.4. Then take the bigger of the 2 numbers.

Run like this:

```
echo 11 | php -nR 'echo max($a=$argn,$a[1]&p?1.4:18);';echo

```

# Explanation

Here's a table of the possible results of the `&"p"` operation:

```
input  binary      &   "p"         result      chr   Truthy/falsy
"."    0010 1110   &   0111 0000   0010 0000   " "   TRUTHY
"0"    0011 0000   &   0111 0000   0011 0000   "0"   FALSY
"1"    0011 0001   &   0111 0000   0011 0000   "0"   FALSY
"2"    0011 0010   &   0111 0000   0011 0000   "0"   FALSY
"3"    0011 0011   &   0111 0000   0011 0000   "0"   FALSY
"4"    0011 0100   &   0111 0000   0011 0000   "0"   FALSY
"5"    0011 0101   &   0111 0000   0011 0000   "0"   FALSY
"6"    0011 0110   &   0111 0000   0011 0000   "0"   FALSY
"7"    0011 0111   &   0111 0000   0011 0000   "0"   FALSY
"8"    0011 1000   &   0111 0000   0011 0000   "0"   FALSY
"9"    0011 1001   &   0111 0000   0011 0000   "0"   FALSY
null   0000 0000   &   0111 0000   0000 0000   0     FALSY

```

When the input is 1 digit, then taking the second digit will result in `null`. `null&"string"` will also conveniently evaluate to false. So only when the second char is a `.` will the expression evaluate to true and `1.4` will be used as the minimum instead of `18`.

# Tweaks

* Saved a byte by using `$argn`

# Answer
> 2 votes
## PHP: 40 bytes

```
$i=is_int($i)?$i>17?$i:18:$i>1.4?$i:1.4;

```

psuedocode, (nested turnary) :

```
if (i is an integer) then
  if (i is bigger than 17) then i=18 else i=i
otherwise (its a decimal)
  if (i is bigger than 1.4) then i=i else i=1.4
end if

```

# Answer
> 2 votes
## Powershell : 58 Bytes

Bit longer than i'd expected, so many brackets required to have it run correctly.

```
.({({1.4},$i)[$i-gt1.4]},{({18},$i)[$i-gt18]})[$i-is[int]]

```

Input as `$i`

```
. #Execute the code.. required.
( #First block
    { #Value if-false of first block
        (
        {1.4} #Return Val
        , #Or
        $i #Return Input
        )[$i-gt1.4] #If input is greater than Val
    },{ #Next Block
    ({18},$i)[$i-gt18]} #Same with different val
)[$i-is[int]] #Decides based on if val is default int

```

Test Cases:

```
@(0,1,2,12,18,43,115,122,0.0,1.04,1.225,1.399,1.4,1.74,2.0,2.72) | % {
$i = $_
Write-Host $i`t`t -NoNewline
.({({1.4},$i)[$i-gt1.4]},{({18},$i)[$i-gt18]})[$i-is[int]]
}

```

returns :

```
0       18
1       18
2       18
12      18
18      18
43      43
115     115
122     122
0       1.4
1.04    1.4
1.225   1.4
1.399   1.4
1.4     1.4
1.74    1.74
2(.0)   2      (this is a value of type 'double' - the default formatting of powershell doesn't add decimals, but the returned value is of the correct type)
2.72    2.72

```

Proof of 2 == 2.0

```
$i = 2.0
$q = .({({1.4},$i)[$i-gt1.4]},{({18},$i)[$i-gt18]})[$i-is[int]]
$q.GetType().Name
Double

```

# Answer
> 2 votes
# Java, 95 bytes

```
void p(double d){if(d%1>0)System.out.print(d<1.4?1.4:d);else System.out.print(d<18?18:(int)d);}

```

5 worse than Kevin's answer, but it has the print statement inside the function so maybe I get some pity points for that.

If this is allowed in Java, you could also use

```
d->{if(d%1>0)System.out.print(d<1.4?1.4:d);else System.out.print(d<18?18:d);};

```

Which could be used like

```
Consumer<Double> func = d->{if(d%1>0)System.out.print(d<1.4?1.4:d);else System.out.print(d<18?18:d);};

```

# Answer
> 2 votes
# Cheddar, ~~23~~ 21 bytes

```
n->[n,n%1?1.4:18].max

```

Nothing super-new but I'll post it as it's pretty short.

# Answer
> 2 votes
# Ruby - 34 bytes

Very straight-forward. Could possibly save 2 bytes by transforming that ternary.

```
->(x){x%1>0?x<1.4?1.4:x:x<18?18:x}

```

# Answer
> 2 votes
# Scala, 44 bytes

```
def?(x:Int)=18 max x
def?(x:Float)=1.4 max x

```

Defines two methods using overloading.

# Answer
> 2 votes
# Julia, 35 bytes

```
f(x)=max(x,1.4)
f(x::Int)=max(x,18)

```

Using multiple dispatch.

# Answer
> 2 votes
# C++14, 52 bytes

As unnamed lambda:

```
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}

```

Assumes `sizeof int==4` and `sizeof double!=4` which is true on most systems. Only side effect: the returned value is always a double.

Usage:

```
//assign to variable
auto f=[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;};
f(10)
f(2.0)

//use directly
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(10);
[](auto t){auto l=sizeof t-4?1.4:18;return t<l?l:t;}(2.0);

```

# Answer
> 2 votes
# Brachylog v2, 11 bytes

```
ℤ;18⌉|;1.4⌉

```

Try it online!

Essentially Fatalize's answer, just a bit shorter because it's a newer version of the language with a non-ASCII codepage.

```
               The output is
    ⌉          the largest of
  18           eighteen
 ;             and
               the input
ℤ              which is an integer,
     |         or
               the output is
          ⌉    the largest of
       1.4     1.4
      ;        and
               the input.

```

# Answer
> 2 votes
# Julia 1.0, 27 bytes

```
x->max(x,18(x≢x/1||7/90))

```

Try it online!

based on Lyndon White's answer and Glen O's comment

I really wanted to use multiple dispatch like Lyndon's answer but it's not the shortest

* `x≢x/1` checks if x is an integer: division will turn an integer into a float, and (`!==`) checks if both arguments are completely identical (including same type)
* when the condition is true, the parenthesis evaluates as `true`, which leaves the `18` unchanged (`n*true === n`)
* otherwise, the parenthesis evaluates `7/90` which results in `18*7/90 === 1.4`
* because I can (same amount of bytes as `!==`)

# Answer
> 1 votes
## Pyke, 15 bytes

```
,16.6*1.4+Qb]Se

```

Try it here!

Takes input in quotes. `is_numeric` returns `1` if the input doesn't contain a `.`, otherwise it returns `0`

```
,16.6*          - 16.6*is_numeric(input)
      1.4+      - ^ + 1.4
          Qb]   - [^, float(input)]
             Se - sorted(^)[-1]

```

# Answer
> 1 votes
## Racket 76 bytes

```
(λ(n)(cond[(integer? n)(if(>= n 18)n 18)][(number? n)(if(>= n 1.4)n 1.4)]))

```

Ungolfed version:

```
(define f
  (λ(n)
    (cond
      [(integer? n) (if(>= n 18) n 18)]
      [(number? n) (if(>= n 1.4) n 1.4)]
      )))

```

Testing:

```
(f 1.3)
(f 15)
(f 19)
(f 1.5)

```

Output:

```
1.4
18
19
1.5

```

# Answer
> 1 votes
# TI-Basic, 31 bytes

```
Prompt O,Str1
Disp max(18,O
Str1
If 1.4>expr(Ans
"1.4
Ans

```

Pretty self-explanatory. Only thing I would note is that in TI-Basic, whatever the last line evaluates to is implicitly displayed. If nothing is evaluated on the last line it will print `Done`.

# Answer
> 1 votes
# GameMaker Language, 74 bytes

```
a=argument1;if real(a)<1.4a="1.4"show_message(string(max(argument0,18))+a)

```

# Answer
> 1 votes
# SQL, 105 bytes

```
IF @v like'%.%'select MAX(p)from(values(@v),(1.400))as X(p)ELSE select MAX(p)from(values(@v),(18))as X(p)

```

tested on MS SQL Server 2008 R2

usage:

```
DECLARE @v as varchar(255) = '1.405'
IF @v like'%.%'select MAX(p)from(values(@v),(1.400))as X(p)ELSE select MAX(p)from(values(@v),(18))as X(p)

```

# Answer
> 1 votes
# k, 20 bytes

Returns the maximum of the input, `x`, and 18 if `x` is integral or 1.4 otherwise.

```
{x|$[-7h=@x;18;1.4]}

```

# Answer
> 1 votes
## Logy, 74 bytes

```
m[X,Y]->X>Y&X|Y;f[X]->include["@stdlib.logy"]~X==ceil[X]&m[X,18]|m[X,1.4];

```

Wow... Outgolfed by Java

```
max[X, Y] -> X > Y & X | Y;
f[X] -> include["@stdlib.logy"]
      ~ X == ceil[X] & max[X, 18] | max[X, 1.4];

```

# Answer
> 1 votes
# Ruby, 31 bytes

```
->x{[x.to_s=~/\./?1.4:18,x].max}

```

Try it online!

# Answer
> 1 votes
**C and C++ : 47 bytes**

```
#define a(b)(sizeof b>4?b>=1.4?b:1.4:b<18?18:b)

```

Please let me know if this is considered a default loophole. The macro assumes that an integer literal is four bytes and a double floating point literal is greater than that.

Test using GCC 6.3.1 (C++) :

```
#include <iostream>

#define a(b)(sizeof b>4?b>=1.4?b:1.4:b<18?18:b)

void print_a (const auto &t) {
  std::cout << a(t) << '\n';
}

template <class T, class...P>
void print_a (const T &t, const P&...p) {
  print_a (t);
  print_a (p...);
}

int main () {

  print_a (0, 1, 2, 12, 18, 43, 115, 122, 0.0, 1.04,
   1.225, 1.399, 1.4, 1.74, 2.0, 2.72);

  return 0;
}

```

# Answer
> 1 votes
# C++ (gcc), 49 bytes

```
-DK(T,u)T=f(T&x){x<u?x=u:x;}

K(int,18)K(float,1.4)

```

Try it online!

# C++ (gcc), 56 bytes

```
-DK(T,u)T=f(T(x)){return+x<u?u:x;}

K(int,18)K(double,1.4)

```

Try it online!

# Answer
> 1 votes
# Ruby, 30 bytes

```
->x{[x.integer??18:1.4,x].max}

```

I'm very surprised that an 8-character method call seems to be the shortest way to switch modes (at least if we want to treat `1.0` as a decimal).

# Answer
> 1 votes
# dc, 34 bytes

```
[1.4]s1[18]s8[d18>8]s*dX0=*d1.4>1p

```

Try it online! *Note: test cases as defined in the footer do include `0.0`, but `dc` prints `0.0` as `0`, so that test case looks like the input is wrong. Also the footer just defines the main chunk as a macro and adds some printing to tidy up the test cases a bit.*

Aside from the case of `0.0` as mentioned above, `dc` prints trailing zeroes in decimals, so we don't really have to do anything special beyond testing for a decimal point and our two less-than tests.

Because conditionals *must* run macros stored in registers, some bytes are spent just storing our min values - `1.4` in macro/register `1`, and `18` in macro/register `8`. Macro `*` just checks whether or not our value is less than 18, and if so runs the aforementioned macro `8` to put `18` on the stack. The main bit is `dX0=*d1.4>1`. This uses the `X` command to see how many digits are to the right of the decimal point. If it's 0, we run the aforementioned macro `*` to either leave the number be, or place 18 on the stack. Fortunately, since 18 is greater than 1.4, we don't really have to worry about finagling else statements or anything (if we needed the integer 1 to pass through unharmed, things would be different). So from here we just test if we're less than 1.4; if so we run macro `1` to put `1.4` on the stack, and finally we print with `p`.

# Answer
> 1 votes
# Lua, 71 bytes

```
function Z(a,b)print(a+0<b and b or a)end R=io.read Z(R(),18)Z(R(),1.4)

```

Tested in Lua 5.1.5. TIO throws an error at `a+0`

Ungolfed

```
function print_min(input,min_value)
    print(input+0<min_value and min_value or input)
end

R=io.read
print_min(R(),18)
print_min(R(),1.4)

```

# Explanation

`a+0` is the shortest way to convert a string to a number. The syntax `a+0<b and b or a` is a replacement for Lua's lack of a ternary operator; equivalent to `a+0<b?b:a`.

# Answer
> 1 votes
# C# (Visual C# Compiler), ~~69~~ 67 bytes

```
s=>int.TryParse(s,out int n)?n<18?"18":s:float.Parse(s)<1.4?"1.4":s

```

Try it online!

**Edit:** Saved 2 bytes thanks to Kevin Cruijssen:

1. Changed double to float
2. Removed trailing semi-colon

# Answer
> 1 votes
# Nim, 48 bytes

```
func a[T](x:T):T=x.max when T is int:18 else:1.4

```

Try it online!

---
Tags: code-golf, arithmetic
---


title: Removing The Nineteenth Byte

text:
# Question
Title: Removing The Nineteenth Byte
# Introduction

The Nineteenth Byte is CGCC's official chatroom (go check it out!). Its name is a play on the nineteenth hole, and it also refers to golf, which is appropriate for CGCC's chatroom's name. The name is also precisely \\$19\\$ bytes long, as its name states.

# Challenge

Your task is to write a program that outputs `Stack Exchange Chat - The Nineteenth Byte` exactly. However, if the nineteenth byte and only the nineteenth byte of your source code is removed, it should output only `Stack Exchange Chat`. Because of this, the best score you can get will be \\$19\\$ bytes. For example, if your code is `abcdefghijklmnopqrstuvwxyz`, then `abcdefghijklmnopqrstuvwxyz` must output `Stack Exchange Chat - The Nineteenth Byte` and `abcdefghijklmnopqrtuvwxyz` must output `Stack Exchange Chat`.

# Rules

* Standard loopholes are forbidden.
* Trailing whitespace is allowed.
* If possible, please link to an online interpreter (e.g. TIO) to run your program on.
* Please explain your answer. This is not necessary, but it makes it easier for others to understand.
* Languages newer than the question are allowed. This means you could create your own language where it would be trivial to do this, but don't expect any upvotes.
* You are scored by the length of the program that outputs `Stack Exchange Chat - The Nineteenth Byte`.
* This is , so shortest code in bytes wins!

# Answer
> 8 votes
# Husk, ~~25~~ 23 bytes

```
ΣüL½¨ḟKȦΞ×ėCȧt-ξḟ%Nhβ/y

```

Try it online!

Try it online without the 19th byte!

### Explanation

`¨ḟKȦΞ×ėCȧt-ξḟ%Nhβ/y` is a compressed string, equivalent to `"Stack Exchange Chat - The Nineteenth Byte"`. If we remove `N` (the nineteenth byte of the program) we get `¨ḟKȦΞ×ėCȧt-ξḟ%hβ/y`, which is equivalent to `"Stack Exchange Chat - Thefischer\n Byte"` (`\n` being a newline character).

Now, starting from one of these two strings:

```
  "Stack Exchange Chat - The Nineteenth Byte"    "Stack Exchange Chat - Thefischer\n Byte"

½   Split the string in half
  ["Stack Exchange Chat -",                      ["Stack Exchange Chat",
   " The Nineteenth Byte"]                        " - Thefischer\n Byte"]

üL   nub by length: remove strings with the same length as previous ones
  ["Stack Exchange Chat -",                      ["Stack Exchange Chat"]
   " The Nineteenth Byte"]

Σ   Join the strings together
  "Stack Exchange Chat - The Nineteenth Byte"    "Stack Exchange Chat"

```

# Answer
> 24 votes
# Jelly, 25 bytes

```
“¡TƑ9ı2ṆR“¡⁸¢6ṅȯ*ỵ#K»iƇ”h

```

Try it online! or Try it without `#`

# Jelly, 25 bytes

```
“¡TƑ9ı2ṆR“¡TḟKY=ɱø~»tƑƇ⁶K

```

Try it online! or Try it without `~`

## How they work

```
“¡TƑ9ı2ṆR“¡⁸¢6ṅȯ*ỵ#K»iƇ”h - Main link. No arguments
“¡TƑ9ı2ṆR“¡⁸¢6ṅȯ*ỵ#K»     - Pair of compressed strings ["Stack Exchange Chat", " - The Nineteenth Byte"]
                      Ƈ   - Keep those for which the following is True:
                     i ”h - They contain "h"; ["Stack Exchange Chat", " - The Nineteenth Byte"]
                            Smash together and output

“¡TƑ9ı2ṆR“¡⁸¢6ṅȯ*ỵK»iƇ”h  - Main link. No arguments
“¡TƑ9ı2ṆR“¡⁸¢6ṅȯ*ỵK»      - Pair of compressed strings ["Stack Exchange Chat", "^Backets reamyappenzell"]
                     Ƈ    - Keep those for which the following is True:
                    i ”h  - They contain "h"; ["Stack Exchange Chat"]
                            Smash together and output

```

And the second one:

```
“¡TƑ9ı2ṆR“¡TḟKY=ɱø~»tƑƇ⁶K - Main link. No arguments
“¡TƑ9ı2ṆR“¡TḟKY=ɱø~»      - Pair of compressed strings ["Stack Exchange Chat", "- The Nineteenth Byte"]
                     ƑƇ   - Keep those where the following has no effect:
                    t  ⁶  -   Removing spaces from the front and end; ["Stack Exchange Chat", "- The Nineteenth Byte"]
                        K - Join with spaces; "Stack Exchange Chat - The Nineteenth Byte"

“¡TƑ9ı2ṆR“¡TḟKY=ɱø»tƑƇ⁶K  - Main link. No arguments
“¡TƑ9ı2ṆR“¡TḟKY=ɱø»       - Pair of compressed strings ["Stack Exchange Chat", " Backets reamyappenzell"]
                    ƑƇ    - Keep those where the following has no effect:
                   t  ⁶   -   Removing spaces from the front and end; ["Stack Exchange Chat"]
                       K  - Join with spaces; "Stack Exchange Chat"

```

# Answer
> 15 votes
# Jelly, ~~25~~ 24 bytes

```
“ÆçƲBnƥẈṛⱮ_ỴȷOṘỵḊĊ»»ḣ19$

```

Try it online!

## Without the nineteenth byte

```
“ÆçƲBnƥẈṛⱮ_ỴȷOṘỵḊĊ»ḣ19$

```

Try it online!

It works no matter if you index from 0 or 1!

## Explanation

```
“ÆçƲBnƥẈṛⱮ_ỴȷOṘỵḊĊ»»ḣ19$   Main niladic link
“ÆçƲBnƥẈṛⱮ_ỴȷOṘỵḊĊ»        "Stack Exchange Chat - The Nineteenth Byte"
                   »       [Calculate the byte-wise maximum with]*
                       $   (
                    ḣ19      Get the first 19 characters
                       $   )

```

\*When indexing from 1, it's actually the first `»` that is removed, but the result is the same.

# Answer
> 14 votes
# JavaScript (V8), 66 bytes

The nineteenth byte is the `X`.

```
print("Stack",(s="X"&&" - The Nineteenth Byte","Exchange Chat"+s))

```

Try it online!

Try it online! (nineteenth byte removed)

### Commented

```
print(                            // print:
  "Stack",                        //   the first word followed by an implicit space
  (                               //
    s = "X" &&                    //   define s as either " - The Nineteenth Byte"
        " - The Nineteenth Byte", //   or an empty string if the 'X' is removed
    "Exchange Chat" + s           //   append "Exchange Chat" followed by s
  )                               //
)                                 // end

```

# Answer
> 12 votes
# Python 2, 66 bytes

```
s,y='Stack Exch',01
print s+'ange Chat'+' - The Nineteenth Byte'*y

```

Try it online!

Not really a smart answer. :p

The nineteenth byte here is the `1`.

y is `0` or `1` depending on if the nineteenth byte is removed.

*thanks to pxeger for -2 bytes*

# Answer
> 12 votes
# Zsh, 54 bytes

```
set Exchange Chat \
- The Nineteenth Byte
<<<Stack\ $@

```

Try it online!

`set` assigns the given words to the default variable `$@`. As with the previous one, `\` joins the two lines into one call to set, instead of treating `- The Nineteenth Byte` as a command (which does nothing).

---

## Zsh, 55 bytes

```
1=" Exchange Chat"\
" - The Nineteenth Byte"
<<<Stack$1

```

Try it online!

Idea boringly copied from @xnor's genius answer. The `\` escapes the newline, which concatenates the two strings; without it, the second line is ignored as an undefined command.

---

## Zsh, 58 bytes

```
1=Stack\ Exchang
2=" - The Nineteenth Byte"
<<<$1e\ Chat$2

```

Try it online!

The 19th byte is the second `=`, which changes that line from a variable assignment to an undefined command which does nothing. Then, when printing, `$2` defaults to empty.

# Answer
> 11 votes
# Emotion, 34 bytes

The nineteenth byte is .

Try it online!

# Answer
> 11 votes
# C (gcc), 69 bytes

Without the removal of the 19th byte, the full string (which is much less than 119 characters) is printed; if the 19th byte is removed, only 19 characters are printed instead.

```
main(){printf("%.119s","Stack Exchange Chat - The Nineteenth Byte");}

```

Try it online!

With the 19th byte removed: Try it online!

# Answer
> 9 votes
# Python 2, 58 bytes

```
s="Exchange Chat "\
"- The Nineteenth Byte"
print"Stack",s

```

Try it online! (no 19th byte)

The 19th byte is the `\` at the end of the first line. It acts as a line continuation character to make the full line be `"Exchange Chat ""- The Nineteenth Byte"` using Python's automatic concatenation of adjacent string literals.

Without the `\`, the line ends there, and the second line is lonely string value that doesn't do anything. The truncated string ends in a space, which is fine because the challenge allows for trailing whitespace.

---

**Python 2, 61 bytes**

```
s="Exchange Chat"+--1*" - The Nineteenth Byte"
print"Stack",s

```

Try it online! (no 19th byte)

The 19th byte is a `-`. Originally we append `--1` (so, `1`) copies of the string `" - The Nineteenth Byte"`, with the 19th byte is removed, this is `-1` copies which is nothing.

# Answer
> 8 votes
# Scala 3, 90 bytes

```
val x="Stack Ex"+a/*/ */+" - The Nineteenth Byte"
def a="change Chat"
@main def m=print(x)

```

Try it in Scastie!

With the nineteenth byte removed:

```
val x="Stack Ex"+a// */+" - The Nineteenth Byte"
def a="change Chat"
@main def m=print(x)

```

Try it in Scastie!

The syntax highlighting should show what happens. This would be a byte shorter in a language without nested comments, since the space in `/*/ */` wouldn't be needed, but I just like Scala :P

A possible solution with a newline that doesn't work because of parsing rules:

```
val x="Stack E"+a//
+" - The Nineteenth Byte"
def a="xchange Chat"
@main def m=print(x)

```

# Answer
> 8 votes
# Python 3.8 (pre-release), 72 bytes

```
print('Stack Exch{1}'.format(x:='ange Chat',x+' - The Nineteenth Byte'))

```

Try it online!

Different approach than @ManishKundu solution

Nineteenth byte is `1` removing it will result `0` to only suffix `hange Chat`

Thanks to @ZaelinGoodman for insight

-6 bytes to @Makonede

# Answer
> 8 votes
# Python 2, 65 bytes

```
b='Stack Excha'
n=88
print b+'nge Chat - The Nineteenth Byte'[:n]

```

**Try all of it**
**Try it without the 19th byte**

Works in Python 3 trivially for 66 bytes

# Answer
> 8 votes
# Scratch 3.0, 10 blocks/160 bytes

```
define
set[outpuuut v]to[Stack Exchange Chat - The Nineteenth Byte
set[outpuuu v]to[Stack Exchange Chat
if<(outpuuut)>(0)>then
say(outpuuut
else
say(outpuuu
end

```

This outputs `Stack Exchange Chat - The Nineteenth Byte`

Because Scratch is a block-based language, it may not seem obvious on how to remove a byte at first. But thankfully, there exists a text format called ScratchBlocks which we seem to allow for scoring. The above ScratchBlocks corresponds to the following real blocks:

Try it on Scratch!

Removing the 19th byte of this program gives

```
define
set[outpuuu v]to[Stack Exchange Chat - The Nineteenth Byte
set[outpuuu v]to[Stack Exchange Chat
if<(outpuuut)>(0)>then
say(outpuuut
else
say(outpuuu
end

```

This outputs `Stack Exchange Chat`

Try it on Scratch!

Explanation coming soon

# Answer
> 7 votes
# Factor, ~~95 94~~ 87 bytes

Saved 1 precious byte thanks to @OriginalOriginalOriginalVI! Saved 7 more bytes thanks to @Bubbler!

```
"Stack Exchange C"f " - The Nineteenth Byte""hat"rot [ prepend nip ] [ glue ] if* print

```

Try it online!

Explained:

```
"Stack Exchange C"f " - The Nineteenth Byte""hat"  ! push items on the stack,
                                                   ! f (false) value is 19th char
rot                                                ! rotate, f now at top of stack
                                                   ! if f is missing, "Stack Exchange C"
                                                   ! is at the top
[ prepend nip ] [ glue] if* print                  ! if* f is found, glue the strings and print.
                                                   ! if* a string is found, it is considered to
                                                   ! be true, retain it on the stack, swap & glue
                                                   ! the top strings, drop the "19th Byte" string,
                                                   ! append and print.

```

Old version:

```
"Stack Exchange C"f "hat"" - The Nineteenth Byte"rot [ nip swap append ] [ 3append ] if* print

```

Try it online!

Explained:

```
"Stack Exchange C"f "hat"" - The Nineteenth Byte"  ! push items on the stack,
                                                   ! f (false) value is 19th char
rot                                                ! rotate, f now at top of stack
                                                   ! if f is missing, "Stack Exchange C"
                                                   ! is at the top
[ nip swap append ] [ 3append ] if* print          ! if* f is found, append the strings and print.
                                                   ! if* a string is found, it is considered to
                                                   ! be true, retain it on the stack, drop the
                                                   ! "19th Byte" string, swap stack strings,
                                                   ! append and print.

```

# Answer
> 7 votes
# \>\<\>, 62 bytes

```
"Stack Exch"\" - "<
" tahC egna"/r>o<r/
eeteniN ehT"\"etyB htn

```

Try it online!

Try it without the Nineteenth byte

I've been playing around with \>\<\> this week and this one was kind of a freebie, although it still turned out to be an interesting packing problem that ended up getting quite lucky at the end.

The Nineteenth byte is unsurprisingly the `<` at the end of the first row. With or without it, we'll execute `"Stack Exchange Chat "`, pushing that string onto the stack (in reverse order; usually we want to push strings backwards but here it's convenient to start with the prefix so we'll just reverse the stack later instead).

At this point, the program encounters the `/` at the end of the second row, hitting it from the right and heading down, *conveniently going through the space between "Nineteenth" and "Byte"*, then wrapping around vertically and either heading leftwards on the first or second row. With the `<`, we execute `"The Nineteenth Byte"`, pushing that string on the stack and then head to the output gadget, and without it we head directly to the output.

The output is done by first reversing the stack with `r`, and then heading into the bottomless pit of `>o<` which executes the output instruction `o` endlessly until the stack is emptied and the program exits via error.

# Answer
> 6 votes
# PowerShell 7, 60 bytes

```
'Stack Exchange'+(!0 ?' Chat - The Nineteenth Byte':' Chat')
#                 ^
#                 19th byte

```

No TIO because the ternary operator is not supported in powershell 6 and below

## Alternate Solutions

### PowerShell 7, 60 bytes

```
"Stack Exchan$($x=!0 ?' - The Nineteenth Byte':'')ge Chat$x"
#                 ^
#                 19th byte

```

### PowerShell, 61 58 bytes

-3 bytes thanks to @mazzy!!

```
"Stack Exchange {01}"-f'Chat','Chat - The Nineteenth Byte'
#                 ^
#                 19th byte

```

Try it online!

# Answer
> 5 votes
# Java, ~~104~~ ~~83~~ 72 bytes

```
$->"Stack ExchangeA Chat".replaceAll("A(.*)","$1 - The Nineteenth Byte")

```

The nineteenth byte is `A`.

*Saved 21 bytes thanks to 79037662.*

*Saved 11 bytes thanks to Olivier Grégoire.*

Try it online!

Try it online (without the nineteenth byte)!

# Answer
> 5 votes
# SNOBOL4 (CSNOBOL4), 90 bytes

```
              Y =1
	X =GT(Y) ' - The Nineteenth Byte'
	OUTPUT ='Stack Exchange Chat' X
END

```

Try it online!

The nineteenth byte here is the `1`. SNOBOL treats an empty string as `0`, and an empty right-hand assignment as an empty string. So when the byte is removed, the program assigns a value of `0` to `Y`, and the comparison `Y GT` (implicit 0) fails, hence `X` is assigned an empty value as well.

# Answer
> 5 votes
# 05AB1E, 27 bytes

```
” -€€¥ŠteenthÄÁ” õs”Â‚‹ºŠÆÿ

```

Try it online! and Try it without `s`

```
” -€€¥ŠteenthÄÁ” # Compressed string " - The Nineteenth Byte"
 õ               # push the empty string
 (s)             # (swap back to the other string)
   ”Â‚‹ºŠÆÿ      # push compressed string "Stack Exchange Chatÿ"
                 # where ÿ is replaced by the string on the top of the stack

```

# Answer
> 4 votes
# Excel, ~~73~~ 70 bytes

*Updated thanks to @EngineeringToast*

```
=LET(a,"Stack ",b,1,a&"Exchange Chat"&IF(b," - The Nineteenth Byte",))

```

*Original*

```
=LET(s,"Sta",n,30--11,LEFT(s&"ck Exchange Chat - The Nineteenth Byte",n))

```

Shows all characters as is; the left 19 characters if the 19th byte (-) is deleted.

# Answer
> 4 votes
# shortC, 54 bytes

```
Ds"Exchange Chat\x20- The Nineteenth Byte"
AJ"Stack "s

```

Try it online!

### Without the Nineteenth byte

```
Ds"Exchange Chat\x0- The Nineteenth Byte"
AJ"Stack "s

```

Try it online!

`\x20` denotes a space character, removing the `2` we get `\x0` (null character) which in C is the string terminator.

# Answer
> 4 votes
# , ~~72~~ ~~68~~ 63 bytes

-4 bytes thanks to Dominic van Essen.

```
cat(scan(,"",3+0004))
Stack Exchange Chat - The Nineteenth Byte

```

Try it online!

The 19th byte is the `4`. In the unaltered version, `scan` will read 7 words from the next line, and then print them. If you remove the `4`, `scan` will read only 3 words and then print them.

# Answer
> 4 votes
# Foo, 46 bytes

```
"Stack Exchange Ch"at"at - The Nineteenth Byte

```

Try it online!

Try it online!

Output the quoted strings, which don't have to be closed. Other commands don't matter.

# Answer
> 4 votes
# Haskell, 63 bytes

```
main=putStr$take 119"Stack Exchange Chat - The Nineteenth Byte"

```

Try it online!

The 19th byte is the center `1` in `119`.

# Answer
> 3 votes
# Wolfram Language (Mathematica), 60 bytes

```
"Stack Exc"~Print~##&["hange Chat"," - The Nineteenth Byte"]

```

Try it online!

The 19th byte is one of the `#`s. `##` represents a sequence of all arguments, but `#` represents only the first argument.

# Answer
> 3 votes
# APL (Dyalog Classic), 61 bytes

```
¯12⌽∊('ge Chat'{⍺ ⍵}' - The Nineteenth Byte'),'Stack Exchan'

```

```
¯12⌽∊  ⍝ Rotate right 12
{⍺ ⍵}  ⍝ Concatenate
,      ⍝ Concatenate

```

Try it online!

# Answer
> 3 votes
# Retina 0.8.2, 51 bytes

```

Stack Exchange Chat - The Nineteenth Byte
ht.*
hat

```

Try it online! Explanation: Tries to insert the whole string, but if the 19th byte (the `a`) is deleted, then replaces everything after the `C` with `hat`.

# Answer
> 3 votes
# Pxem, filename: 2 bytes + content: 64 bytes = 66 bytes.

Thank you for commenting me that I need to use content of the file.

## Filename

```
.e

```

## Content

```
Stack Exchange Cha.p.c.c.zt - The Nineteenth Byte.p.d.a.v.st.v.p

```

## How it works

* Every command substring consists of a dot and a char.
* Every non-command substring is considered to be a command to push each of the string from backwards.
    + I.e. literals.
* Filename is main routine; content is subroutine.
* `.e` calls subroutine.
* 19th byte on content is `.` of `.p` --- a command to pop each to putchar().
    + Then the stack would be empty.
* `.c` is dup() iff not empty; nop() otherwise.
* `.z ... .a` is `while size<2 || pop!=pop; do ... ;done`.
* `.d` is exit() on filename; `return` on content.
* `.v` reverses entire stack.

## Links to TIO

# Answer
> 3 votes
# Python 2, 65 bytes

```
a="Exchange Chat"
"#";a+=" - The Nineteenth Byte"
print"Stack",a

```

The nineteenth byte is the quotation mark before the hashtag. Removing it turns line 2 into a comment.

Works in Python 3 for 67 bytes, by adding brackets for the `print()` function.

# Answer
> 3 votes
# Rust, 63 bytes

```
||print!("Stac{:.105}","k Exchange Chat - The Nineteenth Byte")

```

The nineteenth byte is the `0` in the formatting parameter.

Removing it changes the format string in the closure to print 15 characters from the argument instead of up to 105.

With the 19th byte: Try it online!
Without the 19th byte: Try it online!

*Thanks to @ErikF for his inspiring C solution*

# Answer
> 3 votes
# JavaScript, 101 bytes

```
console.log([[,].splice().length?"":" - The Nineteenth Byte","Stack Exchange Chat"].reverse().join``)

```

Try it Online!, without the 19th byte

It's not the best answer in JavaScript, but I think it's interesting because the 19th byte is `p` of `splice`, making `slice`:

```
[,].splice.length == 0 //Falsey
[,].slice.length == 2 //Truthy

```

It might be golfed more, but idk.

# Answer
> 3 votes
# Lost `-A`, 113 bytes

```
>%?"Stack Exch2/"+\"nge Chat"@
^/+"/% - tahC egn"<
?>"he Nineteenth Byt6/"+@v
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
^<<"

```

The 19th byte is the `\` on the first line.

Try it online or verify that it's deterministic.
Try it online without 19th byte or verify that that is deterministic.

### Explanation:

**Explanation of the language in general:**

Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that ***both the start position AND starting direction it travels in is completely random***. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.

A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east.

In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle.

**Explanation of the program:**

All arrows, including the reflects `/` in the strings, will lead the path towards the leading `>` on the first line. From there the program flow is as follows:

* `>`: Travel towards the right
* `%`: Put the safety 'off'. In a Lost program, an `@` will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character `@` would immediately terminate without doing anything. The `%` will turn this safety 'off', so when we now encounter an `@` the program will terminate (if the safety is still 'on', the `@` will be a no-op instead).
* `?`: Clean the top value on the stack. In some program flows it's highly likely we have a partial string on the stack, so we use this to wipe the stack clean of that potential string. (Minor note: if the stack was not empty when `?` is encountered, the next operation will be skipped.)
* `"`: Start a string, which means it will push the integer code-points of the characters used.
* `Stack Exch2/`: Push the code-points for these characters, being `83 116 97 99 107 32 69 120 99 104 50 47` respectively
* `"`: We're done pushing code-points of this string
* `+`: Add the top two values together: (50+47=) `97`
* With 19th byte:
    + `\`: Reflect the direction downwards
    + `<`: Change the direction towards the left
    + `"` : Start a string again
    + `nge Chat - %/`: Push the code-points `110 103 101 32 67 104 97 116 32 45 32 37 47`
    + `"`: We're done pushing code-points again
    + `+`: Add the top two values together: (37+47=) `84`
    + `/`: Reflect the direction downwards
    + `>`: Change the direction towards the right
    + `"he Nineteenth Byt6/"+`: The same yet again
    + `@`: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. Using the `-A` program argument flag, these code-points will be output as characters instead.
* Without the 19th byte:
    + `"nge Chat"`: Push the code-points `110 103 101 32 67 104 97 116`
    + `@`: Similar again: terminate the program if the safety is 'off' (which it is at this point), and output the values on the stack implicitly (as characters because of the `-A` flag).

*Some things to note:*

* The leading `?` on the third line instead of a `^` is to clean a second unwanted value from the stack, which happens (among others) for the flow {first row, third character, traveling downwards}.
* The bottom row `^<<"`, and primarily the `"`, is for the flow {first row, fourth character, traveling upwards}, which would otherwise keep pushing strings without changing directions.
* The trailing `v` on the third line is for the flow {first row, third character, traveling right}, which skipped the `%` to put the safety off, and would end up in an infinite loop traveling left on the third line.
* The `/` in the strings are to prevent infinite loops as well. The one in `"Stack Exch2/"+` for flow {first row, second character, traveling downward}; the one in `"/% - tahC egn"` for flow {second row, fourth character, traveling left}; and the one in `"he Nineteenth Byt6/"` for flow {third row, third character, traveling left}.

# Answer
> 2 votes
# Japt, 36 bytes

The nineteenth byte is the `i`, if it's removed the two strings are essentially separated by the comma operator instead. The first compressed string is manually unrolled a bit to control the position of the `i` command to be the nineteenth byte.

```
` - T” Ná2çh By’`i`Stack ExÖˆge C•t
` - T” Ná2çh By’`                   // Compressed string " - The Nineteenth Byte", slightly manually decompressed to control the position of the next command.
                 i                  // This is the nineteenth byte, prepend to the above string, if removed, effectively becomes the comma operator instead.
                  `Stack ExÖˆge C•t // Compressed string "Stack Exchange Chat"

```

Try it here.

# Answer
> 2 votes
# Python, 73 bytes

```
x,t="hange Chat"," ";print("Stack Exc"+x,bool(t)*"- The Nineteenth Byte")

```

Sure it could be golfed a bit more... first looking for an alternative to `bool`

# Answer
> 2 votes
# Husk, 31 bytes

```
↓0000+¨ḟKȦΞ×ėCȦt¨↑30¨ -ξḞẊNτβ/y

```

Try it online!

```
↓0000                           Drop 0 (does nothing)
     +                          Concatenate these strings:
      ¨ḟKȦΞ×ėCȦt¨               Compressed "Stack Exchange Chat"
                 ↑30            Take 30 characters from...
                    ¨ -ξḞẊNτβ/y Compressed " - The Nineteenth Byte"

```

The `3` is the 19th byte, so removing it makes `↑0¨ -ξḞẊNτβ/y` which is the empty string.

# Answer
> 2 votes
# Charcoal, 43 bytes

```
”↶/➙→G,″ⅉ∕ι↑ι&}yσ”→¿›ⅈ¹⁹«¹”↶0δ⁶b↔Πξ[9⊕|c#ξ“

```

Try it online! Without the 19th byte (the ): Try it online! Explanation:

```
”↶/➙→G,″ⅉ∕ι↑ι&}yσ”

```

Print compressed(!) string "Stack Exchange Chat".

Move to the 20th column.

```
¿›ⅈ¹⁹«

```

If we are no longer in the 19th column, then:

```
¹

```

Print a `-`.

```
”↶0δ⁶b↔Πξ[9⊕|c#ξ“

```

Print compressed string " The Nineteenth Byte".

# Answer
> 2 votes
# 33, 53 bytes

```
"Stack Exchange "1cp"Chat"p" - The Nineteenth Byte"Np

```

Try it online! and Try it without the `c`

The nineteenth byte is the `c`, which affects the conditional `Np` at the end of the program.

# Answer
> 2 votes
# PHP, 64 bytes

```
<?="Stack Excha".(!($a="nge Chat")?:"$a - The Nineteenth Byte");

```

Try it online!

A kinda trivial answer: the 19th byte is the `!`. Note that in PHP's ternary conditions `a?b:c`, if `b` is missing, `a`'s value is used instead.

# Answer
> 2 votes
# Python 3, 78 bytes

```
exit(('%s %s %s '+10//10*'- The Nineteenth Byte')%('Stack','Exchange','Chat'))

```

Try It Online!

Poor attempt but different. removing the 19th character will make it `0//10` and therefore the second string won't be printed.

# Answer
> 2 votes
# Python 3, 101 bytes

```
def f(gh):
	gh()
	"#";print(" - The Nineteenth Byte")
f(lambda:print(end="Stack Exchange Chat"))

```

Try it online! Minus the 19th byte:

```
def f(gh):
	gh()
	#";print(" - The Nineteenth Byte")
f(lambda:print(end="Stack Exchange Chat"))

```

Try it online! Explanation: Removing a " allows the # symbol to be used as a comment. Yes, I know this isn't very golfed.

*-3 and fixed thanks to Makonede.*

# Answer
> 2 votes
# Knight (c/golf), 50 bytes

```
O+"Stack Exchange"+" Chat"" - The Nineteenth Byte"

```

Try it online!

Every Knight program is actually one expression. It has to manually chain each statement, typically using `;`.

So for example:

```
OUTPUT "Hello"
OUTPUT "World!"

```

will only output `Hello` because output only has one argument. Everything else is undefined behavior, but almost all interpreters ignore it.

So therefore, we can easily truncate a program by breaking the "link".

So in my program, the nineteenth byte is this `+`.

```
O+"Stack Exchange"+" Chat"" - The Nineteenth Byte"
~~~~~~~~~~~~~~~~~~^

```

When the `+` is there, it is parsed as this:

```
# Concatenate " Chat" and " - The...", append to "Stack Exchange" and output
OUTPUT +("Stack Exchange" +(" Chat" " - The Nineteenth Byte"))

```

When we remove it, it is parsed as so:

```
# Concatenate "Stack Exchange" and " Chat", then output
OUTPUT +("Stack Exchange" " Chat")
# ignored because we no longer are concatenating
# " - The Nineteenth Byte"

```

# Answer
> 2 votes
# AsciiDots, 63 bytes

```
/' kcatS'_$-..----\
\$_'Exchange Chat'~$' - The Nineteenth Byte

```

Try it online!

I feel like I can still save a byte or two but I am unsure.

# Answer
> 2 votes
# Pip, 51 bytes

```
O"Stack Exchange "Y" - The Nineteenth Byte""Chat".y
```

Attempt This Online!

### Explanation

```
; Output "Stack Exchange " without a trailing newline
O"Stack Exchange "
; 19th character is Y; with it, yank " - The Nineteenth Byte" into the y variable
; Without Y, the string by itself is a no-op and y keeps its initial value of ""
Y" - The Nineteenth Byte"
; Concatenate "Chat" with y and autoprint the result
"Chat".y

```

# Answer
> 2 votes
# Turing Machine Code, ~~428~~ 447 bytes

```
0 _ _ * 3
1 _ _ * 32
2 _ _ l halt
3 _ S r 4
4 _ t r 5
5 _ a r 6
6 _ c r 7
7 _ k r 8
8 _ _ r 9
9 _ E r a
a _ x r b
b _ c r c
c _ h r d
d _ a r e
e _ n r f
f _ g r g
g _ e r h
h _ _ r i
i _ C r j
j _ h r k
k _ a r l
l _ t r 1
32 _ _ r H
H _ - r I
I _ _ r m
m _ T r o
o _ h r p
p _ e r q
q _ _ r r
r _ N r s
s _ i r t
t _ n r u
u _ e r v
v _ t r w
w _ e r x
x _ e r y
y _ n r z
z _ t r A
A _ h r B
B _ _ r C
C _ B r D
D _ y r E
E _ t r G
G _ e * halt

```

Try it online!

Without 19th:

```
0 _ _ * 3
1 _ _ * 2
2 _ _ l halt
3 _ S r 4
4 _ t r 5
5 _ a r 6
6 _ c r 7
7 _ k r 8
8 _ _ r 9
9 _ E r a
a _ x r b
b _ c r c
c _ h r d
d _ a r e
e _ n r f
f _ g r g
g _ e r h
h _ _ r i
i _ C r j
j _ h r k
k _ a r l
l _ t r 1
32 _ _ r H
H _ - r I
I _ _ r m
m _ T r o
o _ h r p
p _ e r q
q _ _ r r
r _ N r s
s _ i r t
t _ n r u
u _ e r v
v _ t r w
w _ e r x
x _ e r y
y _ n r z
z _ t r A
A _ h r B
B _ _ r C
C _ B r D
D _ y r E
E _ t r G
G _ e * halt

```

Thanks to *@Makonede* for spotting the hyphen gaff.

Try it without the 19th Byte!

# Answer
> 2 votes
# Google Sheets, 64 bytes

```
="Stack Excha"&if(1,"nge Chat - The Nineteenth Byte","nge Chat")

```

# Answer
> 2 votes
# TI-Basic, 83 bytes

```
"nge Chat
If 01
Ans+" - The Nineteenth Byte
"Stack Excha"+Ans

```

-1 byte by replacing `i` with the imaginary number *`i`*

TI-Basic is tokenized, so the nineteenth byte is `1`. Despite being 83 bytes, this is not compatible with the TI-83.

# Answer
> 2 votes
# Batch, 70 bytes

```
set as=e Chat
set as=%as% - The Nineteenth Byte
echo Stack Exchang%as%

```

# Answer
> 2 votes
# Vyxal, 44 bytes

```
⟨`⟩τ •› °ʀ`||` - λƛ ∵∷⟑⌈th ₁ḋ`⟩:£ṅ\+c[¥h|¥ṅ]

```

Try it Online!

When removing the 19th byte it gives:

```
⟨`⟩τ •› °ʀ`||` - λ ∵∷⟑⌈th ₁ḋ`⟩:£ṅ\+c[¥h|¥ṅ]

```

# Answer
> 1 votes
# Stax, 35 bytes

```
`/yT)6bX$`p      01D`|<<T,/-Gk5gD8/

```

Run and debug it

Remove the nineteenth byte(booooo)

The compressed literal for the whole string is \> 19 bytes, so it has to be split for a working solution (unless wastl finds some insane compression exploit)

# Answer
> 1 votes
# Groovy, 66 bytes

```
m='change Chat'+(01?' - The Nineteenth Byte':'')
print'Stack Ex'+m

```

Try it online!

### Without 19th byte

```
m='change Chat'+(0?' - The Nineteenth Byte':'')
print'Stack Ex'+m

```

Try it online!

# Answer
> 1 votes
# Befunge-93, 78 bytes

```
v>"xe kcatS" >:#,_#@"etyB htnee"v
v^"chang"<>:#,_@#"  - The Ninet"<
>"tahC e"^

```

Try it online!

The 19th byte is the '#' right before '@' on the first line. If it is removed, execution will stop at '@'.

### Explanation

```
v>"xe kcatS"          Pushes the first section of the string
v^"chang"<
>"tahC e"^

>:#,_                 Prints it

#@                    '#' is the 19th byte, it will skip the '@'. If it's removed
                      the execution will stop at '@'

   "etyB htnee"v      Push the second section of the string (there is an extra space
"  - The Ninet"<      because one char is lost when printing)

>:#,_@#               Prints it

```

# Answer
> 1 votes
# JavaScript (V8), 60 bytes

```
e="Exchange Chat "+
"- The Nineteenth Byte"
print("Stack",e)

```

Try it online!

Similar to

# Answer
> 1 votes
# Julia, 61 bytes

```
s=" Exchange Chat"*
" - The Nineteenth Byte";print("Stack"*s)

```

Try it online!

port of xnor's answer

`*` is the 19th byte.

with the `*`, the expression is incomplete so it continues an the next line. Without it, the expression ends and the next string is useless

Try it without the 19th character!

# Answer
> 1 votes
# AWK, 68 bytes

```
BEGIN{a="Stack ";b=" - The Nineteenth Byte";print a"Exchange Chat"b}

```

Try it online!

# Answer
> 1 votes
# Hexagony, 125 bytes

```
S;t;a;\;c;h;a\ch;a$].\\;aC;$@h;\;n;"T;h;e\a;tt;e;e;n\;{;";.t;e;@\t;h;..;k;{32;"E;x.n;g;e;{;C;.;g;e;{;"C;{;'45;}.N;i;n;e;{;B;y

```

Try it online!
Try it without 19th Byte!

## Expanded versions:

Original:

```
       S ; t ; a ; \
      ; c ; h ; a \ c
     h ; a $ ] . \ \ ;
    a C ; $ @ h ; \ ; n
   ; " T ; h ; e \ a ; t
  t ; e ; e ; n \ ; { ; "
 ; . t ; e ; @ \ t ; h ; .
  . ; k ; { 3 2 ; " E ; x
   . n ; g ; e ; { ; C ;
    . ; g ; e ; { ; " C
     ; { ; ' 4 5 ; } .
      N ; i ; n ; e ;
       { ; B ; y . .

```

Without 19th:

```
       S ; t ; a ; \
      ; c ; h ; a \ c
     h ; a ] . \ \ ; a
    C ; $ @ h ; \ ; n ;
   " T ; h ; e \ a ; t t
  ; e ; e ; n \ ; { ; " ;
 . t ; e ; @ \ t ; h ; . .
  ; k ; { 3 2 ; " E ; x .
   n ; g ; e ; { ; C ; .
    ; g ; e ; { ; " C ;
     { ; ' 4 5 ; } . N
      ; i ; n ; e ; {
       ; B ; y . . .

```

# Answer
> 1 votes
# Ly, 59 bytes

```
"Stack Exchange "0`sp"Chat"&o"etyB htneeteniN ehT - "l*[o];

```

Try it online!

This code stashes a `0` or `1` depending on whether or not the 19th character is deleted. Then that value is pull back to conditionally print the extra characters after the string both outputs have in common is printed.

```
1. Handles the string both outputs have in common

"Stack Exchange "              - push the start of the common string
                 0`sp          - full code, push 0, increment, save "1"
               -- or --
                 0sp           - w/ 19th char dropped, saves "0"
                     "Chat"    - push the rest of the common string
                           &o  - print stack as string, reverse order

2. Deal with the optional string

"etyB htneeteniN ehT - "        - push remaining string, in reverse
                        l*      - load saved value multiply top of stack
                          [o]   - while top of stack!=0, print as char
                             ;  - exit to avoid printing the stack

```

---
Tags: code-golf, kolmogorov-complexity
---


title: Implement a strange automaton

text:
# Question
Title: Implement a strange automaton
I was playing around with cellular automaton and I found one that had some interesting behavior. Here's how it works:

It reads a binary string from left to right, if it encounters a `1` followed by `2` other values it will append a `0` to the result and continue reading. If it encounters a `0` (or there are less than 3 values left) it will append the current value and a `1` and continue reading. At the end of the string it will append a single `1` to the result.

Here's a worked out example of one generation

```
01011111
^

```

We first encounter a `0` so we append `01` to our result

```
01011111
 ^
01

```

Now we encounter a `1` so we append a zero and skip the next two values

```
01011111
    ^
010

```

We encounter another `1` so we do the same

```
01011111
       ^
0100

```

We now have another `1` but not enough space to jump so we append the current cell and a `1` (in this case `11`)

```
01011111
        ^
010011

```

We are at the end so we append a single `1` and terminate this generation

```
01011111
        ^
0100111

```

# Task

Given input in any reasonable format you must create a function or program that computes one generation of the automaton.

This is a question so answers will be scored in bytes, with fewer bytes being better.

# Sample implementation

Here is a sample implementation in Haskell (defines a function `d`, but the program prints a iterations indefinitely):

```
d('1':_:_:x) = "0" ++ d x
d(a:x) = a:'1':d x
d x = "1"
r x = x:map d(r x)

```

Try it online!

# Answer
# , ~~26~~ ~~22~~ 21 bytes

Thanks to @CowsQuack for 4 bytes by combining regexes! And @ØrjanJohansen for another byte with some regex combinations.

```
Ó1../3
Ó./&1
Ó31/0
A1

```

Try it online!

Uses substitute multiple times and appends a 1 at the end. Nothing too fancy. I have a version that remaps `1` and `0` in insert mode to get the desired effect, but it's quite a bit longer.

(Multiple replacement version: Try it online!)
> 7 votes

# Answer
## JavaScript (ES6), 56 bytes

Takes input as an array of characters. Returns a string, or the number `1` if given an empty array.

```
f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

```

### Demo

```
f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

console.log(f([...'01011111']))
console.log(f([...'10']))
```

### Animated version

Examples of stable inputs: 0101, 010011111

```
f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

s = '1';
setInterval(_=>o.innerHTML=s=''+f([...s]), 200)
```

```
<input oninput="s=this.value" value="1" />
<pre id=o style="font-size:32px"></pre>
```
> 3 votes

# Answer
# Python 2, 89 bytes

```
x=input()
y=0
k=[]
while x[y:]:v=1-x[y]*(y<len(x)-2);k+=[x[y]]*v+[v];y+=3-2*v
print k+[1]

```

Try it online!

-4 bytes thanks to Rod
-6 bytes thanks to ovs
-1 byte thanks to micsthepick
> 2 votes

# Answer
# Python 2, 88 bytes

```
I,r=input(),[]
while I:a=I[0]and len(I)>2;b=a<1;r+=[I[0]]*b+[+b];I=I[a*2+1:]
print r+[1]

```

Try it online!
> 2 votes

# Answer
# Swift 3, 147 bytes

-1 thanks to @Mr.Xcoder

```
func g(i:[Int]){var r=[Int]();var s=ArraySlice(i);while let e=s.popFirst(){if 0<e&&2<s.count{r+=[0];s=s.dropFirst(2)}else{r+=[e,1]}};print(r+[1])}

```

Ungolfed, returning the value rather than printing:

```
func iterate(state: [Int]) -> [Int] {
    var result = [Int]()

    var inputSlice = ArraySlice(state)

    while let element = inputSlice.popFirst() {
        if 0 < element && 2 < inputSlice.count {
            result += [0]
            inputSlice = inputSlice.dropFirst(2)
        }
        else {
            result += [element, 1]
        }

        //debugPrint(result.map(String.init).joined(separator: ""))
    }

    return result + [1]
}

```
> 2 votes

# Answer
# Nim, 70 bytes

```
import re,sugar
x=>x.multiReplace([(re"1..","0"),(re"(.)","$#1")])&"1"

```

Try it online!

`multiReplace` allows us to do substitutions simultaneously. The index of the tuple within the sequence acts as the priority if there is a situation where more than one substitution can be made. The priority rises the lower the index is.
> 2 votes

# Answer
# Perl 5, 62 + 2 (`-F`) = 64 bytes

```
$r.=$F[$i]&&$i+2<@F&&($i+=2)?0:"$F[$i]1";++$i<@F&&redo;say$r.1

```

Try it online!
> 1 votes

# Answer
# Python 2, 81 bytes

**Both input and output are lists** (thanks to Erik the Outgolfer)

```
def f(Z):return Z and((1>Z[0]or 3>len(Z))and[Z[0],1]+f(Z[1:])or[0]+f(Z[3:]))or[1]

```

Try it online!

**Some cases**

```
[0,1,0,1,1,1,1,1] --> [0,1,0,0,1,1,1]
[0] ----------------> [0,1,1]
[1] ----------------> [1,1,1]
[] -----------------> [1]
[0,1] --------------> [0,1,1,1,1]
[1,0] --------------> [1,1,0,1,1]

```

# Python 2, 85 bytes

**Both input and output are strings** (initial solution)

```
def f(Z):return Z and(('0'==Z[0]or 3>len(Z))and Z[0]+'1'+f(Z[1:])or'0'+f(Z[3:]))or'1'

```

Try it online!

**Some cases**

```
'01011111'--> 0100111
'0'---------> 011
'1'---------> 111
''----------> 1
'01'--------> 01111
'10'--------> 11011

```

**Explication** It is simplily a golf of a recursive method.
> 1 votes

# Answer
# Ruby, 47 bytes

This is a direct port of the sample implementation Haskell code.

```
f=->s{s=~/^1../??0+f[$']:s=~/./?$&+?1+f[$']:?1}

```

Attempt This Online!

## More readable

`$&` is the matched text from the previous regexp match (`=~`) and `$'` is the text after the match.

```
f = ->s{
  if s =~ /^1../ then "0" + f[$']
  elsif s =~ /./ then $& + "1" + f[$']
  else "1"
  end
}

```
> 1 votes

# Answer
# Julia 0.6, ~~69~~ 65 bytes

```
~s=s>""?s<"1"?"01"*~s[2:end]:length(s)>2?"0"*~s[4:end]:s*"11":"1"

```

Try it online!

Ungolfed and commentated algorithm:

```
function ~(s)

  # Return "1" on the empty string
  # (End case for automata ending in "0" or "1..")
  if s == ""
    return "1"

  # "0" always becomes "01"
  elseif s[1] == '0'
    return "01" * ~s[2:end]

  # "1.." always becomes "0"
  elseif length(s) > 2
    return "0" * ~s[4:end]

  # Otherwise, append "11"
  # (End case for automata ending in "1" or "1.")
  else return s * "11"

  end
end

```

Try it online!

* -3 bytes thanks to MarcMush: Test the value of `s` instead of `s[1]`
* -1 byte thanks to MarcMush: Rewrite with `s>""` instead of `s==""`
> 1 votes

# Answer
# Scala, 131+29=160 bytes

This is inside a function taking the string `a` as parameter and returning the output as a string.

```
var s=""
var k=0
for(c<-0 to a.length-1)breakable{if(k>0){k-=1
break}
if(a(c)==49&c<a.length-3){s+="0"
k+=2}else s+=a(c)+"1"}
s+"1"

```

I do have to `import util.control.Breaks._`, so I need to add those 28 bytes plus a trailing linefeed.

Try it online!
> 0 votes

# Answer
# C# (.NET Core), 108 bytes

```
n=>{var t="";for(int i=0,b=n.Length;i<b;){if(n[i]>'0'&i+2<b){t+="0";i+=3;}else t+=n[i++]+"1";}return t+"1";}

```

Try it online!

Input taken as a string, and a string is returned as output.
> 0 votes

---
Tags: code-golf, cellular-automata
---