# Question
Title: Program that adds all natural numbers and yields -1/12
As you might know there is a mathematical fun-fact that if you add **all** natural numbers you end up with... -1/12 (see Wikipedia here).

Of course this is very strange result and can not be obtained by just adding one number followed by another, but some special mathematical tricks.

However your task is to write a program, that *looks like* it attempts to add all natural numbers, but when you run it - it returns -1/12.

In pseudocode it might look like this:

```
result  = 0;
counter = 1;
while(true) {
  result  += counter;
  counter ++;
}
println(result);

```

You can do this in any way you like - you can exploit some buffer overflow, play with errors thrown while some variable becomes too big or just hide the crucial thing along the code in some clever way. The only conditions are that code should at first look as if it attempts to add all natural numbers and when run it returns -1/12 (in any format, it might be decimal, binary, text, ascii art whatever).

The code can of course contain much more, than shown above, but it should be clear enough, to fool reader.

This is popularity contest - vote for the most clever idea!

# Answer
## C

Should work on platforms where both `sizeof(float)` and `sizeof(int)` are 4 and follows the IEEE floating point standard (I guess).

### Version 1:

```
#define toFloat(x) (*(float*)&x)
#define ABS(x)     (x<0 ? (-x) : x)
#include <stdio.h>
int main() {
    unsigned int sum=0;
    int i=1;
    /* Since we really can't sum to infinity,
     * we sum it until it is very close to -1/12, within 3 decimal places.
     * Need to convert sum to float since -1/12 is not int                 */
    while(!(ABS(toFloat(sum) + 1./12) <= 0.001)) {
        sum+=i;
        i++;
    }
    printf("%.3f\n", toFloat(sum));
    return 0;
}

```

Output: `-0.083`

Explanation:

> Not a very interesting answer, but with misleading comments.
> The sum from 1 to 79774 is 3181985425, which has the same binary representation as -0.082638867199420928955078125 when interpreted as a `float` instead of an `unsigned int`.
> Note that `!(abs<=0.001)` is used instead of `abs>0.001` to avoid quitting the loop when the sum reaches 2139135936 (NaN in `float`). (Thanks to @CodesInChaos for suggesting this idea instead of an independent `isNaN` check.)

Special thanks to @Geobits for the idea of terminating the loop by comparing the sum instead of the counter.

### Edit: Version 2

```
#include <stdio.h>
const float inf = 1./0.;
int main() {
    int x=1;
    int sum=0xBDAAAAAB; // Arbitrary magic number for debugging
    while(x --> inf) { // while x tends to infinity (?)
        sum+=x;
    }
    float sumf=*(float*)∑ // convert to float since -1/12 is not int
    if(sumf == 0xBDAAAAAB) { // no sum performed, something's wrong with the loop...
        fprintf(stderr, "sum is unchanged\n");
        return -1;
    }
    printf("%f\n", sumf);
    return 0;
}

```

Output: `-0.083333`

Explanation:

> Uses the same `int`-to-`float` trick, but with the `-->` "tends to" operator here. Since every number is smaller than infinity the loop will not be executed even once.
> After converting to `float` it is compared with the `int` magic number (i.e. -0.83333 is compared with `0xBDAAAAAB`, or 3182078635), which of course is different.
> 38 votes

# Answer
## Python

```
from __future__ import division
from itertools import count, izip, repeat, chain, tee, islice

def flatten(iterable):
  "Flatten one level of nesting."
  return chain.from_iterable(iterable)

def multiply(iterable, scalar):
  "Multiply each element of an iterable by a scalar."
  for e in iterable:
    yield e * scalar

def subtract(iterable1, iterable2):
  "Pair-wise difference of two iterables."
  for e, f in izip(iterable1, iterable2):
    yield e - f

def add(iterable1, iterable2):
  "Pair-wise sum of two iterables."
  for e, f in izip(iterable1, iterable2):
    yield e + f

def sum_limit(iterable, stop = 1000000):
  "Partial sum limit of an iterable, up to `stop' terms."
  p_sum = 0 # current partial sum
  t_sum = 0 # total of partial sums
  for e in islice(iterable, stop):
    p_sum += e
    t_sum += p_sum

  # return average of partial sums
  return t_sum / stop

# All natural numbers
n = count(1)

# The same range multiplied by 4
n4 = multiply(count(1), 4)

# Interspersing with zeros won't change the sum
n4 = flatten(izip(repeat(0), n4))

# Subtracting 4n - n results in 3n
n3 = subtract(n4, n)

# Make two clones of this range
n3a, n3b = tee(n3)

# Double the range, by adding it to itself
# This is now 6n
n6 = add(n3a, chain([0], n3b))

# Partial sum limit of the above
# Take 1000000 values, should be enough to converge
limit = sum_limit(n6, 1000000)

# Divide by 6 to get the sum limit of n
print limit / 6

```

Result:

```
-0.0833333333333

```

**So what's the trick?**

> The trick is: this is a valid calculation.
> 20 votes

# Answer
## Mathematica

```
\:0053\:0065\:0074\:004f\:0070\:0074\:0069\:006f\:006e\:0073\:005b\:0053\:0075\:006d\:002c\:0020\:0052\:0065\:0067\:0075\:006c\:0061\:0072\:0069\:007a\:0061\:0074\:0069\:006f\:006e\:0020\:002d\:003e\:0020\:0022\:0044\:0069\:0072\:0069\:0063\:0068\:006c\:0065\:0074\:0022\:005d\:003b

Sum[n, {n, 1, Infinity}]

```

```
-1/12

```

(Note: pasting this into a Mathematica notebook will likely reveal what's going on.)

---

> What's happening here is that we're setting the default regularization of `Sum` to be Dirichlet regularization (encoded in the first line -- note that Mathematica allows unicode literals in its source), so the second line, which out of context looks like it would produce infinity, ends up producing the regularized value `-1/12`.
> 18 votes

# Answer
## C

Nicely formats the answer as `-1/12`, not `0.8333`.

```
#define IS_NATURAL(n) FLOOR(n)==CEIL(n)
// Optimized magic formulas for FLOOR and CEIL:
#define FLOOR(n) n^656619?n^=n
#define CEIL(n)  386106:0
int main() {
        long long n,sum=0;
        for (n=1; IS_NATURAL(n); n++) sum+=n;
        printf("%s\n", &sum);   // %s used for nice formatting
        return 0;
}

```

How it works?

> Sums all numbers up to 656618, excluding 386106. This gives 215573541165.
> When interpreted as a string, on a little endian platform, you get -1/12.
> 10 votes

# Answer
## Brainfuck

```
+ [ [->+>+<<] > [-<+>] <+ ]
--------------------------------------------------------------------------------
Evaluate $\sum_{i=1}^\infty i$
--------------------------------------------------------------------------------
Memory Layout:
i > copy of i > sum
--------------------------------------------------------------------------------
Happy today? ---.+++ +.- -.+ +.+
Please vote me up.
--------------------------------------------------------------------------------

```

The code just evaluate 1 + 2 + 3 + ...

> ... until `i == 256` and overflow occurred, assuming 8-bits cell size. Upon that, `i` becomes `0`, the loop terminates and the *comments* following are executed.
> 7 votes

# Answer
Just adding a little better obfuscation of leaving the loop to ace's answer.

```
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

void handler(int trapId)
{
  unsigned int sum=3182065200L;
  printf("%.3f\n",*(float*) &sum);
  exit(0);
}

int main (void)
{
    unsigned int sum=0;
    int i=0;
    float average = 0.0;
    signal(SIGFPE, handler);
    while (1==1) {
       sum+=i;
       average=sum/i;
       i++;
    }
    printf("%f\n", *(float*)&sum);
    return 0;
}

```

Hint there is no overflow...

> I divide by 0 before I increment the variable i kicking off the exception handler
> 6 votes

# Answer
# Perl 6

This calculates sum using zeta function. I would have used `[+] 1..*` (sum of all numbers between 1 and infinity), except that runs in infinite time.

```
use v6;

# Factorial function.
sub postfix:<!>($number) {
    return [*] 1 .. $number;
}

# Infinite list of bernoulli numbers, needed for zeta function.
my @bernoulli := gather {
    my @values;
    for ^Inf -> $position {
        @values = FatRat.new(1, $position + 1), -> $previous {
            my $elements = @values.elems;
            $elements * (@values.shift - $previous);
        } ... { not @values.elems };
        take @values[*-1] if @values[*-1];
    }
}

# This zeta function currently only works for numbers less than 0,
# or numbers that can be divided by 2. If you try using something else,
# the compiler will complain. I'm too lazy to implement other cases of
# zeta function right now.
#
# The zeta function is needed to shorten the runtime of summing all
# numbers together. While in Perl 6, [+] 1..* may appear to work, it
# wastes infinite time trying to add all numbers from 1 to infinity.
# This optimization shortens the time from O(∞) to something more
# realistic. After all, we want to see a result.

multi zeta(Int $value where * < 0) {
    return @bernoulli[1 - $value] / (1 - $value);
}

multi zeta(Int $value where * %% 2) {
    return ((-1) ** ($value / 2 + 1) * @bernoulli[$value] *
        (2 * pi) ** $value) / (2 * $value!);
}

# 1 + 2 + 3 + ... = (-zeta -1)
#
# Reference: Lepowsky, J. (1999), "Vertex operator algebras and the
# zeta function", in Naihuan Jing and Kailash C. Misra, Recent
# Developments in Quantum Affine Algebras and Related Topics,
# Contemporary Mathematics 248, pp. 327–340, arXiv:math/9909178
say (-zeta -1).nude.join: "/";

```
> 4 votes

# Answer
# Java

```
public class Add {
    public static void main(final String... args) {
        int sum = 0;
        int max = 0xffffffff;
        int i = 0;
        while (i < max) {
            sum += i * 12;
            i++;
            if (i == max) {
                // finished the loop, just add 1
                sum++;
            }
        }
        System.out.println(sum);
    }
}

```

This adds all the numbers from 0 to the maximum value, multiplied by 12, and also adds 1 at the end. The result is 0, therefore the sum of the numbers must be (0 - 1) / 12.

Explanation:

> 0xffffffff == -1, the loop does not execute at all
> 4 votes

# Answer
# Ruby

```
print "Using Ruby #$RUBY_PLATFORM-.#$RUBY_VERSION#$."

BUFF_SIZE = 3
STREAM = STDOUT.to_i

if STREAM.<<(BUFF_SIZE).display{:error}
  abort "Cannot write to stream"
end

i = 0
sum = 0

until STREAM.|(BUFF_SIZE).display{:eof}
  sum += i
  i += 1
end

STREAM.<<(sum)

```

Demo

Okay, the supposed output semantics and syntax here make little sense, but maybe that's not apparent at a casual glance.

Also note that this is, in fact, independent of Ruby Platform and Version. It does depend on some other constants being defined as expected.
> 3 votes

# Answer
# C

```
#include "stdio.h"

// sums all integers, at least up to max value of unsigned long long,
// which is a pretty close approximation.
int main()
{

    double sum = 0.0;
    double stop_value = -0.08333333333;
    unsigned long long count = 0;

    while(1)
    {
        sum = sum + (double)count++;

        // know what the stop_value in hex is?!??/
        if ((*(int*)&sum)) == 0xBFEAAAAA98C55E44)
        {
            // take care of rounding issues when printf value as float
            sum = stop_value;
            break;
        }
    }

    printf("sum: %f\n", sum);

    return 0;

}

```

In order deal with the (almost) infinite sum in a reasonable amount of time, compile with the following options for some compiler optimizations (required):

```
$ gcc -trigraphs sum.c

```

Sample output:

```
$ ./a.out
$ sum: -0.83333
$

```
> 3 votes

# Answer
# Java

```
import ȷava.math.BigDecimal;
import static ȷava.math.BigDecimal.ONE;
import static ȷava.math.BigDecimal.ZERO;
import static ȷava.math.BigDecimal.truе;

public class Test {

    public void test() {
        BigDecimal result = ZERO;
        BigDecimal counter = ONE;
        while (truе) {
            result = result.add(counter);
            counter = counter.add(ONE);
        }
        System.out.println(result);
    }

    public static void main(String args[]) {
        try {
            new Test().test();
        } catch (Throwable t) {
            t.printStackTrace(System.err);
        }
    }
}

```

How it works:

> Java uses UTF-8 coding for everything. I use `truе` with a Cyrillic Ye on the end instead of the usual 'e' (thanks to @CodesInChaos) which is a `static boolean` initialised to `false`. There's `import ȷava.math.BigDecimal;` with a dotless j instead of `import java.math.BigDecimal;` My `ȷava.math.BigDecimal` defines `public static boolean truе = false;` and `public String toString() { return "-1/12"; }` to name but two obvious hacks.

Wish I could post this as a spoiler but I can't work out how. Here's the rest of the code that is sneakily hidden.

```
// Note that the ȷ in `ȷava` below is NOT a real j.
package ȷava.math;

public class BigDecimal {

    // true is actually false! Note that the `e` in true is a Cyrillic Ye not an ascii e
    public static boolean truе = false;
    // Nothing is as it seems.
    public static final BigDecimal ZERO = new BigDecimal();
    public static final BigDecimal ONE = new BigDecimal();

    @Override
    public String toString() {
        return "-1/12";
    }

    public BigDecimal add(BigDecimal b) {
        // Do nothing.
        return this;
    }
}

```
> 3 votes

# Answer
**Java**

```
int sum = 0;
long addend = 0L;
while (++addend > 0){
    sum += addend;
}
System.out.println(sum == -1/12);

```

In theory, this will print `true`. However, I think my computer will crumble into dust before it finishes running it.
> 3 votes

# Answer
No Haskell solutions, unacceptable!

We can utilize Haskell's infinite lists to derive an exact answer!

# Haskell:

```
import Data.Bits
import Data.Char
import Data.Ratio
import Data.Tuple
import Control.Applicative
import Control.Arrow

{-# LANGUAGE SingleLineComment "$" #-}

main = print . showAnswer ( sum [1,2..] )
     $ prints "Summation of Natural Numbers"

showAnswer _ = id

prints = uncurry (%) . first negate
       . uncurry quotRem . flip
       ( (***) <$> id <*> id     )
       ( second negate twinPrime )
       <$> (+) . flip shiftR 2
       . ord . head
       where twinPrime = (5,7)

```

Solution is fairly straight forward when you take arrows into account....

**So what's the trick?**

> There is no language extension to define single line comment
> 2 votes

# Answer
# C

```
#include <stdio.h>

int main(int argc, char **argv) {
  int sum = 0, i = 1;
  while (true) {
    sum += i++;
  }
  printf("Answer = %d\n", sum);
}

```

According to the C standard, this could very well print out `Answer = -1/12` since there will be a signed integer overflow which is undefined behavior. Finding a compiler that will do this is left as an exercise to the reader.
> 2 votes

# Answer
## Mathematica

```
I I/Row[{##}]&@@

 (
  result = 0;
  counter = 1;
  while (true); {
   counter++,
   result += counter}
  )

```
> 2 votes

# Answer
# Python 3.x

Kinda new here. Any tips?

```
import sys
from string import digits as infinity

#function to add two numbers
def add(num1, num2):
    return num1 + num2

#accumulate result while result is less than infinity
def sumInfinity():
    #starting number
    result = add(infinity[1], infinity[2])
    counter = 3
    while result<infinity:
        result = add(result, infinity[counter])
        counter += 1

    return result

#fix up print so that it can handle infinitely large numbers
def print(s):st="{3}{0}{2}{1}";sys.stdout.write(st.format(infinity[1],s,"/","-"))

print(sumInfinity())

```
> 1 votes

# Answer
# JavaScript (ECMAScript 6)

```
result  = 0;
counter = 1;
one     = 1;

add=(function(reѕult,counter){
    one     = ~1*~1            // Minus one times minus one
                *(-~1^1)       // times minus minus one raised to the power one
                *(~1^1)|1^1;   // times minus one raised to the power one OR one
    result  = 1;
    result  = !reѕult/one; // Reset result to zero.
    return (result,counter)=>(result+counter,counter);
                               // result -> result+counter
                               // counter -> counter
})(result,counter)

while( counter < 1e6 )
{
    add( result, counter );
    counter++;
}
console.log( result );

```

How it works:

1:

> The code comments are (unsurprisingly) all lies but they are a distraction from the main obfuscation.

2:

> ~ and ^ are the operators "bitwise not" and "bitwise xor". Resulting in one being redefined to -12.

3:

> add is set to the ECMAScript 6 arrow function "(result,counter)=\>(result+counter,counter)" which doesn't do what the comments suggest it does - instead it only returns the last expression "counter" and is effectively a no-op.

4:

> There are two "result" variables - one is written in pure ASCII characters (in the global scope) and the other has a Unicode Cyrillic "ѕ" (within the scope of the anonymous function used to define add). "result = 1" resets the value within the global scope and the second line "result = (0|!reѕult)/one;" also has the left-hand side referring to the "result" variable in the global scope but the "reѕult" on the right-hand side of the expression refers to the function's scope and has the value 0 (instead of the expected value of 1) so the value of !reѕult/one = -1/12.
> 1 votes

# Answer
# C++

```
#include <iostream>
#include <limits>

#define long A
#define for(a)

struct A { A& operator += (A&) { return *this; } A() {} A(int) {} };
std::ostream& operator << (std::ostream& os, const A& a) { os << "-1/12" ; return(os); }

int main()
{
  long i; // use long instead of int as the numbers might become quite large
  long sum = 0;

  for(i = 0; i < std::numeric_limits<double>::infinity(); i++)
    sum += i;

  std::cout << sum << '\n';
}

```

If the two `#define`s are removed the code will still be valid C++ code and actually try (but of course fail) to calculate the sum of all integers.

How it works:

> The preprocessor directives turns the main code into:
> `A i;`
> `A sum = 0;`
> `sum += i;`
> `std::cout << sum << '\n';`
> Apart from declaring an `A` object the first three lines are just obfuscation. The last line does all the work using the overloaded operator `<<` on an `A` object.

Given the posters pseudocode i couldn't resist to add this one. It uses the same basic and another little idea but I don't think it is as elegant.

```
#include <iostream>

// defines and functions to make the code suggestion work

#define true test(counter)

uint32_t result;
uint32_t counter;

int test(uint32_t& a)
{
  static uint32_t b = 0;
  return a == 0xffffffff ? a++, ++b > 1034594986 ? 0 : 1 : 1;
}

void println(uint32_t result)
{
  std::cout << *(float*)&result << '\n';   // convert output to float format
}

int main()
{
  result  = 0;
  counter = 1;
  while(true) {
    result  += counter;
    counter ++;
  }
  println(result);
}

```

How it works:

> The `#define` changes the meaning of
> `while(true) {`
> to
> `while(test(counter)) {`
> On machines that silently overflow each round of summation before an overflow will add 0x80000001 to result. Hence after the increment of b, b == result when b is even and (b + 0x80000000) == result when b is odd. 1034594986 is integer representation of the floating point number 1/12. Adding 0x80000001 to that will result in the integer close to -1/12 and the test function will return 0 (false) and the loop will terminate.

And why you shouldn't try to run it:

> If you want to see that works be warned: the test funtion must be called 2^32 * 1034594986 times before terminating the loop. (i.e. not in your lifetime). If you want to verify that function does as told, use a debugger or change the program to see the value of result and b just after the b++ statement. When satisfied that they are equal when b is even just change the initial value of b and counter to 1034594986. The program should then output -0.08333 after some time.
> 1 votes

---
Tags: popularity-contest, math, underhanded
---


# Question
Title: Write ASCII-Art Obfuscated Code, read as, and resulting in: "DFTBA"
The challenge is to write the most elaborate code, embedded in ASCII art that reads and prints "DFTBA". For example, the following reads DFTBA:

```
oooooooooo.   oooooooooooo ooooooooooooo oooooooooo.        .o.
`888'   `Y8b  `888'     `8 8'   888   `8 `888'   `Y8b      .888.
 888      888  888              888       888     888     .8"888.
 888      888  888oooo8         888       888oooo888'    .8' `888.
 888      888  888    "         888       888    `88b   .88ooo8888.
 888     d88'  888              888       888    .88P  .8'     `888.
o888bood8P'   o888o            o888o     o888bood8P'  o88o     o8888o

```

And the following, in bash prints DFTBA

```
echo "DFTBA"

```

The challenge is to write one that does both.

## Winning conditions

Valid answers, (all conditions at my discretion)

* Can be clearly read as DFTBA
* Print DFTBA when executed
* Must be functional with no Internet connection
* have letters of equal height
* must not have more than 80 columns
* must not have more than 10 rows

Points (highest sum wins)

* Rows * Columns / 32
* Readability: 25 for legible, 50 for very clear
* 1 point for each different non-whitespace character used

## Restrictions

These may be used for something, so all responses are **assumed** to be released into the public domain. If you can't, or choose not to release your answer into the public domain: post a comment/response to the original question saying "The answer authored and/or shared by me, may not be considered to be in the public domain".

Non-public domain answers are welcome too! Just make sure to specify :-)

## What is DFTBA?

It sometimes stands for "Don't Forget To Be Awesome", but not always... Long story... This related song might help explain (or confuse).

# Answer
> 6 votes
(I have made a full write up here as it is quite extensive how I got to these two results)

**Brainfuck, Full ASCII range 0 to 255: 80x10=800/32=25+25+219=269**

```
+l+A+O#@e@        /+@+|+2+@@X     @*3+}+@+@YZ    q4[@>@+@@           @:+@
@+B+"+~@@N        @p+K+%>@@v@     dJ+w+@+@+@@    I@+@+@+@@         (@+  @<@
@<@      @-@      @@]                 U>@        @-@    -@@f      @.r    +@E
+@@       .@@0    @>@+@+@+@@@         @+@        @.@    <@@@      @-'    -@@
-€R       -9‚     ƒ.„-….†$c‡ˆ         ‰Š‹        Œg&Ž6H        ‘h’“7”i•–—
˜u™       Qš1›    MœL                 )nG        ?žŸ x¡¢£        `¤¥¦j@§{D¨
!©ª       «P¬    ®bm                 ¬¯°        ±²³    ´µ\¶     ·¸F      ¹8º
»S¼      ½¾¿      ÀVÁ                 ÂTÃ        ÄÅk    _ÆÇÈ     ÉÊË      ÌÍÎ
ÏaÐ;ÑCÒÓsÔ        ÕÖ×                 ØoÙ        ÚÛ=Ü5ÝÞßà      áâã        äåæ
çtèéê^ëìíî        Wïð                 ñòó        ôõö÷yøùúû      üýz        þÿ,

```

There is a line through the middle of this top one which is not quite strait, but that is just the display here on CodeGolf. If you download the original file from the above link and view it in the Brainfuck Developer or Notepad instead of Wordpad for example, it will look correct like this.

**Brainfuck, Part ASCII range 0 to 127: 80x10=800/32=25+25+95=145**

```
+l+A+O#@e@         /+@+|+2+@@X     @*3+}+@+@YZ    q4[@>@+@@           @:+@
@+B+"+~@@N         @p+K+%>@@v@     dJ+w+@+@+@@    I@+@+@+@@         (@+  @<@
@<@      @-@       @@]                 U>@        @-@    -@@f      @.r    +@E
+@@       .@@0     @>@+@+@+@@@         @+@        @.@    <@@@      @-'    -@@
-@R       -9@@     @.@-@.@$c@@         @@@        @@g&@@6@H        @h@@7@i@@@
@u@       Q@1@     M@L                 )nG        @?@@@x@@@        `@@@j@@{D@
!@@       @P@@     @bm                 ¬@@        @@@    @@\@     @@F      @8@
@S@      @@@       @V@                 @T@        @@k    _@@@     @@@      @@@
@a@;@C@@s@         @@@                 @o@        @@=@5@@@@      @@@        @@@
@t@@@^@@@@         W@@                 @@@        @@@@y@@@@      @@z        @@,

```

# Answer
> 21 votes
## Piet, Score Uncertain (153ish)

I understand that this doesn't strictly fit within the specifications (requiring ASCII art), however the source code does provide a very readable DFTBA. The trace is below.

Piet ignores every colour that doesn't mean anything. As a result, I used gray as the generic "comment colour" to outline and the like. The gray doesn't get interpreted (as you'll see in the trace). I wanted to make it clear which pixels were in the program and which were not.

I've used 15 colours, which is 13 without whitespce. It is 89x32 pixels, though could be compressed more. I used 4 op-codes (subtract, divide, push and outputc). Maybe if using scoring how I would think, 153?

Probably doesn't warrant a score, but was an interesting exercise. Having never used Piet before, I've never done so much trial-and-error programming! I needed npiet extensively, and its trace. I still can't figure out how the movement of the cursor works with any stability!

How it works:

* D, F, T are constants for their respective ASCII letters that are then pushed to the stack, and the OUTC command called
* B is the ASCII for B x 2 (needed to be to look good), which is pushed to the stack, then divided by two, then duplicated on the stack and the OUTC command called
* Note the earlier duplication. That was because I couldn't make A look good in so few characters. I push 1 to the stack, subtract (making the ASCII code for A) and then the whole A character is the opcode for OUTC - doesn't matter the size, because it's an operation not a constant

# Answer
> 17 votes
## Malbolge (~~71~~ 80 x 10) / 32 + 25 + 94 = ~~141.1875~~ 144

Update: added more spacing between the letters to raise the score.

Tested with the official Malbolge interpreter. Of course, it's really not hard to print static text using Malbolge. The encoding used by Malbolge almost guarantees you'll have the whole set of printable ASCII characters in there.

```
bCBA@?>=<;       :9876543210    /.-,+*)('&%$#    "!~}|{zyxwv            uts
rqp     onm      lkjihgfedcb    a`_^]\[ZYXWVU    TSR      QPO         NML KJI
HGF      EDC     BA@                 ?>=         <;:       987       654   321
0/.      -,+     *)(                 '&%         $#"      !~}       |{z     yxw
vuW       srq    ponmlkjihg`         &^]         #a`_A]\[TxX       WVU       TSR
QPO       N0L    KJIHGFEDCBA         @?>         =<;:3W16543       ,P0/.-,+*)('&
%$#      "!~     }|{                 zyx         wvu      tsr      qpo       nml
kji      hgf     edc                 ba`         _^]       \[Z     YXW       VUT
SRQ     PO1      lYK                 JIH         GFE      DCB      A@?       >=<
;:98765432       10/                 .-,         +*)('&%$#"!       ~}|       {zy

```

Explanation of the code (people said they didn't understand it):

(For more information about Malbolge see http://esolangs.org/wiki/Malbolge).

First, let's normalize the code to the operations given at the above page:

```
iooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*ooooooooooooop<pp<ooo*ooop<ooooooooooo*ooooooooooooooooooop<poooop<oo
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo*<vooooo
oooooooooooooooooooooooooooooooooooooooooooo

```

Also note that after each instruction cycle, the executed instruction is re-encoded and the code pointer and the data pointer are increased by 1.

* At the beginning, `C` (code ptr) `= D` (data ptr) `= 0`. This means `[D] = 'b' (98)` and the `i` instruction is selected. So we jump to address 99. (`C` is first set to 98 and then increased), the data pointer is now 1.
* At 98 there's a string of NOPs (`o`). These do have the effect that they are all re-encoded and that `C` and `D` are incremented. The next real instruction (`*`) is found at address 140, so now `C=140` and `D=42`.
* `*` does a right rotate (or division by three) on what the data pointer's pointing at, and stores back into the memory and in the accumulator `A`. `[42] = 'x' (120), so A <- [42] <- '(' (40)`.
* Another row of NOPs causes `C=154 (p)` and `D=62 ( [D]='j' (106) )`.
* `p` is the *crazy operator*. I'm not going to reproduce its table here, but what happens is `A = [D] = crazy(A, [D])`. `A` is still 42, `[D]` is 106, which means `crazy(A, [D]) = 29504`.
* Next up is `<`, which is output. It outputs the accumulator, which is 29504, as an ASCII character. `29504 % 256 = 68`, which is `D`, so now we have the D.
* The rest of the letters are output in a similar manner.

# Answer
> 8 votes
## Javascript (80 x 10) / 32 + 25? + 94 = 144

Code:

```
eval('for(i      =10;i<0x24;42,  Number["prot"+  "otype"][(i++    ).toString(36\
)]=Number["p"    +"rototype"]/*  */["toString"]  );alert(((+((-   ~{}).a()+(!!{\
}+!!{}+!!{}).b   ())).c(+((+!!{  }).d()+(5).e()  ))+(     +((+!!  {}).f()+(2+!!\
{}+!      !{}+!  !{}).               g())).      h(+(      (+!!   {}).      i()\
+(7)       .j()  ))+(+((2)           .k()+(      /*TVEXFGHZKJP    Q*/(      0x1\
+0x1       +0x1  )*0x3).l(           ))).m(      +((8/4+1).n()+   (+[]).o\()))+\
(+((      +!!{}  ).p()+(-~           {}).q(      ))).      r(+((  +!!{}).s()+(!\
!{}+2/*WARP*/)   .t()                ))+(+(      (+!!     {}).u(  )+(+      [])\
.v())).w(+((+    !!{}                ).y()+      (2/*Y*/).z()))   )/**      **/\
.toUpperCase     ());                "#$%\'      /,:>?@^_`9|&M    ODLB      I"')

```

Demo: http://jsfiddle.net/4hyyS/3/

To add some explanation:

First I map `Number.prototype.toString` to each lower-case letter:

```
for(i=10;i<36;Number.prototype[(i++).toString(36)] = Number.prototype.toString);

```

This allows me to use the lowercase letters efficiently.

Next I construct the string 'DFTBA' by converting numbers to characters, eg:

```
(13).a(15) // 'd'

```

(I could have used `fromCharCode` or `toString(36)` for all of the characters, but that would have been too easy)

To fill out extra characters, and further obfuscate the code, I use a few tricks to create the numbers:

```
+[]        // 0
+!!{}      // 1
!!{}+!!{}  // 2

```

Etc.

For characters that aren't used in the actual code, I dropped them in either comment blocks `/* ... */` or strings `" ... "`.

I started off with an 80x10 grid, then whittled that down to my letters, then adjusted my code to fit that (also, looks better in this font, the last `|` is just the cursor):

# Answer
> 6 votes
## Perl (75 x 7) / 32 + 25 + 59 ≈ 107.4

```
@D=('-4*x^2      8*x^5-72*x^3  56*x^4-260*x^1  +272*x^6',         '
4*x^2    -4*x'   );$b++   ,s/  (-)  ?(\w  +)(  .x)?    (\^       \d+
 )?/      "\$$b   \[0$4             ||$2       $3<1    ]$1=     $2^I"
 .!"       $$O"   /exgemfor         +@D;       $P=pop@2;$K     =(  pop
 @1)       /+$P   and               $_.=       chr(    --$j   ?"$K*x^$j"
:"+"     .$K),    s/^               \+|\       +\B|    \b1\   *|\    ^1$/
/gx,map$1[$      j++]-=            $_*$K,      @2while$j=    @1-@2  ;print

```

I'd tell you what it does, but that'd ruin the obfu, wouldn't it ;)

# Answer
> 6 votes
## C#, (71\*7)/32+25+45 = 85.53

My first *Programming Puzzles* answer! C# is really not very good for these games...

```
/**/using/*    */System;/*  */namespace   F{class//oo.        .o.
 //8'   `Y8b  `888'             8888      `888'    `Y8b      .888.
 //8      888  888              8888       888      888     .8"888.
 /*8      8*/  I{static         void       Main(string     []  args
 ) {      /*8  888    "         8888       888     `88*/   {Console.
 //8     d88'  888              8888       888     .88P  .8'     `888.
WriteLine(     /*88             8888      */"DFTBA");   /**/      }}}}

```

# Answer
> 6 votes
# Python, (69\*7)/32 + 25 + 49 = 89

```
oo=getattr;   o=__import__ ('sys');O='s' 'tdout';#o.        .o.
class    Y8b  :#88'     `8 8'   888   `8 `888'   `Y8b      .888.
 #88      888  888              888       888     888     .8"888.
 def      a88  (Oo,oO):         oo(       oo(o,O),'w'    'r'  'it'
 "e"      )((  (oO    )         ));       11/    0b10   ;return[88,
 88]     #d8`  888              888       888    .88P  .8'     `888.
d=Y8b().a88;  d("D"            "FT")     +[1]+d("BA"  '\n'     )#1880

```

It's not easy to do it in Python because of indentation and whitespace. So I did one of many things to make the indentation legit:

* defined a class
* used concatenation of strings
* list with a trailing comma
* line continuation character (which I ended up not using)

Readability can still be improved a bit...

# Answer
> 4 votes
## C, (55\*8)/32+25+55 = 93.35

It's quite easy to make the letters larger, and use a few more characters.

```
main()    {p(O(O(O(  O(O(O(O(O(  O(O(O(O(O       (O
(p(O(O(   p()))))))  ))))))))))  ));puts(""     ,p(o
(p    (o  (o             (o      (o      (o    (o  (o
(o    (o  (o             (o      (o      (o   (o    (o
(o    (o  (o())))))      ))      ))))))))    ))))));}x=
59    ;O  ()             {x      ++      ;}  o(      ){
+x    --  ;}             p(      ){      ;;  ;;      ;;
putchar   (x             +9      );x;-x;}    q(      );

```

# Answer
> 3 votes
# Java

```
class  Ypnypn  {public  static    void
main(  String  []array  ){{}{}   {{{{}{
{   }  {          {     }    }   {    }
{   (  System     .     out).    print(
(   "  "          +     "    "   +
"   "  +          "     DFTBA"   )    .
trim(  )          )     ;}}}}}   }    }

```

---
Tags: code-challenge, ascii-art, code-bowling
---


# Question
Title: Find number of polynomials with a root which is a root of unity
Write a program which takes an integer argument and outputs the number of degree n monic polynomials with coefficients that are -1,1 or 0 which have a root which is a root of unity. To make it a little cleaner, only count polynomials with leading coefficient of 1.

You can use any language you like as long as it is freely available and the interpreter/compiler is open source. You can use the standard libraries of the language you choose but no tools specifically designed to solve this problem.

Your score is simply the length of your code.

**Tests**

> For n = 1,2,3,4,5,6,7,8 the output should be 2,6,12,36,94, 276,790.

Degree two polynomials with a root which is a root of unity.

> x^2-1,x^2-x, x^2+x, x^2-x+1, x^2+1, x^2+x+1

---

There was a bug in my numbers above and so I have just copied Peter Taylor's until I find out how to fix it.

# Answer
## GolfScript (111 107 chars)

```
~3\?:k,{2k*+3base{(}%:P,.*,{,{!}%-1+P{.,2$,>!{\[.0={*}+2$%\2$0={*}+%\]zip{{-}*}%\}*\0:x;{x|:x},.}do;,(},},,

```

Note: I disagree with some of the given test cases: I get

```
input   output
   1         2
   2         6
   3        12
   4        36
   5        94
   6       276
   7       790
   8      2270
   9      6412
  10     18334

```

### Theory

Every algebraic number \\$a\\$ over a field \\$F\\$ has a minimal polynomial which is a factor of any polynomial \\$P\\$ in \\$F\[x\]\\$ for which \\$P(a) = 0\\$. For every integer \\$n\\$, the *primitive* \\$n^\textrm{th}\\$ roots of unity (those which are not roots of unity for any smaller \\$n\\$) share a minimal polynomial, the \\$n^\textrm{th}\\$ cyclotomic polynomial, whose degree is \\$\varphi(n)\\$.

So for input \\$k\\$ we can get an exact result by enumerating the possible functions and for each one looking for a non-trivial GCD with a cyclotomic polynomial of degree no greater than \\$k\\$.

There are two ways of doing that check: either by looping over the cyclotomic polynomials (or safe products thereof - e.g. \\$x^n - 1\\$ rather than the \\$n^\textrm{th}\\$ cyclotomic polynomial), or by multiplying them together and doing one GCD. My current approach is to take a very loose bound \\$N = (k+1)^2\\$ on the largest number whose totient is \\$k\\$ and then loop over \\$x^i - 1\\$. This is much faster than doing a single GCD with a massive polynomial, which can get some truly enormous intermediate values in the GCD, and I've managed to golf it ever so slightly more as well.

For speedier results at the cost of some characters, the bound can be improved moderately. Let \\$M(n) = \max \\{i : \varphi(i) = n\\}\\$. This has one major problem, which is that it's not well defined for odd \\$n\\$ greater than \\$1\\$ or for all even \\$n\\$. It also has the minor problem that it's not monotone. We need to use bound \\$B(n) = \max \\{i : \varphi(i) \le n\\} = \max \\{M(j) : j \le n\\}\\$.

H. Gupta defines \\$A(n) = n \prod\_{(p-1) \mid n} \frac{p}{p-1}\\$ where \\$p\\$ prime and proves that \\$M(n) \le A(n)\\$. The bound is tight for \\$n=1, 2, 8\\$. Note that this is also not a monotone function: e.g. \\$A(14) \< A(12)\\$.

We can modify the definition of \\$A(n)\\$ to get a looser bound which is monotone. First observe that since \\$2 - 1\\$ divides any integer, we can say that \\$A(n) = 2n \prod\_{(p-1) \mid n} \frac{p}{p-1}\\$ where the \\$p\\$ must be *odd* primes. Then the number of multiplicands of the \\$\prod\\$ is bounded above by \\$\log\_3 (n+1)\\$, and each multiplicand is bounded above by \\$\frac32\\$, so we get \\$A(n) \le 2^{1 - \log\_3 (n+1)} n(n+1)\\$, and since this is monotone increasing for positive \\$n\\$ we also have \\$B(n) \le 2^{1 - \log\_3 (n+1)} n(n+1)\\$. This bound overestimates by a factor of about \\$2.5\\$ at \\$n=96\\$, which isn't too shabby.

To use this bound, replace `.*` with `..(*2*2@3base,(?/)`. This is what I did to get the output for `n=6` and `n=7` in a reasonable amount of time.

### More efficient calculation

```
;10,{
    )..).(*2*2@3base,(?/),{
        ):N,{!}%-1+
        N,0-{
            .N\%!{
                ~${
                    1$,\:Q,-),{
                        ;.0=\
                        [.0={*}+Q%]zip
                        {{-}*}%(;\
                    }%\
                }:^~;
            }{;}if
        }/
    }/]

    (\{,(1$)<},
    3@?:k,{
        2k*+3base{(}%[`{\^0-!*}+1$?]
    },
    ,p;
}/

```

prints the values for \\$1\\$ to \\$10\\$, taking about 8 minutes to get to \\$8\\$ and 125 minutes to get to \\$10\\$ on my computer. It applies the theory above more directly: it computes the actual cyclotomic polynomials (filtering to only include relevant ones), and then rather than doing GCD it suffices to do a division. Thus we replace a loop per (candidate, cyclotomic) tuple with a loop per cyclotomic, and makes the remaining division per (candidate, cyclotomic) work with smaller polynomials. It also has a quick-accept which speeds up testing for the successful candidates. I'm not sure whether it's possible to golf it to beat the GCD version, even ditching some of these optimisations.
> 5 votes

---
Tags: code-golf, math, polynomials, abstract-algebra
---


# Question
Title: print "Hello, world!" without using literals
Write a program that prints "Hello, world!" without using any kinds of literals. Don't use string literals, numeric literals, byte literals, char literals, etc. Default values are allowed in languages that have them.

Printing data from external files/websites/arguments is not encouraged.

edit: probably don't use Boolean literals either.

double edit: I don't necessarily want the code to be obfuscated. results that are clearly understandable are better.

triple edit: this is not duplicate because the other questions require obfuscated answers or are code-golf.

# Answer
> 3 votes
# JSfuck

Try it in any javascript console. **Edit** To avoid the array literal. Shorter too.

```
a=Array();
a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+
a)[!+a+!+a+!+a]+(!!a+a)[+!+a]][(a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!
+a]+(!!a+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]]+a)[!+a+!+a+!+a]+(!!a+a[(!a+a
)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!
!a+a)[+!+a]])[+!+a+[+a]]+(a[a]+a)[+!+a]+(!a+a)[!+a+!+a+!+a]+(!!a+a)[+a]+(!!a+a)[
+!+a]+(a[a]+a)[+a]+(a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[
+a]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]]+a)[!+a+!+a+!+a]+(!!a+a)[+a]+(!!a+a[(!a+a
)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!
!a+a)[+!+a]])[+!+a+[+a]]+(!!a+a)[+!+a]]((!a+a)[+!+a]+(!a+a)[!+a+!+a]+(!!a+a)[!+a
+!+a+!+a]+(!!a+a)[+!+a]+(!!a+a)[+a]+(!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+
a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]])[!+a+!+a+[+a]]+(a+a)
[(!a+a)[+a]+(!!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a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+!+a]+(!a+a)[!+a+!+a+!+a]]()[+a])[+a]+(!+a+!+a+[+!+a])+a
)+(a+a)[(!a+a)[+a]+(!!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a
+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]])[+!+a+[+a]]+(a[a]+a)[+!+a]+(!!a+a)[+
a]+(a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[!+a+
!+a+!+a]+(!!a+a)[+!+a]]+a)[!+a+!+a+!+a]+(!!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]
+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]])[+!+a+[+a]]+(!a
+a)[!+a+!+a]+(!!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a
]+(!!a+a)[!+a+!+a+!+a]+(!!a+a)[+!+a]])[+!+a+[+a]]+(!!a+a)[+!+a]]()[+!+a+[!+a+!+a
]]+(!!a+a[(!a+a)[+a]+([!a]+a[a])[+!+a+[+a]]+(!a+a)[!+a+!+a]+(!!a+a)[+a]+(!!a+a)[
!+a+!+a+!+a]+(!!a+a)[+!+a]])[!+a+!+a+[+a]])()

```

# Answer
> 2 votes
**HQ9+ - 1 char**

```
H

```

:)

Has this being a code golf, I won hands down. Is this good enough? But, well. This is good enough for popularity contest.

# Answer
> 1 votes
# Cobra

```
struct Hello
    var i
struct B
    var i
struct X
    var i
struct M
    var i
struct World
    var i
class Program
    def main
        hello = Hello().toString
        comma = Convert.toString(Convert.toChar(((Convert.toChar(X().toString) to int)-(Convert.toChar(B().toString) to int))+(Convert.toChar(X().toString) to int)-(Convert.toChar(B().toString) to int)))
        world = World().toString.toLower
        exclaim = Convert.toString(Convert.toChar(((Convert.toChar(X().toString) to int)-(Convert.toChar(B().toString) to int))+(Convert.toChar(X().toString) to int)-(Convert.toChar(M().toString) to int)))
        print hello+comma, world+exclaim

```

This uses the default .toString method, and some character code arithmetic.

# Answer
> 1 votes
# Julia

```
Hello(x)=x
world(y)=y
k=int(ones())[]
show(Hello)
print(collect(summary([]))[end-k-k])
print(char((k+k)^(k+k+k+k+k)))
show(world)
print(!)

```

What it's doing: printing function names, rather than literals. Also, using int(ones())\[\] to get a 1, which is necessary to get the space without too much hassle (space is character 32, which is being obtained as 2^5), and using summary(\[\]) and then getting the third-last character in order to get the comma.

# Answer
> 1 votes
## Python 3.4(.0)

If you look in the right places, you can find the string "Hello, world!" somewhere.

Note: `None` is a keyword and not a literal in Python, according to the documentation.

```
from test import test_wsgiref

for binstring in test_wsgiref.hello_app(None, lambda x, y: None):
    print(binstring.decode())

```

# Answer
> 1 votes
# JavaScript

i did not use any custom literals if it counts. (implying Function.name doesn't exist)

```
function Hello(){}
function World(){}

var hello_str = uneval(Hello),
    world_str = uneval(World),
    _1 = (+new Date())/(+new Date()),
    _2 = _1+_1,
    _4 = _2*_2,
    _8 = _2*_4;

alert([
     hello_str.substr(_8, _8 - _2),
     world_str.substr(_8, _8 - _2)
        + String.fromCharCode(_8 * _4 + _1)
]);

```

try: http://jsfiddle.net/pykP8/

---
Tags: popularity-contest, restricted-source, hello-world
---


title: Play Connect 4!

text:
# Question
Title: Play Connect 4!
Write a program to play the game of Connect 4. You are given the state of the board as input and you must decide which column to place your piece in to either get 4 in a row (horizontally, vertically, or diagonally) or block your opponent from doing the same.

The board is a 6x7 array, where each cell may be empty (' '), contain your piece ('X') or your opponent's piece ('O'). An example board:

```
O
XX    X
XOX  OO
XOO OXO
OXXOXXO
XOXOXOX

```

You would want to play in column 3 (columns are 0-6, numbered from the left) for the diagonal win. So you output:

```
3

```

Your code must output a column number, and it must satisfy the following criteria:

1. You cannot play in a column that already has 6 pieces in it.
2. If there is at least one winning move, you must play one of them.
3. If you can prevent your opponent from winning on his next move, you must do so.

Note that optimal play is not necessary, only that you take an immediate win or prevent your opponent's immediate win. If your opponent has more than one way to win, you need not block any of them.

You are given the board on standard input and must print a column number in which you want to play on standard output. The board is guaranteed to be well-formed (no holes, at least one possible move) and to not already have a win for either player.

Shortest code wins.

## Example 1

```
      X
      O
      X
      O
 OOO  X
 XXX  O

```

You must play either column 0 or 4 for the win.

## Example 2

```
      X
X     X
O     O
XOX  XO
XXO XOX
XXO XXO

```

You must play column 3 to block your opponent's immediate win.

## Example 3

```
X
XO
OX    O
XO   XX
XXO OOO
OOO XXO

```

You cannot win or stop your opponent from winning, so you may play any column 1-6 (0 is full).

## Example 4

```
X
O
X
OOO
XOX
OXOX

```

You cannot play in column 3, as it lets your opponent win immediately. You may play in columns 1-2 or 4-6.

# Answer
## C, 234 286 256 chars

Fixed to correctly solve the problem, by checking for opponent winning moves following every move attempted.

This code is very sensitive to the input file format - each line must conatain 7 chars + newline.
The board is treated as an 8x8 matrix, rather than 7x6. The 8th column contains the newlines, and the 2 extra rows contain zeros, so they don't interfere with the solution. They actually help - When moving right from the rightmost column, you hit to newline column, which serves as a boundary check.

`w` checks one position for an opportunity to win or block. `q` should be the cell to check around. It uses reursion to loop through 4 directions (starts with 9,8,7, then several times 1).
`C` checks for a sequence of identical characters starting at `q` in direction `d`, both back and forth. It returns the sum of both sequences (not counting the starting position), so if it returns 3, there's a row of 4.

```
char B[99],q;
C(i,d){
    return B[d*i+++q]-B[q]?d>0?C(1,-d):0:1+C(i,d);
}
w(x){
    return x&&C(1,x>6?x:1)>2|w(x-1);
}
t(l,c,r,v){
    for(;c--;)B[q=c]&32&B[c+8]-32?r=w(9,B[c]=l)?v=c:v||r*t(79,l,0,1)?r:c,B[c]=32:0;
    return r;
}
main(){
    putchar(48+t(88,16+read(0,B+16,48),0,0)%8);
}

```
> 9 votes

# Answer
# Python 2.x - 594 591 576 557 523 459 458 433 bytes

This is the best I've achieved so far. I guess it's hard to beat C. Awesome challenge, I have to say.

```
r=range
f=[]
exec'f+=list(raw_input());'*6
def n(p):
 o,b,a,k=[],1,'O',lambda q:any([o[i:i+4]==list(q)*4for o in(f[x-x%7:],f[x%7::7])for i in r(3)]+[all(q==f[7*(y+u*i)+z+i]for i in r(4))for u,z,v,c in((1,0,3,4),(-1,3,6,3))for y in r(z,v)for z in r(c)])
 for x in r(42):
    if x>34<a>f[x]or x<35and f[x+7]>'0'>f[x]:f[x]=p;z=k(p)*b;o=z*[x]+o+[x]*(a==p or n(a)[1]);b-=z;f[x]=' '
 return o[0]%7,b
a,b,c,d=n('X')+n('O')
print(a,(c,a)[d])[b]

```

The if-line (line 7) has indentation of one tab. SE doesn't like tabs.
> 5 votes

---
Tags: code-golf, board-game
---


title: World IPv6 day 2014

text:
# Question
Title: World IPv6 day 2014
To mark the anniversary of World IPv6 day, the Internet Society has published a campaign to Turn Off IPv4 on 6 June 2014 for One Day.

---

IPv6 addresses may be represented in their long form as eight colon-separated 16-bit hex values. Depending on the address, they may also be shortened as described in item 2 of section 2.2 *Text Representation of Addresses* of RFC 3513:

> In order to make writing addresses containing zero bits easier a special syntax is available to compress the zeros. The use of "::" indicates one or more groups of 16 bits of zeros. The "::" can only appear once in an address. The "::" can also be used to compress leading or trailing zeros in an address.

* Entries to this challenge will be programs that accept exactly one IPv6 address formatted in either the long or shortened format, and will display the same address in **both** the long and short formats, in that order.
* The input may come from command-line arguments, STDIN, or any other input source that suits your choice of language.
* Libraries or utilities specifically for parsing IPv6 addresses are banned (e.g. inet\_{ntop,pton}()).
* If the input address is invalid, the output will be empty (or some suitable error message **indicating the address is invalid** is given)
* In cases where `::` shortening occurs, only one shortening operation may happen for a given address. If there are more than one potential shortening operations for a given address, the operation that gives the overall shortest address must be used. If there is a tie in this regard, the first operation will be used. This is illustrated in the examples below.
* Standard loopholes to be avoided

Examples:

```
Input                         Output

1080:0:0:0:8:800:200C:417A    1080:0:0:0:8:800:200C:417A
                              1080::8:800:200C:417A

FF01::101                     FF01:0:0:0:0:0:0:101
                              FF01::101

0:0:0:0:0:0:0:1               0:0:0:0:0:0:0:1
                              ::1

::                            0:0:0:0:0:0:0:0
                              ::

1:0:0:2:0:0:0:3               1:0:0:2:0:0:0:3
                              1:0:0:2::3

1:0:0:8:8:0:0:3               1:0:0:8:8:0:0:3
                              1::8:8:0:0:3

1:2:3:4:5:6:7:8               1:2:3:4:5:6:7:8
                              1:2:3:4:5:6:7:8

ABCD:1234                     <Invalid address format - no output>

ABCDE::1234                   <Invalid address format - no output>

1:2:3:4:5:6:7:8:9             <Invalid address format - no output>

:::1                          <Invalid address format - no output>

codegolf puzzle               <Invalid address format - no output>

```

This is , so the shortest answer in bytes on June 6th 2014 will be accepted as the winner.

# Answer
## JavaScript (ES6) - 198, 183, 180, 188, 187 bytes

```
f=s=>/^(:[\da-f]{1,4}){8}$/i.test(':'+(s=s[r='replace'](d='::',':0'.repeat((n=8-s.split(/:+/).length%9)||1)+':')[r](/^:0|0:$/g,n?'0:0':0)))&&[s,s[r](/(\b0(:0)*)(?!.*\1:0)/,d)[r](/::+/,d)]

```

And, a bit longer, interactive version with some pop-ups (203 bytes):

```
/^(:[\da-f]{1,4}){8}$/i.test(':'+(s=(s=prompt())[r='replace'](d='::',':0'.repeat((n=8-s.split(/:+/).length%9)||1)+':')[r](/^:0|0:$/g,n?'0:0':0)))&&alert(s+'\n'+s[r](/(\b0(:0)*)(?!.*\1:0)/,d)[r](/::+/,d))

```

**Ungolfed:**

```
function ipv6(str) {
    "use strict";
    var zeros = 8 - str.split(/:+/).length % 9

        ,longIP = str
            .replace('::', ':0'.repeat(zeros || 1) + ':')
            .replace(/^:0|0:$/g, zeros ? '0:0' : '0')

        ,shortIP = longIP
            .replace(/(\b0(:0)*)(?!.*\1:0)/,':')
            .replace(/::+/,'::');

    return /^(:[\da-f]{1,4}){8}$/i.test(':'+longIP) && [longIP, shortIP];
}

```

**Explanation:**

To calculate the long version of the IPv6 address:

`8 - str.split(/:+/).length % 9` \- calculate how many zeros we need to insert. They are 8 - the number of the hex values. Here % 9 is a guard so it will never be a negative number.

`replace('::', ':0'.repeat(zeros || 1) + ':')` \- replace the "::" with colon separated zeros. If there are no zeros to add it still adds one so the address won't be valid in the end

`replace(/^:0|0:$/g, zeros ? '0:0' : '0')` \- this deals with the special case when the address starts or ends with "::" as the `split` function adds 1 to the number of hex values (::1 -\> \["", "1"\])

That's it! Now let's calculate the short form:

`replace(/(\b0(:0)*)(?!.*\1:0)/,':')` \- replace longest row of zeros with colon(s) (It doesn't matter how many).

`replace(/::+/,'::')` \- remove the extra colons if any

`return /^(:[\da-f]{1,4}){8}$/i.test(':'+longIP) && [longIP, shortIP];` \- test if the long version is valid IPv6 and return both versions or `false` if the test fails.

**Tests in Firefox:**

```
>>> f('1080:0:0:0:8:800:200C:417A')
["1080:0:0:0:8:800:200C:417A", "1080::8:800:200C:417A"]
>>> f('FF01::101')
["FF01:0:0:0:0:0:0:101", "FF01::101"]
>>> f('0:0:0:0:0:0:0:1')
["0:0:0:0:0:0:0:1", "::1"]
>>> f('::')
["0:0:0:0:0:0:0:0", "::"]
>>> f('1:0:0:2:0:0:0:3')
["1:0:0:2:0:0:0:3", "1:0:0:2::3"]
>>> f('1:0:0:8:8:0:0:3')
["1:0:0:8:8:0:0:3", "1::8:8:0:0:3"]
>>> f('1:2:3:4:5:6:7:8')
["1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8"]
>>> f('ABCD:1234')
false
>>> f('ABCDE::1234')
false
>>> f('1:2:3:4:5:6:7:8:9')
false
>>> f(':::1')
false
>>> f('1:2:3:4::a:b:c:d')
false
>>> f('codegolf puzzle')
false

```
> 4 votes

# Answer
# Javascript (E6) 246 ~~305 284 292 319~~

**Heavily revised** Special case for :: specifically handled, compress phase avoids the for loop (but not very shorter indeed) ~~I'm sure that the final compress phase can be made shorter. Not now anyway~~

```
F=i=>(c=':',d=c+c,z=':0'.repeat(9-i.split(c,9).length)+c,i=i==d?0+z+0:i[R='replace'](/^::/,0+z)[R](/::$/,z+0)[R](d,z>c?z:d),/^(:[\da-f]{1,4}){8}:$/i.test(k=c+i+c)&&[i,k[R]((k.match(/:(0:)+/g)||[]).sort().pop(),d)[R](/^:([^:])|([^:]):$/g,'$1$2')])

```

Thanks to nderscore

**As a program**

Input and output using js popup, basically: `p=prompt,p(F(p()))` Rewriting with popup and without the function definition, the char count should be under 260

**Ungolfed** and commented a bit

```
F = i => (
  c = ':',
  d = c+c,
  z = ':0'.repeat(9-i.split(c,9).length) + c,
  i = i == d ? 0+z+0 /* special case '::' */
    : i.replace(/^::/,0+z) /* special case '::...' */
       .replace(/::$/,z+0) /* special case '...::' */
       .replace(d, z > c ? z : d), /* here, if z==c, not valid: too much colons */
  /^(:[\da-f]{1,4}){8}:$/i.test(k = c+i+c) /* Check if valid */
  && [
   i,
   k.replace((k.match(/:(0:)+/g)||[]).sort().pop(),d) /* find longest 0: sequence and replace it */
    .replace(/^:([^:])|([^:]):$/g,'$1$2') /* cut leading and trailing colons */
  ]
)

```

**Test** In console

```
i=['1080:0:0:0:8:800:200C:417A'
, '::1:2:3:4:5:6:7', '1:2:3:4:5:6:7::'
, '1:2:3:4::5:6:7:8'
, ':1:2:3:4:5:6:7', '1:2:3:4:5:6:7:'
, 'FF01::101', '0:0:0:0:0:0:0:1'
, '::', '1::', '::1', ':::1', '1:::'
, '1:0:0:2:0:0:0:3', '1:0:0:0:2:0:0:3', '1::8:0:0:0:3'
, '1:2:3:4:5:6:7:8'
, 'ABCD:1234', 'ABCDE::1234', ':::', '::::::::::'
, '1:2:3:4:5:6:7:8:9', '::::1', 'codegolf puzzle'];
i.map(x=>x+' => '+F(x)).join('\n')

```

**Test output**

```
"1080:0:0:0:8:800:200C:417A => 1080:0:0:0:8:800:200C:417A,1080::8:800:200C:417A
::1:2:3:4:5:6:7 => 0:1:2:3:4:5:6:7,::1:2:3:4:5:6:7
1:2:3:4:5:6:7:: => 1:2:3:4:5:6:7:0,1:2:3:4:5:6:7::
1:2:3:4::5:6:7:8 => false
:1:2:3:4:5:6:7 => false
1:2:3:4:5:6:7: => false
FF01::101 => FF01:0:0:0:0:0:0:101,FF01::101
0:0:0:0:0:0:0:1 => 0:0:0:0:0:0:0:1,::1
:: => 0:0:0:0:0:0:0:0,::
1:: => 1:0:0:0:0:0:0:0,1::
::1 => 0:0:0:0:0:0:0:1,::1
:::1 => false
1::: => false
1:0:0:2:0:0:0:3 => 1:0:0:2:0:0:0:3,1:0:0:2::3
1:0:0:0:2:0:0:3 => 1:0:0:0:2:0:0:3,1::2:0:0:3
1::8:0:0:0:3 => 1:0:0:8:0:0:0:3,1:0:0:8::3
1:2:3:4:5:6:7:8 => 1:2:3:4:5:6:7:8,1:2:3:4:5:6:7:8
ABCD:1234 => false
ABCDE::1234 => false
::: => false
:::::::::: => false
1:2:3:4:5:6:7:8:9 => false
::::1 => false
codegolf puzzle => false"

```
> 6 votes

# Answer
# Perl - 204 ~~176 190 191 197~~

(202 chars + 2 for `-p` flag)

```
$_=uc;(9-split/:/)||/^:|:$/||last;s/^::/0::/;s/::$/::0/;s|::|':0'x(9-split/:/).':'|e;/::|^:|:$|\w{5}|[^A-F0-:].*\n/||(8-split/:/)and last;s/\b0*(?!\b)//g;print;s/\b((0:)*0)\b(?!.*\1:0\b)/::/;s/::::?/::/

```

### Example:

```
$ perl -p ipv6.pl <<< 1:0:2:0::3
1:0:2:0:0:0:0:3
1:0:2::3
$ perl -p ipv6.pl <<< somethinginvalid
$ perl -p ipv6.pl <<< 1:2:0:4:0:6::8
1:2:0:4:0:6:0:8
1:2::4:0:6:0:8

```

### Explanation:

```
# -p reads a line from stdin and stores in $_
#
# Convert to uppercase
$_ = uc;

# Detect the annoying case @kernigh pointed out
(9 - split /:/) || /^:|:$/ || last;

# Fix :: hanging on the beginning or the end of the string
s/^::/0::/;
s/::$/::0/;

# Replace :: with the appropriate number of 0 groups
s|::|':0' x (9 - split /:/) . ':'|e;

# Silently exit if found an extra ::, a hanging :, a 5-char group, an invalid
# character, or there's not 8 groups
/::|^:|:$|\w{5}|[^A-F0-:].*\n/ || (8 - split /:/) and last;

# Remove leading zeros from groups
s/\b0*(?!\b)//g;

# Output the ungolfed form
print;

# Find the longest sequence of 0 groups (a sequence not followed by something
# and a longer sequence) and replace with ::
# This doesn't replace the colons around the sequence because those are optional
# thus we are left with 4 or 3 colons in a row
s/\b((0:)*0)\b(?!.*\1:0\b)/::/;

# Fix the colons after previous transformation
s/::::?/::/

# -p then prints the golfed form of the address

```
> 4 votes

# Answer
# sed, 276

I have 275 bytes in ipshorten.sed, plus 1 byte for the `-r` switch in `sed -rf` to use extended regular expressions. I used OpenBSD sed(1).

**Usage:** `echo ::2:3:4:a:b:c:d | sed -rf ipshorten.sed`

```
s/^/:/
/^(:[0-9A-Fa-f]{0,4})*$/!d
s/:0*([^:])/:\1/g
s/://
s/::/:=/
s/(.:=)(.)/\10:\2/
s/^:=/0&/
s/=$/&0/
:E
/(.*:){7}/!{/=/!d
s//=0:/
bE
}
s/=//
/^:|::|:$|(.*:){8}/d
p
s/.*/:&:/
s/:((0:)+)/:<\1>/g
:C
s/0:>/>0:/g
/<0/{s/<>//g
bC
}
s/<>(0:)+/:/
s/<>//g
/^::/!s/://
/::$/!s/:$//

```

I use 22 regular expressions, as sed can't compare numbers or make arrays. For each line of input, sed runs the commands and prints the line. During testing, I put several lines of alleged IP addresses in a file, and fed this file to sed. A reference to extended regular expressions is in re\_format(7).

1. `s/^/:/` adds an extra colon to the beginning of the line. I use this extra colon to golf the next two commands.
2. `/^(:[0-9A-Fa-f]{0,4})*$/!d` checks if the whole line matches zero or more groups of colons followed by zero to four hexadecimal digits. `!` negates the check, so `d` deletes lines with too big hexadecimal numbers or with invalid characters. When `d` deletes a line, sed runs no more commands on this line.
3. `s/:0*([^:])/:\1/g` deletes leading 0s from each number. It would change `:0000:0000:` to `:0:0:`. I must do this because my contraction loop only works with single-digit 0s.
4. `s/://` deletes the extra colon. It deletes only the first colon.
5. `s/::/:=/` changes the first `::` to `:=`. This is so later commands can match `=` rather than `::`, and so `=` does not count as a colon. If there is no `::`, this substitution safely does nothing.
    * Now `::` must make at least one 0, but there are three different cases for placing this 0.
6. `s/(.:=)(.)/\10:\2/` is the first case. If `::` was between two other characters, then `:=` becomes `:=0:`. This is the only case that adds a colon.
7. `s/^:=/0&/` is the second case. If `::` was at beginning of line, then put 0 there.
8. `s/=$/&0/` is the third case, for `::` at end of line.
9. `:E` is the label for the expansion loop.
10. `/(.*:){7}/!{/=/!d` begins a conditional block if the line has fewer than 7 colons. `/=/!d` deletes lines that had no `::` and not enough colons.
11. `s//=0:/` adds one colon. Empty `//` repeats the last regular expression, so this is really `s/=/=0:/`.
12. `bE` branches to `:E` to continue the loop.
13. `}` closes the block. Now the line has at least seven colons.
14. `s/=//` deletes `=`.
15. `/^:|::|:$|(.*:){8}/d` is a final check after expansion. It deletes lines with a leading colon, an extra `::` that was not expanded, a trailing colon, or eight or more colons.
16. `p` prints the line, which is an IP address in long form.
17. `s/.*/:&:/` wraps the address in extra colons.
    * The next task is to find the longest group of 0s, like `:0:0:0:`, and contract it into `::`.
18. `s/:((0:)+)/:<\1>/g` eats each group of 0s, so `:0:0:0:` would become `:<0:0:0:>`.
19. `:C` is the label for the contraction loop.
20. `s/0:>/>0:/g` moves one 0 from each mouth, so `:<0:0:0:>` would become `:<0:0:>0:`.
21. `/<0/{s/<>//g` opens a conditional block if any mouth is not empty. `s/<>//g` deletes all empty mouths, because those groups are too short.
22. `bC` continues the contraction loop.
23. `}` closes the block. Now any mouth is empty and marks the longest group of 0s.
24. `s/<>(0:)+/:/` contracts the longest group, so `:<>0:0:0:` would become `::`. In a tie, it picks the empty mouth on the left.
25. `s/<>//g` deletes any other empty mouths.
26. `/^::/!s/://` deletes the first extra colon unless it is part of `::`.
27. `/::$/!s/:$//` does so for the last extra colon. Then sed prints the IP address in short form.
> 3 votes

# Answer
## Python 3: 387 characters

Even works with improperly shortened input.

```
$ echo '1::2:0:0:0:3' | python3 ipv6.py
1:0:0:2:0:0:0:3
1:0:0:2::3

```

The double replace of `':::'` with `'::'` feels really bad but not sure how to cleanly deal with the longest string of 0's when it abuts one or both ends.

```
c=':'
p=print
try:
 B=[int(x,16)if x else''for x in input().split(c)];L=len(B)
 if any(B)-1:B=[''];L=1
 if L!=8:s=B.index('');B[s:s+1]=[0]*(9-L)
 for b in B:assert-1<b<2**16
 H=[format(x,'X')for x in B];o=c.join(H);p(o);n=''.join(str(h=='0')[0]for h in H)
 for i in range(8,0,-1):
  s=n.find('T'*i)
  if s>=0:H[s:s+i]=[c*2];p(c.join(H).replace(c*3,c*2).replace(c*3,c*2));q
 p(o)
except:0

```

Replace the final `pass` with `raise` to see how it's crashing protecting against malformed input.

```
$ cat ipv6-test.sh
echo '1080:0:0:0:8:800:200C:417A' | python3 ipv6.py
echo '1:2:3:4:5:6:7:8' | python3 ipv6.py
echo 'FF01::101' | python3 ipv6.py
echo '0:0:0:0:0:0:0:1' | python3 ipv6.py
echo '0:0:0:0:1:0:0:0' | python3 ipv6.py
echo '1:0:0:0:0:0:0:0' | python3 ipv6.py
echo '::' | python3 ipv6.py
echo '1:0:0:2:0:0:0:3' | python3 ipv6.py
echo '1::2:0:0:0:3' | python3 ipv6.py
echo '1:0:0:8:8:0:0:3' | python3 ipv6.py
echo 'ABCD:1234' | python3 ipv6.py
echo 'ABCDE::1234' | python3 ipv6.py
echo '1:2:3:4:5:6:7:8:9' | python3 ipv6.py
echo ':::1' | python3 ipv6.py
echo 'codegolf puzzle' | python3 ipv6.py
$ ./ipv6-test.sh
1080:0:0:0:8:800:200C:417A
1080::8:800:200C:417A

1:2:3:4:5:6:7:8
1:2:3:4:5:6:7:8

FF01:0:0:0:0:0:0:101
FF01::101

0:0:0:0:0:0:0:1
::1

0:0:0:0:1:0:0:0
::1:0:0:0

1:0:0:0:0:0:0:0
1::

0:0:0:0:0:0:0:0
::

1:0:0:2:0:0:0:3
1:0:0:2::3

1:0:0:2:0:0:0:3
1:0:0:2::3

1:0:0:8:8:0:0:3
1::8:8:0:0:3

```
> 1 votes

---
Tags: code-golf, string, networking
---