title: The Symbols vs. The Letters

text:
# Question
Title: The Symbols vs. The Letters
# The Symbols vs. The Letters

The ASCII characters have been divided once again! Your sets are **The Letters** and **The Symbols**.

## The Letters

```
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

```

## The Symbols

```
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~

```

The task is to write two programs:

1. Print each of **The Letters** exactly once without using any of them in your program.
2. Print each of **The Symbols** exactly once without using any of them in your program.

# Rules

* Whitespace may appear in your program or the output.
* Non-ASCII characters are not allowed.
* Output goes to standard out or to a file as either the contents or name of the file.
* No input.
* Output must only contain ASCII characters from one set or the other.
* The programs can be written in different languages or the same language with one exception:
* The Whitespace language may only be used for one of the programs.
* Standard loopholes apply.

# Scoring

`# of characters in program 1` **+**`# of characters in program 2` = `Score`

Lowest score wins!

## Note:

To encourage more submissions, you may still post an answer with a solution for only one of the programs. You won't be able to win, but you would still be able to show off something cool.

Thanks to Calvin's Hobbies for inspiring the idea with his previous question.

# Answer
# Total: 53 characters

# Total in a single language: 230 characters, Pyth

# Part 1: Golfscript, 15

```
91,65>123,97>++

```

Outputs:

```
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

```

Explanation:

```
91,           Make the list, [0 1 .. 90]
65>           Take elements after the 65th, [65 66 .. 90]
123,97>       Same, but [97 98 .. 122]
+             Add the list above to the newline character that is automatically pushed to
              the stack. List + str coerces to string by ascii encoding.
+             Same, for the other list.

```

# Part 2: Pyth, 38

```
JhCeGLjkmCdbsrCdCPhGsrhCPeGChGsrJhhhhJ

```

Outputs:

```
 !"#$%&'()*+,-./0123456789:;<=>?@
[\]^_`
{|}~

```

Explanation:

```
G = "abcdefghijklmnopqrstuvwxyz"   Implicit.
k = ""                             Implicit.
d = " "                            Implicit.
JhCeG                              J = 1 + chr(end(G))          # J = 123
L                                  def d(b): return
 jk                                                k.join(
   m                                                      map(lambda d:
    Cd                                                                 chr(d),
    b                                                                  b))
s                                  print(s(                    #print is implicit.
 rCd                               range(chr(d),                 # chr(d) = 32
 CPhG                                    chr(upper(head(G))))    # chr("A") = 65
srhCPeGChG                         print(s(range(1+chr(upper(end(G))),chr(head(G)))
srJhhhhJ                           print(s(range(J, 1+1+1+1+J)))

```

---

# Bonus solution:

# Part 1: Pyth, 192

```
%*$"%\143"$52(65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

```

Explanation:

`$"%\143"$` =\> "%c". `$` switches to and from Python parsing style, and in Python string parsing, `\143` is the octal escape sequence for `c`. This answer is thus equivalent to the following Python-style code:

```
("%c" * 52) % (65, 66, 67, ...)

```

Of course, this doesn't work in Python, because printing in Python uses `print`, but printing in Pyth is implicit, so it works.

---

Pyth solutions do not use any of the features added since the question was asked.
> 7 votes

# Answer
# Python (Symbols, ~~87~~ 82)

```
from string import punctuation
from string import digits
print digits
print punctuation

```

I just love Python's string module...

Edit:

```
from string import punctuation as p
from string import digits as d
print d
print p

```

Output:

```
0123456789
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

```

# ~~FALSE (Letters, 21)~~ DUP (Letters, 20):

FALSE solution:

```
65[$91\>][$,$32+,1+]#

```

DUP sollution (1 char shorter)

```
65[$91<][$,$32+,1+]#

```

Output (for both):

```
AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz

```

Interpreter for FALSE.

---

## Total: 102
> 23 votes

# Answer
## GolfScript (14 chars) + Deadfish x (116 chars) = 130 chars

```
91,65>{.32+}%+

```

and

```
xxcxxcdddKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKxKDxxxccxxxxxxxxxxKxKxKxKxKxKDxxxcxxcxxKxKxKxK

```
> 13 votes

# Answer
# Parts 1 and 2 in Ruby 2, 56 + 484 = 540

Part 1:

```
__=->_{(91..96)===_||$><<(''<<_);_>121||__[-~_]}
__[65]

```

For more on this style of Ruby, check out narfnme.

Part 2 (this bit is Ruby 2.0+ only, works perfectly with ruby-2.1.0 but may give warnings in earlier versions):

```
class Fixnum
def c
String def a
end
end
def b
String def A
end
end
def x
String def z
end
end
def y
String def Z
end
end
def inspect
case chr
when c
when b
when y
p succ
else
print chr
p succ
end
p
rescue
p
end
end
def x
String def z
end
end
def y
String def Z
end
end
class String
def inspect
p size
p
end
end
p String p
class String
def inspect
p ord
p
end
end
p y
class Fixnum
def inspect
case chr
when x
p succ
else
send chr
print chr
p
end
p
rescue
print chr
p succ
p
end
end
p x

```

That one was hard. Calling built-in Fixnum methods like `chr` and `succ` requires opening up the Fixnum class and redefining `inspect`, since I can trigger a call to `x.inspect` with `p x`. I need inspect to return `nil` so that `p` will only print a newline, any string will be framed in double quotes. But as a side effect, it loops. I can terminate the first loop and second loops using a string comparison to see when I've reached a letter range, but since I can't write a string literal I need to get one by calling `String()` on the symbol returned (in Ruby 2) by the `def` keyword. Since that's a multiline syntax and I can only do string comparison via `case`, which can't take multiline expressions, I need to wrap the literal in a method (since I obviously can't do assignment). The last loop is harder to terminate. I need it to stop at `~`. Luckily, of the ascii characters in that range, `~` is the only one that can be called on a Fixnum with no arguments without raising an error, so I can use `send chr` to detect when I'm at the end and stop looping.

Not the best score in this thread, but thus far the only one that uses the same language for both parts. Yay Ruby.
> 10 votes

# Answer
# Part 2 in Applescript, 654

*wait... where's the "**tips for golfing in Applescript**" page?*

```
global a
global b
global c
global s
on f at n
set end of b to a
end
on g at n
f at a
f at a
end
on h at n
g at a
g at a
end
on i at n
h at a
h at a
end
on j at n
repeat with t in system info
f at a
end
end
on m at n
set end of b to a
set c to count of b
set end of s to ASCII character c
end
on n at n
m at a
m at a
m at a
end
on o at n
repeat with t in system info
m at a
end
end
set a to random number
set b to a as list
j at a
j at a
set c to count of b
set s to ASCII character c
set s to s as list
o at a
n at a
n at a
n at a
n at a
n at a
j at a
i at a
g at a
f at a
n at a
m at a
m at a
j at a
i at a
g at a
n at a
m at a
display dialog s as text

```

### Output:
> 8 votes

# Answer
# CJam \+ AlphaBeta, 62 bytes

---

## Letters, CJam, 12 bytes

```
"[{"{,-26>}/

```

Try it online!

### Output

```
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

```

### How it works

```
"[{"{     }/   For each of the characters "[" and "{",
     ,         push an array of all ASCII characters before it
      -26>     and discard all but the last 26 characters.

```

---

## Symbols, AlphaBeta, 50 bytes

```
ZaaAccctFUaCLOrEbbCLbCLbCLbCLdddACLbCLbCLgDLgDLgDL

```

Try it online!

The official C++ interpreter has a bug that makes loops impossible and I can't figure out how to use the Lua interpreter. I fixed that bug. You can verify that it works as intended by running the example programs from the EsoLang page.

### Output

```
!"#$%&'()*+,-./0123456789:;<=>?@~}|{]\[^_`

```

### How it works

```
Z      Switch register 4 to the position register.
aa     Set registers 1 to 2.
A      Copy the value from register 1 to register 2.
ccc    Add 30 to register 1 (result: 31).
tF     Set register 2 to the product of registers 1 and 2 (result: 64).
U      Add 10 to the position register (result: 10, i.e., the position of the next byte).
aCL    Add 1 to register 1 and print the corresponding ASCII character.
O      If register 1 != register 2, go to the position in the position register.
rEb    Set register 1 to the sum of registers 1 and 2 minus 1 (result: 127).
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
ddd    Subtract 30 from register 1 (result: 93).
A      Copy the value from register 1 to register 2.
CL     Print the ASCII character corresponding to register 1.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
bCL    Subtract 1 from register 1 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.
gDL    Add 1 to register 2 and print the corresponding ASCII character.

```
> 4 votes

# Answer
# Part 1 in BrainFuck: ~~80~~ 74 bytes

```
>-[+>+<[+<]>]>+.<<+++++[>+++++[>+.<-]<-]>>+++++++.<<+++++[>+++++[>+.<-]<-]

```
> 3 votes

# Answer
# Total 318 bytes

I was really hoping to figure out an answer with both programs in the same language, but so far nothing. Here's this instead:

# Part 1: Pure bash, 129 bytes

```
_0=`$ 2>&1`
_0=${_0##*:}
_1=${_0:5:1}
_5=${_0:1:1}$_1${_0:11:1}
. <($_5<<<_2=\({${_1^}..$_1}\))
_3=${_2[@]:0:26}
$_5<<<$_3${_3,,}

```

### Output:

```
$ ./letsym.sh
A B C D E F G H I J K L M N O P Q R S T U V W X Y Za b c d e f g h i j k l m n o p q r s t u v w x y z
$

```

# Part 2: GNU dc, 189 bytes

```
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzPzzzzzzzzzzzzzzzzzzzzzzzzzzzzPzzPzzPzzPzzPzzPzzBDPBEdPBFPdkvZP

```

### Output:

```
$ dc symlet.dc
!"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~$

```
> 3 votes

# Answer
Well, you know, someone should get it going.

## Part 1 in BrainFuck: 174 bytes

```
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+++++++
.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.

```
> 2 votes

# Answer
## Part 1: Ruby, 45 bytes

```
_=[*?@...?[,*?`...?{]
_[0],_[27]=*$_
$><<_*''

```

### Explanation

* A Range containing a-z (`?@...?[`) and a Range containing A-Z (`?`...?{`) become the elements of the array `_` using the splat operator (`*`).
* The 0th element (`"@"`) and 27th element (`"`"`) of the array `_` are set to `nil`.
* The array `_` is joined together using `Array#*` and printed to stdout (`$>`)
> 1 votes

---
Tags: code-golf, restricted-source
---


title: Easily Typeable Words

text:
# Question
Title: Easily Typeable Words
**This competition is over.**

The winner is CJam with 22 characters, beating TwiNight's answer by one character. Congratulations Dennis!

An honorable mention goes to Falko, who went totally crazy with the free imports.

.

---

A while ago I wanted to know how I can out-type modern smartphones with my Nokia 3310, and while some answers were really good, I still can't keep up! Maybe I should take a different approach and simply not write any words that are awkward to type.

We'll call a piece of text easily typeable if no two consecutive letters are on the same button on the telephone keyboard, given the standard layout:

---

## Your task

Your task is to write a program/function that accepts a string `s` from stdin/as a parameter and returns a truthy value if `s` is easily typeable and a falsy value otherwise. The input will only consist of lowercase letters and spaces and is guaranteed to be non-empty!

## Scoring

This is codegolf, so lowest character-count wins.

Import statements will not be counted towards your final score, so if you've ever wanted to use `std::set_symmetric_difference`, `liftM4`, or `itertools.combinations` in your code, now is the time!

**-3** if your source code is easily typeable, assuming everything that's not a letter is on button 0. After all, I might want to message your code to some friends!

## Testcases

Here are a few testcases to check if your code is working as intended:

```
"x" -> True
"aardvark" -> False
"ardvark" -> True
"flonk" -> False

"im codegolfing all day long" -> False
"i indulge in minimizing bytecount" -> True

"havent heard from you in a long time" -> False
"your silence was of undue permanence" -> True

"how are  you" -> False
"how are you" -> True

```

Happy golfing!

# Answer
# CJam, ~~34~~ ~~31~~ ~~27~~ 22 characters

```
1l{'h-_9/-D+3/X\:X^*}/

```

Try it online.

### Example run

```
$ cjam <(echo "1l{'h-_9/-D+3/X\:X^*}/") <<< 'aardvark'; echo
0
$ cjam <(echo "1l{'h-_9/-D+3/X\:X^*}/") <<< 'ardvark'; echo
66000

```

### How it works

```
1l                         " Push a R := 1 and read a line L from STDIN.                  ";
                           " Initialize X := 1. (implicit)                                ";
  {                  }/    " For each character C of L, do the following:                 ";
    'h-                    "     C -= 'h'                                                 ";
       _9/-D+3/            "     Y := (C - C / 9 + 13) / 3                                ";
               X\  ^*      "     R *= X ^ Y                                               ";
                 :X        "     X := Y                                                   ";
                           " Print R. (implicit)                                          ";

```

### Background

The core of the code consists in applying a map **F** to each character **C** of the input string so that the images of symbols on the same key match. I found the a suitable map by observing the following:

The map **T : C ↦ (C - 'h') + 13** transforms the string **S := " abcdefghijklmnopqrstuvxyz"** as follows:

```
[-59   6  7  8   9 10 11  12 13 14  15 16 17  18 19 20  21 22 23 24  25 26 27  28 29 30 31]

```

For the keys `0` to `6`, it would suffice to divide **T(C)** by **3**, but we have to apply some sort of correction to the characters in **s**, **t**, **v**, **y** and **z**.

The map **D : C ↦ (C - 'h') / 9** transforms the string **S** into the following array:

```
[ -8   0  0  0   0  0  0   0  0  0   0  0  0   0  0  0   0  1  1  1   1  1  1   1  1  1  2]

```

This corrects the quotients of **s**, **t**, **v**, **y** and **z**, without affecting the others.

Finally, the map **F : C ↦ (T(C) - D(C)) / 3** transforms the string **S** as follows:

```
[-17   2  2  2   3  3  3   4  4  4   5  5  5   6  6  6   7  7  7  7   8  8  8   9  9  9  9]

```

All that rests is to compare the consecutive characters somehow. For that purpose, we XOR **F(C)** with the image of the previous character – for the first, we XOR **F(C)** with **1** (default value of the variable **X**), which has no preimage – and multiply all the results.

The product will be falsy if and only if one of the factors is zero, i.e., if and only if two consecutive characters have the same image by **F**.
> 6 votes

# Answer
# Python 2 - ~~80, 68, 64, 61, 58, 50, 48, 45, 44~~ 42

Even though it's getting a little ridiculous now, I'll keep on making use of free library imports, even the `__builtin__` library:

```
from numpy import diff as D
from pprint import pprint as P
from __builtin__ import all as A
from __builtin__ import raw_input as I
from __builtin__ import bytearray as B

```

So only the following short line counts towards the code length:

```
P(A(D([(o-o/112-o/59)/3for o in B(I())])))

```

Credits to Markuz for the ideas regarding `input()`! These free-import challenges always introduce you to some lesser known libraries. ;)

---

Alternative using only the `operator` library (~~98, 83~~ 79):

```
from operator import ne as n
K=[(ord(c)-1-(c>'p')-(c>'w'))/3for c in input()]
print all(map(n,K[1:],K[:-1]))

```

I'll stop here. But you could further golf this version using `sys`, `pprint` and other libraries...

---

Alternative without libraries (105):

```
s=input()
n=lambda c:(ord(c)-1-(c>'p')-(c>'w'))/3
print all([n(s[i])!=n(s[i+1])for i in range(len(s)-1)])

```
> 27 votes

# Answer
# ~~Ruby~~ Regex (most popular flavours), ~~106~~ 83 bytes

Because regex

```
^(?!.*(  |[abc]{2}|[def]{2}|[ghi]{2}|[jkl]{2}|[mno]{2}|[p-s]{2}|[tuv]{2}|[w-z]{2}))

```

I've just cut the middleman (Ruby) and made this a pure-regex solution. Works in a lot of flavours and only finds a match if the string does not contain two consecutive characters on the same button.
> 20 votes

# Answer
# Bash+coreutils, 49

```
tr a-z $[36#8g7e9m4ddqd6]7778888|grep -Pq '(.)\1'

```

Returns an exit code of 1 for TRUE and 0 for FALSE:

```
$ for s in "x" "aardvark" "ardvark" "flonk" "im codegolfing all day long" "i indulge in minimizing bytecount" "havent heard from you in a long time" "your silence was of undue permanence" "how are  you" "how are you"; do echo "./3310.sh <<< \"$s\" returns $(./3310.sh <<< "$s"; echo $?)"; done
./3310.sh <<< "x" returns 1
./3310.sh <<< "aardvark" returns 0
./3310.sh <<< "ardvark" returns 1
./3310.sh <<< "flonk" returns 0
./3310.sh <<< "im codegolfing all day long" returns 0
./3310.sh <<< "i indulge in minimizing bytecount" returns 1
./3310.sh <<< "havent heard from you in a long time" returns 0
./3310.sh <<< "your silence was of undue permanence" returns 1
./3310.sh <<< "how are  you" returns 0
./3310.sh <<< "how are you" returns 1
$

```
> 12 votes

# Answer
## APL(Dyalog), ~~24~~ 23

```
~∨/2=/⌊¯13⌈.21-.31×⎕AV⍳⍞

```

---

```
∧/2≠/⌊¯13⌈.21-.31×⎕AV⍳⍞

```

**Explanation**

: Takes string input from screen
`⎕AV`: This is the atomic vector which is bascially a string of all characters APL recognizes, which of course include all lowercase letters (index 18~43) and space (index 5)
: `IndexOf` function. For many functions in APL that takes one or two scalar arguments, you can feed it an array in place of a scalar - APL will do the looping for you. So  returns a numeric array of indices. `.21-.31×`: Times 0.31 and then subtract from 0.21. This is a little trick that maps letter on the same key (especially PQRS) to the same number (when rounded down to integers), except Z, which get mapped to its own group
`¯13⌈`: `max` with -13. This brings Z back to the group with WXY
: Round down to integers
`2≠/`: Pairwise-. Returns a boolean array for each consecutive pair.
`∧/`: AND together all entries of the resulting array.
> 9 votes

# Answer
## Perl - 44

This is basically a Perl adaptation of @DigitalTrauma's answer posted with his permission. Shaved off 2 characters thanks to @KyleStrand.

```
y/b-y/aadddgggjjjmmmpppptttzzz/;$_=!/(.)\1/

```

43 characters + 1 for `-p` flag. `y///` is the same as `tr///`. It prints `1` for true and nothing for false. I can post a detailed explanation if requested.

Example run:

```
perl -pE'y/b-y/aadddgggjjjmmmpppptttzzz/;$_=!/(.)\1/' <(echo "x")

```

---

## Perl - 81

```
$s=join"]{2}|[",qw(abc def ghi jkl mno p-s tuv w-z);say/^(?!.*(  |[$s]{2}))/?1:0

```

+1 for `-n` flag. It works by using `join` to create the regex (same one as Martin's), which shaves of a few bytes.

Example run:

```
perl -nE'$s=join"]{2}|[",qw(abc def ghi jkl mno p-s tuv w-z);say/^(?!.*(  |[$s]{2}))/?1:0' <(echo "your silence was of undue permanence")

```
> 7 votes

# Answer
# JavaScript - 159 156 bytes

```
function g(s){p=n=-1;for(i=0;i!=s.length;i++){p=n;n=s.charCodeAt(i);n-=97;if(n>17)n--;if(n>23)n--;if(p==-1)continue;if(~~(p/3)==~~(n/3))return 0;}return 1;}

```

Returns 1 for truthy and 0 for falsy.

If only I could get rid of the keywords.
> 4 votes

# Answer
# c, 74 bytes

```
main(c,d,r){for(;~(c=getchar());r*=d!=c/3,d=c/3)c-=--c/'p'*(c-'k')/7;c=r;}

```

Returns a non-zero exit status for TRUE and 0 for FALSE:

```
$ for s in "x" "aardvark" "ardvark" "flonk" "im codegolfing all day long" "i indulge in minimizing bytecount" "havent heard from you in a long time" "your silence was of undue permanence" "how are  you" "how are you"; do echo "./3310 <<< \"$s\" returns $(./3310 <<< "$s"; echo $?)"; done
./3310 <<< "x" returns 40
./3310 <<< "aardvark" returns 0
./3310 <<< "ardvark" returns 216
./3310 <<< "flonk" returns 0
./3310 <<< "im codegolfing all day long" returns 0
./3310 <<< "i indulge in minimizing bytecount" returns 72
./3310 <<< "havent heard from you in a long time" returns 0
./3310 <<< "your silence was of undue permanence" returns 232
./3310 <<< "how are  you" returns 0
./3310 <<< "how are you" returns 8
$

```
> 4 votes

# Answer
## Ruby 1.8, ~~89~~ ~~83~~ ~~81~~ 78 bytes

```
p$*[0].chars.map{|c|c=c[0];(c-c/?p-c/?w-1)/3}.each_cons(2).map{|a,b|a!=b}.all?

```

Here is another submission. To my shame, it beats the regex. :(

This takes the string via command-line argument and prints a boolean.

As for the algorithm, I'm shifting down the letters after `p` by one and after `z` by two, and then I check that there are no collisions after integer division by 3.

PS: This is the first time, that using Ruby 1.8 shortened the code (due to the shorter way to get character codes).
> 3 votes

# Answer
# Cobra - 80

```
def f(s)
    for c in s
        for x in 9,if' adgjmptw'[x]>c,break
        t,f=x,t<>x
    print f

```
> 3 votes

# Answer
# JavaScript (ES6) 66 ~~74~~

```
F=s=>[...s].every(c=>[...' adgjmptw'].map(x=>s+=c<x,w=s,s=0)|s!=w)

```

The inner loop find the group for each character. Conceptually is a 'reduce' but 'map' is shorter. The outer loop compare the group of consecutive chars and exits with false if they are equal.

**Test** In Firefox/Firebug console

```
;["x","aardvark","ardvark","flonk","im codegolfing all day long",
"i indulge in minimizing bytecount","havent heard from you in a long time",
"your silence was of undue permanence","how are  you","how are you"]
.forEach(x=>console.log(x + ' -> ' + F(x)))

```

*Output*

```
x -> true
aardvark -> false
ardvark -> true
flonk -> false
im codegolfing all day long -> false
i indulge in minimizing bytecount -> true
havent heard from you in a long time -> false
your silence was of undue permanence -> true
how are  you -> false
how are you -> true

```
> 3 votes

# Answer
# Perl, 83 bytes

```
$_=<>;chop;map{$_=ord;$_=($_-$_/112-$_/119-1)/3;die 0 if$l==$_;$l=$_}split//;die 1

```

Making heavy abuse of $\_ in Perl.
> 2 votes

# Answer
Two tasks are tricky in Python; detecting chains, and assigning the groups. Both can be assisted using numpy, but it is not in the standard library.

# Python 2 (only standard library) - 59 chars function

```
from itertools import imap as M
from __builtin__ import bytearray as A, all as E
from operator import ne as D, not_ as N
from re import S, sub as X, search as F

# 68
#def f(s):
# g=[(n-n/115-n/61)/3for n in A(s)]
# return E(M(D,g,g[1:]))

# 67 with regex via regex
#f=lambda s:N(F(X('(\S)(.)',r'|[\1-\2]{2}','  acdfgijlmopstvwz'),s))

# 59 slightly optimized ordinal classifier and regex sequence detector
f=lambda s:N(F(r'(.)\1',A((n-n/23-n/30)/3for n in A(s)),S))

# 69 using itertools.groupby
#from itertools import groupby as G
#from __builtin__ import sum as S, len as L
#f=lambda s:N(S(L(A(g))-1for _,g in G((n-n/115-n/61)/3for n in A(s))))

```

# Python 2 (only standard library) - 53 chars stdin to exit value

Here I abuse the fact that `issubclass(bool,int)`, so changing `all()` to `any()` gets me a valid exit value, shaving off the `not()` from the return value. The removal of function overhead made the regex versions fall behind in size.

```
from itertools import groupby as G, imap as M
from __builtin__ import bytearray as A, any as E
from __builtin__ import raw_input as I
from sys import exit as Q
from operator import eq as S

g=[(n-n/23-n/30)/3for n in A(I())]
Q(E(M(S,g,g[1:])))

```
> 2 votes

# Answer
# J - 42 char

Function taking string on the right.

```
*/@(2~:/\(I.4 3 4 1,~5#3){~(u:97+i.26)&i.)

```

First we map the alphabet (`u:97+i.26`) into the numbers 0 through 25, all other characters (including spaces) going to 26 (`i.`). Then we map (`{~`) the first three elements map to the first key, the next three to the next key, and so on through the keys of the phone pad, making sure to map the space/other punctuation to a separate key at the end. (`4 3 4 1,~5#3` is equal to `3 3 3 3 3 4 3 4 1` and `I.` turns that into a 27-item array where the first three are key 1, etc.) Then we check for pairwise inequality (`2~:/\`) and AND all the results together (`*/`).

```
   */@(2~:/\(I.4 3 4 1,~5#3){~(u:97+i.26)&i.) 'i indulge in minimizing bytecount'
1
   f =: */@(2~:/\(I.4 3 4 1,~5#3){~(u:97+i.26)&i.)
   f 'im codegolfing all day long'
0
   f '*/@(2~:/\(I.4 3 4 1,~5#3){~(u:97+i.26)&i.)'  NB. no -3 bonus :(
0

```
> 2 votes

# Answer
# Racket, 119

```
(define(f t)(for*/and([s(map ~a'(abc def ghi jkl mno pqrs tuv wxyz))][i s][j s])(not(regexp-match(format"~a~a"i j)t))))

```

Ungolfed (combinatoric regexing):

```
(define(f t)
  (for*/and([s (map ~a '(abc def ghi jkl mno pqrs tuv wxyz))]
            [i s]
            [j s])
    (not (regexp-match (format "~a~a" i j) t))))

```
> 2 votes

# Answer
## ES6, JavaScript ~~89~~ 70 characters

I know its not a winner because when coming to handy operations like getting ASCII value of character, JS puts a lot of bloat (`.charCodeAt()`).

```
N=s=>[...s].every(c=>l-(l=(c.charCodeAt()-(c>"r")-(c>"y")-1)/3|0),l=1)

```

Run it in Web Console of latest Firefox.

Usage:

```
N("testing if this works")

```

The function returns either true or false.

**EDIT**: Golfed a lot using the `[...x].every` trick learned from @edc65 (Thanks!)

I will try to golf it more :)
> 1 votes

# Answer
# JavaScript - 152

Not a winner but I gave it a shot. Beats @Lozzaaa by 4 bytes as of posting time :)

```
function m(a){c="abc-def-ghi-jkl-mno-pqrstuv-wxyz";j=a.split("");for(z in j)if(j[z]=Math.floor(c.indexOf(j[z])/4),0!=z&&j[z-1]==j[z])return 0;return 1};

```

Passes all the tests.
Takes advantage of JS's lack of typing to make a multi type array, and it takes advantage of indexOf returning -1 for space support.

Usage:

```
m("string here")

```

Assumes lowercase alphabetic characters and spaces only. Returns 1 for true, 0 for false.

Maybe if I knew ES6 I could try the second challenge...
> 1 votes

# Answer
# Python 3 - 152 chars

Not the shortest I could go, but it'll do for now

```
k=['abc','def','ghi','jkl','mno','pqrs','tuv','wxyz',' ']
x=input()
l=2>1
for i in range(len(x)-1):
 for j in k:
  if x[i+1] in j and x[i] in j:l=1>2
print(l)

```
> 0 votes

# Answer
# GML (Game Maker Language), 149

```
s=argument0p=n=-1for(i=0;i<string_length(s);i++){p=n;n=string_char_at(s,i)-97;x=n>17&&n--;x=n>23&&n--;if(!p)x=1if(!(p/3)=!(n/3))x=0}show_message(x)

```
> 0 votes

---
Tags: code-golf
---


title: Radioactive Quines

text:
# Question
Title: Radioactive Quines
A *radioactive quine* is a quine-like program that has an even number of characters and, when run, outputs itself with exactly half of its characters removed.

The output itself may be a radioactive quine, so the program can "decay" multiple times.
It could be said that the half-life of a radioactive quine is one run, up to a certain number of runs (decays).

# Example

The Python 2 program (28 characters)

```
1234;print'print\'abcdefg\''

```

is a radioactive quine with 2 decay steps because when it is run it outputs

```
print'abcdefg'

```

which is the original program with these 14 characters removed: `1234;print'\\'`.

When `print'abcdefg'` is run in turn it outputs `abcdefg` which is `print'abcdefg'` with the 7 characters `print''` removed.

The program `abcdefg` is not a radioactive quine so the cycle has come to an end.

# Challenge

Write a radioactive quine **in 1024 characters or less** that has the most decay cycles.

The 1024 character limit means that the maximum number of decay cycles possible is 10 since the
`1024 → 512 → 256 → 128 → 64 → 32 → 16 → 8 → 4 → 2 → 1` decay pattern would be optimal.

The example above has 2 decay cycles.

### Details

* Just like normal quines, radioactive quines may not take input or read their own source.
* All output must go to stdout or your language's closest alternative.
* You may use any characters. It is not limited to ASCII.
* The characters in a radioactive quine that are removed may be removed from any indices (but the remaining characters may not be rearranged). So `radquine` could decay into `radq` or `uine` or `rdui` or `rain`, etc.
* Note that only a program with an **even number of characters** can possibly be a radioactive quine.
* It's fine if the final output of the decay cycle (`abcdefg` in the example) has an even number of characters. It doesn't matter what happens when this output is run as a program.

# Winning

The winner will be the submission with the most decay cycles.

**Update:** Since trivial answers are possible I'm following yasen's advice and saying that in case of ties, the starting radioactive quine with the most unique characters wins. (Naturally 1024 is the limit here.)

In the rare chance there is still a tie, the highest voted answer wins.

# Answer
# CJam, 10 cycles, 1023 unique characters

```
"39c'LS 0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃǄǅǆǇǈǉǊǋǌǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰǱǲǳǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈ̴̵̶̷̸̯̰̱̲̳̹̺̻̼͇͈͉͍͎͓͔͕͖͙͚̽̾̿̀́͂̓̈́͆͊͋͌͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡ͅͰͱͲͳʹ͵Ͷͷ͸͹ͺͻͼͽ;Ϳ΀΁΂΃΄΅Ά·ΈΉΊ΋Ό΍ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ΢ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϏϐϑϒϓϔϕϖϗϘϙϚϛϜϝϞϟϠϡϢϣϤϥϦϧϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖֽ־ֿ׀ׁׂ׃ׅׄ׆ׇ׈׉׊׋׌׍׎׏אבגדהוזחטיךכלםמןנסעףפץצקרשת׫׬׭׮ׯװױײ׳״׵׶׷׸׹׺׻׼׽׾׿؀؁؂؃؄؅؆؇؈؉؊؋،؍؎؏ؘؙؚؐؑؒؓؔؕؖؗ؛؝؞؟ؠءآأؤࡋࡌࡍࡎࡏࡐࡑࡒࡓࡔࡕࡖࡗࡘ࡙࡚࡛࡜࡝࡞࡟ࡠࡡࡢࡣࡤࡥࡦࡧࡨࡩࡪ࡫࡬࡭࡮࡯ࡰࡱࡲ૙૚૛૜૝૞૟ૠ൧൨ྲྀླྌྊྉྈྒ೨ഥദ೾೯ംഢ೼೻೺ബೳഇഄਗ਼ગઘੰ੡ੴઔ੮੭੬ઞ੥ઌੜ੤੯੣ઑ੧એ੢੹ੳ੶ߌࠉࠊߢߓߦࠆߠߟߞࠐߗ߾ߎߖߡߕࠃߙࠁߔ߫ߥߨԾջռՔՅ՘ոՒՑՐւՉհՀՈՓՇյՋճՆ՝՗՚ʰ˭ˮˆʷˊ˪˄˃˂˴ʻˢʲʺ˅ʹ˧ʽ˥ʸˏˉˌ"_`8)<\654f-T$,7+Y/W*A;>

```

### Output

```
"39c'LS 0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈ̴̵̶̷̸̯̰̱̲̳̹̺̻̼͇͈͉͍͎͓͔͕͖͙͚̽̾̿̀́͂̓̈́͆͊͋͌͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ͘͜͟͢͝͞͠͡ͅͰͱͲͳʹ͵Ͷͷ͸͹ͺͻͼͽ;Ϳ΀΁΂΃΄΅Ά·ΈΉΊ΋Ό΍ΎΏΐΑΒΓΔΕΖֽ־ֿ׀ׁׂ׃ׅׄ׆ׇ׈׉׊׋׌׍׎׏אבגדהוזחטיךכלםמןנסעףפࡋࡌࡍࡎࡏࡐࡑࡒ૙૚೨ഥ೾೼೻೺ഄਗ਼ગઘੰ੡ੴઔ੮੭੬ઞ੥੹੶ߌࠉࠊߢߓߦࠆߠߟߞࠐߗ߾ߎߖߡߕࠃߙࠁߔ߫ߥߨԾջռՔՅ՘ոՒՑՐւՉհՀՈՓՇյՋճՆ՝՗՚ʰ˭ˮˆʷˊ˪˄˃˂˴ʻˢʲʺ˅ʹ˧ʽ˥ʸˏˉˌ"_`8)<\654f-T$,7+Y/W*A;>
"39c'LS 0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈ̴̵̶̷̸ֽ̯̰̱̲̳̹̺̻̼͇͈͉͍͎͓͔͕͖̽̾̿̀́͂̓̈́͆͊͋͌͐͑͒ͅ־ֿ׀ׁׂ׃ׄࡋࡌਗ਼ગੰ੮੭੬੶ߌࠉࠊߢߓߦࠆߠߟߞࠐߗ߫ߨԾջռՔՅ՘ոՒՑՐւՉհՀՈՓՇյՋճՆ՝՗՚ʰ˭ˮˆʷˊ˪˄˃˂˴ʻˢʲʺ˅ʹ˧ʽ˥ʸˏˉˌ"_`8)<\654f-T$,7+Y/W*A;>
"39c'LS 0¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ̴̵̶ֽ̯̰̱̲̳־ߌࠉߢߠߟߞߨԾջռՔՅ՘ոՒՑՐւՉ՝՚ʰ˭ˮˆʷˊ˪˄˃˂˴ʻˢʲʺ˅ʹ˧ʽ˥ʸˏˉˌ"_`8)<\654f-T$,7+Y/W*A;>
"39c'LS 0¡¢£¤¥¦§¨̯̰ԾջՔՒՑՐ՚ʰ˭ˮˆʷˊ˪˄˃˂˴ʻˏˌ"_`8)<\654f-T$,7+Y/W*A;>
"39c'LS 0¡¢ʰ˭ˆ˄˃˂ˌ"_`8)<\654f-A>
"39c'LS 0"_8654>
39c'LS 0
'L 0
L0
0

```

### How it works

* ``8)<` returns the first 9 characters of the string with double quote.
* `654f-` decreases each character by 654.
* `T$,` returns the string length on the top of the stack.
* `7+Y/W*>` returns appropriate number of characters from the end of the decoded string.
* `_`8)<\654f-A>` is a simplified version without calculating the number of characters.
* `_8654>` does nothing useful.
* `39c` is the character `'`.

The string in each program ends with the output without `"39c'LS 0`, with each character value increased by 654. And each string is a substring of the one in the previous program, because it is the substring if both of them are decoded.

The only character used twice is the double quote (`"`).

Non-ascii characters cannot appear in blocks directly without a string in CJam. And there are no comment characters. So I think 1024 in CJam is impossible. It might be possible in GolfScript. And it should be easier in languages like Sclipting. But I'm too lazy to do that.

It can be generated with the following program:

```
{9>654f+}:U;
{"\"39c'LS 0"\+}:V;
{
  _,24-,'¡f+
  \U+
  V
  "\"_`8)<\654f-T$,7+Y/W*A;>"+
}:T;

"\"39c'LS 0\"_8654>"
U"¡¢"\+V"\"_`8)<\654f-A>"+
TTTTT

```

# CJam, 10 cycles, all printable ascii

```
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''']_" !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJK";

```

### How it works

In the first time it prints 512 `'`s. Then it works just like Dennis's answer.
> 18 votes

# Answer
# CJam, 10 cycles

```
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

```

---

# CJam, 10 cycles, 876 unique characters

```
"\"''''''''\""'""'BCD'µϨ¶'·ϩ¸'¹Ϫº'»ϫ¼'½Ϭ¾'¿ϭÀ'ÁϮÂ'ÃϯÄ'ÅϰÆ'ÇϱÈ'ÉϲÊ'ËϳÌ'ÍϴÎ'ÏϵÐ'Ñ϶Ò'ÓϷÔ'ÕϸÖ'×ϹØ'ÙϺÚ'ÛϻÜ'ÝϼÞ'ßϽà'áϾâ'ãϿä'åЀæ'çЁè'éЂê'ëЃì'íЄî'ïЅð'ñІò'óЇô'õЈö'÷Љø'ùЊú'ûЋü'ýЌþ'ÿЍĀ'āЎĂ'ăЏĄ'ąАĆ'ćБĈ'ĉВĊ'ċГČ'čДĎ'ďЕĐ'đЖĒ'ēЗĔ'ĕИĖ'ėЙĘ'ęКĚ'ěЛĜ'ĝМĞ'ğНĠ'ġОĢ'ģПĤ'ŃЯń'ţпŤ'ťрŦ'ŧсŨ'ũтŪ'ūуŬ'ŭфŮ'ůхŰ'űцŲ'ųчŴ'ŵшŶ'ŷщŸ'Źъź'Żыż'Žьž'ſэƀ'ƁюƂ'ƃяƄ'ƅѐƆ'Ƈёƈ'ƉђƊ'Ƌѓƌ'ƍєƎ'ƏѕƐ'Ƒіƒ'ƓїƔ'ƕјƖ'ƗљƘ'ƙњƚ'ƛћƜ'Ɲќƞ'ƟѝƠ'ơўƢ'ƣџƤ'ƥѠƦ'Ƨѡƨ'ƩѢƪ'ƫѣƬ'ƭѤƮ'Ưѥư'ƱѦƲ'Ƴѧƴ'ƵѨƶ'ƷѩƸ'ƹѪƺ'ƻѫƼ'ƽѬƾ'ƿѭǀ'ǁѮǂ'ǃѯǄ'ǅѰǆ'Ǉѱǈ'ǉѲǊ'ǋѳǌ'ǍѴǎ'Ǐѵǐ'ǑѶǒ'Ǔѷǔ'ǕѸǖ'Ǘѹǘ'ǙѺǚ'ĥРĦ'ħСĨ]Ǜѻǜ_ǝѼǞ\\Ǥ\"ǥҀǦ썐īУĬ썑ĭФĮ썒ĩТĪ썓Ņаņ썔Ňбň썕ŉвŊ썖ŋгŌ썗ōдŎ썘ŏеŐ썙őжŒ썚œзŔ썛ŕиŖ썜ŗйŘ썝řкŚ썞śлŜ썟ŝмŞ썠şнŠ썡šоŢ썢įХİ썣ıЦĲ썤ĳЧĴ썥ĵШĶ썦ķЩĸ썧ĹЪĺ써ĻЫļ썩ĽЬľ썪ĿЭŀ썫ŁЮł썬ǟѽǠ썭ǡѾǢ썮ǧҁǨ썯ǩ҂Ǫ썰ǫ҃Ǭ썱ǭ҄Ǯ썲ǯ҅ǰ썳Ǳ҆ǲ썴ǳ҇Ǵ썵ǵ҈Ƕ썶Ƿ҉Ǹ썷ǹҊǺ썸ǻҋǼ썹ǽҌǾ썺ǿҍȀ썻ȁҎȂ썼ȃҏȄ썽ȅҐȆ썾ȇґȈ썿ȉҒȊ쎀ȋғȌ쎁ȍҔȎ쎂ȏҕȐ쎃ȑҖȒ쎄ȓҗȔ쎅ȕҘȖ쎆ȗҙȘ쎇șҚȚ쎈țқȜ쎉ȝҜȞ쎊ȟҝȠ쎋ȡҞȢ쎌ȣҟȤ쎍ȥҠȦ쎎ȧҡȨ쎏ȩҢȪ쎐ȫңȬ쎑ȭҤȮ쎒ȯҥȰ쎓ȱҦȲ쎔ȳҧȴ쎕ȵҨȶ쎖ȷҩȸ쎗ȹҪȺ쎘Ȼҫȼ쎙ȽҬȾ쎚ȿҭɀ쎛ɁҮɂ쎜ɃүɄ쎝ɅҰɆ쎞ɇұɈ쎟ɉҲɊ쎠ɋҳɌ쎡ɍҴɎ쎢ɏҵɐ쎣ɑҶɒ쎤ɓҷɔ쎥ɕҸɖ쎦ɗҹɘ쎧əҺɚ쎨ɛһɜ쎩ɝҼɞ쎪ɟҽɠ쎫ɡҾɢ쎬ɣҿɤ쎭ɥӀɦ쎮ɧӁɨ쎯ɩӂɪ쎰ɫӃɬ쎱ɭӄɮ쎲ɯӅɰ쎳ɱӆɲ쎴ɳӇɴ쎵ɵӈɶ쎶ɷӉɸ쎷ɹӊɺ쎸ɻӋɼ쎹ɽӌɾ쎺ɿӍʀ쎻ʁӎʂ쎼ʃӏʄ쎽ʅӐʆ쎾ʇӑʈ쎿ʉӒʊ쏀ʋӓʌ쏁ʍӔʎ쏂ʏӕʐ쏃ʑӖʒ쏄ʓӗʔ쏅ʕӘʖ쏆ʗәʘ쏇ʙӚʚ쏈ʛӛʜ쏉ʝӜʞ쏊ʟʠʡ\\Ӟ\"ʢʣӟ;"2%'""Y%a"

```

Try it online.

### How it works

* `"xyzw"` pushes the string `xyzw`.
* `"xyzw"2%` pushes the string `xz`.
* `"xyzw";` pushes nothing.
* `]_` duplicates the entire stack.
* `'x` pushes the character `x`.

### Example run

```
$ C=$(cat decay); while ((${#C} > 1)); do echo $C; C=$(cjam <(echo $C)); done; echo $C
"\"''''''''\""'""'BCD'µϨ¶'·ϩ¸'¹Ϫº'»ϫ¼'½Ϭ¾'¿ϭÀ'ÁϮÂ'ÃϯÄ'ÅϰÆ'ÇϱÈ'ÉϲÊ'ËϳÌ'ÍϴÎ'ÏϵÐ'Ñ϶Ò'ÓϷÔ'ÕϸÖ'×ϹØ'ÙϺÚ'ÛϻÜ'ÝϼÞ'ßϽà'áϾâ'ãϿä'åЀæ'çЁè'éЂê'ëЃì'íЄî'ïЅð'ñІò'óЇô'õЈö'÷Љø'ùЊú'ûЋü'ýЌþ'ÿЍĀ'āЎĂ'ăЏĄ'ąАĆ'ćБĈ'ĉВĊ'ċГČ'čДĎ'ďЕĐ'đЖĒ'ēЗĔ'ĕИĖ'ėЙĘ'ęКĚ'ěЛĜ'ĝМĞ'ğНĠ'ġОĢ'ģПĤ'ŃЯń'ţпŤ'ťрŦ'ŧсŨ'ũтŪ'ūуŬ'ŭфŮ'ůхŰ'űцŲ'ųчŴ'ŵшŶ'ŷщŸ'Źъź'Żыż'Žьž'ſэƀ'ƁюƂ'ƃяƄ'ƅѐƆ'Ƈёƈ'ƉђƊ'Ƌѓƌ'ƍєƎ'ƏѕƐ'Ƒіƒ'ƓїƔ'ƕјƖ'ƗљƘ'ƙњƚ'ƛћƜ'Ɲќƞ'ƟѝƠ'ơўƢ'ƣџƤ'ƥѠƦ'Ƨѡƨ'ƩѢƪ'ƫѣƬ'ƭѤƮ'Ưѥư'ƱѦƲ'Ƴѧƴ'ƵѨƶ'ƷѩƸ'ƹѪƺ'ƻѫƼ'ƽѬƾ'ƿѭǀ'ǁѮǂ'ǃѯǄ'ǅѰǆ'Ǉѱǈ'ǉѲǊ'ǋѳǌ'ǍѴǎ'Ǐѵǐ'ǑѶǒ'Ǔѷǔ'ǕѸǖ'Ǘѹǘ'ǙѺǚ'ĥРĦ'ħСĨ]Ǜѻǜ_ǝѼǞ\\Ǥ\"ǥҀǦ썐īУĬ썑ĭФĮ썒ĩТĪ썓Ņаņ썔Ňбň썕ŉвŊ썖ŋгŌ썗ōдŎ썘ŏеŐ썙őжŒ썚œзŔ썛ŕиŖ썜ŗйŘ썝řкŚ썞śлŜ썟ŝмŞ썠şнŠ썡šоŢ썢įХİ썣ıЦĲ썤ĳЧĴ썥ĵШĶ썦ķЩĸ썧ĹЪĺ써ĻЫļ썩ĽЬľ썪ĿЭŀ썫ŁЮł썬ǟѽǠ썭ǡѾǢ썮ǧҁǨ썯ǩ҂Ǫ썰ǫ҃Ǭ썱ǭ҄Ǯ썲ǯ҅ǰ썳Ǳ҆ǲ썴ǳ҇Ǵ썵ǵǶ썶ǷǸ썷ǹҊǺ썸ǻҋǼ썹ǽҌǾ썺ǿҍȀ썻ȁҎȂ썼ȃҏȄ썽ȅҐȆ썾ȇґȈ썿ȉҒȊ쎀ȋғȌ쎁ȍҔȎ쎂ȏҕȐ쎃ȑҖȒ쎄ȓҗȔ쎅ȕҘȖ쎆ȗҙȘ쎇șҚȚ쎈țқȜ쎉ȝҜȞ쎊ȟҝȠ쎋ȡҞȢ쎌ȣҟȤ쎍ȥҠȦ쎎ȧҡȨ쎏ȩҢȪ쎐ȫңȬ쎑ȭҤȮ쎒ȯҥȰ쎓ȱҦȲ쎔ȳҧȴ쎕ȵҨȶ쎖ȷҩȸ쎗ȹҪȺ쎘Ȼҫȼ쎙ȽҬȾ쎚ȿҭɀ쎛ɁҮɂ쎜ɃүɄ쎝ɅҰɆ쎞ɇұɈ쎟ɉҲɊ쎠ɋҳɌ쎡ɍҴɎ쎢ɏҵɐ쎣ɑҶɒ쎤ɓҷɔ쎥ɕҸɖ쎦ɗҹɘ쎧əҺɚ쎨ɛһɜ쎩ɝҼɞ쎪ɟҽɠ쎫ɡҾɢ쎬ɣҿɤ쎭ɥӀɦ쎮ɧӁɨ쎯ɩӂɪ쎰ɫӃɬ쎱ɭӄɮ쎲ɯӅɰ쎳ɱӆɲ쎴ɳӇɴ쎵ɵӈɶ쎶ɷӉɸ쎷ɹӊɺ쎸ɻӋɼ쎹ɽӌɾ쎺ɿӍʀ쎻ʁӎʂ쎼ʃӏʄ쎽ʅӐʆ쎾ʇӑʈ쎿ʉӒʊ쏀ʋӓʌ쏁ʍӔʎ쏂ʏӕʐ쏃ʑӖʒ쏄ʓӗʔ쏅ʕӘʖ쏆ʗәʘ쏇ʙӚʚ쏈ʛӛʜ쏉ʝӜʞ쏊ʟʠʡ\\Ӟ\"ʢʣӟ;"2%'""Y%a"
"''''''''""'C'Ϩ'ϩ'Ϫ'ϫ'Ϭ'ϭ'Ϯ'ϯ'ϰ'ϱ'ϲ'ϳ'ϴ'ϵ'϶'Ϸ'ϸ'Ϲ'Ϻ'ϻ'ϼ'Ͻ'Ͼ'Ͽ'Ѐ'Ё'Ђ'Ѓ'Є'Ѕ'І'Ї'Ј'Љ'Њ'Ћ'Ќ'Ѝ'Ў'Џ'А'Б'В'Г'Д'Е'Ж'З'И'Й'К'Л'М'Н'О'П'Я'п'р'с'т'у'ф'х'ц'ч'ш'щ'ъ'ы'ь'э'ю'я'ѐ'ё'ђ'ѓ'є'ѕ'і'ї'ј'љ'њ'ћ'ќ'ѝ'ў'џ'Ѡ'ѡ'Ѣ'ѣ'Ѥ'ѥ'Ѧ'ѧ'Ѩ'ѩ'Ѫ'ѫ'Ѭ'ѭ'Ѯ'ѯ'Ѱ'ѱ'Ѳ'ѳ'Ѵ'ѵ'Ѷ'ѷ'Ѹ'ѹ'Ѻ'Р'С]ѻ_Ѽ\"Ҁ썐У썑Ф썒Т썓а썔б썕в썖г썗д썘е썙ж썚з썛и썜й썝к썞л썟м썠н썡о썢Х썣Ц썤Ч썥Ш썦Щ썧Ъ써Ы썩Ь썪Э썫Ю썬ѽ썭Ѿ썮ҁ썯҂썰썱썲썳썴҇썵썶썷Ҋ썸ҋ썹Ҍ썺ҍ썻Ҏ썼ҏ썽Ґ썾ґ썿Ғ쎀ғ쎁Ҕ쎂ҕ쎃Җ쎄җ쎅Ҙ쎆ҙ쎇Қ쎈қ쎉Ҝ쎊ҝ쎋Ҟ쎌ҟ쎍Ҡ쎎ҡ쎏Ң쎐ң쎑Ҥ쎒ҥ쎓Ҧ쎔ҧ쎕Ҩ쎖ҩ쎗Ҫ쎘ҫ쎙Ҭ쎚ҭ쎛Ү쎜ү쎝Ұ쎞ұ쎟Ҳ쎠ҳ쎡Ҵ쎢ҵ쎣Ҷ쎤ҷ쎥Ҹ쎦ҹ쎧Һ쎨һ쎩Ҽ쎪ҽ쎫Ҿ쎬ҿ쎭Ӏ쎮Ӂ쎯ӂ쎰Ӄ쎱ӄ쎲Ӆ쎳ӆ쎴Ӈ쎵ӈ쎶Ӊ쎷ӊ쎸Ӌ쎹ӌ쎺Ӎ쎻ӎ쎼ӏ쎽Ӑ쎾ӑ쎿Ӓ쏀ӓ쏁Ӕ쏂ӕ쏃Ӗ쏄ӗ쏅Ә쏆ә쏇Ӛ쏈ӛ쏉Ӝ쏊ʠ\"ʣ;"Y%a
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''']_"썐썑썒썓썔썕썖썗썘썙썚썛썜썝썞썟썠썡썢썣썤썥썦썧써썩썪썫썬썭썮썯썰썱썲썳썴썵썶썷썸썹썺썻썼썽썾썿쎀쎁쎂쎃쎄쎅쎆쎇쎈쎉쎊쎋쎌쎍쎎쎏쎐쎑쎒쎓쎔쎕쎖쎗쎘쎙쎚쎛쎜쎝쎞쎟쎠쎡쎢쎣쎤쎥쎦쎧쎨쎩쎪쎫쎬쎭쎮쎯쎰쎱쎲쎳쎴쎵쎶쎷쎸쎹쎺쎻쎼쎽쎾쎿쏀쏁쏂쏃쏄쏅쏆쏇쏈쏉쏊";
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''
''''''''''''''''
''''''''
''''
''
'

```
> 19 votes

# Answer
# Marbelous, 10 cycles

```
3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334

```

There are 1023 3's and then one 4. This will print 511 3's (since 33 is the hexadecimal ascii value of 3) and one 4 (since 3 is the hexadecimal ascii value of 4). This keeps going until we are left with:

```
34

```

which prints `4` and is not a valid Marbelous program.

**Another solution, using 22 distinct characters:**

```
01333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334
23
45
67
89
AB
CD
EF
AA
AA
AA
AA
AA
AA
AA
AA
ab
:ab
}0
\/3333

```

In this one I've defined a function that takes one input and prints two 3's. I then feed 16 inputs to it, which prints the number 3 32 times. This all consists of 64 characters. , then there are 959 3's and one 4. This all reduces to 511 3's and one 4. This then continues like the solution above. Since I can print two 3's by adding just 3 characters (any literal plus a newline), I can add a bunch more useless devices to the `ab` function to use more distinct characters. As long as 511 of the characters I use stay 3's and one a 4.
> 14 votes

# Answer
## CJam, 10 Cycles, 947 Unique characters

I think I am getting a hang of it now. A sweet tricky approach to the problem brings be 937 unique characters and still space for more.

```
"\"['''''''''''''''']_\""`'`'''`"\"\\\"0123456789\\\";\"\"@ABCDEFGHIJKLMNOPQRSTUV\";"`'`'''`"\"WXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~®¯°±²³´\";"`'`"\"µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪ\";"`"īĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃǄǅǆǇǈǉǊǋǌǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰǱǲǳǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞ"`';"ȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼʽʾʿˀˁ˂˃˄˅ˆˇˈˉˊˋˌˍˎˏːˑ˒˓˔˕˖˗˘˙˚˛˜˝˞˟ˠˡˢˣˤ˥˦˧˨˩˪˫ˬ˭ˮ˯˰˱˲˳˴˵˶˷˸˹˺˻˼˽˾˿̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎͓͔͕͖͙͚̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ̕̚͘͜͟͢͝͞͠͡ͅͰͱͲͳʹ͵Ͷͷ͸͹ͺͻͼͽ;Ϳ΀΁΂΃΄΅Ά·ΈΉΊ΋Ό΍ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ΢ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϏϐϑϒϓϔϕϖϗϘϙϚϛϜϝϞϟϠϡϢϣϤϥϦϧϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏ";

```

---

Here is the output of all the cycles starting from initial state

```
"\"['''''''''''''''']_\""`'`'''`"\"\\\"0123456789\\\";\"\"@ABCDEFGHIJKLMNOPQRSTUV\";"`'`'''`"\"WXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~®¯°±²³´\";"`'`"\"µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪ\";"`"īĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃǄǅǆǇǈǉǊǋǌǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰǱǲǳǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞ"`';"ȟȠȡȢȣȤȥȦȧȨȩȪȫȬȭȮȯȰȱȲȳȴȵȶȷȸȹȺȻȼȽȾȿɀɁɂɃɄɅɆɇɈɉɊɋɌɍɎɏɐɑɒɓɔɕɖɗɘəɚɛɜɝɞɟɠɡɢɣɤɥɦɧɨɩɪɫɬɭɮɯɰɱɲɳɴɵɶɷɸɹɺɻɼɽɾɿʀʁʂʃʄʅʆʇʈʉʊʋʌʍʎʏʐʑʒʓʔʕʖʗʘʙʚʛʜʝʞʟʠʡʢʣʤʥʦʧʨʩʪʫʬʭʮʯʰʱʲʳʴʵʶʷʸʹʺʻʼʽʾʿˀˁ˂˃˄˅ˆˇˈˉˊˋˌˍˎˏːˑ˒˓˔˕˖˗˘˙˚˛˜˝˞˟ˠˡˢˣˤ˥˦˧˨˩˪˫ˬ˭ˮ˯˰˱˲˳˴˵˶˷˸˹˺˻˼˽˾˿̴̵̶̷̸̡̢̧̨̛̖̗̘̙̜̝̞̟̠̣̤̥̦̩̪̫̬̭̮̯̰̱̲̳̹̺̻̼͇͈͉͍͎͓͔͕͖͙͚̀́̂̃̄̅̆̇̈̉̊̋̌̍̎̏̐̑̒̓̔̽̾̿̀́͂̓̈́͆͊͋͌͐͑͒͗͛ͣͤͥͦͧͨͩͪͫͬͭͮͯ̕̚͘͜͟͢͝͞͠͡ͅͰͱͲͳʹ͵Ͷͷ͸͹ͺͻͼͽ;Ϳ΀΁΂΃΄΅Ά·ΈΉΊ΋Ό΍ΎΏΐΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ΢ΣΤΥΦΧΨΩΪΫάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώϏϐϑϒϓϔϕϖϗϘϙϚϛϜϝϞϟϠϡϢϣϤϥϦϧϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏ";
"\"['''''''''''''''']_\""`'`"\"\\\"0123456789\\\";\"\"@ABCDEFGHIJKLMNOPQRSTUV\";"`'`"\"WXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~®¯°±²³´\";"`"\"µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪ\";""īĬĭĮįİıĲĳĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňŉŊŋŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƒƓƔƕƖƗƘƙƚƛƜƝƞƟƠơƢƣƤƥƦƧƨƩƪƫƬƭƮƯưƱƲƳƴƵƶƷƸƹƺƻƼƽƾƿǀǁǂǃǄǅǆǇǈǉǊǋǌǍǎǏǐǑǒǓǔǕǖǗǘǙǚǛǜǝǞǟǠǡǢǣǤǥǦǧǨǩǪǫǬǭǮǯǰǱǲǳǴǵǶǷǸǹǺǻǼǽǾǿȀȁȂȃȄȅȆȇȈȉȊȋȌȍȎȏȐȑȒȓȔȕȖȗȘșȚțȜȝȞ";
"\"['''''''''''''''']_\""`"\"\\\"0123456789\\\";\"\"@ABCDEFGHIJKLMNOPQRSTUV\";"`"\"WXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~®¯°±²³´\";""µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂăĄąĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪ";
"\"['''''''''''''''']_\"""\"\\\"0123456789\\\";\"\"@ABCDEFGHIJKLMNOPQRSTUV\";""WXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~®¯°±²³´";
"['''''''''''''''']_""\"0123456789\";""@ABCDEFGHIJKLMNOPQRSTUV";
['''''''''''''''']_"0123456789";
''''''''''''''''
''''''''
''''
''
'

```

As you can see, in each iteration, the right half of the line is a single string appended with `;`, thus it gets removed while evaluating.

Try it online
> 11 votes

# Answer
## APL, 10 cycles

```
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''01'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

```

That is 511 `'`s, characters `01`, and then 511`'`s

**Explaintion**
In APL, `'` are NOT escaped as `\'` but `''`. Yes, double quote marks!!

**Proof of correctness**
Suppose there are `x` quote marks on the left side of `01`, and `x` is odd.
Then, number of quote marks on the left side of `01` in the output = `(x-1)/2`
Similarly, for `x` quote marks on the right, there is `(x-1)/2` quote marks on the right in the output

So, for a program of length `L`, which has `L/2-1` quote marks on each side, the output contains:

* `((L/2-1)-1)/2 = L/4-1` quote marks on the left
* 2 characters `01`
* and `L/4-1` quote marks on the right

which gives a total of `L/2` characters in the output.

Note that because `x` is a power of 2 minus 1, `(x-1)/2 = ((2^n-1)-1)/2 = 2^(n-1)-1` is still a power of 2 minus 1 and odd if n\>1

When n = 1, there are 0 quote marks on each side, so the output is `01`, which evaluates to `1`.
> 9 votes

---
Tags: code-challenge, quine, source-layout
---


title: Check the jumbled words

text:
# Question
Title: Check the jumbled words
This is an easy one.

Anagrams are words which have the same characters but in different order. All you have to do is to figure out if two strings are anagram or not.

Rules:

* Take two strings as a function argument, command-line argument or from standard input.
* Write a function or program which returns truthy value if strings are anagram, falsy value otherwise
* Anagrams may have different number of spaces () characters in them.
* Anagrams are case insensitive matches.
* Anagrams can only have printable ASCII characters for this code-golf.

For example(taken from the Wikipedia page itself): `Doctor Who` is an anagram of `Torchwood` . Note missing space and lack of capital D and W in `Torchwood`

This is code-golf so minimum bytes code win!

Happy golfing.

# Answer
## CJam, ~~15~~ 11 bytes

Just thought I'd practice CJam a bit more. This is basically the same as my Ruby answer (or most answers):

```
ea{S-el$}/=

```

Quick explanation

```
ea          "Push command line arguments";
ea{     }/  "For each element in that array";
ea{S-   }/  "Push a space character onto the stack and remove spaces from string";
ea{S-el }/  "Convert string to lower case";
ea{S-el$}/  "Sort the characters in the string";
ea{S-el$}/= "Check for equality";

```

Prints `1` for anagrams and `0` otherwise.
> 3 votes

# Answer
# Java, 146 131 144 134 131 128

Not a very exciting answer. Returns true for anagrams, false for others. Actually works now. Cheapass abuse of generics in class declaration.

```
boolean b(T a,T b){return c(a).equals(c(b));}T c(T a){char[]c=a.toLowerCase().toCharArray();sort(c);return(T)valueOf(c).trim();}

```

Ungolfed:

```
boolean b(T a,T b) {
    return c(a).equals(c(b));
}

T c(T a) {
    char[] c = a.toLowerCase().toCharArray();
    sort(c);
    return (T) valueOf(c).trim();
}

```
> 4 votes

# Answer
## Ruby, ~~65~~ ~~60~~ ~~58~~ ~~57~~ ~~51~~ ~~48~~ 46 bytes

```
s,t=$*.map{|u|u.upcase.scan(/\S/).sort};p s==t

```

~~**Edit:** Switched to STDIN to save a few bytes.~~

**Edit:** Switched to ARGV to save three more bytes.

Quite long for such a simple problem, hmmmm.

* For each string:
    + Turn to upper case (to make it case in-sensitive).
    + Split into non-whitespace characters.
    + Sort (by character code).
* Then check that the results are equal.
> 3 votes

# Answer
# Rebol  ~~44~~  40

(Rebol 2)

Define a function `m` which takes two values `a` and `b`. `Sort` each string, `trim` the whitespace and use `=` to check if the strings are the same.

```
m: func[a b][(trim sort a)= trim sort b]

```

~~m: func\[a b\]\[equal? trim sort a trim sort b\]~~

Example

```
>> m: func[a b][(trim sort a)= trim sort b]
>> m "Doctor Who" "Torchwood"
== true

```

It is useful handy that `sort` is case insensitive by default. Note: This function does have side effects if you use this code elsewhere as `sort` modifies a and b directly.

(`sort` should work in Rebol 3 but doesn't as there is a known bug)
> 3 votes

# Answer
# JavaScript (ES6) 68 ~~99~~

Generate a key for each word and compare them. If only JS had some shorter ucase method...

```
A=(a,b,k=s=>[...s.toUpperCase()].sort().join('').trim())=>k(a)==k(b)

```
> 2 votes

# Answer
# Python 3 -- ~~73~~ 67 bytes

---

Code:

```
f=lambda:sorted(i for i in input().upper()if" "!=i);print(f()==f())

```

As usual, nice looking, but not very short. Typical python...
> 2 votes

# Answer
# Cobra - 130

```
do(a='',b='')
    print (f=Func<of String,String>(do(s='')=s.toLower.toCharArray.toList.sorted.join('').trim)).invoke(a)==f.invoke(b)

```
> 2 votes

# Answer
# JavaScript (ES6) 82

Returns true if the two strings are anagrams, otherwise returns false or throws an exception

```
e=(a,b)=>(a.replace(/\S/g,c=>b=b.replace(b.match(RegExp(c,'i'))[0],'')),!b.trim())

```
> 1 votes

# Answer
# Perl - 84

Always need Perl in these...

```
sub c{map{s/\s//}@a=@_;(join'',sort split//,lc$a[0])eq join'',sort split//,lc$a[1]}

```

Wanted to be able to modify @\_ directly but perl wont allow that
> 1 votes

# Answer
# Bash+coreutils, 62 bytes

```
s()(tr -d '     '<<<"${@^^}"|fold -1|sort)
cmp <(s $1) <(s $2)

```

Takes arguments from the command line. Return code 0 for TRUE and 1 for FALSE. Also something like `/dev/fd/63 /dev/fd/62 differ: byte 1, line 1` is output in the FALSE case.

### Output:

```
$ ./anagram.sh "Doctor Who" Torchwood; echo $?
0
$ ./anagram.sh "Doctor Watson" Torchwood; echo $?
/dev/fd/63 /dev/fd/62 differ: byte 1, line 1
1
$

```
> 1 votes

# Answer
## Clojure : 84 chars

Golfed:

```
(defn g[s](sort(remove #(= \  %)(seq(.toLowerCase s)))))
(defn f[a b](=(g a)(g b)))

```

Ungolfed:

```
(defn g[s] (sort (remove #(= \  %) (seq (.toLowerCase s)))))
(defn f[a b] (= (g a) (g b)) )

```

Driver program with execution:

```
(def a "Doctor   Who")
(def b "Torch woo d")
(println (f a b))

bash$ java -jar clojure-1.6.0.jar anagram.clj
true

```
> 1 votes

# Answer
## Groovy : 96 77 chars

Golfed:

```
g={it.findAll{it!=" "}.collect{it.toLowerCase()}.sort()}
f={a,b->g(a)==g(b)}

```

Ungolfed:

```
g = { it.findAll{ it!=" " }.collect{ it.toLowerCase() }.sort() }
f = { a,b -> g(a)==g(b) }

```

Example main program and execution:

```
a="Doctor Who x x"
b="Tor chwoo dxx"
println f(a,b)

$ groovy Anagram.groovy
$ true

```
> 0 votes

---
Tags: code-golf
---


title: Unnecessary Text Abbreviations

text:
# Question
Title: Unnecessary Text Abbreviations
## Introduction

I can't stand text abbreviations, mainly because for the most part I have no idea what most of them mean. Of course, cut backs need to be made, so if they are necessary to fit the text in the character limit, I'll allow them.

## Challenge

You have to write a program that takes passage of text and determines whether text abbreviations are required to fit the passage in the 140 character limit (as used by Twitter).

The passage can be read from a plaintext file, supplied via system arguments or input by a user. You may not hardcode it.

## Determining

Your program needs to replace all abbreviations (*Note:* Don't, can't, won't etc. are allowed) found in the passage and replace them with full words. If the expanded passage fits within 140 characters, then abbreviations are unneccessary. Otherwise, abbreviations are necessary. Any unknown abbreviations should be treated as standard words.

The output should be boolean (**`True`** if necessary or **`False`** otherwise) but if the passage was longer than 140 characters in the first place, then **`Tl;dr`** should be printed.

## Abbreviations

All abbreviations required are detailed here. You decide how you parse the information. You may store the list in a local file of any name, providing that the list is taken from the provided URL.

Abbreviations should be defined as all in capital letters (eg. LOL, LMFAO, OP not lol, lmfao, op).

***Note:*** In several cases, the abbreviation is not the standard format (`abbreviation -> meaning`) and sometimes has multiple meanings, words and/or spellings. Ignore all of these cases. For clarification, all abbreviations that you need to worry about should be single word.

Ignore all non alphabetic abbreviations (e.g. Ignore \<3,99). Abbreviations that start with an alphabetic character can be parsed (e.g. Do not ignore A/S/L,L8).

## Test cases (taken from random tweets)

### 1: Returns `true`

> IDG people who MSG U and still lag even THO U reply straight away like how did U become that busy in 5 secs that U can't communicate LOL CYA

### 2: Returns `false`

> If your role models are celebrities; Athletes, Actors, Singers, Politicians, etc then you need a life coach. ASAP.

### 3: Returns `Tl;dr`

> For your information: we technically live about 80 milliseconds in the past because that's how long it takes our brains to process information.

## Winning Criteria

The shortest code wins.

***Based upon the alt-text of xkcd 1083***

## Thanks to Ingo Bürk, here's a JSON file of the list

# Answer
> 1 votes
# ECMAScript 6 + HTML (117 ~~123~~ ~~144~~)

Using HTML to store the dictionary. Try it online (with any ECMAScript 6 browser such as Firefox).

```
d=eval(d.innerHTML),t=r=prompt(l=140);for(k in d)r=r.replace(RegExp(k,'g'),d[k])
alert(t.length>l?'Tl;dr':r.length>l)

```

I'm just blatantly ignoring the currently open questions to this challenge, hoping it won't render my solution incorrect. YOLO #abbreviations

## Explanation

The dictionary has been filtered according to the rules (ignoring abbreviations starting with non-alphanumeric character, ignoring multi word abbreviations, only considering uppercase abbreviations, using first replacement if there are options).

To save bytes in the code, the dictionary has also been transformed such that the key is already a regular expression with word boundary match to deal with punctuation.

Then the actual code becomes a matter of reading the tweet, doing all the replacements and checking for the length.

The script used for preparation can be found here. It is based upon the JSON file I have extracted from the website.

* *Edit #1:* Thanks to Optimizer for golfing it down for a win of 21 bytes
* *Edit #2:* Another 6 bytes thanks to Optimizer's tip of using `eval`.

---
Tags: code-golf
---


title: CodeBots 2: Event Driven Design

text:
# Question
Title: CodeBots 2: Event Driven Design
Welcome to Code Bots 2!

You've learned your lesson since the last Code Bots. You've tried to figure out more ways to fit more actions in less lines, and now you finally have it. You're going to make an event-driven Code Bot.

Your bot must consist of 24 lines. Each line follows one of the two formats:

```
Condition:Action

```

or

```
Action

```

Your bot also have enough storage to store 5 integers named `A` through `E`. An integer can store values from 0 to 23.

Each turn, you will execute line `C`, *unless* one of the conditions is true. If so, then `C` will then contain the line number of the conditional that is true, and then that line will be executed. At the end of each turn, `C` will be incremented.

There are the available conditions:

1. `Start` is true only on the first turn. You must have this in your code exactly once
2. `BotAt(N)` is true if there is a bot at the location defined by N
3. `Equals(A,B)` is true if A equals B. They can be different types, if so, they will not be equal.
4. `Modified(A)` is true if `A` was copied to during the last turn. `A` must be a variable name, a line, or a condition
5. `Any(C1,C2,...)` is true if any of the conditions are true
6. `None(C1,C2,...)` is true if none of the conditions are true
7. `All(C1,C2,...)` is true if all of the conditions are true
8. `Not(C)` is true if C is false. `C` must be a condition.

Variables can be in one of the following formats. The first 9 are numerical, and can be be used for whenever N is used in this page.

1. `A`,`B`,`C`,`D`,`E`
2. A number from 0 to 23
3. `This` will return the line number it is currently on
4. `Add(N1,N2,...)` will return the sum of all values
5. `Sub(N1,N2)` will return N1 minus N2
6. `Mult(N1,N2,...)` will return the product of all values
7. `Div(N1,N2)` will return N1 divided by N2
8. `Mod(N1,N2)` will return N1 mod N2
9. `OVar(N)` will accept a variable name, and will return the opponent's variable
10. `Line(N)` will return the Nth line in your code
11. `Type(N)` will return the Nth line type in your code (the types are the names of the actions)
12. `Cond(N)` will return condition on the Nth line
13. `CondType(N)` will return the condition type on the Nth line (the types are the names of the conditions)
14. `OLine(N)` will return the Nth line in your opponent's code
15. `OType(N)` will return the Nth line type in your opponent's code
16. `OCond(N)` will return the condition on the Nth line
17. `OCondType(N)` will return the condition type on the Nth line

`A` and `B` are for your personal use, `C` is used to determine which line to execute in your code, and `D` is used as a direction. Each value of `D` refer to a different square and direction pair.`E` produces a random value each time. `D` and `E` will be initialized to a random value, otherwise `0`.

The direction used will be `[North,East,South,West][D%4]`. Your opponent is the bot in the immediate square in that direction.

There are 4 actions available to you:

1. `Move` will move you 1 square forward in the `D`th direction. If there is a bot there, you will not move.
2. `Copy(A,B)` will copy the variable `A` to `B`. `B` cannot be a numerical value, except for a variable name. `A` and `B` cannot be of different types. Copying a line does not copy the condition.
3. `Flag` does nothing. **The bot with the most flags in your code will get a point. The bot with the most points wins.**
4. `If(C,L1,L2)` will perform the line on `L1` if `C` is true, else performs `L2`. `C` is a condition, and `L1` and `L2` must be lines.

# The Big Picture

50 copies of every bot will be placed in the world. Your goal is to get your flag into as many bots as possible. For each bot that has more of your flag type than any other flag type, you get a point.

The bots will be placed as follows:

```
B...B...B...B...
..B...B...B...B.
B...B...B...B...

```

There will be 10 games run, and points will be averaged across all of the games, determining who the winner is.

# Side Notes

If multiple conditions apply, then the one that most immedately follows `Start` will be executed

The bots will be closely packed but you will not start neighboring another bot. (It techincally will be the same format as the last CodeBots)

As this challenge was not posted in the sandbox (to give nobody an advantage), I reserve the right to change small details for fairness, or additional capabilities. Also, if there is a bug in the CodeBots runner, I will change it, even if a bot depended on that bug for its success. I am trying to be as *fair* as possible.

Recursive `If` statements will not be executed

If your bot is shorter than 24 lines, the remaining lines will be filled with `Flag`

Remember when copying to your own `C`, that `C` is incremented at the end of your turn.

The CodeBots interpreter can be found here. It includes a .jar file for easy execution. Simply add your bot to the bots folder

# Scores

1. 893.9 Borg
2. 1.3 LazyLioness
3. 0.9 Defender
4. 0.5 Flagger
5. 0.4 CliqueBot
6. 0.4 Insidious
7. 0.3 Attacker
8. 0.3 Gard
9. 0.3 SingleTarget
10. 0.2 FreezeBot
11. 0.2 Sentinel
12. 0.2 Driveby
13. 0.0 AntiInsidious
14. 0.0 MoveBot
15. 0.0 CliqueBorg
16. 0.0 Calculator
17. 0.0 TestBot
18. 0.0 Imitator

## UPDATE

Lines of code are now rotated when you view your opponent's code. That means, your opponent's line 1 may be line 14 (or whatever line). A bot will have a fixed offset which will offset his lines by `X` amount *when viewed by an opponent*. The opponent's `C` variable will also be offset by the same `X` amount. `X` will not change within the same game, but it will change from game to game.

# Answer
> 13 votes
# Borg

Converts all other bots into clones of itself. Resistance is futile.

```
Start:Copy(2,A)                               # Cloning will begin at line 2
All(Not(BotAt(D)),Not(Equals(2,A))):Copy(2,A) # Reset A if the opp left before we were done
Not(BotAt(D)):Move
All(Equals(Line(Sub(This,3)),OLine(0)),Equals(Line(Sub(This,2)),OLine(1)),Equals(Line(Sub(This,1)),OLine(2)),Equals(Line(This),OLine(3)),Equals(Line(Add(This,1)),OLine(4)),Equals(Line(Add(This,2)),OLine(5)),Equals(Line(Add(This,3)),OLine(6)),Equals(Line(Add(This,4)),OLine(7)),Equals(Line(Add(This,5)),OLine(8))):Copy(E,D) #  Check if cloning is complete
All(Equals(A,2),Not(Equals(OCond(1),Cond(Add(This,4))))):Copy(Cond(Add(This,4)),OCond(1)) # Copy freeze cond to OLine(1) before cloning starts
All(Equals(A,2),Not(Equals(OLine(1),Line(Add(This,3))))):Copy(Line(Add(This,3)),OLine(1)) # Copy freeze line
Not(Equals(Cond(Add(Sub(This,6),A)),OCond(A))):Copy(Cond(Add(Sub(This,6),A)),OCond(A))    # Copy Cond(A) to OCond(A)
Not(Equals(Line(Add(Sub(This,7),A)),OLine(A))):Copy(Line(Add(Sub(This,7),A)),OLine(A))    # Copy Line(A) to OLine(A)
Equals(A,A):Copy(Add(A,1),A) # Increment A. It will wrap around all 24 lines before the completion check matches

```

*Edit: Small fix to reset A if the opponent moves before I'm done with him. Doesn't seem to affect the score but it makes me feel better.*

*Edit #2: Added a more complete check to ensure the cloning process has completed properly (line 3)*

*Edit #3: Update to handle the new random offsets. The difficulty here was that new clones would have their code located at random offsets which means they don't know the location of their own lines. That means that all references to my own lines must be relative (to `This`). Opponent line numbers can still be absolute since they are random anyway.*

# Answer
> 5 votes
# Flagger

*Shoot for the moon*

```
Start:Flag

```

And the rest gets auto-filled with flag.

# Answer
> 3 votes
# Calculator

This bot doesn't understand the goal of this challenge, so he decided to calculate some numbers for the enemy.

```
Equals(Mod(OVar(E),5),0):Copy(Add(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),1):Copy(Sub(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),2):Copy(Mult(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),3):Copy(Div(OVar(A),OVar(B)),OVar(D))
Equals(Mod(OVar(E),5),4):Copy(Mod(OVar(A),OVar(B)),OVar(D))
Start:Move

```

# Answer
> 3 votes
# CliqueBot

```
Flag
Start: Copy(11,B)
Not(Equals(Line(20),Line(21))): If(Equals(Line(21),Line(22)),Line(7),Line(8))
Not(Equals(Line(21),Line(22))): If(Equals(Line(20),Line(21)),Line(9),Line(10))
All(BotAt(D),Not(Equals(11,OVar(B)))): If(Equals(Line(20),OLine(OVar(C))),Line(10),Line(11))
Any(BotAt(D),Equals(E,B)): Copy(Add(D,1),D)
Equals(1,1): Move
Copy(Line(21),Line(20))
Copy(Line(20),Line(21))
Copy(Line(21),Line(22))
If(Equals(Line(20),OLine(Sub(OVar(C),1))),Line(5),Line(12))
Copy(Line(20),OLine(OVar(C)))
Copy(Line(20),OLine(E))

```

Recognizes friends via their `B` value, fills everyone else's lines with flags. Also goes to some length to preserve the integrity of one of its own flags (this part is cute but probably not very useful).

~~Edit: Unsurprisingly, there appears to be a bug here somewhere, judging by the score.~~

Suspect that lines are 0-indexed and my code is 1-indexed. Should really have checked that earlier. Added a Flag at the beginning to bump everything up one.

# Answer
> 2 votes
# Defender

```
Start:Copy(0,A)
Copy(0,B)
Flag
Flag
All(Modified(Line(2)),Equals(A,0)):Copy(1,A)
Copy(Line(3),Line(2))
Copy(0,A)
Copy(10,C)
All(Modified(Line(3)),Equals(B,0)):Copy(1,B)
Copy(Line(2),Line(3))
Copy(0,B)
BotAt(D):Copy(Line(2),OLine(E))

```

# Answer
> 2 votes
# MoveBot

```
Start:Move
Copy(E,D)
Copy(-1,C)

```

# Answer
> 2 votes
# Attacker

```
Start:Move
BotAt(D):Copy(Line(Add(Mod(E,6),4)),OLine(E))
Any(BotAt(0),BotAt(1),BotAt(2),BotAt(3)):Move
None(BotAt(0),BotAt(1),BotAt(2),BotAt(3)):Copy(E,D)

```

# Answer
> 2 votes
# Single Target

```
Start:Move
All(BotAt(D),Not(Equals(OVar(D),D))): Copy(D,OVar(D))
BotAt(D):Copy(Line(E),OLine(E))
Equals(A,A):Move

```

Will hunt you down and fill you with flags!

# Answer
> 2 votes
# Insidious

```
Start:Flag           # comments -->                                                                                # why move when we can fit another flag here?
Equals(E,0):Copy(Add(D,Sub(Mult(2,Mod(E,2)),1)),D)                                                                  # 1/24 chance to turn left or right
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),1)),Cond(Add(This,4))))):Copy(Cond(Add(This,4)),OCond(Sub(OVar(C),1)))    # Copy the freeze condition
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),1)),Line(Add(This,4))))):Copy(Line(Add(This,4)),OLine(Sub(OVar(C),1)))    # Copy the flag-copying line
All(BotAt(D),Not(Equals(OLine(Add(OVar(C),0)),Line(Add(This,Add(4,Mod(E,14))))))):Copy(Line(Add(This,Add(4,Mod(E,14)))),OLine(Add(OVar(C),0))) # copy one of my flags to them
BotAt(D):Copy(Add(D,Sub(Mult(2,Mod(E,2)),1)),D)                                                                     # turn left or right if we've infected our target
Equals(A,A):Move                                                                                # move if all else fails, also infection freeze condition
Copy(Line(Add(This,1)),Line(Add(This,Mod(E,22))))                                                                   # infection line 1
Flag                                                                                # first of many flags

```

Similar idea to the bot by the same name in the previous contest. Move until I hit another bot, then freeze it into a loop overwriting its own code with my flags. This time the infected bots overwrite random lines instead of sequential lines, making the infection process a little less effective but much faster.

# Answer
> 1 votes
# Gard

```
Start: Move
BotAt(D):IF(Equals(Line(7),OLine(C)),Line(6),Line(5))
BotAt(Add(D,1)):Copy(Add(D,1),D)
BotAt(Add(D,2)):Copy(Add(D,2),D)
BotAt(Add(D,3)):Copy(Add(D,3),D)
Copy(Line(7),OLine(OVar(C)))
Copy(Cond(7),OCond(Sub(OVar(C),1)))

```

Attacks any robot next to it.

# Answer
> 1 votes
# Freeze Bot

```
Start:Move
All(BotAt(D),Not(Equals(OCond(1),Cond(5)))):Copy(Cond(5),OCond(1))
All(BotAt(D),Not(Equals(OLine(1),Line(6)))):Copy(Line(6),OLine(1))
All(BotAt(D),Equals(Mod(OVar(A),24),0)):Copy(Add(D,1),D)
BotAt(D):Copy(Line(20),OLine(OVar(A)))
Equals(A,A):Move
Copy(Add(A,1),A)

```

Traps you in a loop Incriminating your own `A` variable, then fills you with flags and moves on to the next victim.

# Answer
> 1 votes
# Imitator

```
Start:Move
BotAt(D):If(OCond(0),OLine(0),Line(2))
If(OCond(1),OLine(1),Line(3))
If(OCond(2),OLine(2),Line(4))
If(OCond(3),OLine(3),Line(5))
If(OCond(4),OLine(4),Line(6))
If(OCond(5),OLine(5),OLine(OVar(C)))
Not(BotAt(D)):If(BotAt(Add(D,1)),Line(8),Line(0))
Copy(Add(D,1),D)

```

Predicts what you would do, then does that.

# Answer
> 1 votes
# Lazy Lioness

Originally just "Lioness", my first submission to the contest earned the title "lazy" by literally doing nothing when introduced into the simulator.

Her lethargy is in fact due to a bug (or possibly my misunderstanding the event model) wherein the conditions in the first three lines (a simple parity check for ensuring that flags are not overwritten) occasionally, inexplicably evaluate `true`, locking leo in a lemniscate loop. Several other conditions (particularly those that rely on the `BotAt()` condition) also evaluate `true` at times when no adjacent bot(s) are present. Finally, `Move` and `Copy` directives are clearly ignored when stepping through the simulator. Since my conditional logic chains are somewhat epic, there's plenty of room for bugs in my code *and* in the simulator. ;)

In any case, I submit Lazy Lioness as a test case for either error diagnosis or simulator debugging, which will hopefully lead to the emergence of not-so-lazy Lioness that I can then simulate and refine as my first bona fide submission to the Bots v2 competition.

**It Does Nothing**

```
All(Not(Equals(Line(18),Line(21))),Equals(Line(21),Line(22))):Copy(Line(21),Line(18))
All(Not(Equals(Line(21),Line(22))),Equals(Line(22),Line(18))):Copy(Line(22),Line(21))
All(Not(Equals(Line(22),Line(18))),Equals(Line(18),Line(21))):Copy(Line(18),Line(22))
All(Any(BotAt(Add(D,1)),BotAt(Add(D,2)),BotAt(Add(D,3))),Not(BotAt(D))):Move
All(Any(All(BotAt(D),BotAt(Add(D,2))),All(BotAt(D),BotAt(Add(D,1))),All(BotAt(Add(D,1)),BotAt(Add(D,2)))),Not(BotAt(Add(D,3)))):Copy(Add(D,3),D)
Any(All(Any(All(BotAt(D),BotAt(Add(D,2))),All(BotAt(D),BotAt(Add(D,3))),All(BotAt(Add(D,2)),BotAt(Add(D,3)))),Not(BotAt(Add(D,1)))),All(BotAt(Add(D,1)),BotAt(D),Any(Equals(OCond(2),Cond(20)),Equals(OLine(2),Line(19))))):Copy(Add(D,1),D)
All(BotAt(Add(D,3)),BotAt(D),Any(Equals(OCond(2),Cond(20)),Equals(OLine(2),Line(19)))):Copy(Add(D,3),D)
All(BotAt(D),Not(Equals(OCond(2),Cond(20))),Not(Equals(OLine(2),Line(19)))):Copy(Cond(20),OCond(2))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OLine(3),Line(18)))):Copy(Line(18),OLine(3))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OLine(4),Line(21)))):Copy(Line(21),OLine(4))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OCond(0),Cond(22)))):Copy(Cond(22),OCond(0))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OLine(0),Line(17)))):Copy(Line(17),OLine(0))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OCond(1),Cond(21)))):Copy(Cond(21),OCond(1))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OLine(1),Line(20)))):Copy(Line(20),OLine(1))
All(BotAt(D),Equals(OCond(2),Cond(20)),Not(Equals(OLine(2),Line(19)))):Copy(Line(19),OLine(2))
All(BotAt(D),Not(Equals(OCond(2),Cond(20))),Equals(OLine(2),Line(19))):Copy(Add(D,A),D)
Equals(E,1):Copy(Add(A,2),A)
Any(Equals(E,4),Equals(E,8)):Copy(Add(D,E,A),D)
Not(Equals(A,A)):Flag
Not(Equals(A,A)):Copy(Line(3),OLine(E))
Equals(A,A):Move
Any(Equals(E,4),Equals(E,5),Equals(E,6),Equals(E,7),Equals(E,8),Equals(E,9)):Flag
Any(Equals(E,10),Equals(E,11),Equals(E,12),Equals(E,13)):Flag
Start:Copy(1,A)

```

# Answer
> 1 votes
# sentinel

improvment on `Gard`. Hits nearby bots with flags on the first 8 lines. (that is, all the most used ones)

```
flag
flag
Start:Copy(11,B)
All(BotAt(D),Not(Equals(OLine(Mod(E,8)),Line(0))),Not(BotAt(Add(D,1,Mod(E,3))))):If(Equals(OVar(D),Add(D,2)),Line(7),Line(8))
BotAt(Add(D,1)):Copy(Add(D,1),D)
BotAt(Add(D,2)):Copy(Add(D,2),D)
BotAt(Add(D,3)):Copy(Add(D,3),D)
copy(D,OVar(D))
copy(Line(Mod(E,2)),OLine(Mod(E,8)))
Not(Equals(Line(0),Line(1))):copy(Line(Add(9,Mod(E,16))),Line(Mod(E,2)))

```

# Answer
> 1 votes
# CliqueBorg

```
Flag
BotAt(D): Copy(Line(Sub(This,1)),OLine(E))
Equals(1,1): Copy(Line(Sub(This,2)),Line(Add(This,Mod(E,21))))
Start: Move
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),1)),Line(3)))):Copy(Line(3),OLine(Sub(OVar(C),1)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),1)),Cond(3)))):Copy(Cond(3),OCond(Sub(OVar(C),1)))
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),2)),Line(2)))):Copy(Line(2),OLine(Sub(OVar(C),2)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),2)),Cond(2)))):Copy(Cond(2),OCond(Sub(OVar(C),2)))
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),3)),Line(1)))):Copy(Line(1),OLine(Sub(OVar(C),3)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),3)),Cond(4)))):Copy(Cond(4),OCond(Sub(OVar(C),3)))

```

Trying to combine CliqueBot and Borg technology to create a bot that recognizes copies of itself despite the line offset. It also starts its copying process at the last executed line of code on the opposing bot, rather than line 0, which is more likely to freeze it in place but also more likely to result in a corrupted copy (in fact, I'm not sure this even works, I haven't tested it and it's pretty complex).

# Answer
> 1 votes
# Driveby

One last try before the deadline.

```
Flag
Flag
BotAt(D):Copy(Line(Sub(This,1)),OLine(E))
Equals(1,1):Copy(Line(Sub(This,2)),Line(Add(This,Mod(E,21))))
Start:Move
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),1)),Line(3)))):Copy(Line(3),OLine(Sub(OVar(C),1)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),1)),Cond(3)))):Copy(Cond(3),OCond(Sub(OVar(C),1)))
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),2)),Line(2)))):Copy(Line(2),OLine(Sub(OVar(C),2)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),2)),Cond(2)))):Copy(Cond(2),OCond(Sub(OVar(C),2)))
All(BotAt(D),Not(Equals(OLine(Sub(OVar(C),3)),Line(1)))):Copy(Line(1),OLine(Sub(OVar(C),3)))
All(BotAt(D),Not(Equals(OCond(Sub(OVar(C),3)),Cond(4)))):Copy(Cond(4),OCond(Sub(OVar(C),3)))
BotAt(D):Copy(Add(D,1),D)
Equals(1,1):Move

```

---
Tags: king-of-the-hill
---


title: How NOT to reduce fractions

text:
# Question
Title: How NOT to reduce fractions
## Reducing fractions *the wrong way*

In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number.

**Note:** reducing fractions *the wrong way* does here have an exact definition, see details.

Example:

64/16 = 64/16=4/1 = 4

Of course you cannot just strike both 6es but here you still end up with the correct value. In this challenge you have to find examples like this.

### Details

You have to write a function/program that accepts one positive integer `n` as input and outputs/returns a list/array of the fractions in format
`numerator1,denominator1,numerator2,denominator2,...`

The program has to find out for each fraction `a/b` with `a+b=n` and `a,b>0` whether it can be reduced *the wrong way*. (It does not matter whether if it can be reduced in the conventional way or whether there are many possibilities of reductions, it just has to be possible to reduce it *the wrong way* in at least one way.)

**Definition of** ***the wrong way:*** A fraction can be reduced *the wrong way* if and only if the same sequence of successive digits appears in a and b *and* if the value of the fraction stays the same if you remove the substring.

Example: 1536/353 can be 'reduced' to 16/3 but those two values are not equal so you cannot reduce this fraction *the wrong way*.

Note that this definition of reducing *the wrong way* can also include fractions that are reduced the right way: `110/10 = 11/1` is within the definition of reducing *the wrong way* even though it is a valid step.

### Scoring

The least number of bytes wins. You can write a function or program that accepts an integer and returns an array or a program that uses stdin/stdout or you can consider n saved in a variable and in the end of the program the list must be saved in an other variable.

### Test cases

Please include following testcases (Tell me which ones I should add, I have no idea how many of those fractions there are / how many examples to expect)

```
n=80 (64/16 should be in this list)
n=147 (98/49 should be in this list)
n=500 (294/196 should be in this list) WRONG since 294+196 != 500 Thanks Falko

```

# Answer
> 3 votes
# Python 2 – ~~183~~ 180

```
r=range
s=lambda a:[(a[i:j],int(a[:i]+a[j:]))for i in r(len(a))for j in r(i+1,len(a)+(i>0))]
l=sum([[a,n-a]for a in r(n)for p,x in s(`a`)for q,y in s(`n-a`)if(n-a)*x==a*y<p==q],[])

```

the input must be stored in `n`, the output will be stored in `l`.

### Test cases:

n = 80:

```
[10, 70, 16, 64, 20, 60, 30, 50, 40, 40, 40, 40, 50, 30, 60, 20, 64, 16, 70, 10]

```

n = 147:

```
[49, 98, 98, 49]

```

n =490:

```
[10, 480, 20, 470, 30, 460, 40, 450, 50, 440, 60, 430, 70, 420, 80, 410, 90, 400, 90, 400, 98, 392, 100, 390, 100, 390, 110, 380, 120, 370, 130, 360, 140, 350, 150, 340, 160, 330, 170, 320, 180, 310, 190, 300, 190, 300, 196, 294, 200, 290, 200, 290, 210, 280, 220, 270, 230, 260, 240, 250, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 250, 240, 260, 230, 270, 220, 280, 210, 290, 200, 290, 200, 294, 196, 300, 190, 300, 190, 310, 180, 320, 170, 330, 160, 340, 150, 350, 140, 360, 130, 370, 120, 380, 110, 390, 100, 390, 100, 392, 98, 400, 90, 400, 90, 410, 80, 420, 70, 430, 60, 440, 50, 450, 40, 460, 30, 470, 20, 480, 10]

```

---

Should duplicates in the output be forbidden, it gets 10 characters longer:

```
r=range
s=lambda a:[(a[i:j],int(a[:i]+a[j:]))for i in r(len(a))for j in r(i+1,len(a)+(i>0))]
l=sum(map(list,{(a,n-a)for a in r(n)for p,x in s(`a`)for q,y in s(`n-a`)if(n-a)*x==a*y<p==q}),[])

```

# Answer
> 3 votes
### Haskell, ~~207~~ 206 (209?) characters

```
import Data.List
x![]=[x];(w:x)!(y:z)|w==y=x!z;_!_=[]
a@(w:x)%b=a!b++[w:e|e<-x%b];a%b=a!b
h=show
f n=[(c,n-c)|c<-[1..n-1],i<-inits$h c,s<-init$tails i,s/=h c,a<-h c%s,b<-h(n-c)%s,read a*(n-c)==read('0':b)*c]

```

If it's not allowable to return the same ratio more than once (400/400 = 40/40 = 4/4), use `f n=nub[...` to filter them out.

Returns a list of pairs. A list of two-element pairs costs the same. A list of actual fractions would require importing `Data.Ratio` or fully qualifying `Data.Ratio.%` (which also collides with the `%` function defined here)

**test cases** (with `nub`):

```
Prelude Data.List> f 80
[(10,70),(16,64),(20,60),(30,50),(40,40),(50,30),(60,20),(64,16),(70,10)]
Prelude Data.List> f 147
[(49,98),(98,49)]
Prelude Data.List> f 500
[(10,490),(20,480),(30,470),(40,460),(50,450),(60,440),(70,430),(80,420),(90,410
),(100,400),(110,390),(120,380),(130,370),(140,360),(150,350),(160,340),(170,330
),(180,320),(190,310),(200,300),(210,290),(220,280),(230,270),(240,260),(250,250
),(260,240),(270,230),(280,220),(290,210),(300,200),(310,190),(320,180),(330,170
),(340,160),(350,150),(360,140),(370,130),(380,120),(390,110),(400,100),(410,90)
,(420,80),(430,70),(440,60),(450,50),(460,40),(470,30),(480,20),(490,10)]

```

**ungolfed and commented**:

```
import Data.List

-- haystack ! needle - the haystack with the needle removed, wrapped in a single-element list
--                       or an empty array if the haystack does not start with the needle

x ! [] = [x]                        -- case: empty needle = match with the full haystack left
(h:hs) ! (n:ns) | h == n = hs ! ns  -- case: needle and haystack match
_ ! _ = []                          -- case: no match

-- haystack % needle - the haystack with the needle removed
--                       for all positions of the needle in the haystack

a@(h:hs) % b = a ! b ++ map (h:) (hs%b) -- either remove the needle here, or elsewhere
a % b = a                               -- empty haystack cannot be popped

-- f - the function we are interested in

f total = [ (num, total - num)
          | num   <- [1 .. total-1],            -- for each numerator in range
            i     <- inits $ show num,          -- for each postfix of the numerator
            sub   <- init $ tails i,            -- for each prefix of the postfix except the last (empty) one
            sub /= show num,                    -- that isn't equal to the numerator
            reNum <- show num % sub,            -- remove the substring from the numerator
            reDiv <- show (total - num) % sub,  -- as well as from the denominator.

                                                -- the resulting ratios must be equal by value:
            (read reNum) ^ (total - num) == (read '0':reDiv) * num]

```

# Answer
> 1 votes
# Python 3 - 302

***Note:*** Due to parsing difficulties, there are no fractions with the number 0 in (so no fractions are calculated using the correct method).

```
n=int(input());s=str;r=range
print([[a,b]for a in r(1,n)for b in r(1,a)for i in r(1,n)if i!=a and i!=b and s(i)in s(a)and s(i)in s(b)and s(a).count(s(i))<len(s(a))and s(b).count(s(i))<len(s(b))and not'0'in s(a)and not'0'in s(b)and eval(s(a).replace(s(i),'')+'/'+s(b).replace(s(i),''))==a/b and a+b<=n])

```

### With n=80:

```
[[64, 16]]

```

### With n=147

```
[[64, 16], [65, 26], [95, 19], [98, 49]]

```

### With n=500

```
[[64, 16], [65, 26], [95, 19], [98, 49], [136, 34], [192, 96], [194, 97], [195, 39], [196, 49], [196, 98], [231, 132], [238, 34], [238, 136], [242, 143], [253, 154], [264, 165], [268, 67], [275, 176], [286, 187], [291, 97], [291, 194], [294, 49], [294, 98], [294, 196], [295, 59], [297, 198], [298, 149], [325, 13], [341, 143], [345, 138], [392, 49], [392, 98], [395, 79]]

```

# Answer
> 1 votes
# Python 2 - 236

```
n=input()
r=range
f=float
l=len
for a in r(n):
 A=`a`;B=`n-a`
 for i in r(l(A)):
  for j in r(i+1,l(A)+1):
   for u in r(l(B)):
    C=A[:i]+A[j:];D=B[:u]+B[u+j-i:]
    if A[i:j]==B[u:u+j-i]and l(C)*l(D)and f(C)==f(A)/f(B)*f(D):print A,B

```

---
Tags: code-golf, math, rational-numbers
---


title: Rolling digital number lock

text:
# Question
Title: Rolling digital number lock
There's a simple digital number lock. After each button press the lock checks if the previous four presses constitute the correct code. I.e. typing 44445 tests two codes: 4444 and 4445. You must brute force it with a code golfed program.

## Rules

* Your program must test numbers by printing ASCII digits 0-9 to standard output. Other output, if any, will be ignored.
* The program must be deterministic. If you need "random" numbers, you must use a deterministic generator with a well defined seed.
* Infinite output beyond all 10^4 codes is allowed. Opening the lock is considered to stop the program.

## Scoring

* Calculate the average digits of output needed to crack the lock. I.e. search the output string for every possible four digit sequence and record where it first appears.
* Add the source code length in bytes. The program must be fully functional, you are not allowed to omit imports or other boilerplate.

> **Score = Average digits to crack + codelength in bytes**

## Example entry

Python, 35 bytes.

```
for i in range(9001):print '%.4d'%i

```

Score: 8444.9837 + 35 = 8479.9837

## Other

Simple, stupid Python program to verify score of an output string:

```
d = {}
s = ''.join(c for c in s if '0' <= c <= '9')
for i in range(len(s)-4):
    t = s[i:i+4]
    if t in d:
        continue
    d[t] = i + 4
    if len(d) == 10000:
        break
print sum(d.values()) / 10000.

```

# Answer
> 4 votes
# Java 5218

This is the (golfed) code:

```
class a{int[]a=new int[5];public static void main(String[]a){new a().b(1,1);}void b(int t,int p){if(t>4)for(t=0;++t<=p&&4%p==0;)System.out.print(a[t]);else{a[t]=a[t-p];b(t+1,p);for(a[t]=a[t-p];++a[t]<=9;)b(t+1,t);}}}

```

It prints a specially crafted sequence to stdout. The completed sequence has all combinations, only once, in the shortest way possible. The total length is 10.000 with the first combination after 4 (obviously) and the last after 10.000. So if I understand the challenge correctly my score is:

```
4 + ((10000-4)/2) = 5002 avg length to break the code
5002 + 216 (code length) = 5218

```

Obviously this score will be improved (Java is pretty verbose), so I'm not going to tell you the name of the sequence I'm using...

# Answer
> 0 votes
# Haskell, 120 bytes + 5001.5 = 5121.5

```
import Data.List
main=print$(nub$sort[sort s|x<-[1,2,5,10],s<-sequence$replicate x['0'..'9'],any(/=s!!0)s||x<2])>>=id++"000"

```

---
Tags: code-challenge
---