title: It almost works (Cops' Thread)

text:
# Question
Title: It almost works (Cops' Thread)
Robbers' Thread

Your challenge is to find an existing challenge, and implement it in a way such that certain inputs fail. At least one input must not produce the correct output (use the other submissions on the challenge as a reference for this, but be sure to double-check). This must fail *consistently*, and you must know at least one input that fails.

The challenge must satisfy the following:

* +10 net score
* Open
* Not language-specific
* Posted before 8 Jul 2021
* Unlocked
* Not
*
* Have at least 3 existing answers

The robbers will be trying to find an input which fails.

You must share the challenge, the language and your code. If a robber has not cracked your solution after a week, it is safe and you can reveal your failing input.

You may specify bounds - for example, you can say that inputs must have less than 20 digits, as long as there is an invalid value within those bounds. You should also say that input is a string/list of numbers/number/tuple/whatever.

# Scoring

Your score is the length of your shortest *safe* program, in bytes, with shorter being better. You are allowed to post multiple submissions.

Here's an SEDE query for valid questions kindly provided by fireflame241.

# Answer
> 8 votes
# Python 2, 120 bytes, “DDoouubbllee ssppeeaakk!!”, cracked by Sisyphus

```
import re
def f(s):
 try:s=re.search('[a-z]{4}|[^a-z()]',s)<0<eval(s)=='hax'or s
 except:0
 return''.join(c*2for c in s)

```

Try it online!

As in the question, only printable ASCII are allowed as input.

(Guess my password is possibly a better fit for this challenge, ¯\\\_(ツ)\_/¯).

---

The cracked solution used a Python bug to segfault the program. I'll reveal mine in two days, but before then I'd love to see if anyone can figure out a solution closer to what I had intended.

~~As an incentive, I'll offer +50 rep to any new answer which cracks this before the two days. In particular, it must not produce an error on the line containing `s=...`, regardless of whether it gets caught.~~

---

**No one found my intended solution, so here it is**:

> `max(max(dir()for(hax)in(dir)()))`, Try it online!

And here is an explanation:

> First, let's determine what is expected of us to solve this challenge. We must input a Python expression, such that it evaluates to the string `'hax'`. The regex also places two restrictions upon us: only letters and parentheses are allowed, and there can be no consecutive substring consisting of four letters.
> These restrictions don't leave us with many options. We're essentially being limited to a small set of builtins (e.g. `max`, `chr`), and a few basic constructs like `for` or `and`. I've so concluded that most of the obvious approaches are very unlikely to succeed. You may or may not have noticed that the target string, `'hax'`, exactly matches the regex; this tiny detail is a crucial one.
> I've teased you long enough, so let's begin dissecting the solution:
> `max(max(dir()for(hax)in(dir)()))`
> Some of the parentheses used here are only to ensure that no spaces exist in our program. Removing the extra obfuscation, we get:
> `max(max(dir()for hax in dir()))`
> A lot easier to read!
> Within all the `max`s, there is a list comprehension, which iterates through `dir()` using the variable `hax`. The `dir()` is completely arbitrary, anything will work as long as we can loop over it. For each iteration in the comprehension, we store the result of `dir()`. When no arguments are given like this, it returns a list of names in the current local scope (see **`dir`**). As a result, the entire comprehension contains `[['.0', 'hax'], ['.0', 'hax'], ...]` Note that the `.0` is a "secret" variable which stores the list comprehension itself.
> We are now 90% of the way there! By calling `max` once on the result, we obtain a single copy: `['.0', 'hax']`. Calling it once more, we finally get our result: `'hax'`.

# Answer
> 7 votes
# Jelly, 7 bytes, Is it double speak?, Cracked by Stephen

```
ṾḊṖ⁼2/Ạ

```

Try it online!

Given how difficult Jelly can be to understand, I've provided an explanation to help the Robbers:

```
ṾḊṖ⁼2/Ạ - Main link. Takes a string L on the left
Ṿ       - Uneval L. This makes sure we're processing a string, as Jelly can
          try to evaluate the input if it's all digits
 ḊṖ     - Dequeue and pop. Remove the quotes that Ṿ puts around the string
    2/  - Split into chunks of 2 (e.g. [A, B]), then over each chunk:
   ⁼    -   Is A equal to B?
      Ạ - Is this true for all A?

```

---

Note that this wasn't my intended crack. Another answer incoming

# Answer
> 7 votes
# Taxi, 1134 bytes, Draw an asterisk triangle, Cracked by Unrelated String

```
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to The Underground.'\n'is waiting at Writer's Depot.Go to Writer's Depot:n 5 l 2 l.Pickup a passenger going to Rob's Rest.Go to Rob's Rest:n 1 r 1 r 1 r 1 r.[a]Pickup a passenger going to KonKat's.'*'is waiting at Writer's Depot.Go to Writer's Depot:s 1 l 1 l 1 l 1 l.Pickup a passenger going to KonKat's.Go to KonKat's: n 3 r 2 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 2 l.Pickup a passenger going to Post Office.Pickup a passenger going to Rob's Rest.Go to Rob's Rest:s 1 l 1 r 1 r 1 r.0 is waiting at Starchild Numerology.Go to Starchild Numerology:s 1 l 1 r 2 l.Pickup a passenger going to Magic Eight.Go to Post Office:w 1 r 2 r 1 r 1 l.Go to The Underground:n 1 r 1 l.Pickup a passenger going to Cyclone.Go to Cyclone:n 3 l 2 l.Pickup a passenger going to The Underground.Pickup a passenger going to Magic Eight.Go to Magic Eight:s 1 l 2 r.Pickup a passenger going to Riverview Bridge.Go to Riverview Bridge:s 2 l 4 l.Go to Rob's Rest:w 2 l 2 l 1 r 1 r 1 r.Switch to plan "a".

```

Try it online!

Terminates by error. Prints leading newline (allowed by linked challenge, see comments).

Always fun to bang my head against Taxi's map :D

# Answer
> 6 votes
# Jelly, 12 bytes, Make a ;# interpreter, Cracked by Stephen

```
ṣ”#Ṗċ€”;%Ø⁷Ọ

```

Try it online!

Since the challenge was first posted, Jelly's had a few updates, including some nice new nilads (`127` \\$\to\\$ `Ø⁷`) to save a byte :)

# Answer
> 6 votes
# Python 3, 252 bytes, Is this number a prime?, cracked by ovs

```
I=int(input())
L=I<2
l=int('1ecvme02wjate5lzjhukn4elhetiycct0crct68uhrtiafbxxfcmvqjvz',36)
while l:
 i=I;j=J=l&131071;_=1
 while j:
  while~j%2:j>>=1;_*=1|-(i&7in(3,5))
  j,i=i,j;_*=1|-(j&3==i&3>2);j%=i
 L+=pow(J,~-I>>1,I)!=(i<2)*_%I
 l>>=17
print(L<1)

```

Try it online!

Inputs should be positive integers please. I don't expect this to be cracked (prove me wrong!)

# Answer
> 5 votes
# Jelly, 6 bytes, Is it double speak?, Cracked by hyper-neutrino

```
ṾḊṖŒœE

```

Try it online!

My last answer got cracked due to weird `2/` behaviour, so here's a golfier version. I've got the explanation as well:

```
ṾḊṖŒœE - Main link. Takes a string L on the left
Ṿ      - Uneval L. This makes sure we're processing a string, as Jelly can
          try to evaluate the input if it's all digits
 ḊṖ    - Dequeue and pop. Remove the quotes that Ṿ puts around the string
   Œœ  - Odd-even. Group the elements at even indices, and those at odd indices
     E - Are they both equal?

```

---

(uneval) will surround a string with `“...”`, which `ḊṖ` will remove. Unless the string has  in it, in which case it will treat each character in the string as a char literal `”x` and will join them by commas:

`“abc`  is `”“,”a,”b,”c`

# Answer
> 5 votes
# JavaScript, 163 bytes, Hello, world!, cracked by Stephen

```
n=>{if(typeof n=="object"||n-32!=n-32)return "Hello, World!";var d=n-32;return [40,69,76,76,79,12,0,55,79,82,76,68,1].map(x=>String.fromCharCode(n-d+x)).join("")};

```

Small byte save by offsetting the char codes by 32.

**Intended crack:**

> ```
> (() => {
>     var f = x => x;
>     var i = 0;
>
>     f.valueOf = () => i++ < 2 ? 0 : i;
>
>     return f;
> })()
> ```
>
> This is a function which will return `0` the first two times it's cast to a number (to bypass the initial checks), then return an incrementing value. It results in an output of `Igopt2'_x|wp.`, instead of the correct one.

# Answer
> 4 votes
# Vyxal, 4 bytes, Shortest code to determine if a string is a palindrome, cracked by A username

```
Ǎ⇩Ḃ=

```

Try it Online!

Returns `1` for palindromes and `0` for non-palindromes.

The challenge states that numbers affect palindrominess, but as A username pointed out, this ignores numbers.

# Answer
> 4 votes
# Vyxal, 4 bytes, Least common multiple

```
Π?ġ/

```

Try it Online!

Cracking it should be easy, so no Hints

# Answer
> 4 votes
# Python 3, 580 bytes, Simulate a Rubik's cube \- Safe!

Not going to win by byte count but maybe it'll make for an enjoyable rob.

```
import re
exec("d,*r=[[f]*9for f in' YBRGOW'];u,q,v,p,s,w,x,y,z=lambda v:[v[x],y(y(y(v[z]))),v[s],y(v[q]),v[0][::-z],v[p][::-z]],3,lambda w:[y(w[0])]+[w[j%p-~all(s<len(set(f))for f in w)][:q]+w[j][q:]for j in(z,x,q,p)]+[w[s]],4,5,lambda u:[y(u[0])]+u[x:s]+[u[z],y(y(y(u[s])))],2,lambda f:[f[int(v)]for v in'630741852'],1;r="+"(r);r=".join("".join("uuuvu v uuvuu wwwuvuuuw uvuuu wuvuuuwww".split()[778194%ord(t)%9]*(ord(n or'y')%6)for t,n in re.findall("([B-U])(['2i]?)",input())))+"(r);y=' '.join")
for u in[d,r[0]],r[z:s],[d,r[s]]:
 for w in 0,q,6:print(y(y(v[w:w+q])for v in u))

```

A full program reading a valid move sequence from STDIN that attempts to print the net of a Rubik's cube scrambled as instructed. I'll also specify a bound of 20 face turns :)

**Try it online!** Or see a few working ones here (the last one places the cube into the Superflip)

### Failing inputs

> The simulator performs a quarter-turn of a face by rotating the entire cube as need be, turning the cube's "U" face a quarter-turn, and rotating back. To turn the "U" face it permutes the stickers on the face and, separately, the stickers around the "U" face's edge, on the "L", "F", "R", and "B" faces. The latter is performed by concatenating two slices, but the code:
> `...+[w[j%p-~all(s<len(set(f))for f in w)][:q]+w[j][q:]for j in(z,x,q,p)]+...`
> should be:
> `...+[w[j%p+z][:q]+w[j][q:]for j in(z,x,q,p)]+...`
> ...or with less obscured code:
> `...+ [faces[j%4+1][:3] + faces[j][3:] for j in (1,2,3,4)] +...`
> i.e:
> `...+ [first_3_of_previous + last_6_of_current for LFRB] +...`
> This is only the case when `all(s<len(set(f))for f in w)` is `False` (`~False = ~0 = -1-0 = -1`) or, equivalently, when:
> `all(5 < len(set(stickers)) for stickers in faces)`
> Otherwise `~all(...)` evaluates to `~True = ~1 = -1-1 = -2` and stickers are copied from the wrong faces for this band (instead of using the first three stickers of each of the FRBL faces to fill the LFRB band it uses the first three stickers of each of the RBDF faces.
> Thus, **after the cube shows all six colours on every one of its six sides** the simulator fails.
> An 8-move sequence that achieves such a state is `F' B L R' B F R2 D2`, so adding one more face turn does it, thus a crack is something like `F' B L R' B F R2 D2 U` \- see that the fourth cube net output **here** is different to the, correct, third cube net, while the first and second are the same, and show all six colours on all faces prior to the attempted final "U".

# Answer
> 3 votes
# Vyxal, 17 bytes, Stack Exchange Vote Simulator, Cracked because I misread the challenge

```
C⁽꘍R:£80>[¥₁-±N|0

```

Try it Online! ~~Just to start things off. I feel this will get cracked very easily though.~~

I misread the challenge. My intended crack was an empty string - Vyxal barfs on reducing empty lists/strings.

Input is a string of `^v`.

Here's an explanation:

```
C                 # Charcodes
   R              # Reduced by...
 ⁽꘍               # Bitwise xor
    :£            # Store a copy to register
      80>[        # If it's over 80
          ¥₁-     # Subtract 100
             ±N   # Get the sign negated
               |0 # Else return 0.

```

Hint: The bug's in Vyxal itself, not my code.

# Answer
> 3 votes
# Vyxal , 0 bytes, Simple Cat Program, cracked by A username

Try it Online!

# Answer
> 3 votes
# Python 3, 71 bytes, Convert YYYYMM to MMMYY, cracked by SevC\_10

```
lambda s:" JFMAMJJASONDAEAPAUUUECOENBRRYNLGRTVC"[int(s[4:])::12]+s[2:4]

```

Try it online!

Probably way too easy, but worth a try.

# Answer
> 3 votes
# Python 3, 119 bytes, Simple cat program

```
while 1:
 i=input()
 if 1583454170589139748634332997977758356543730781438558028881854463983253%ord((i+'e')[0]):print(i)

```

Try it Online!

It's not the prettiest or the shortest, but I'm hoping it at least takes you all a second to figure it out.

# Answer
> 2 votes
# Jelly, 15 bytes, Generate Recamán's sequence, cracked by pajonk

```
ạLṪḟȯ+L$Ṫ;@
Ç¡Ṗ

```

A full program that accepts a non-negative integer, `n` and attempts to print the first `n` terms of the Recamán sequence.

**Try it online!**

Shouldn't prove at all difficult to crack.

---

> This actually implements A335299, which first differs from Recamán's sequence at \\$n=57\\$ for which this gives \\$27\\$ instead of \\$87\\$ due to the code using the absolute difference instead of (a) performing subtraction and (b) ignoring negative values.

# Answer
> 2 votes
# JavaScript, 151 bytes, Is this even or odd?, cracked by Bubbler

```
x=>{var b=[...x.toString(2)].reverse()+"";try{eval.call(window,(t=y=>y?t(y/256n)+String.fromCharCode(Number(y%256n)):"")(x))}catch{};return +[...b][0]}

```

Input must be a positive bigint.

**Intended Solution:** (similar to Bubbler's):

> ```
> 3615512360242432329658769258555380793536772285803851385241947165871497272426648554788915044798172040751481373577054244237102559357n
> ```
>
> This is a representation of the payload:
>
> ```
> String.prototype[Symbol.iterator]=function*(){yield 0}
> ```
>
> This results in `[...b]` always returning `[0]`, so the input (which is odd) results in the output returned for even numbers.

# Answer
> 2 votes
# Python 3, 74 bytes, Is this number a prime, cracked by dingledooper

```
x=int(input())
print(x>1 and next(d for d in range(2,x+1)if x/d==x//d)==x)

```

Try it online!

# Answer
> 2 votes
# Pip, 11 bytes, Output a string's cumulative slope \- Safe!

```
Yq$-A[RVyy]

```

Try it online! (The crack also works on TIO.)

### Explanation

```
Yq           Read a line of input and store it in y
     [    ]  Make a list containing
      RVy     y, reversed
         y    and y
    A        Get the ASCII value of (the first character of) each of those strings
  $-         Fold on subtraction

```

---

Failing inputs:

> `00`, `000`, `.0`, and in general anything that looks like a numeric literal for `0`. These inputs do not output anything. If you turn warnings on using the `-w` flag, you'll see a warning "Cannot take ASC of empty string."

Why?

> It's an interpreter bug which was fixed in this commit (thus the requirement to use the TIO version of Pip).
> When I wrote the code for the `A` operator, I wanted to raise a warning and return nil if the operand was an empty string. So I started by testing whether the operand was falsey. I must have been thinking about Python strings, which are only falsey if they're empty; but in Pip, strings and numbers are a single type, Scalar. A Scalar is falsey if it is the empty string *or* if it is zero. Thus, the implementation of `A` choked if you passed it `0` or any other literal for zero--a pretty annoying bug.

# Answer
> 1 votes
# Vyxal, 40 bytes, Find the first word starting with each letter, cracked by EliteDaMyth

```
kBð\_9ɾṅṠ↔⌈:£ƛh⇩⅛¥ƛh⇩;¼ḟ¥$i=[|¤;;';ðvp∑Ṫ

```

Try it Online!

I made this while navigating various random bugs. It should work on the current implementation of Vyxal, but may not in the future.

My intended crack: Anything involving zeroes. `kBð\_9ɾṅṠ` assembles a string, and here's how it works:

```
kB        # Push lowercase + uppercase alphabet
  ð       # Push space
   \_     # Push underscore
     9ɾṅ  # Push 1-9 - no 0!
        Ṡ # Concatenate all

```

Then everything not in that is removed, including zeroes.

# Answer
> 1 votes
# Rattle, 3 bytes, Simple cat program, cracked by hyper-neutrino

```
|!p

```

Try it Online!

This should be relatively easy to crack. It takes advantage of one of Rattle's core features!

Hint: A perfect cat program is simply `|`

# Answer
> 1 votes
# Python 3, 63 bytes, Is this number a prime, cracked by pppery

```
lambda x:next(d for d,_ in enumerate(iter(int,1),2)if x%d<1)==x

```

Try it online!

---
Tags: code-golf, cops-and-robbers
---


# Question
Title: Happy Birthday... caird coinheringaahing? ChartZ Belatedly?
When this question was posted, it was caird coinheringaahing's birthday! (source: , , , ) (It was also World Emoji Day.)

As a bit of some CGCC lore, caird's name came from a Jelly answer by Dennis (source) - the compressed form of "Code Golf" in Jelly is `“½ċṭ6Ỵ»`, and if you insert a space (`“½ċṭ6 Ỵ»`), it becomes "caird coinheringaahing" instead, which was important for this challenge as the former is lexicographically smaller than "Programming Puzzles", but the latter is larger.

Shifting the space around also gives some other resulting strings, and among them is "ChartZ Belatedly", which was caird's username during March of 2021.

## Challenge

Output the string `Happy Birthday, caird coinheringaahing!` exactly.

The catch: for every character in your code, there must be at least one valid position that you can move it to such that the resulting program outputs `Happy Birthday, ChartZ Belatedly!` exactly.

For example, if `abcd` outputs the first string and `bcad`, `acdb`, `cabd`, and `abdc` output the second string, then this would be a valid program (`a` can be moved to the third position, `b` to the fourth, `c` to the first, and `d` to the third).

(The idea for this came from caird themself, actually, so thanks to them :P)

## Rules

* You may output any amount of leading or trailing whitespace, and it does not have to be consistent either between the two strings or between varying programs printing the second string. For example, printing `"Happy Birthday, ChartZ Belatedly! "` for `bcad` and `" \nHappy Birthday, ChartZ Belatedly! \t \r\n"` for `acdb` would be valid.
* No input will be given (the standard rules like allowing accepting an empty/null input apply).
* Your output method must be consistent though, so for example, if you print to STDOUT for the first string, you must do so for all other strings.
* You must not output anything else with the chosen output method, but you can output to other methods (what I mean by this is if you output to STDOUT, you can flood STDERR with random garbage, and if your submission is a function that produces the result, you can output freely to STDOUT, etc.)

## Scoring

This is a challenge still, so the shortest answer in bytes wins among submissions in its language.

# Answer
# Zsh `-y`, <sup>~~145~~ ~~148~~ ~~144~~ ~~142~~ ~~131~~</sup> 130 bytes

```
1="echo Happy Birthday, ";$1caird coinheringaahing!>x
"\";$1ChartZ Belatedly!>x #"
"\";echo Happy Birthday, ChartZ Belatedly!>x #"
```

Attempt This Online!

Outputs to a file called `x`, which allows us to save bytes exiting because we can overwrite the file to change the output instead of needing to exit the program.

* Any character on the first line, including its trailing newline, should go between the `\` and `"` on the third line
* The final `"` on the second line should go at the end of the third, and vice versa
* Any other character on the second line, including its trailing newline, should go between the `\` and `"` on the third line, and vice versa

---

Some of the modified programs are highly cursed. For instance, moving the `x` on the first line:

```
1="echo Happy Birthday, ";$1caird coinheringaahing!>
"\";$1ChartZ Belatedly!>x #"
"\x";echo Happy Birthday, ChartZ Belatedly!>x #"

```

This produces a "parse error" because of the trailing `>`, but zsh ...just continues executing the program??
> 17 votes

# Answer
# Jelly, ~~88~~ 69 bytes

```
FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN»

```

Try it online!

A niladic link that prints "Happy Birthday, caird coinheringaahing!"

Thanks to @JonathanAllan for pointing out I could save 19 bytes by changing the last string to a compressed one.

Explanation of base script:

```
F         | Flatten
 L        | Length
  e33,39  | Is one of 33 or 39
        ḷ | Left (effectively a no-op here)

```

```
““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»                                           | ["", "Happy Birthday, caird coinheringaahing!"]
                                 Ç?                         | If helper link returns truthy:
                 ¹                                          | - Identity function
                  “®Ẉ'¶ẒȮzṂ#jKgN»                           | Else: ["", "Happy Birthday, ChartZ Belatedly!"]
                                   Çȧ$                      | helper(x) logical and x
                                      Çȧ$                   | helper(x) logical and x
                                         ḷ                  | Left (effectively a no-op here)
                                          ȯ““®Ẉ'¶ẒȮzṂ#jKgN» | logical or ["", "Happy Birthday, ChartZ Belatedly!"]

```

Here are the variants (produced by this script) that print "Happy Birthday, ChartZ Belatedly!":

```
 0 F 10 Le33,39ḷ¶“F“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 1 L 10 Fe33,39ḷ¶“L“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 2 e 26 FL33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»e¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 3 3 10 FLe3,39ḷ¶“3“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 4 3 10 FLe3,39ḷ¶“3“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 5 , 10 FLe3339ḷ¶“,“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 6 3 10 FLe33,9ḷ¶“3“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 7 9 10 FLe33,3ḷ¶“9“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 8 ḷ 10 FLe33,39¶“ḷ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
 9 ¶  1 F¶Le33,39ḷ““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
10 “ 13 FLe33,39ḷ¶“ṂḤ“¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
11 “ 13 FLe33,39ḷ¶“ṂḤ“¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
12 Ṃ 13 FLe33,39ḷ¶““ḤṂ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
13 Ḥ 11 FLe33,39ḷ¶“Ḥ“Ṃ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
14 ¿ 11 FLe33,39ḷ¶“¿“ṂḤ§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
15 § 11 FLe33,39ḷ¶“§“ṂḤ¿⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
16 ⁹ 10 FLe33,39ḷ¶⁹““ṂḤ¿§Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
17 Ṫ 11 FLe33,39ḷ¶“Ṫ“ṂḤ¿§⁹¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
18 ¶ 11 FLe33,39ḷ¶“¶“ṂḤ¿§⁹Ṫ3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
19 3 10 FLe33,39ḷ¶3““ṂḤ¿§⁹Ṫ¶ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
20 Ẋ 11 FLe33,39ḷ¶“Ẋ“ṂḤ¿§⁹Ṫ¶3ñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
21 ñ 10 FLe33,39ḷ¶ñ““ṂḤ¿§⁹Ṫ¶3ẊɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
22 ɼ 11 FLe33,39ḷ¶“ɼ“ṂḤ¿§⁹Ṫ¶3ẊñṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
23 ṃ 10 FLe33,39ḷ¶ṃ““ṂḤ¿§⁹Ṫ¶3ẊñɼṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
24 Ṁ 11 FLe33,39ḷ¶“Ṁ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
25 Ƙ 11 FLe33,39ḷ¶“Ƙ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
26 » 10 FLe33,39ḷ¶»““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
27 ¹ 10 FLe33,39ḷ¶¹““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
28 “ 27 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»“¹®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
29 ® 11 FLe33,39ḷ¶“®“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
30 Ẉ 11 FLe33,39ḷ¶“Ẉ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
31 ' 11 FLe33,39ḷ¶“'“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
32 ¶ 11 FLe33,39ḷ¶“¶“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
33 Ẓ 11 FLe33,39ḷ¶“Ẓ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
34 Ȯ 11 FLe33,39ḷ¶“Ȯ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
35 z 11 FLe33,39ḷ¶“z“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
36 Ṃ 11 FLe33,39ḷ¶“Ṃ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮz#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
37 # 11 FLe33,39ḷ¶“#“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂjKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
38 j 10 FLe33,39ḷ¶j““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#KgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
39 K 11 FLe33,39ḷ¶“K“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
40 g 11 FLe33,39ḷ¶“g“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
41 N 11 FLe33,39ḷ¶“N“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKg»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
42 » 41 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKg»NÇ?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
43 Ç 11 FLe33,39ḷ¶“Ç“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
44 ? 43 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»?ÇÇȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
45 Ç 11 FLe33,39ḷ¶“Ç“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?ȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
46 ȧ 10 FLe33,39ḷ¶ȧ““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Ç$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
47 $ 11 FLe33,39ḷ¶“$“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?ÇȧÇȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
48 Ç 11 FLe33,39ḷ¶“Ç“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$ȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
49 ȧ 43 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»ȧÇ?Çȧ$Ç$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
50 $ 27 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»$¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧḷȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
51 ḷ 10 FLe33,39ḷ¶ḷ““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ȯ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
52 ȯ 11 FLe33,39ḷ¶“ȯ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷ““®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
53 “ 14 FLe33,39ḷ¶““ṂḤ“¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ“®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
54 “ 14 FLe33,39ḷ¶““ṂḤ“¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ“®Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
55 ® 11 FLe33,39ḷ¶“®“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““Ẉ'¶ẒȮzṂ#jKgN» Try It Online!
56 Ẉ 11 FLe33,39ḷ¶“Ẉ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®'¶ẒȮzṂ#jKgN» Try It Online!
57 ' 11 FLe33,39ḷ¶“'“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ¶ẒȮzṂ#jKgN» Try It Online!
58 ¶ 11 FLe33,39ḷ¶“¶“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'ẒȮzṂ#jKgN» Try It Online!
59 Ẓ 11 FLe33,39ḷ¶“Ẓ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ȮzṂ#jKgN» Try It Online!
60 Ȯ 11 FLe33,39ḷ¶“Ȯ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒzṂ#jKgN» Try It Online!
61 z 11 FLe33,39ḷ¶“z“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮṂ#jKgN» Try It Online!
62 Ṃ 11 FLe33,39ḷ¶“Ṃ“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮz#jKgN» Try It Online!
63 # 11 FLe33,39ḷ¶“#“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂjKgN» Try It Online!
64 j 10 FLe33,39ḷ¶j““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#KgN» Try It Online!
65 K 11 FLe33,39ḷ¶“K“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jgN» Try It Online!
66 g 11 FLe33,39ḷ¶“g“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKN» Try It Online!
67 N 11 FLe33,39ḷ¶“N“ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKg» Try It Online!
68 » 42 FLe33,39ḷ¶““ṂḤ¿§⁹Ṫ¶3ẊñɼṃṀƘ»¹“®Ẉ'¶ẒȮzṂ#jKgN»»Ç?Çȧ$Çȧ$ḷȯ““®Ẉ'¶ẒȮzṂ#jKgN Try It Online!
```
> 14 votes

# Answer
# C, 148 bytes

```
/**/main(){printf("Happy Birthday, %s!",'\0'?"ChartZ Belatedly":"caird coinheringaahing");}///*/b;main(){puts("Happy Birthday, ChartZ Belatedly!");}

```
* Any character within the first `main` definition is moved to separate the first `*/`, so the comment does not end there; it ends at the second `*/`, and the second `main` definition applies.
* Any of the first four characters `/**/`, except the first, is moved to make it `/*/*`, with the same effect.
* The first character, `/`, is moved one step right, making the program begin `*/*/`. This leaves `*` outside the comment, which combines with the later `b;` (a declaration of an implicit-`int` global variable) to form `* b;` (which declares `b` as a pointer to `int`).
* Any other character (starting from `///*/`) is moved into `'\0'`, after the first `'`, to make it a multicharacter constant with a nonzero value, changing the string selected by the `? :`; the last part originally beginning with three slashes ensures that it remains a line comment after any character is taken out from it.
> 10 votes

# Answer
# Klein 000, ~~133~~, ~~120~~, ~~119~~, 111 bytes

```
.\"Happy Birthday, "\"ChartZ Belatedly!"@
>."Happy Birthday, ChartZ Belatedly!"@
"oinheringaahing!"@.>"caird c"

```

Try it online!

The idea of this follows the classic klein / approach. We have 3 programs and we use the alignment to select which one we run. All of our swaps move one character to a different line breaking the alignment and putting it into a different program.

## The breakdown

If the character is one of the first two then we swap them

```
\."Happy Birthday, "\"ChartZ Belatedly!"@
>."Happy Birthday, ChartZ Belatedly!"@
"oinheringaahing!"@.>"caird c"

```

Anything else on the first line we can put at the begining of the second line.

```
.\"Happy Birhday, "\"ChartZ Belatedly!"@
t>."Happy Birthday, ChartZ Belatedly!"@
"oinheringaahing!"@.>"caird c"

```

For the first two characters of the second line we can swap them too.

```
.\"Happy Birthday, "\"ChartZ Belatedly!"@
.>"Happy Birthday, ChartZ Belatedly!"@
"oinheringaahing!"@.>"caird c"

```

For the rest of the line we can insert it before the `.` in the third line

```
.\"Happy Birthday, "\"ChartZ Belatedly!"@
>."Happy Birhday, ChartZ Belatedly!"@
"oinheringaahing!"@t.>"caird c"

```

Any character on the third line can be inserted at the front of the second line.

```
.\"Happy Birthday, "\"ChartZ Belatedly!"@
a>."Happy Birthday, ChartZ Belatedly!"@
"oinheringahing!"@.>"caird c"

```

Finally we can do the newlines as follows:

```
.\"Happy Birthday, "\"ChartZ Belatedly!"
@>."Happy Birthday, ChartZ Belatedly!"@
"oinheringaahing!"@.>"caird c"

```

```
.\"Happy Birthday, "\"ChartZ Belatedly!"@
>."Happy Birthday, ChartZ Belatedly!"@"oinheringaahing!"@.>"caird c
"

```
> 8 votes

# Answer
# Python 3, 130 bytes

```
'''''';print("Happy Birthday,",""and"ChartZ Belatedly!"or"caird coinheringaahing!")#''';print('Happy Birthday, ChartZ Belatedly!')

```

Try it online!

## Alternate programs

* Byte 1 to 6: The `'` is moved behind the first `;`, therefore characters 1 to 87 are a string and are disregarded. Characters 89+ are executed.

```
''''';'print("Happy Birthday,",""and"ChartZ Belatedly!"or"caird coinheringaahing!")#''';print('Happy Birthday, ChartZ Belatedly!')

```
* Byte 7 to 84: The byte is moved behind the fifth byte. As none of these characters is a `'`, this also creates a string from character 1 to character 87, with the same effects as above.

```
'''''"';print(Happy Birthday,",""and"ChartZ Belatedly!"or"caird coinheringaahing!")#''';print('Happy Birthday, ChartZ Belatedly!')

```
* Byte 85-130: The byte is moved between the `""` at position 32-33. This makes the string a truthy value and the other string is printed. There is no `"` in byte 85-130, so this will always work. The second part of the program is not executed, because it is commented out.

```
'''''';print("Happy Birthday,","'"and"ChartZ Belatedly!"or"caird coinheringaahing!")#''';print(Happy Birthday, ChartZ Belatedly!')

```
> 7 votes

# Answer
# JavaScript (browser), ~~146~~ 136 bytes

Based off of the C and python answers.

This is too long and it still seems sketchy to me

```
0/**/;;alert("Happy Birthday, "+(""?"ChartZ Belatedly!":"caird coinheringaahing!"))//*/-2;alert('Happy Birthday, ChartZ Belatedly!')//*/

```

## Where to move:

* The 0 goes after the second asterisk
* The first slash moves to the right, forming `0* -1`
* The first two asterisks and the second slash can move to right anywhere before the `//*/-1`
* The first two semicolons go inside the empty string
* Any text between the two semicolons and the `//*/-1` go after the second asterisk
* Any text starting from `//*/-1` goes inside the empty string

Try this mess online!

Hope this is valid and it works aaaa
> 7 votes

# Answer
# JavaScript, 123 bytes

```
17/**/,x=>"Happy Birthday, "+(''?"ChartZ Belatedly!":"caird coinheringaahing!")//**/,x=>"Happy Birthday, ChartZ Belatedly!"

```

Try it online!

## Variations

(full text omitted for brevity)

```
17/**/,x=>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
7/**1/,x=?"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
1/**7/,x=>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
17**/,x=>"HB"+(''?"CB":"cc")//*/*/,x=>"HBCB" (syntax highlighting is broken, but runs ok)
17/*/*,x=>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
17/**,/x=>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
17/**x/,=>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
17/**=/,x>"HB"+(''?"CB":"cc")//**/,x=>"HBCB"
// ...
17/**"/,x=>"HB'+('"?"CB":"cc)//**/,x=>"HBCB"
17/**)/,x=>"HB"+(''?"CB":"cc"//**/,x=>"HBCB"
17/**/,x=>"HB"+('/'?"CB":"cc")/**/,x=>"HBCB"
17/**/,x=>"HB"+('*'?"CB":"cc")//*/,x=>"HBCB"
17/**/,x=>"HB"+('/'?"CB":"cc")//**,x=>"HBCB"
17/**/,x=>"HB"+('x'?"CB":"cc")//**/,=>"HBCB"
// ...
17/**/,x=>"HB"+('B'?"CB":"cc")//**/,x=>"HBC"
17/**/,x=>"HB"+('"'?"CB":"cc")//**/,x=>"HBCB

```
> 6 votes

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


title: String to Bit Transition

text:
# Question
Title: String to Bit Transition
# Task

Given an input string of one or more ASCII characters which codepoints are between 0 and 128 (exclusive), do the following:

1. Convert each character into its 7-bit ASCII code (if the ASCII code is less than 7 bits, put leading zero bits)
2. Concatenate all bits (this results in `7*n` bits where `n` is the number of characters)
3. For each bit in this bitstream, print 1 if it is different from the previous bit, and print 0 otherwise. The first output bit is always 1.

# Example

Input:

```
Hi

```

Output:

```
11011001011101

```

Explanation:

> The string "Hi" has the ASCII codes
>
> `72 105`
>
> which in bits are:
>
> `1001000 1101001`
>
> And the transition bits indicators:
>
> `11011001011101`

This is code golf. Lowest byte count wins.

# Test Cases

Test case 1:

```
Hello World!
110110010101110011010101101010110001110000111110000110000001011101101010101100110001

```

Test case 2:

```
%% COMMENT %%
1110111111011111100001100010010100001010110101011010011101010011111110011000001101111110111

```

Test case 3 (credit to Luis Mendo):

```
##
11100101110010

```

---

Congrats to Luis Mendo for the shortest solution with 9 bytes in MATL!

# Answer
# MATL, 9 bytes

```
Hj7&B!hdg

```

Try it online!

### Explanation

```
H     % Push 2
j     % Read line of input, unevaluated
7&B   % Convert to binary with 7 bits. Gives a 7-column matrix
!     % Transpose
h     % Concatenate horiontally. The matrix is read in column-major order
d     % Consecutive differences
g     % Convert to logical. Implicitly display

```
> 5 votes

# Answer
# Python 2, 58 bytes

```
n=1
for c in input():n=n<<7|ord(c)
print'1'+bin(n^n/2)[4:]

```

Try it online!
> 6 votes

# Answer
# Japt `-P`, 11 bytes

Takes advantage of the fact that spaces can be coerced to `0` in JavaScript when trying to perform a mathematical or, in this case, bitwise operation on it.

```
c_¤ù7Ãä^ i1

```

Try it or run all test cases

```
c_¤ù7Ãä^ i1     :Implicit input of string
c_              :Map codepoints
  ¤             :  Convert to binary string
   ù7           :  Left pad with spaces to length 7
     Ã          :End map
      ä^        :XOR consecutive pairs
         i1     :Prepend 1
                :Implicitly join and output

```
> 4 votes

# Answer
# Jelly, 12 bytes

```
O+Ø⁷BḊ€FIA1;

```

Try it online!
> 3 votes

# Answer
# Octave, ~~36~~ 30 bytes

*Fix thanks to Luis Mendo*

*-2 bytes thanks to Sanchises*

```
@(a)[1;~~diff(de2bi(a,7)'(:))]

```

Try it online!
> 3 votes

# Answer
# CJam, 21 bytes

```
1q{i2b7Te[}%e__(;.^);

```

Try it online!

## Explanation

Showing the stack with a sample input of `5`:

```
1 q      e# Push 1 and then the whole input: 1 "5"
{
  i      e# Convert to its char code: 1 [53]
  2 b    e# Convert to binary: 1 [[1 1 0 1 0 1]]
  7 T e[ e# Left-pad with 0 to length 7: 1 [[0 1 1 0 1 0 1]]
} %      e# Map this block over every character in the string
e_       e# Flatten array: 1 [0 1 1 0 1 0 1]
_ ( ;    e# Duplicate array and remove its first element: 1 [0 1 1 0 1 0 1] [1 1 0 1 0 1]
. ^      e# Element-wise xor: 1 [1 0 1 1 1 1 1]
) ;      e# Remove and pop the last element of the array: 1 [1 0 1 1 1 1]
         e# Stack implicitly printed: 1101111

```

To see if a bit is different from the previous bit, we do a vector (element-wise) xor between the bit array and the bit array without the first element. We also remove the last bit of the result, because it is always the last bit of the longer array unchanged.
> 2 votes

# Answer
# Ruby `-p`, ~~68~~ 57 bytes

-11 bytes by shamelessly stealing the method used by xnor's Python solution.

```
l=1
gsub(/./){l=l<<7|$&.ord}
$_=?1+(l^l/2).to_s(2)[2..-1]

```

Try it online!

Original solution:

```
gsub(/./){'%07b'%$&.ord}
l=p
gsub(/./){b=$&.ord-48;r=l ?l^b:1;l=b;r}

```

Try it online!
> 2 votes

# Answer
# APL (Dyalog Unicode), 16 bytesSBCS

Full program. Prompts for string from stdin.

```
1,2≠/∊1↓¨11⎕DR¨⍞

```

Try it online!

prompt for input ("a quote in a console")

`11⎕DR¨` change each character to bit-Boolean **D**ata **R**epresentation

`1↓¨` drop the first bit from each

**ϵ**nlist (flatten)

`2≠/` pairwise difference

`1,` prepend a one
> 2 votes

# Answer
# Dart, ~~213~~ 168 bytes

```
f(s,{t,i}){t=s.runes.map((r)=>r.toRadixString(2).padLeft(7,'0')).join().split('').toList();for(i=t.length-1;i>0;i--)t[i]=t[i]==t[i-1]?'0':'1';t[0]='1';return t.join();}

```

Previous one-liner

```
f(String s)=>'1'+s.runes.map((r)=>r.toRadixString(2).padLeft(7,'0')).join().split('').toList().reversed.reduce((p,e)=>p.substring(0,p.length-1)+(p[p.length-1]==e?'0':'1')+e).split('').reversed.join().substring(1);

```

Try it online!

This verbosity and lack of easy built ins is really killing this one. Still managed to pull a one liner though.

* -45 bytes by not using a one liner and using a for loop
> 2 votes

# Answer
# Charcoal, 25 bytes

```
⭆θ◧⍘℅ι²¦⁷←Ｗⅈ←Ｉ﹪⍘ＫＤ²←01 ²1

```

Try it online! Link is to verbose version of code. Explanation:

```
⭆θ◧⍘℅ι²¦⁷←

```

Convert all the characters to binary and pad them to a length of 7 and then print them, but leave the cursor over the last digit.

```
Ｗⅈ

```

Repeat until the cursor is over the first digit.

```
←Ｉ﹪⍘ＫＤ²←01 ²

```

Calculate whether the digits are different and overwrite each digit with the difference.

```
1

```

Overwrite the first digit with a `1`.
> 2 votes

# Answer
# PowerShell, ~~73~~ ~~56~~ 49 bytes

```
$args|%{$b=+$_
6..0}|%{+($c-ne($c=($b-shr$_)%2))}

```

Try it online!

*-17 bytes thanks to mazzy* :)
> 2 votes

# Answer
# 05AB1E (legacy), 12 bytes

```
Çb7jð0:¥ÄJ1ì

```

Uses the legacy version of 05AB1E, since `j` implicitly joins the strings together, which requires an explicit `J` after the `j` in the new version of 05AB1E.

Try it online or verify all test cases.

**Explanation:**

```
Ç             # Convert the (implicit) input-string to a list of ASCII code-points
              #  i.e. "Hi#" → [72,105,35]
 b            # Convert each integer to a binary string
              #  → ["1001000","1101001","100011"]
  7j          # Prepend each with spaces to make them length 7,
              # and join everything together to a single string implicitly
              #  → "10010001101001 100011"
    ð0:       # Replace all those spaces with 0s
              #  → "100100011010010100011"
       ¥      # Get the deltas of each pair of 1s/0s
              #  → [-1,0,1,-1,0,0,1,0,-1,1,-1,0,1,-1,1,-1,0,0,1,0]
        Ä     # Get the absolute value of this
              #  → [1,0,1,1,0,0,1,0,1,1,1,0,1,1,1,1,0,0,1,0]
         J    # Join them all together
              #  → "10110010111011110010"
          1ì  # And prepend a 1
              #  → "110110010111011110010"
              # (after which the result is output implicitly)

```
> 2 votes

# Answer
# Husk, ~~16~~ ~~15~~ 14 bytes

```
:1Ẋ≠ṁȯΩo=7LΘḋc

```

Try it online!
> 2 votes

# Answer
# Vyxal, ~~20 16~~ 15 bytes

```
bƛṅS7↳vċ†;f¯ȧ1p

```

Try it Online!

A mess. -4 thanks to Aaron Miller. -1 thanks to lyxal.
> 2 votes

# Answer
# Stax, ~~13~~ 12 bytes

```
ìEÖâU₧(~¬8IE

```

Run and debug it

If it's guaranteed that all input characters have the 7th bit set, as some answers assume, it can be done in 10 bytes
> 1 votes

# Answer
# Python 2, 104 bytes

```
lambda w:reduce(lambda(A,P),C:(A+'10'[P==C],C),bin(reduce(lambda a,c:a*128+ord(c),w,1))[3:],('','x'))[0]

```

Try it online!

A quick stab at it.
> 1 votes

# Answer
# K (ngn/k), ~~9~~ 13 bytes

**Solution:**

```
~=':,/(7#2)\'

```

Try it online!

**Explanation:**

```
~=':,/(7#2)\' / the solution
           \' / convert each
      (   )   / do this together
       7#2    / 2 2 2 2 2 2 2
    ,/        / flatten
 =':          / equal to each-previous?
~             / not

```

**Notes:**

* **+4 bytes** to support strings consisting only of 6-bit chars
> 1 votes

# Answer
# Python 3, 88 84 bytes

```
l=2;s=''
for c in''.join(f'{ord(c):07b}'for c in input()):s+='01'[l!=c];l=c
print(s)

```

Try it online!

I feel that the assignments should be avoidable, but couldn't think of any way to do that.

**Update:**
> 1 votes

# Answer
# Kotlin, 182 bytes

```
var l='6'
fun f(b:String)=b.fold(""){t,i->t+"".a(i.toInt())}.map{if(l==it){l=it;0} else {l=it;1}}
fun String.a(v:Int):String=if(v<=0)"${this}0".reversed() else "${this}${v%2}".a(v/2)

```

Try it online!

Hopefully I can improve this soon, I feel like there must be some spots for improvement but I can't think right now
> 1 votes

# Answer
# JavaScript (V8), ~~150~~ 95 bytes

*-55 thanks to @dana*

```
x=>[...[...x].reduce((a,c)=>a+c.charCodeAt(0).toString(2).padStart(7,0),"")].map(c=>x!=(x=c)|0)

```

Try it online!
> 1 votes

# Answer
# Ruby `-p`, 50 bytes

```
gsub(/./){"%07b"%$&.ord}
gsub(/./){$`=~/#$&$/?0:1}

```

Try it online!

## Explanation

First line, same as Value Ink's answer:

```
gsub(/./){       $&    }   # Replace each character $&…
                   .ord    # …with its ASCII code…
                %          # …formatted as…
          "%07b"           # …binary digits padded to 7 places.

```

Second line:

```
gsub(/./){      $&      }  # Replace each character $&…
          $`               # …if the text to its left…
            =~             # …matches…
              /#  $/       # …the Regexp /c$/ where "c" is the character…
                    ?0:1   # …with 0, or 1 otherwise.

```

In Ruby you can use interpolation in Regexp literals, e.g. `/Hello #{name}/`, and for variables that start with `$` or `@` you can omit the curly braces, so if e.g. `$&` is `"0"` then the grawlixy `/#$&$/` becomes `/0$/`.
> 1 votes

# Answer
# Perl 5 `-p`, 60 bytes

```
s/./sprintf'%07b',ord$&/ge;s/.(?=(.))/0|$&^$1/ge;s/^/1/;chop

```

Try it online!
> 1 votes

# Answer
# C (gcc (MinGW)), 90 bytes

Requires a compiler providing `itoa()`.

```
n[9],b,c;f(char*s){for(b=*s<64;c=*s++;printf("%07s",itoa((c^c/2)&127,n,2)))c|=b<<7,b=c&1;}

```
> 1 votes

# Answer
# Emojicode, 263 bytes

```
➡sb❗❗sb❗➕128 2❗1 7❗➡s?➡pb s↪bp0❗1❗b➡p

```

Try it online here.

Ungolfed:

```
    Main code block
     ➡   s   Start with s as the empty string
     b       For each byte b in the input ...
    ❗ ❗
         s   ... append ...
              b ❗ ➕ 128   ... b + 128 (this gives the leading zero(s) in case the binary representation of b is shorter than 7 digits) ...

                 2   ... in binary ...
              ❗
              1 7   ... without the leading one ...
           ❗

        ➡  s   ... to s

    ? ➡   p   This will be used as the previous character, by assigning it neither 0 nor 1 we assure the first bit output is always a one
     b s    For each character in s:
        ↪ b  p    If it is the same as the previous character ...
             0 ❗   ... output a zero ...
              ... else ...
             1 ❗  ... output a one

        b ➡  p   And the current character becomes the new previous character.

```
> 1 votes

# Answer
# Tcl, ~~215~~ ~~167~~ 140 bytes

```
{{s {B binary} {X ~$w/64}} {join [lmap c [split $s {}] {$B scan $c c w;$B scan [$B format i [expr 2*$w^$w^$X<<7]] B7 r;set X $w;set r}] ""}}

```

Try it online!

Uses shift-by-one and exclusive-or to detect transitions. Carries lsb of current character to msb of next character. Combines output for each character by joining list returned by lmap.

Uses lambdas with default arguments to save bytes on initialization and repeated commands.

Relies heavily on order of operation. Works for empty string.
> 1 votes

# Answer
# Python3.8, 72 bytes

**Solution:**

```
lambda a:["10"[a==(a:=x)]for x in"".join(bin(ord(i)+128)[3:]for i in a)]

```

**Explanation:**

Ever since Python 3.8 introduced assignment expressions (rather than the standard assignment statements), I have wanted to use them in a list comprehension that needs to remember the last item. This is not the best way to do this but demonstrates an interesting method of using the assignment expression.

The code creates a lambda function which takes the required argument which is the string to convert. When called, the function proceeds as follows. Every character in a is converted to its character code which 128 is added to for dealing with 6-bit characters (the binary representation will always be 8 bits and we can chop off the first bit). This number is converted to binary and the header (0x) and the initial 1 from adding 128 is chopped off. These new strings are then joined into one larger string.

For each character in this new string (which contains the concatenated 7-bit representation of the text), it is checked if the character is the same as the previous character. What happens with the first character? The first result character should always be "1" so we just have to make sure that whatever is in the last character variable is neither "1" nor "0". We do this by reusing the original parameter now that we are not using it anymore. This may be a problem if the original string was a single "0" (a single "1" just happens to work) but we will ignore that.

During the comparison, the previous character was evaluated first so when we use the assignment expression to set the previous character variable to the current character, it does not affect the comparison expressions' evaluation.

The comparison either produces True or False which can also be used as 1 or 0 respectively in Python, so they are used to look up either a "1" or "0" in a string
> 1 votes

# Answer
# Haskell, 137 bytes

```
import Data.Char
b 0=[]
b n=odd n:b(n`div`2)
d x|x='1'|1<2='0'
c=('1':).map d.(zipWith(/=)<*>tail).concatMap(reverse.take 7.b.(+128).ord)

```

Try it online!

The biggest problem here is converting booleans (result of the XOR) to '0'/'1'.
> 1 votes

# Answer
# PHP, 90 bytes

```
for(;$c=ord($argn[$j++]);$o.=sprintf('%07b',$c));for(;($q=$o[$i++])>'';$p=$q)echo$p!=$q|0;

```

Try it online!
> 1 votes

# Answer
# C# (Visual C# Interactive Compiler), 80 bytes

```
s=>{for(int p,c=2,i=0;i<7*s.Length;Write(p==c?0:1))(p,c)=(c,1&s[i/7]>>6-i++%7);}

```

Try it online!
> 0 votes

# Answer
# JavaScript (V8), 73 bytes

```
s=>[...c=s.repeat(7)].map((_,i)=>(c=1&s.charCodeAt(i/7,p=c)>>6-i%7)!=p|0)

```

Try it online!
> 0 votes

---
Tags: code-golf, string, bitwise
---