62
6
Why was 6 afraid of 7? Because 7 8 9!
Given a string apply the following transformations:
- If there is a 6 next to a 7 remove the 6 (6 is afraid of 7)
- If the sequence "789" appears remove the 8 and the 9 (7 ate 9)
(If I'm not mistaken it doesn't matter what order you do the transformations in)
Keep applying these transformations until you can no longer.
Example:
78966
First we see "789", so the string becomes "766". Then we see "76", so we take out the 6, and the string becomes "76". Then we see "76" again, so we are left with "7".
Test Cases:
987
=>987
(Not in the right order. Does nothing.)6 7
=>6 7
(The whitespace acts as a buffer between 6 and 7. Nothing happens)676
=>7
7896789
=>77
7689
=>7
abcd
=>abcd
130Why was Vista afraid of 7? Because 7 8 10. – lirtosiast – 2015-12-14T18:12:18.717
2Another test case
68978966897896
=>68977
– Brad Gilbert b2gills – 2015-12-14T18:29:16.28019@ThomasKwa Oh, I get it: Microsoft skipped Windows 9 because they were going along with the riddle. ;) – ETHproductions – 2015-12-14T19:18:42.447
43
Why afraid of seven was five? Because six seven eight. --Yoda
– Jakuje – 2015-12-14T22:05:10.643I could be wrong but I'm sure this is an example of a Lindenmayer system. – Pharap – 2015-12-17T12:12:16.473
@Pharap Link, please. – geokavel – 2015-12-17T15:40:38.350
@geokavel Facinating stuff. Here's three as a start: 1 2 3
– Pharap – 2015-12-17T15:57:29.330@Pharap Thanks for the links! I guess the difference is mine always makes the string smaller, so maybe it's an inverse L-System? – geokavel – 2015-12-17T16:02:39.590
@geokavel
Alphabet: 6789; Axiom: 78966; Rules: 67 -> 7, 789 -> 7;
Not sure if that's entirely correct but you can see how it would be mapped to an L-system. – Pharap – 2015-12-17T16:14:01.263@Pharap Nice. Also,
76 -> 7
. – geokavel – 2015-12-17T16:16:04.213@geokavel That too. If I knew of a language centred around L-Systems I'd submit an answer but I don't believe that there is one. – Pharap – 2015-12-17T16:18:15.593
2Six was afraid seven because seven had cold, dead eyes. – Conor O'Brien – 2016-01-15T20:07:56.903
Because of the "Keep applying these transformations until you can no longer.", it would be good to add some test cases reflecting that.. Like
68978966897896
that @BradGilbertb2gills suggested almost 3 years ago, or7689689
→7
. – Kevin Cruijssen – 2018-09-06T08:14:33.050