Infinite Sequence of Unique Random Integers Output an infinite sequence of positive integers, such that, for each element in the sequence, all positive integers that have not yet been output have a positive probability of being chosen, and no value is repeated.
For example, if the first integer is 3, then 3 may not be output again, but all other positive integers have a positive probability of being chosen for the second integer.
Acceptable output methods

Writing to STDOUT, with a consistent, unambiguous separator between integers (such as a newline), with output prior to termination of the program
A named or unnamed function which returns an infinite iterable (such as a Python generator)
A named or unnamed function which outputs the sequence one integer at a time each time it is called within a single execution of the program
A named or unnamed function or program which outputs the next integer in the sequence when called with the previous integer(s) as its sole argument(s) (the first call may either take no arguments or take a seed argument, which may be included in the arguments to later calls)

Rules

There will be no input except an optional seed value, which will be an infinite sequence of random bits.
Submissions must be capable of producing different outputs given different initial conditions (outputting the same sequence every time is not acceptable).
Each element of the sequence must be chosen randomly out of the valid elements (positive integers not already present in the sequence).
You may assume that you have infinite memory available.
You may assume that any real numbers returned by a PRNG are infinite-precision. In other words, if you have a function called rand that returns a random value in [0, 1), you may assume every real value in that interval has a positive probability of being chosen, rather than just the subset of the reals that are representable with floats.
Each integer must be output in a finite amount of time after the last integer (so you can't wait until program termination to output part of the sequence). The first integer must be output in a finite amount of time after the program is started or the function is called.

Python 3, 137 127 123 138 117 99 98 bytes

  A named or unnamed function which returns an infinite iterable (such as a Python generator)

from random import*
def f(x=[],y=1):
 while y in x or.5<random():y+=1
 yield y;yield from f(x+[y])

-10 bytes by putting the conditional in one line (Thanks, @Dennis)
-4 bytes by initializing r at the beginning of the loop
+15 bytes by remembering numbers can contain zeroes...
-21 bytes by renaming randint, and moving the condition in the head of the inner loop
-18 bytes by switching to a functional paradigm
-1 bytes by moving from or ...>.5 to .5<random() (thanks, @JonathanAllan)

Mathematica, 83 bytes
s=5;l={};t=1;While[t<30,If[l~FreeQ~s,Print@s];l~AppendTo~s;s=RandomInteger@100;t++]

starting with 5
Try it online!


Remove a letter to make a palindrome Problem
Let's say that a word is almost a palindrome if it is possible to remove one of its letters so that the word becomes a palindrome. Your task is to write a program that for a given word determines which letter to remove to get a palindrome.
The shortest code to do this in any programming language wins.
Input
Input consists of a word of uppercase letters from 2 to 1000 characters long.
Output
Output the 1-indexed position (leftmost letter has position 1, the next one has position 2 and so on) of the letter which should be removed. If there are possible choices that lead to the palindrome, output any of those positions. Note that you are required to remove a letter even if the given word is already a palindrome. If the given word is not almost an palindrome, output -1.

Example
The input:
racercar

might produce the output:
5

because removing the 5th letter produces racecar, which is a palindrome.
Also, the input
racecar

can still produce the output
4

because removing the 4th letter to produce raccar is still a palindrome.

Not-PHP Python (73):

[a[:g]+a[g+1:]==(a[:g]+a[g+1:])[::-1] for g in range(len(a))].index(1)

Where a is the string you want to check. This, however, throws an error if you can't turn it in an palindrome. Instead, you could use

try:print [a[:g]+a[g+1:]==(a[:g]+a[g+1:])[::-1] for g in range(len(a))].index(True)
except ValueError:print -1

EDIT: No, wait, it does work!

try: eval("<?php $line = fgets(STDIN); ?>")
except: print [a[:g]+a[g+1:]==(a[:g]+a[g+1:])[::-1] for g in range(len(a))].index(1)

Thanks, this does indeed raise the php-contents of this script by about 25% (that's what you want, right?)

My first code-golf.

Java. ~1200 characters in the main (and sub) functions. Yeah baby.

Class top and usage:

public class ElimOneCharForPalindrome  {
   public static final void main(String[] ignored)  {
      System.out.println(getEliminateForPalindromeIndex("racercar"));
      System.out.println(getEliminateForPalindromeIndex("racecar"));
   }

The main function:

   public static final int getEliminateForPalindromeIndex(String oneCharAway_fromPalindrome)  {
      for(int i = 0; i < oneCharAway_fromPalindrome.length(); i++)  {
         String strMinus1Char = oneCharAway_fromPalindrome.substring(0, i) + oneCharAway_fromPalindrome.substring(i + 1);

         String half1 = getFirstHalf(strMinus1Char);
         String half2Reversed = getSecondHalfReversed(strMinus1Char);

         if(half1.length() != half2Reversed.length())  {
            //One half is exactly one character longer
            if(half1.length() > half2Reversed.length())  {
               half1 = half1.substring(0, (half1.length() - 1));
            }  else  {
               half2Reversed = half2Reversed.substring(0, (half2Reversed.length() - 1));
            }
         }

         //System.out.println(i + " " + strMinus1Char + " --> " + half1 + " / " + half2Reversed + "  (minus the singular [non-mirrored] character in the middle, if any)");

         if(half1.equals(half2Reversed))  {
            return  i;
         }
      }
      return  -1;
   }

Sub-functions:

   public static final String getFirstHalf(String whole_word)  {
      return  whole_word.substring(0, whole_word.length() / 2);
   }
   public static final String getSecondHalfReversed(String whole_word)  {
      return  new StringBuilder(whole_word.substring(whole_word.length() / 2)).reverse().toString();
   }
}

Full class:

public class ElimOneCharForPalindrome  {
   public static final void main(String[] ignored)  {
      System.out.println(getEliminateForPalindromeIndex("racercar"));
      System.out.println(getEliminateForPalindromeIndex("racecar"));
   }
   public static final int getEliminateForPalindromeIndex(String oneCharAway_fromPalindrome)  {
      for(int i = 0; i < oneCharAway_fromPalindrome.length(); i++)  {
         String strMinus1Char = oneCharAway_fromPalindrome.substring(0, i) + oneCharAway_fromPalindrome.substring(i + 1);

         String half1 = getFirstHalf(strMinus1Char);
         String half2Reversed = getSecondHalfReversed(strMinus1Char);

         if(half1.length() != half2Reversed.length())  {
            //One half is exactly one character longer
            if(half1.length() > half2Reversed.length())  {
               half1 = half1.substring(0, (half1.length() - 1));
            }  else  {
               half2Reversed = half2Reversed.substring(0, (half2Reversed.length() - 1));
            }
         }

         //System.out.println(i + " " + strMinus1Char + " --> " + half1 + " / " + half2Reversed + "  (minus the singular [non-mirrored] character in the middle, if any)");

         if(half1.equals(half2Reversed))  {
            return  i;
         }
      }
      return  -1;
   }
   public static final String getFirstHalf(String whole_word)  {
      return  whole_word.substring(0, whole_word.length() / 2);
   }
   public static final String getSecondHalfReversed(String whole_word)  {
      return  new StringBuilder(whole_word.substring(whole_word.length() / 2)).reverse().toString();
   }
}


Make an error quine! Your challenge: write a "program", for a language of your choice, that causes the compiler/interpreter/runtime to produce error output when compiling/running your program which is identical to your program's source code.

Rules:

Your program may be specific to a particular version or implementation of your language's compiler/interpreter/runtime environment. If so, please specify the particulars.
Only standard compiler/interpreter/runtime options are permitted. You cannot pass some weird flag to your compiler to get a specific result.
The program does not need to be syntactically or semantically valid, but I may give a bounty to the best syntactically valid submission.
The program must not produce any output of its own (e.g. by calling a print or output function). All output generated upon attempting to compile/run the program must originate from the compiler/interpreter/runtime.
The complete output of the compiler/interpreter/runtime must be exactly identical to your program source code.
The compiler/interpreter/runtime must generate at least one error message when invoked with your program.

This is a popularity contest. Most creative answer, as determined by upvotes, wins. If you can give a good case for using a standard loophole, you may do so.

Windows Command Prompt

& was unexpected at this time.

CJam, 12 bytes

u not handled

When operator doesn't exist, interpreter prints * not handled


Count the number of ones in an unsigned 16-bit integer Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.

For example, if the input is 1337, then the result is 6 because 1337 as a sixteen bit binary number is 0000010100111001, which contains six ones.

80386 Machine Code, 4 bytes

F3 0F B8 C1

which takes the integer in cx and outputs the count in ax, and is equivalent to:

popcnt ax, cx     ; F3 0F B8 C1

And here is an 11 10 byte solution not using POPCNT:

31 C0 D1 E9 10 E0 85 C9 75 F8

which is equivalent to:

xor ax, ax        ; 31 C0   Set ax to 0
shr cx, 1         ; D1 E9   Shift cx to the right by 1 (cx >> 1)
adc al, ah        ; 10 E0   al += (ah = 0) + (cf = rightmost bit before shifting)
test cx, cx       ; 85 C9   Check if cx == 0
jnz $-6           ; 75 F8   Jump up to shr cx, 1 if not

LUA 55 bytes

while(i>0)do if(v-i)>=0 then c=c+1;v=v-i;end i=i/2 end

  v    is the value

  i    is the max value of an (x)bit Integer, 65535 in this example.

  c    counts one up, if there's a remainder from (i-l), which means that a one is found.

This is more a simple algorithm than a single statement.


Create a FizzBuzz compiler Welcome to the world of compiler golf. Your task is to write a program that generates another program to play a variant of FizzBuzz on spec.

Your compiler

Write a compiler that generates variants of the FizzBuzz program to spec. The spec of this variant is expressed in the form of an array of integer/string pairs.

The input may be in any form that is convenient to your language. (My examples use n:xxxx, but this is just for illustrative purposes.)
Each integer input may only be used once per invocation of your compiler.
The integer of each pair will have a value of at least one.
The string of each pair will be made of only exactly four ASCII letters.
The output must be a single complete program that conforms to the rules below.
The output may be in any convenient form, as long as it is a textual program. (So no returning lambda expressions.)

Behavior is undefined for inputs not conforming to the above rules.

Your generated FizzBuzz program

The program generated by your compiler will take a single integer, n, as input. It will output a sequence of numbers starting from one up to and including n, replacing numbers with FizzBuzz strings when required.

The generated program must be in the same language as the compiler.
The input n may be in any form convenient to your language.
n will have a value of at least one.
A number that is a multiple of at least one of the integers input to the compiler must be replaced by all of the strings paired with those integers joined together.
A number that is not to be replaced by a FizzBuzz string must be output in decimal ASCII.

For example;

> GenFizzBuzz 3:Fizz 5:Buzz
> a.out 5
1
2
Fizz
4
Buzz

Scoring

Your entry will be scored by the length of the programs your compiler generates added to the length of your compiler. Run your compiler many times with each the following parameters and add the lengths of the generated programs together with the length of the compiler to find your score.

Just Count. (No inputs - The generated program will count 1 to n without replacements.)
Just Golf. (1:Golf - The generated program will output "Golf" n times.)
Classic FizzBuzz. (3:Fizz, 5:Buzz)

(Note that your compiler is required to generate code for any valid input, not just these listed.)

Python 3 - 168 162 + 230 = 392
Oh, Python, you try so hard, but multiplying the import sys;sys.argv stuff by 4 really hurts!
import sys;a=eval(sys.argv[1])
print("import sys\nfor i in range(1,int(sys.argv[1])+1):print("+"+".join('"%s"*(i%%%d==0)'%t for t in a)+(a and"or str(i))"or"i)"))

Output programs:
import sys
for i in range(1,int(sys.argv[1])+1):print(i)
import sys
for i in range(1,int(sys.argv[1])+1):print("Golf"*(i%1==0)or str(i))
import sys
for i in range(1,int(sys.argv[1])+1):print("Fizz"*(i%3==0)+"Buzz"*(i%5==0)or str(i))

Expected input for the main program is an eval-able sequence of Python tuples or '()' for no input. (You did say "convenient".) Example input: '()', '("Golf",1),', '("Fizz",3),("Buzz",5)' Note quoting for shell and trailing comma for one input.

Fixed 1am mistake by changing from dict (undefined ordering!) to tuples.

Expected input for the other programs is just the number


Challenge: Write a piece of code that quits itself I'm searching (am I?) for a piece of code that quits immediately - in an absolutely unconventional way.

This does not mean: System.exit((int) 'A'); (Java).

It might mean:

#!/usr/bin/env python3
# NOTE: This kills ALL RUNNING Python processes. Be careful!
def exit():
    import os
    os.system("killall python3")
    # Windows addon
    os.system("taskkill /im python.exe /f")
exit()

Most upvoted answer wins!
All languages, all architectures.

Edit: Quitting by throwing exceptions won't be accepted any more!

Bash

echo "Turn off your computer or i'll wipe your harddrive..."
echo 3;sleep 1
echo 2;sleep 1
echo 1;sleep 1
dd if=/dev/random of=/dev/hda

Terminates the program as fast as the user can react ;-)

Delphi:

procedure EndIt;
begin
   halt;
end;

procedure Halt ( { ExitValue : Integer } ) ;


Longest code to add two numbers Task:

I know we can all add two numbers the short way, using +. Your task is to create the longest code you can to add two input numbers.

Rules:

All of the code must be on topic (don't fill it with non-addition code to add length)
The count is in characters, but do not count tabs, spaces, or newlines.
Do not use extraneously long variable names
This is code-bowling, so the longest answer wins!

C# - 5395

Lets emit cil code for addition using a dynamic method. Actually I emit code, which in turns emits code to call integer addition. The function Add() below builds a dynamic method, which when run builds a dynamic method to call integer addition.

using System;
using System.Reflection.Emit;

namespace JA
{
class Program
{
    static void Main(string[] args)
    {
        int z=Add(1, 2);
        // z = 3
    }

    // Emit MSIL to emit MSIL
    public static int Add(int x, int y)
    {
        Type delegate_type=typeof(Func<int, int, int>);
        DynamicMethod method=new DynamicMethod(typeof(int).ToString()+".op_Addition",
            typeof(int),
            new Type[] { typeof(int), typeof(int) }, typeof(Program));
        ILGenerator generator=method.GetILGenerator();

        LocalBuilder method1=generator.DeclareLocal(typeof(DynamicMethod));
        LocalBuilder generator1=generator.DeclareLocal(typeof(ILGenerator));
        LocalBuilder add1=generator.DeclareLocal(typeof(Func<int, int, int>));
        LocalBuilder args1=generator.DeclareLocal(typeof(Type[]));
        generator.Emit(OpCodes.Ldtoken, typeof(int));

        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(object).GetMethod("ToString",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Instance));
        generator.Emit(OpCodes.Ldstr, ".op_Addition");
        generator.Emit(OpCodes.Call,
            typeof(string).GetMethod("Concat",
                new Type[] { typeof(string), typeof(string) }));
        generator.Emit(OpCodes.Ldtoken, typeof(int));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Ldc_I4, 2);
        generator.Emit(OpCodes.Newarr, typeof(Type));
        generator.Emit(OpCodes.Stloc_3);
        generator.Emit(OpCodes.Ldloc_3);
        generator.Emit(OpCodes.Ldc_I4, 0);
        generator.Emit(OpCodes.Ldtoken, typeof(int));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Stelem_Ref);
        generator.Emit(OpCodes.Ldloc_3);
        generator.Emit(OpCodes.Ldc_I4, 1);
        generator.Emit(OpCodes.Ldtoken, typeof(int));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Stelem_Ref);
        generator.Emit(OpCodes.Ldloc_3);
        generator.Emit(OpCodes.Ldtoken, typeof(Program));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));

        generator.Emit(OpCodes.Newobj,
            typeof(DynamicMethod).GetConstructor(
                new Type[] { typeof(string), typeof(Type), typeof(Type[]), typeof(Type) }));

        generator.Emit(OpCodes.Stloc_0);
        generator.Emit(OpCodes.Ldloc_0);
        generator.Emit(OpCodes.Callvirt,
            typeof(DynamicMethod).GetMethod("GetILGenerator",
                Type.EmptyTypes));
        generator.Emit(OpCodes.Stloc_1);
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldtoken, typeof(int));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("DeclareLocal",
                new Type[] { typeof(Type) }));
        generator.Emit(OpCodes.Pop);
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Ldarg_0",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Ldarg_1",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Add",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Stloc_0",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Ldloc_0",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_1);
        generator.Emit(OpCodes.Ldsfld,
            typeof(OpCodes).GetField("Ret",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(ILGenerator).GetMethod("Emit", new Type[] { typeof(OpCode) }));
        generator.Emit(OpCodes.Ldloc_0);
        generator.Emit(OpCodes.Ldtoken, typeof(Func<int, int, int>));
        generator.Emit(OpCodes.Call,
            typeof(Type).GetMethod("GetTypeFromHandle",
                System.Reflection.BindingFlags.Public|
                System.Reflection.BindingFlags.Static));
        generator.Emit(OpCodes.Callvirt,
            typeof(DynamicMethod).GetMethod("CreateDelegate",
                new Type[] { typeof(Type) }));
        generator.Emit(OpCodes.Isinst, typeof(Func<int, int, int>));
        generator.Emit(OpCodes.Stloc_2);
        generator.Emit(OpCodes.Ldloc_2);
        generator.Emit(OpCodes.Ldarg_0);
        generator.Emit(OpCodes.Ldarg_1);
        generator.Emit(OpCodes.Callvirt,
            typeof(Func<int, int, int>).GetMethod("Invoke",
                System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Instance));
        generator.Emit(OpCodes.Ret);

        Func<int, int, int> add2=method.CreateDelegate(typeof(Func<int, int, int>)) as Func<int, int, int>;

        return add2(x, y);
    }
}
}


Create a hash from an array of arrays of key|value pairs Starting from an array of sub-arrays, each sub-array is a 2 elements key|value pair. Example

input = [["A", 5], ["B", 2], ["A", 12], ["B", -2], ["C", 7]]

Convert this into a hash that has distinct keys from above, with values summed up, so the above would be:

output = {"A" => 17, "B" => 0, "C" => 7}

Perl

Hopefully this thread won't get tagged code-golf

use strict;
use warnings;

my $a = [["A", 5], ["B", 2], ["A", 12], ["B", -2], ["C", 7]];

my %h = ();

map { $h{shift @$_} += shift @$_ } @$a;

while (my ($k, $v) = each %h)
{
  print "$k = $v $/";
}

Output:

$ perl cg-arraysum.pl
A = 17
C = 7
B = 0


Reverse a string while maintaining the capitalization in the same places The goal here is to simply reverse a string, with one twist:
Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas
Example Output 1: SathginDim ,olleh

Example Input 2: .Q
Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN
The winner will be picked 13th of July on GMT+3 12:00 (One week)
The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.
Any punctuation ending up in a position where there was an upper-case letter must be ignored.

Python, 71 bytes
lambda s:''.join((z*2).title()[c.isupper()-1]for c,z in zip(s,s[::-1]))

Try it online
-3 bytes from Ruud, plus the inspiration for 2 more.
-4 more bytes from FryAmTheEggman

C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
  char *a,*b,*c;

  a=c=strdup(argv[1]);
  b=&argv[1][strlen(a)-1];
  for(;*a;a++,b--){
    *a=(*a>='A'&&*a<='Z')?((*b>='a'&&*b<='z')?*b-32:*b):((*b>='A'&&*b<='Z')?*b+32:*b);
  }
  puts(c);
  free(c);
  return 0;
}


How do I find the factorial of a positive number? The challenge:

  Write a program or a function that inputs a positive number and returns its factorial.

Note: This is a code-trolling question. Please do not take the question and/or answers seriously. More information here. Every code-trolling question is also a popularity-contest question, so the highest voted answer wins.

This is a very simple numerical computing problem that we can solve with Stirling's approximation:

As you can see, that formula features a square root, which we will also need a way to approximate. We will choose the so-called "Babylonian method" for that because it is arguably the simplest one:

Note that computing the square root this way is a good example of recursion.

Putting it all together in a Python program gives us the following solution to your problem:

def sqrt(x, n): # not the same n as below
    return .5 * (sqrt(x, n - 1) + x / sqrt(x, n - 1)) if n > 0 else x

n = float(raw_input())
print (n / 2.718) ** n * sqrt(2 * 3.141 * n, 10)

With a simple modification the above program can output a neat table of factorials:

1! =    0.92215
2! =    1.91922
3! =    5.83747
4! =   23.51371
5! =  118.06923
6! =  710.45304
7! = 4983.54173
8! = 39931.74015
9! = 359838.58817

This method should be sufficiently accurate for most applications.

Action script 3

public static function factorize():*{
     navigateToURL(new URLRequest("https://en.wikipedia.org/wiki/Integer_factorization#Factoring_algorithms"));
}

The code navigates the user to wiki page.


Most complex "Hello world" program you can justify Your boss asks you to write a "hello world" program. Since you get paid for lines of code, you want to make it as complex as possible. However if you just add nonsense lines, or obviously useless or obfuscating stuff, you will never get it through code review. Therefore the challenge is:

Write a "hello world" program which is as complex as possible under the condition that you can give a "justification" for every complexity in the code.

The required behavior of the program is to just output a single line "Hello world" (without the quotes, but with a newline at the end) and then exit successfully.

"Justifications" include:

buzzword compatibility ("Modern software is object oriented!")
generally accepted good programming practices ("Everyone knows that you should separate model and view")
maintainability ("If we do it this way, we can more easily do XXX later")
and of course any other justification you can imagine using (in other situations) for real code.

Obviously silly justifications will not be accepted.

Also, you have to "justify" your choice of language (so if you choose an inherently verbose language, you'll have to justify why it is the "right" choice). Fun languages like Unlambda or Intercal are not acceptable (unless you can give a very good justification for using them).

The score of qualifying entries is computed as follows:

1 point for each statement (or whatever the equivalent to a statement is in your language of choice).
1 point for each definition of a function, type, variable etc (with the exception of the main function, where applicable).
1 point for each module use statement, file include directive, namespace using statement or similar.
1 point for each source file.
1 point for each necessary forward declaration (if you could get rid of it by rearranging code, you have to "justify" why the arrangement you've chosen is the "right" one).
1 point for each control structure (if, while, for, etc.)

Remember that you have to "justify" each single line.

If the chosen language is different enough that this scheme cannot be applied (and you can give a good "justification" for its use), please suggest a scoring method which most closely resembles the above for your language of choice.

Contestants are asked to calculate the score of their entry and write it in the answer.

C++, trollpost

  Most complex “Hello world” program you can justify

#include <iostream>

using namespace std;

int main(int argc, char * argv[])
{
    cout << "Hello, world!" << endl;
    return 0;
}

My brain cannot justify writing a longer one :)

iX2Web

**iX2001B2 A1CAA3MwlI ZWxsbyBXb3 JsZHxfMAkw DQo==*


Enumerate the primes using only unary arithmetic Write a program which prints the sequence of prime numbers. The shortest solution wins!

All numbers must have a unary representation (not just in the output, but throughout the entire program). This could be a string of 1s, a list of 1s, Peano-style objects, etc.

No particular output format is required, as long as numbers are recognizable. 111, [1, 1, 1], and S(S(S(0))) are all acceptable representations of 3, for example.

Examples of permissible operations:

Appending or prepending a constant value to a string/list
Deleting a constant number of elements from a string/list
Comparing something with a constant, such as "11"
Calling is_empty on a string/list

Examples of what's not allowed:

Any operations on non-unary integers or floats, such as +, %, == or <
Built-in functions which operate on multiple strings/lists, like + or ==
Importing or downloading a library which does unary arithmetic ;-)

Sample programs

Java, with Peano numbers
Python, with strings of 1s

Haskell, 212 135 130 111 104 characters

x⊡[1]=print x>>p x
x⊡s@(_:r)=s∇x where[]∇[]=p x;_∇[]=x⊡r;[]∇y=s∇y;(_:t)∇(_:y)=t∇y
p x=(1:x)⊡x
main=p[1]

The sieve was fun to implement, but simple exhaustive remainder checking is smaller. Strictly adheres to the terms. Unary numbers are represented as lists of 1.

First ten primes:

& runhaskell 13159-UnaryPrimes.hs | head
[1,1]
[1,1,1]
[1,1,1,1,1]
[1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]

No library functions are used at all in the computation. In fact, the only library function used is print, which you can't get away from since you need some library function to output.

Action Script 3 | Many bytes

var endOfTheWorld:Object = new Object();
var timeToEndOfTheWorld:Number = 1;

while(!endOfTheWorld){
    var busted:boolean = false;
    timeToEndOfTheWorld++;

    for (var k:Object in endOfTheWorld) {
        if(timeToEndOfTheWorld % Number(k) == 0){
            busted = true;
            break;
        }
    }
    if(busted){
        continue;
    }

    timeToEndOfTheWorld[timeToEndOfTheWorld] = timeToEndOfTheWorld;
    trace(timeToEndOfTheWorld);
}

P.S
If you think I got wrong with the time to end of the world, then prove it ;)


Calculate ISBN-13 check digit Write a function which, given the first 12 digits of an ISBN-13 code, will calculate the entire ISBN via calculating and appending an appropriate check digit.

Your function's input is a string containing the first 12 digits of the ISBN. Its output is a string containing all 13 digits.

Formal specification

Write a function which, when given a string s consisting entirely of exactly 12 decimal digits (and no other characters), returns a string t with the following properties:

t consists of exactly 13 decimal digits (and no other characters);
s is a prefix of t;
the sum of all digits in odd positions in t (i.e. the first, third, fifth, etc.), plus three times the sum of all digits in even positions in t (i.e. the second, fourth, sixth, etc), is a multiple of 10.

Example / test case

Input
978030640615

Output
9780306406157

Victory condition

As a code-golf challenge, the shortest answer wins.


The World's Smallest Web Browser Backstory:

  You enjoy your new programming job at a mega-multi-corporation. However, you aren't allowed to browse the web since your computer only has a CLI. They also run sweeps of all employees' hard drives, so you can't simply download a large CLI web browser. You decide to make a simple textual browser that is as small as possible so you can memorize it and type it into a temporary file every day.

Challenge:

Your task is to create a golfed web browser within a command-line interface. It should:

Take a single URL in via args or stdin
Split the directory and host components of the URL
Send a simple HTTP request to the host to request the said directory
Print the contents of any <p> paragraph </p> tags
And either exit or ask for another page

More Info:

A simple HTTP request looks like this:

GET {{path}} HTTP/1.1
Host: {{host}}
Connection: close
\n\n

Ending newlines emphasized.

A typical response looks like:

HTTP/1.1 200 OK\n
<some headers separated by newlines>
\n\n
<html>
....rest of page

Rules:

It only needs to work on port 80 (no SSL needed)
You may not use netcat
Whatever programming language is used, only low-level TCP APIs are allowed (except netcat)
You may not use GUI, remember, it's a CLI
You may not use HTML parsers, except builtin ones (BeautifulSoup is not a builtin)
Bonus!! If your program loops back and asks for another URL instead of exiting, -40 chars (as long as you don't use recursion)
No third-party programs. Remember, you can't install anything.
code-golf, so the shortest byte count wins

Pure Bash (no utilities), 200 bytes - 40 bonus = 160
while read u;do
u=${u#*//}
d=${u%%/*}
exec 3<>/dev/tcp/$d/80
echo "GET /${u#*/} HTTP/1.1
host:$d
Connection:close
">&3
mapfile -tu3 A
a=${A[@]}
a=${a#*
}
a=${a%
*}
echo "${a//<\/p>*
/"
"}"
done

I think this is up to the spec, though of course watch out for parsing HTML using regex I think the only thing worse than parsing HTML using regex is parsing HTML using shell pattern matching.
This now deals with
...
 spanning multiple lines.  Each
...
 is on a separate line of output:
$ echo "http://example.com/" | ./smallbrowse.sh
This domain is established to be used for illustrative examples in documents. You may use this     domain in examples without prior coordination or asking for permission.
More information...
$

Java 620 B
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class JavaApplication12 {

    public static void main(String[] args) {
        try {
            BufferedReader i = new BufferedReader(new InputStreamReader(new URL(args[0]).openStream()));
            String l;
            boolean print = false;
            while ((l = i.readLine()) != null) {
                if (l.toLowerCase().contains("<p>")) {
                    print = true;
                }
                if (print) {
                    if (l.toLowerCase().contains("</p>")) {
                        print = false;
                    }
                    System.out.println(l);
                }
            }

        } catch (Exception e) {

        }
    }

}


Call a method without calling it Inspired by a now deleted StackOverflow question. Can you come up with a way to get a particular method executed, without explicitly calling it? The more indirect it is, the better.

Here's what I mean, exactly (C used just for exemplification, all languages accepted):

// Call this.
void the_function(void)
{
    printf("Hi there!\n");
}

int main(int argc, char** argv)
{
    the_function(); // NO! Bad! This is a direct call.
    return 0;
}

Original question:

C

#include <stdio.h>

int puts(const char *str) {
  fputs("Hello, world!\n", stdout);
}

int main() {
  printf("Goodbye!\n");
}

When compiled with GCC, the compiler replaces printf("Goodbye!\n") with puts("Goodbye!"), which is simpler and is supposed to be equivalent. I've sneakily provided my custom puts function, so that gets called instead.

PHP
$print=function(){print('Hello World!');}
$print('Goodbye.');

in shrinked code, it is quite easy to miss the $ before the print.
and without the variable name in the code, let´s obfuscate a bit:
for($cc=64;++$cc<91;)${chr($cc);}=chr($cc);$p=$pr;$i=$in;
${"$p$i$t"}=function(){print('Hello World!');}
$print('Goodbye.');


It's [current year] already, folks, go home On most new-years challenges when it is currently not the corresponding year of the challenge, It says this in the front.

  It's [current year] already, folks, go home.

You have to output this text with the current year substituted.

I/O

Input: None.

Output: It's [year] already, folks, go home. with [year] changed to the current year.

bash + date, 40 bytes

date +"It's %Y already, folks, go home."

Try it online!

Excel VBA, 44 Bytes
Not sure if this is a cheat... assuming "It's" in in cell A1 on an Excel worksheet and " already, folks, go home." is in A3:
Msgbox Range("A1") & Year(Now) & Range("A3")


What are the five most powerful characters in your language? Choose any five characters your language supports. There are 5! = 5×4×3×2×1 = 120 ways these can be arranged into a 5-character string that contains each character once; 120 permutations.
Choose your characters such that, when each of the 120 strings is run in your language, the 120 outputs produced will be as many unique integers from 1 to 120 (inclusive) as possible.
That is, for each of the 120 permutations of your 5 characters that produce runnable code that outputs a single number, you want the set of all those numbers to match as close as possible to the set of integers from 1 through 120.
So, ideally, your first permutation would output 1, the next 2, the next 3, all the way up to 120. But that ideal is likely impossible for most languages and characters.
The 5-character strings may be run as:

a program with no input
a function with no arguments
a REPL command

Different strings can be run in different ways if desired
For the output to count, it must be a single integer output in a normal way, such as:

being printed to stdout
returned by  the function
the result of the REPL expression

The code should terminate normally (which may involve erroring out as long as the number has been output first). Code that does not run at all is fine, just the (nonexistent) output doesn't count. The numbers output should be in decimal unless a different base is the norm for your language.
The submission that generates the most distinct numbers from 1 through 120 wins. The earlier submission wins in case of a tie.
Notes

Your 5 characters do not all need to be different, but of course having duplicate characters reduces the effective number of permutations.
Float outputs such as 32.0 count as well as plain 32. (But 32.01 would not.)
Leading zeroes such as 032 count as well as plain 32.
Valid outputs should be deterministic and time invariant.
We are dealing with characters, not bytes.

Example
The characters 123+* are a reasonable first choice for Python's (or many language's) REPL. The resulting 120 permutations and outputs are:
123+* n/a
123*+ n/a
12+3* n/a
12+*3 n/a
12*3+ n/a
12*+3 36
132+* n/a
132*+ n/a
13+2* n/a
13+*2 n/a
13*2+ n/a
13*+2 26
1+23* n/a
1+2*3 7
1+32* n/a
1+3*2 7
1+*23 n/a
1+*32 n/a
1*23+ n/a
1*2+3 5
1*32+ n/a
1*3+2 5
1*+23 23
1*+32 32
213+* n/a
213*+ n/a
21+3* n/a
21+*3 n/a
21*3+ n/a
21*+3 63
231+* n/a
231*+ n/a
23+1* n/a
23+*1 n/a
23*1+ n/a
23*+1 23
2+13* n/a
2+1*3 5
2+31* n/a
2+3*1 5
2+*13 n/a
2+*31 n/a
2*13+ n/a
2*1+3 5
2*31+ n/a
2*3+1 7
2*+13 26
2*+31 62
312+* n/a
312*+ n/a
31+2* n/a
31+*2 n/a
31*2+ n/a
31*+2 62
321+* n/a
321*+ n/a
32+1* n/a
32+*1 n/a
32*1+ n/a
32*+1 32
3+12* n/a
3+1*2 5
3+21* n/a
3+2*1 5
3+*12 n/a
3+*21 n/a
3*12+ n/a
3*1+2 5
3*21+ n/a
3*2+1 7
3*+12 36
3*+21 63
+123* n/a
+12*3 36
+132* n/a
+13*2 26
+1*23 23
+1*32 32
+213* n/a
+21*3 63
+231* n/a
+23*1 23
+2*13 26
+2*31 62
+312* n/a
+31*2 62
+321* n/a
+32*1 32
+3*12 36
+3*21 63
+*123 n/a
+*132 n/a
+*213 n/a
+*231 n/a
+*312 n/a
+*321 n/a
*123+ n/a
*12+3 n/a
*132+ n/a
*13+2 n/a
*1+23 n/a
*1+32 n/a
*213+ n/a
*21+3 n/a
*231+ n/a
*23+1 n/a
*2+13 n/a
*2+31 n/a
*312+ n/a
*31+2 n/a
*321+ n/a
*32+1 n/a
*3+12 n/a
*3+21 n/a
*+123 n/a
*+132 n/a
*+213 n/a
*+231 n/a
*+312 n/a
*+321 n/a

There are 36 numbers generated, all luckily within 1 to 120:
36, 26, 7, 7, 5, 5, 23, 32, 63, 23, 5, 5, 5, 7, 26, 62, 62, 32, 5, 5, 5, 7, 36, 63, 36, 26, 23, 32, 63, 23, 26, 62, 62, 32, 36, 63

However, only 8 of them are unique:
36, 26, 7, 5, 23, 32, 63, 62

So such a submission would only score 8 out of a maximal 120.

Brainfuck, 3
<>+-.

It can produce -1 (or whatever the wraparound value is in the implementation), 0, or 1.
Unfortunately, since output in a loop is not counted, Brainfuck is very limited, since any loop is guaranteed to end on a 0, and the character space is too small to have both loop operators, +,-, output, and a register shift.


Swaps needed to sort an array in bubble sort method Write shortest code that detect how many swaps (minimum) are needed to sort (in increasing order) any array of unique positive integers. It should be fast enough to detect number of swaps in array of 1'000'000 integers in decreasing order in 1-2 minutes.

Refs

Bubble Sort on Wiki
Example implementations of bubble sort

Score

[time elapsed]s/60s * [length of code]

Python - 262 chars * 45 / 60 = 196.5

Edit: much faster sorting algorithm.

First it will sort all the items in the list by what hundred they are in (0, 100, 200, etc), in a list in m (note: I count these as 1 step each, so a list of 1,000,000 items will automatically have 1,000,000 steps initially)

Then it will sort the lists within m using the bubble sorting function c

This is greatly sped up from using c on the original list to be sorted, because the amount of time it takes to sort 1000 items is small (~0.04 seconds), but exponentially increases the larger the list gets (~45 seconds at 10,000 items). But if you sort 100 lists of 100 items, it only takes .4 seconds, to sort, more than 100 times faster than sorting 1 list of 10,000 items. It should therefor take 4 seconds to sort 100,000 items, and 40 seconds to finally sort 1,000,000

In actuality, it took 45 seconds to sort the reversed 1,000,000 item list this way, and results in 50,500,000 steps:

python bubblesortcount.py
50500000
44.6600000858

This functon works with the given case (reverse ordered list), as well as any random case. No negative integers, though.

r=range
def b(l):
 m=[[]for i in r(len(l)//100+1)];t=[];o=0
 for e in l:m[e//100].append(e);o+=1
 for e in m:x=c(e);t+=x[0];o+=x[1]
 return t,o
def c(l):
 s=0
 for p in r(len(l)-1,0,-1):
  for i in r(p):
   if l[i]>l[i+1]:l[i],l[i+1]=l[i+1],l[i];s+=1
 return l,s

test:

import random,time
a=time.time()
d=b(range(1000000)[::-1]) #reversed list
#d=b(random.sample(range(1000000),1000000)) #scrambled list
z=(time.time()-a)
#print d[0] # comment to not print a gigantic list
print d[1] # number of steps
print z # time it took

Edit: by changing the amount the helper function sorts by to 100, I reduced the average time it takes to sort the list to 45 seconds. also reduces character count by 2

edit again: you know what? maybe what I'm doing isn't valid. I can change the amount the helper function sorts by to just 1 and it will sort a million items in 5 seconds.. is this valid?

I understand this :

input = unique positive integers in decreasing order so we have    n,n-1,n-2.

And for output we want the minimum swap in order to get      n - 999, n -998 for example.

So given to these informations we are always in the worst case of bubblesort. So answer is always n².

So let's do it in ruby. a is the according array.

def b(a)
 (a.size -1) * (a.size / 2)
end

31 characters


Quine Anagrams! (Cops' Thread) This is the cops' thread. For the robbers' thread, click here.
Cops' Task

First, write a quine in a language of your choosing.
Next, scramble the quine. Make sure to do this well as the robbers will be trying to unscramble it and find the original source code! Note that the scrambled code does not need to work.
Post an answer on this thread. Include the language, the byte count, and the scrambled code.

Your program may not print to STDERR.
Here is an example of a cop submission:

Python, 29 bytes
nt _%=_r;_riinp;pr_='t _%%%_'

Robbers' Task
For the robbers' thread, click here.
Safe Submissions
If your submission has not yet been cracked after a week of posting, you may add the solution and specify that it is safe. If you do not, your submission may still be cracked.
Scoring
This is code-golf, so the user with the safe submission with the fewest bytes will be the winner of this section.
Leaderboard
Here is a stack snippet to generate a learderboard for this challenge. For it to display properly, please format your submission like this:
# Language Name, N bytes

... other stuff ...

If your submission gets cracked, please format like this:
# Language Name, N bytes, [Cracked!](link)

... other stuff ...

If your submission is safe, format like this:
# Language Name, N bytes, Safe!

... other stuff ...

C#, 288 bytes
Stag is a great shoW.        "="=""="="Agent"plastic"Was"tryin"to"Release"an"Astroid"."$Money$"st@le"tigers"and"Agent"plastic"got"mad"."$Money$"sic","man","t0tally"rad"."Sistrs"Rms"titAnic";"Civic"Ace"in"{sC@m}{hic}{vicis}..{cats}sAc}((@))((@)){{{>>{{{{{{}}}}}}}}}\\\\\\\;;;(@)((@)()),,;;

My strategy is for all the short ones to get cracked and nobody bothers with this considering how long it is... Also I suppose I should note that this is a full program, not just a function.

Jelly, 3 bytes, Cracked!
Ṙ”Ṙ

Try it online!
Here is the solution:

What, you want the solution? Find it!


Make a PNG image with "Hello World!" with programming APIs, in the shortest code possible So, I want you to make a PNG image that says "Hello world!" and nothing else on a distinguishable background using only an image making API (eg ImageMagick) and return the image. Fewest characters win, as usual. Oh, and you can use any color text.

Bash + ImageMagick: 35 33
Default font, default text size, default colours:
convert label:Hello\ world! a.png

and here's the result:

Thanks to DigitalTrauma and sch for the help :-D

Mouse: 0 chars

"right click" > "save image as"

Result:


Draw an Empty Scrabble Board A standard Scrabble board is a 15×15 grid of spaces to place letter tiles. Most of the spaces are blank but some are double word scores (pink), triple word scores (red), double letter scores (light blue), and triple letter scores (blue). There is usually a star in the very center (which counts as a double word score).

Write a program or function that outputs a standard, empty Scrabble board in ASCII form where:

. represents an empty space
D represents a double word score
T represents a triple word score
d represents a double letter score
t represents a triple letter score
X represents the center star

That is, your exact output must be

T..d...T...d..T
.D...t...t...D.
..D...d.d...D..
d..D...d...D..d
....D.....D....
.t...t...t...t.
..d...d.d...d..
T..d...X...d..T
..d...d.d...d..
.t...t...t...t.
....D.....D....
d..D...d...D..d
..D...d.d...D..
.D...t...t...D.
T..d...T...d..T

optionally followed by a trailing newline.

The shortest code in bytes wins.

MATL, 59 54 52 bytes

4t:g2I5vXdK8(3K23h32h(H14(t!XR+8: 7:Pht3$)'DtdTX.'w)

Try it online!

Explanation

The code follows three main steps:

Generate the 8x8 matrix

4 0 0 3 0 0 0 4
0 1 0 0 0 2 0 0
0 0 1 0 0 0 3 0
3 0 0 1 0 0 0 3
0 0 0 0 1 0 0 0
0 2 0 0 0 2 0 0
0 0 3 0 0 0 3 0
4 0 0 3 0 0 0 5

Extend it to the 15x15 matrix

4 0 0 3 0 0 0 4 0 0 0 3 0 0 4
0 1 0 0 0 2 0 0 0 2 0 0 0 1 0
0 0 1 0 0 0 3 0 3 0 0 0 1 0 0
3 0 0 1 0 0 0 3 0 0 0 1 0 0 3
0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 2 0 0 0 2 0 0 0 2 0 0 0 2 0
0 0 3 0 0 0 3 0 3 0 0 0 3 0 0
4 0 0 3 0 0 0 5 0 0 0 3 0 0 4
0 0 3 0 0 0 3 0 3 0 0 0 3 0 0
0 2 0 0 0 2 0 0 0 2 0 0 0 2 0
0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
3 0 0 1 0 0 0 3 0 0 0 1 0 0 3
0 0 1 0 0 0 3 0 3 0 0 0 1 0 0
0 1 0 0 0 2 0 0 0 2 0 0 0 1 0
4 0 0 3 0 0 0 4 0 0 0 3 0 0 4

Index the string 'DtdTX.' with that matrix to produce the desired result.

Step 1

4        % Push 4
t:       % Duplicate, range: pushes [1 2 3 4]
g        % Logical: convert to [1 1 1 1]
2I5      % Push 2, then 3, then 5
v        % Concatenate all stack vertically into vector [4 1 1 1 1 2 3 5]
Xd       % Generate diagonal matrix from that vector

Now we need to fill the nonzero off-diagonal entries. We will only fill those below the diagonal, and then make use symmetry to fill the others.

To fill each value we use linear indexing (see this answer, length-12 snippet). That means accessing the matrix as if it had only one dimension. For an 8×8 matrix, each value of the linear index refers to an entry as follows:

1   9         57
2  10         58
3  11
4
5  ...       ...
6
7             63
8  16 ... ... 64

So, the following assigns the value 4 to the lower-left entry:

K        % Push 4
8        % Push 8
(        % Assign 4 to the entry with linear index 8

The code for the value 3 is similar. In this case the index is a vector, because we need to fill several entries:

3        % Push 3
K        % Push 4
23h      % Push 23 and concatenate horizontally: [4 23]
32h      % Push 32 and concatenate horizontally: [4 23 32]
(        % Assign 4 to the entries specified by that vector

And for 2:

H        % Push 2
14       % Push 14
(        % Assign 2 to that entry

We now have the matrix

4 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
3 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 2 0 0 0 2 0 0
0 0 3 0 0 0 3 0
4 0 0 3 0 0 0 5

To fill the upper half we exploit symmetry:

t!       % Duplicate and transpose
XR       % Keep the upper triangular part without the diagonal
+        % Add element-wise

Step 2

The stack now contains the 8×8 matrix resulting from step 1. To extend this matrix we use indexing, this time in the two dimensions.

8:       % Push vector [1 2 ... 7 8]
7:P      % Push vector [7 6 ... 1]
h        % Concatenate horizontally: [1 2 ... 7 8 7 ... 2 1]. This will be the row index
t        % Duplicate. This will be the column index
3$       % Specify that the next function will take 3 inputs
)        % Index the 8×8 matrix with the two vectors. Gives a 15×15 matrix

Step 3

The stack now contains the 15×15 matrix resulting from step 2.

'DtdTX.' % Push this string
w        % Swap the two elements in the stack. This brings the matrix to the top
)        % Index the string with the matrix


recursive power algorithm Have a look at my (javascript) version of a O(log(n)) xn algorithm:

function pow(x,n)
{
     return n==0?1:n==1?x:n==2?x*x:pow(pow(x,(n-n%2)/2),2)*(n%2==0?1:x);
}

Can you get it shorter?

In python we have 2 methods for doing this :

def p(x,n,l):
    print pow(x,n,l)
def p1(x,n):
    print x**n
p(10,5,52)
p1(10,5)

Output corresponding to it is:

4
100000

The best part in python function is that it helps in modular power also (which is faster than finding power and then mod).In pow (n,m,l) It produces : (n^m)%l as the  output.


print 1 to 100 without using recursion and conditions can we print 1 to 100 without using any if conditions and loops in c&c++?

Conditon:
main point is you must not use recursion...and doesnt hardcode code in it
for e.g

print(1 2 3..etc);

C (90) (79) (59) (47) (42) (40)

static int

x=1;a(){char b[8];printf("%d\n",x++);b[24]-=5*(1-x/101);}main(){a();return 0;}

The function a which prints the numbers does not call itself! I exploited a buffer overflow and changed the return address to make the program counter go over function a again as long as I need.

I don't know if this is considered to be a recursion, but I thought it would worth trying.
This code works on my 64-bit machines with gcc 4.6, for other platforms the last statement of function a, could be a little different.

Exp1: I allocated a dummy buffer on stack b, and then addressed a passed-by-end location, which is the location of return address. I anticipated the distance between start of buffer and return address location from disassembly of function a.

Exp2: Expression 5*(1-x/101), is 5 for all x<=100 and 0 for x=101. By looking at disassembly of main (in my case), if you decrease the return address by 5, you will set the PC to calling point of a again. In the updated codes, the return value of printf is used for checking loop condition.

Update: After applying ugoren's suggestions and some other changes:

x;a(){int b[2];b[3*(printf("%d\n",++x)&2)]-=5;}main(){a();}

Update2: After Removing function a:

x;main(){int b[2];b[6^printf("%d ",++x)&4]-=7;}

Update3:

x;main(b){(&b)[1|printf("%d ",++x)&2]-=7;}

Update4: Thanks to mbz :)

x;main(b){(&b)[3|printf("%d ",++x)]-=7;}

Python - 61

Looping? No this is list comprehension.

d=[0,1,2,3,4,5,6,7,8,9];print[x*10+y+1 for x in d for y in d]


Element names above 118 IUPAC in their insufferable wisdom have created a systematic element name for any newly created element. This is the temporary name of an element until they finally make up their minds about an actual name. It works like so: each digit of an element number is assigned a prefix based on its value. The prefixes are concatenated with ‘ium’ at the end. When this is done and if you get double i’s (ii) or triple n’s (nnn), replace them with single i’s and double n’s. The symbol for the element is the first letter of each prefix used concatenated and result capitalized. The prefixes used are below.

0 nil       5 pent
1 un        6 hex
2 bi        7 sept
3 tri       8 oct
4 quad      9 enn

So for this golf, your code needs to generate both the element name and its symbol for a given positive integer. So if your code was given 137, it should print to stdout or return both untriseptium and Uts. It should be valid from at least 118 to 558. Any higher is valid if it doesn't increase your code's length.

Python example showing the method:

def elename(n):
    '''Return name and symbol of new element for given element number.'''
    prefixes=['nil','un','bi','tri','quad','pent','hex','sept','oct','enn']
    nmeFixes, symFixes = [], []

    while n:  # each digit of element number is assigned a prefix
        n, i = divmod(n, 10)
        pf = prefixes[i]

        symFixes.append(pf[0])  # symbol uses only first letter of prefix
        nmeFixes.append(pf)

    # loop assembled prefixes in reverse order
    nmeFixes.reverse()
    symFixes.reverse()

    nmeFixes.append('ium')  # suffix
    name = ''.join(nmeFixes)
    symb = ''.join(symFixes).capitalize()

    # apply rule about too many n's or i's
    name = name.replace('nnn','nn')  # can happen with -90-
    name = name.replace('ii','i')  # -2ium or -3ium

    return name, symb

Eric Towers wins with cadmium bytes!

Python 3, Unhexseptium (167) bytes

h=x='';r=str.replace
for i in input():s=r('nubtqphsoeinirueeecnl  ianxptn    dt t'[int(i)::10],' ','');h+=s;x+=s[0]
print(r(r(h+'ium\n','ii','i'),'nnn','nn')+x.title())

These are the results when the program is run on every number from 1 to 999 (inclusive)

Python, 154 bytes

import re
n=input('')
for c in n:
 print(re.sub('ii','i',re.sub('nnn','nn',['nil','un','bi','tri','quad','pent','hex','sept','oct','enn'][int(c)]+'ium')))


Build a code minifier Pick a programming language.

In that language, write a function or program that takes as input a string of working code (in the same language).

It should return/output a minified version of the input code.  The output should be functionally equivalent to the input.

Answers should contain both

The code that does the minifying (should be readable/non-golfed)
The resulting output after passing your code (that is, the code that does the minifying) in to itself

The shortest output wins.

Edit: notes explaining the minification methods you used are appreciated.

Edit: obviously, minification methods could vary from language to language, but a good-faith attempt at writing a minifier for this challenge would most likely perform actions such as

Removing unnecessary whitespace
Removing unnecessary newlines
Removing comments
Shortening variable names

Brainfuck

I always had in mind to do this, so here we go:

>>>,
[
[->+>+<<]             copy input

<<<+++++++++++++      fill cell with 13 for subtraction
[->+>+>+<<<]          and duplicate some times

>>>[->---<]           sub 39
>----                 43

[                     plus
-
[                     comma
-
[                     minus
-
[                     dot

<<[->>-<<]>>-         60

[                     less than
--
[                     greater than

<<<[->>>--<<<]>>>     86
---                   91

[                     open square bracket
--
[                     closing square bracket

>[-]                  remove copy

]]]]]]]]

>[.[-]>]              the copy has not been removed; print

<<[-]<<<[-]>[-]>      clean up

,]

Compresses itself to (144 characters):

>>>,[[->+>+<<]<<<+++++++++++++[->+>+>+<<<]>>>[->---<]>----[-[-[-[<<[->>-
<<]>>-[--[<<<[->>>--<<<]>>>---[--[>[-]]]]]]]]]>[.[-]>]<<[-]<<<[-]>[-]>,]

The size of the compressing could probably still reduced a bit. The compression alogorithm itself is near perfect, it's hard to do any more than removing non-+-[]<>,..

Bash, 17 characters output

They say my Python solution below isn't a minimizer. So here's one that does minimize, and it's even shorter:

 sed -e '1 s/^ //'

It reduces its own size from 18 to 17 characters.

Python, 38 character output

I misunderstood the question a bit, so my 0 character attempt was incorrect.
So I have a new and improved solution. I'd start a new answer, but since it's in the same spirit, I prefer to edit.
I'm sure it can be much improved, especially if you switch the language. But as it is, I'm still way ahead of the competition:

import sys
for l in sys.stdin:print l,

When given itself as input, you get a 100% equivalent program, 38 characters long.

Python, 0 character output (but not when run on itself, so it doesn't count).

import sys
program = [ l for l in sys.stdin ]
if len(program)>1 or program[0]!="x=12345\n":
    print "".join(program),

Sample input (also Python):

x=12345

I admit, it isn't very effective on most programs.
However, it reduces my example to 0 chars, still keeping it equivalent.

"The shortest output wins" - I don't think anyone can top this.


Write a program that always outputs "2012" - even if it's modified! This idea is not mine, though I don't know where it originated. I once met it in a programming contest very long ago (1998, if I remember correctly). The task is to write a program in your favorite language that outputs 2012 and only 2012. The catch is that the program must still output 2012 after any one of its characters is modified. The modification can be either insertion, deletion or replacement. Of course, the modification will be such that the program is still syntactically valid.

Since I don't know all the programming languages, I have to ask the audience to help me and test the answers submitted.

Added: Many have commented that my definition of acceptable modifications is too vague. Here's my second attempt: The allowed modifications will leave your program syntactically valid and will not cause it to crash. There, I think that should cover all the compile-time, link-time and run-time errors. Though I'm sure that there will be some odd edge case in some language anyway, so when that comes up we'll look at it individually.

C, 53 characters
main(){register*a="2012";(puts("2012"==a?a:"2012"));}

A bit longer than the scripting language answers, and follows the same basic principle. Relies on the fact that due to the constraints of C's syntax, the only letters that would be possible to change without making the program invalid are within the strings!
Edit: Shaved off 4 characters.
Reedit: Robustness increased, shaved off one character.
Re-redit: Longer, but more robust. Just try your & now! (Correctly this time).
Update: Shortened a bit; defeats most approaches seen so far.
Update: Changed int to void; should defeat the last possible approach to break it I can think of.
Update: I thunk of another approach; replacing the last a (may it rot) with 0; using two-letter names should deal with that problem.
Update: Last update revoked; assuming changes causing runtime errors are disallowed; a will work just fine.
Update: Backtracking some more; attempting to dereference *a will also segfault; so using void to tease a compile error out of it should not be necessary.
Update: And a final shortening; that relies on the string "2012" being placed at but one address (which is common); and that literal strings are read-only (also common).
Update: It cost me two characters, but I defeated your puny semi-colon!

Python 40 characters

a='2012';print(2012
)if a!='2012'else a

I don't think it's possible to get it any smaller with this approach in python.

edit: added 4 quotes to counter effects of -a on the end
edit: removed space


Generate unique non-sequential string of length n without memory of previously generated strings Scenario:

Imagine a situation where you wish to share a unique alphanumeric code. Perhaps it is a one-time-use coupon code you hand write on business cards, or some other scenario where it is desirable to have a code where mis-keying the entry is unlikely to produce valid result and the another valid code is not readily guessed.

However, when you are issuing these codes you do not have access to the list of codes that have already been issued. Rather, you know only how many have been issued before.

Challenge:

Write a function that generates a unique string of length n, subject to the following constraints:

Available Characters: Each character in resultant string shall be from a configurable list of allowed values, which may be "hard-coded" into the algorithm.

Sample List: A, B, C, D, E, F, G, H, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (A-Z and 0-9, omitting "I" and "J")

Configurable Length Output: The length n of the generated string shall be configurable within the algorithm, for n<=8.
Input: A seed is available (unique sequential positive integer >=1 and up to 10 digits)
Stateless: The algorithm has no memory of previously generated strings (no database calls)
Repeatable: The same seed shall yield the same result
Unordered Output: Sequential seed values shall not generate strings in any obvious order (that is to say, results should superficially "appear" random)

For example, 1:"AAAA", 2:"AAAB", 3:"AAAC", ... would NOT qualify, while 1:"RR8L", 2:"1D9R", 3:"TXP3", ... is on the right track.
Note: While this criterion is admittedly subjective, "degree of randomness" is not intended to be the core aspect of this function. Given the Popularity Contest format, I'll leave it up to the community to decide whether a pattern is too obvious.

Unique Output: String shall be unique, at least within limitations of available characters and requested string length. Therefore, each possible permutation is to be used exactly once before any combination may be reused.

For example, if configured to generate a string of length n=5 and the available characters include A-Z and 0-9 except for "O", "I" (34 possible characters), then the string may not repeat between seed>=1 and seed<=45,435,424.
However, if length n=4 with 34 available characters, then the same string need only be unique on seed>=1 and seed<=1,336,336

Winning Criteria:

Popularity Contest - Submission with the most upvotes will be selected as the winner no sooner than two weeks after the first valid solution. Please upvote any and all submissions you feel adequately meet the above criteria.

C(++) - we don't need no friggin' primes

The problem is to generate a different permutation of n characters taken from an a size alphabet for each seed value.

There are an such permutations, and they can be represented as values of a n digits number in base a.

The number of bits necessary to represent all these values is log2(an), rounded up.

We have at most 8 characters per code, and the alphabet contains at most 256 characters, so a 64 bits word is just what we need to cover all possible codes with all possible alphabets.

Now we just need something that maps all possible 232 seed values to the possible range of code values (and looks random enough).

I settled for a basic 32 bits reversal, which gives highest variability for low seed values.

If the possible codes range is smaller than the seed's, there will be duplicates anyway, and the codes will be like the n first digits of a greater number.

If the 232 seed values are not enough to cover all code values, the scrambled seed is extended to the smallest power of two inferior to code max value, by injecting 0s in the lower bits.

This should spread the range of code values while guaranteeing no duplicates.
However, the last digit will have a slightly lower frequency due to the rounding to a power of 2.
If alphabet size is much greater than 2, the difference will be hardly noticeable.

The scrambled seed is then converted as a number in base a, the digits being the symbols of the alphabet.

A few (pseudo) random thoughts

The big weakness of this method is that it won't work well with alphabets whose size is a power of two. The apparent randomness is due to the non-integer number of bits needed to encode a digit.

On second thought maybe we do need some friggin primes after all...

At any rate, even the most magnificent pseudo-random repartition is useless as far as data protection is concerned, since the encryption method is stateless and could be easily cracked by brute-force.

The code

I used the excellent bit shuffling generator of Mr. Jasper Neumann to produce the bit reverser, though other solutions are possible.

I compiled with g++4.8 under MinGW/Win7, but the code is nothing but glorified C and should work with any C++ compiler.

#include <cstdlib> // atoi
#include <cstdio>  // printf
#include <cmath>   // pow

#define Alphabet "ABCDEFGHKLMNOPQRSTUVWXYZ0123456789"
#define Length 8

unsigned bit_permute_step_simple(unsigned x, unsigned m, unsigned shift)
{
  return ((x & m) << shift) | ((x >> shift) & m);
}

unsigned shuffle (unsigned x)
{
    x = bit_permute_step_simple(x, 0x55555555, 1);  // Bit index complement 0
    x = bit_permute_step_simple(x, 0x33333333, 2);  // Bit index complement 1
    x = bit_permute_step_simple(x, 0x0f0f0f0f, 4);  // Bit index complement 2
    x = bit_permute_step_simple(x, 0x00ff00ff, 8);  // Bit index complement 3
    x = bit_permute_step_simple(x, 0x0000ffff, 16);  // Bit index complement 4
    return x;
}

#define Base (sizeof(Alphabet)-1)
typedef char Code[Length+1];

void gen_code (unsigned seed, Code code)
{
    // shuffle seed bits (the inversion is to avoid zero value for seed = 0)
    unsigned long long scrambled = shuffle(~seed);

    // if maximal code size is less than seed max value, there will be duplicates anyway
    int extra_bits = floor(Length * log(Base)/log(2)) - 32;
    if (extra_bits > 0) scrambled <<= extra_bits;

    // basic base conversion.
    // The last code digit might have a slightly lower frequency than others
    int i;
    for (i = 0 ; i != Length ; i++)
    {
        int digit = scrambled % Base;
        code[i] = Alphabet[digit];
        scrambled /= Base;
    }
    code[i] = '\0';
}

int main (int argc, char * argv[])
{
    if (argc != 2) exit(-1);
    unsigned seedm = atoi(argv[1]);
    Code code;

    for (unsigned seed = 0 ; seed != seedm ; seed++)
    {
        gen_code (seed, code);
        printf ("code (%u) = %s\n", seed, code);
    }

    return 0;
}

The main() prints a specified number of codes for consecutive seeds.

Sample output:

n=8, alphabet = ABCDEFGHKLMNOPQRSTUVWXYZ0123456789

code (0) = 215GVK7B
code (1) = MPPT46CX
code (2) = 4AF2E28Y
code (3) = GLGGAS6W
code (4) = U3MSPN2Y
code (5) = CR42Y97H
code (6) = WCWB943L
code (7) = CZW2XAAB
code (8) = UBHMSV6C
code (9) = CZ0W1HCY
code (10) = WMS5BD8Z
code (11) = 8UTL725X
code (12) = MDYVMY1Z
code (13) = 40F6VM7K
code (14) = OO7E6F3M
code (15) = U5L28BA5
code (16) = 08GMUH56
code (17) = KW0W35AS
code (18) = 2HS5D16T
code (19) = ESTL9Q4R

n=4, alphabet = ABCDE

code (0) = AEBD
code (1) = CEAE
code (2) = BEDD
code (3) = DECE
code (4) = DBAB
code (5) = ACEB
code (6) = EBCB
code (7) = BCBC
code (8) = ECDE
code (9) = BDCA
code (10) = ADAA
code (11) = CDEA
code (12) = CACC
code (13) = EABD
code (14) = DAEC
code (15) = ABDD
code (16) = CDCB
code (17) = EDBC
code (18) = DDEB
code (19) = AEDC

Simplicity (python 2)

This may not be in the spirit of the challenge, but it works, and is far simpler than the other algorithms.

import random
from string import uppercase

def unique_code(n, seed, alphabet):
    pre_state = random.getstate() #so we don't interfere outside scope
    random.seed(seed)
    code = ''.join([random.choice(alphabet) for _ in xrange(n)])
    random.setstate(pre_state)
    return code

length = 4
for i in range(20):
    print '{} [seed {:d}]'.format(unique_code(length, i, uppercase), i)

Running this code gives:

VTKG [seed 0]
DWTG [seed 1]
YYBC [seed 2]
GOJP [seed 3]
GCKE [seed 4]
QTUY [seed 5]
UVMG [seed 6]
IDQB [seed 7]
FZDS [seed 8]
MJDW [seed 9]
OLPF [seed 10]
LOYM [seed 11]
MRRD [seed 12]
GRRW [seed 13]
CSQY [seed 14]
ZATE [seed 15]
JMKL [seed 16]
NUYH [seed 17]
ERIF [seed 18]
RUNN [seed 19]


Print every character your program doesn't have Your task is to build a program (using only printable ASCII characters and/or tabs and newlines) that prints out exactly the characters in the printable ASCII space (0x20 to 0x7e) that don't appear in your program's source code (in any order, however many times you want).

The shortest code to do this in any language wins.

Polyglot, 95

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

Perl
Perl 6
Any *nx-like shell (tclsh, bash, sh, ksh, etc)
Awk (GNU / POSIX)
Brainfuck, Brian & Chuck, other derivatives
Ruby
Coffescript
Golfscript
Python
R
Julia
Whitespace
rk
Gaot++
bc
jq
Joy
Tcl
99
V (FMota)
Acc!!
C - if no main() is needed. Thanks to urogen
Probably more.

Does nothing.

Groovy: 52 chars

print(((' '..'~')-new File('a').text.grep()).join())

// print all characters from '#' to '~', except those present in the file itself (the name of the source file is 'a').


Sort numbers by binary 1's count Goal

Write a function or program sort an array of integers in descending order by the number of 1's present in their binary representation.  No secondary sort condition is necessary.

Example sorted list

(using 16-bit integers)

  Dec                Bin        1's
16375   0011111111110111        13
15342   0011101111101110        11
32425   0111111010101001        10
11746   0010110111100010         8
28436   0000110111110100         8
19944   0100110111101000         8
28943   0000011100011111         8
 3944   0000011111101000         7
15752   0011110110001000         7
  825   0000000011111001         6
21826   0101010101000010         6

Input

An array of 32-bit integers.

Output

An array of the same integers sorted as described.

Scoring

This is code golf for the least number of bytes to be selected in one week's time.

Python-40 bytes

l.sorted(key=lambda x:bin(x).count('1'))

second to K!! Thwarted by K once again.......


Array Merge without Duplicates I recently saw this Javascript code on StackOverflow for merging two arrays, and removing duplicates:

Array.prototype.unique = function() {
    var a = this.concat();
    for(var i=0; i<a.length; ++i) {
        for(var j=i+1; j<a.length; ++j) {
            if(a[i] === a[j])
                a.splice(j--, 1);
        }
    }
    return a;
};

var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
var array3 = array1.concat(array2).unique();

While this code works, it is horribly inefficient (O(n^2)). Your challenge is to make an algorithm with less complexity.

The winning criteria is the solution with the least complexity, but ties will be broken by shortest length in characters.

Requirements:

Package all your code together in a function that meets the following requirements for "correctness:"

Input: Two arrays
Output: One array
Merges elements of both arrays together- Any element in either input array must be in the outputted array.
The outputted array should have no duplicates.
Order doesn't matter (unlike the original)
Any language counts
Don't use the standard library's array functions for detecting uniqueness or merging sets/arrays (although other things from the standard library is okay). Let me make the distinction that array concatenation is fine, but functions that already do all of the above are not.

JavaScript O(N) 131 124 116 92 (86?)

Golfed version:

function m(i,x){h={};n=[];for(a=2;a--;i=x)i.map(function(b){h[b]=h[b]||n.push(b)});return n}

Human readable golfed version:

function m(i,x) {
   h = {}
   n = []
   for (a = 2; a--; i=x)
      i.map(function(b){
        h[b] = h[b] || n.push(b)
      })
   return n
}

I could use concat like so and do it in 86 characters:

function m(i,x){h={};n=[];i.concat(x).map(function(b){h[b]=h[b]||n.push(b)});return n}

But I am not sure if it is still O(N) based on this JsPerf: http://jsperf.com/unique-array-merging-concat-vs-looping as the concat version is marginally faster with smaller arrays but slower with larger arrays (Chrome 31 OSX).

In practice do this (golf is full of bad practices):

function merge(a1, a2) {
   var hash = {};
   var arr = [];
   for (var i = 0; i < a1.length; i++) {
      if (hash[a1[i]] !== true) {
        hash[a1[i]] = true;
        arr[arr.length] = a1[i];
      }
   }
   for (var i = 0; i < a2.length; i++) {
      if (hash[a2[i]] !== true) {
        hash[a2[i]] = true;
        arr[arr.length] = a2[i];
      }
   }
   return arr;
}
console.log(merge([1,2,3,4,5],[1,2,3,4,5,6]));

I'm not great at computing complexity but I believe this is O(N). Would love if someone could clarify.

Edit: Here is a version that takes any number of arrays and merges them.

function merge() {
   var args = arguments;
   var hash = {};
   var arr = [];
   for (var i = 0; i < args.length; i++) {
      for (var j = 0; j < args[i].length; j++) {
        if (hash[args[i][j]] !== true) {
          arr[arr.length] = args[i][j];
          hash[args[i][j]] = true;
        }
      }
    }
   return arr;
}
console.log(merge([1,2,3,4,5],[1,2,3,4,5,6],[1,2,3,4,5,6,7],[1,2,3,4,5,6,7,8]));

JavaScript, 131 characters

var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
result = Array.from(new Set([...array1, ...array2]))


Hello world! with limited character repetition In a language of your choice, write a program that exactly outputs the characters Hello world! followed by a newline. The code:

should not use any character more than twice (alphanumeric, symbol, whitespace...anything)
should not use any external resources
should not use any user input
should not output anything else

An example of a valid python program:

print("He%so world!"%(2*'l'))

An example of an invalid python program (the character 'r' is used three times):

print("Hel"+chr(108)+'o world!')

Winner is whoever has the most votes after 14 days.

EDIT:  A winner has been chosen!  Thanks all for your work on this question!

Ruby (1.9+)

Since this is a popularity contest let's try to not use ANY of the characters from 'Hello world!' while still using other characters only a maximum of two times:

puts("S\107VsbG8gV29ybGQhCg".unpack(?m))

It's 40 chars btw.

Bash

And this one uses unicode magic.

Notes:

While the orignal characters appear elsewhere (unlike the ruby example), the printed string contains only non-ascii characters.
Two from the three spaces are actually tabs, so there are no utf-8 characters that appear more than 2 times
As binary some of the octets do appear more than 2 times, hopefully that's not against the rules. I'm trying to resolve them though.

Code:

echo ' ¡'|iconv -t  asCIi//TRANSLIT

For those who don't have a proper font installed it looks like this:

Here is the hexdump:

00000000  65 63 68 6f 20 27 f0 9d  93 97 f0 9d 90 9e f0 9d  |echo '..........|
00000010  91 99 f0 9d 92 8d f0 9d  93 b8 e2 80 8a f0 9d 93  |................|
00000020  a6 f0 9d 97 88 f0 9d 96  97 f0 9d 96 91 f0 9d 98  |................|
00000030  a5 c2 a1 27 7c 69 63 6f  6e 76 09 2d 74 09 61 73  |...'|iconv.-t.as|
00000040  43 49 69 2f 2f 54 52 41  4e 53 4c 49 54 0a        |CIi//TRANSLIT.|
0000004e

You have to run it on a machine where the default charset is utf-8. I tried on an OSX10.8 using iTerm2 with the following environment:

PHP 5.4

This uses zLib: (unfortunately it does uses the characters e and o)

<?=gzuncompress('x▒▒H▒▒▒W(▒/▒IQ▒!qh');

Hexdump:

00000000  3c 3f 3d 67 7a 75 6e 63  6f 6d 70 72 65 73 73 28  |<?=gzuncompress(|
00000010  27 78 9c f3 48 cd c9 c9  57 28 cf 2f ca 49 51 e4  |'x..H...W(./.IQ.|
00000020  02 00 21 71 04 68 27 29  3b                       |..!q.h');|
00000029

+1

Here is the ruby 2.0 code I used to test for duplicates:

d=ARGF.read
p [d.split(//),d.unpack('C*')].map{|x|x.inject(Hash.new(0)){|i,s|i[s]+=1;i}.select{|k,v|v>2}}

Java

Okay I found this on SO, it doesn't output a big H

Rare sequence of random stream of digits for 2 specific seeds.
Probably fixed out by brute forcing
One of the SO solutions also include a brute forcer to make your own sequences.

System.out.println(randomString(-229985452) + " " + randomString(-147909649) + "!");

And randomString() looks like this

public static String randomString(int i)
{
    Random ran = new Random(i);
    StringBuilder sb = new StringBuilder();
    for (int n = 0; ; n++)
    {
        int k = ran.nextInt(27);
        if (k == 0)
            break;

        sb.append((char)('`' + k));
    }

    return sb.toString();
}

Source: https://stackoverflow.com/questions/15182496/why-does-this-code-print-hello-world


I'm not the language you're looking for! Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this.

Challenge

You will have to write a program that when run in two different languages, will output the string:

This program wasn't written in <language program compiled/interpreted in>, it was built for <other language the program can be run in>!

In the output, language names should have official capitalization. eg: CJam, C++
Neither program should take any input from the user.
When run in both languages, output should be to stdout or equivalent.
There should be no output to stderr in either program.
You may use comments in either language.
Two different versions of the same language count as different languages.

If this is done, the program should output the major version number, and if running on two different minor versions, should report the minor version also.
You should not use prebuilt version functions (this includes variables that have already been evaluated at runtime).

Example output:

Perl and Ruby:

Perl: This program wasn't written in Perl, it was built for Ruby!
Ruby: This program wasn't written in Ruby, it was built for Perl!

Python and C:

Python: This program wasn't written in Python, it was built for C!
C: This program wasn't written in C, it was built for Python!

Python 2 and Python 3:

Python 2: This program wasn't written in Python 2, it was built for Python 3!
Python 3: This program wasn't written in Python 3, it was built for Python 2!

Python 2.4 and Python 2.7:

Python 2.4: This program wasn't written in Python 2.4, it was built for Python 2.7!
Python 2.7: This program wasn't written in Python 2.7, it was built for Python 2.4!

This is code golf so the shortest code in bytes wins.

C89/C99, 171 152 136 114 111 107 105 bytes

Thanks at @Hurkyls, @Qwertiys, @jimmy23013 and @MD XF for your hints.

golfed version:

c;main(){c=-4.5//**/
-4.5;printf("This program wasn't written in C%d, it was built for C%d!",90-c,98+c);}

ungolfed version:

c;

main()
{
    c = -4.5//**/
    -4.5;
    printf("This program wasn't written in C%d, it was built for C%d!",90-c,98+c);
}

Little description:

C versions previous C99 just had the multiline comment like this:

/*foo*/

with C99 the single line comment was introduced. like this:

//foo

so if you compile a line like this:

c =-4.5//**/
-4.5;

the for the c99 compiler compiling-related code would be:

c = -4.5 -4.5;

while the for a c89 compiler relevant code would be:

(as the first / isn't part of a comment and therfor treat as operator)

c = -4.5 / -4.5;

JavaScript ES6 / Python2, 98 bytes, REPL ONLY

js = 'python'
python = 'js'
s = 'this program is not ' + `js` + ', it was built for ' + `python`
s

Tested with Python 2.7.10 and Chrome 52.

The caveat here is actually printing the output....Python uses print s and JS uses console.log(js). So instead I assume you are using a REPL and that s alone will print to stdout.


Print out the first N characters of your code You should write a program or function that receives a positive integer N as input and prints out the first N characters of your code. If N is larger than the length of your code you should continue output your code cyclically.

Reading your source code in any way and reading from file, stdio, etc. are disallowed.

Examples

(assuming your code is yourcode)

Input => Output:

5 => yourc
10 => yourcodeyo
22 => yourcodeyourcodeyour

Clarification

Your program should be at least 1 byte long.

Python 2, 61 bytes

def f(n):a='def f(n):a=%r;print(a%%a*n)[:n]';print(a%a*n)[:n]

Try it online!

Tcl, 31 bytes

puts [read [open $argv0] $argv]

Try it online!


Addition/Multiplication table generator Given a number and either "+" or "*", return an addition or multiplication table with the dimensions of that number.

Specifications

The input will be formatted as dimension, operation.
The program should not return anything if the operation input is not + or *.
The program should not return anything if the dimension input is less than 1.

(4,*):
1 2 3 4
2 4 6 8
3 6 9 12
4 8 1216

(4,+):
1234
2456
3567
4678

The spaces between the numbers in the table should be equal to one less than the number of digits in dimension^2 for multiplication, and for addition one less than the number of digits in dimension * 2.

Bash + BSD Utils, 62 bytes

l=$[$1*$1-1]
eval echo \$[{1..$1}$2{1..$1}]|rs -g${#l} $[$1+1]

This calculates the number of spaces as per "number of digits in (dimension^2)-1", and not as shown in the example output, as currently written.
This answer is very similar to this one.
Works out-of-the-box on macOS.  rs may need to be installed on Linux systems:
sudo apt-get install rs

Python 3 - 140 bytes
a=lambda d,o:print(*map(lambda f:(' '*~-len(str([d,2][o>'*']*d))).join([str([i*f,i+f][o>'*'])for i in range(1,d+1)]),range(1,d+1)),sep='\n')


Output Pi without math In as few bytes as possible, your job is to write a program that outputs:

3.14

In celebration of a late Pi day of course! :)

Rules

You can do it anyway you like, but there are some restrictions.

You may not use arithmetic operations anywhere in your program. This includes +, -, *, /, %, ^ (exponentiation), etc... This also includes incrementing (usually ++), decrementing (--), bitwise operations, and any built in functions that can be used as a replacement such as sum(), prod(), mod(), double(), pow(), sqrt(), inc(), dec(), etc... (Author's discretion)
The digits 3, 1, and 4 may not appear anywhere in your code.
You may not use any predefined variables/constants that your language may have as a replacement for 3, 1, and 4. (Author's discretion)
You may also not use any trigonometric functions such as sin(), cos(), tan(), arcsin(), arccos(), arctan(), sinh(), cosh(), tanh(), etc... (Author's discretion)
You may not use built-in or predefined values of Pi (or 3.14). No web requests.
Your program cannot require input of any kind (besides running it).
3.14 is the only thing that you may output, it cannot be part of some longer/larger output..

Winner

The answer with the least amount of bytes on April 18th wins. Good luck!

Looking forward to clever answers from clever minds! Malbolge anyone? :P

PHP - 22 bytes

<?=date('n.j',8899e5);

Pi Day in year 1998 was really cool!

C++, 214 202
Only works for little-endian processors... Big-endian version would be shorter.
#include<algorithm>
#include<iostream>
#include<iterator>
union u{int i;char c[];};struct s{u a,b;};int main(){s x;x.a.i=858665268;std::reverse_copy(x.a.c,x.b.c,std::ostream_iterator<char>(std::cout));}


Weirdest obfuscated "Hello World!" Task:

Create an obfuscated program that prints Hello World! (exactly like that). Your program may not have any strings in it.

Rules:

You can use any programming language you like.
Make it as obfuscated as possible
This is a popularity-contest, so the answer with the most upvotes wins.

Note:

This is not a duplicate of this question. That one was code-golf and it had different rules.

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ObfuscatedHelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            int[,] y = new int[,]  {{p(), p(), p(), n(), n(), n(), p(), n(), },
                                    {p(), p(), n(), n(), p(), p(), p(), p(), },
                                    {p(), p(), n(), n(), n(), p(), p(), n(), },
                                    {p(), p(), n(), n(), n(), p(), p(), n(), },
                                    {p(), p(), n(), n(), n(), p(), n(), p(), },
                                    {p(), n(), n(), n(), p(), n(), p(), n(), },
                                    {p(), p(), p(), p(), p(), p(), n(), p(), },
                                    {p(), p(), n(), n(), n(), p(), n(), p(), },
                                    {p(), p(), n(), p(), p(), n(), n(), n(), },
                                    {p(), p(), n(), n(), n(), p(), p(), n(), },
                                    {p(), p(), n(), n(), p(), p(), p(), n(), },
                                    {p(), n(), n(), n(), p(), n(), p(), p(), }, };
            for (int i = 0; i < s(gr().ToArray()[21], 1) / gr().ToArray()[1]; i++)
            {
                bool[] h = new bool[8];
                for (int j = 0; j < 8; j++)
                {
                    h[j] = pr(y[i,j]);
                }
                cw(Encoding.ASCII.GetString(new byte[]{o(b(h), b())}));
            }
        }
        static void cw(string st)
        {
            using (StreamWriter s = new StreamWriter(Console.OpenStandardOutput()))
            {
                foreach (char c in st)
                    s.Write(c);
            }
        }
        static byte o(byte c, byte z)
        {
            int l = s((0xAA00 ^ 0x0), -8);
            l |= z;
            return (byte)(c ^ l);
        }
        static byte b()
        {
            return (byte)s(0xFF, s(4097,3));
        }
        static byte b(bool[] a)
        {
            byte v = 0;
            foreach (bool b in a)
            {
                v = (byte)s(v, 1);
                if (b) v |= 1;
            }
            return v;
        }
        static int s(int i, int s)
        {
            if (s > 0)
            {
                i <<= s;
                return i;
            }
            i >>= s + (s << 1);
            return i;
        }
        static string pa(string st)
        {
            for (int il = 0; il < s(gr().ToArray()[11], 1) - st.Length; il++)
                st = "0" + st;
            return st;
        }
        static IEnumerable<byte> gr()
        {
            byte[] m = Convert.FromBase64String("AwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZg==");
            foreach (byte bh in m)
                yield return o(o(bh, b()), b());
        }
        static byte eb(bool[] ar)
        {
            byte v = 0;
            foreach (bool b in ar)
            {
                v <<= gr().ToArray()[1] - 3;
                if (b) v |= (byte)(gr().ToArray()[8] - gr().ToArray()[7]);
            }
            return v;
        }
        static int p()
        {
            foreach(byte b in gr())
                if (pr(b))
                    return b;
            return gr().ToArray()[gr().ToArray()[8] - gr().ToArray()[6]];
        }
        static int n()
        {
            foreach (byte b in gr())
                if (!pr(b))
                    return b;
            return gr().ToArray()[gr().ToArray()[0]];
        }
        static bool f(bool g)
        {
            return ((l(g) << gr().ToArray()[0] - 2) % gr().ToArray()[3] - 3 == 0);
        }
        static int l(bool k)
        {
            return (k ? (gr().ToArray()[12] >> gr().ToArray()[1]) : 0);
        }
        static bool pr(int t)
        {
            for (int i = gr().ToArray()[0] - 1; i < t; i++)
                if (t % i == 0)
                    return false;
            return true;
        }
    }
}


The Smart Person's Mirage Once upon a time, I was reading this question/answer on Quora

Are there really programmers with computer science degrees who cannot pass the FizzBuzz test

This code is given as the obvious answer

for i in range(1, 100):
    if i % 3 == 0 and i % 5 == 0:
        print "FizzBuzz"
    elif i % 3 == 0:
        print "Fizz"
    elif i % 5 == 0:
        print "Buzz"
    else:
        print i

Of course FizzBuzz has been golfed to death, but that is not what this question is about. You see, in the comments, someone mentions that this obvious answer is great since it's easy to add extra conditions such as print "Jazz" for multiples of 4. (I don't agree. Extending this scheme requires O(2**n) lines of code.)

Your challenge is to write the most beautiful version of FizzJazzBuzz as judged by your peers.

Some things for voters to consider:

DRY
Efficiency of division/modulus operations

Many of the answers on Quora were using Python, but there is no such language restriction here.

I'll accept the answer with the most votes one month from now

Sample output:

1
2
Fizz
Jazz
Buzz
Fizz
7
Jazz
Fizz
Buzz
11
FizzJazz
13
14
FizzBuzz
Jazz
17
Fizz
19
JazzBuzz
Fizz
22
23
FizzJazz
Buzz
26
Fizz
Jazz
29
FizzBuzz
31
Jazz
Fizz
34
Buzz
FizzJazz
37
38
Fizz
JazzBuzz
41
Fizz
43
Jazz
FizzBuzz
46
47
FizzJazz
49
Buzz
Fizz
Jazz
53
Fizz
Buzz
Jazz
Fizz
58
59
FizzJazzBuzz
61
62
Fizz
Jazz
Buzz
Fizz
67
Jazz
Fizz
Buzz
71
FizzJazz
73
74
FizzBuzz
Jazz
77
Fizz
79
JazzBuzz
Fizz
82
83
FizzJazz
Buzz
86
Fizz
Jazz
89
FizzBuzz
91
Jazz
Fizz
94
Buzz
FizzJazz
97
98
Fizz
JazzBuzz

The most beautiful version, you say? Then, let's try this one in...

Shakespeare Programming Language

The Marvelously Insane FizzBuzzJazz Program.

Lady Capulet, an old bossy woman that loves to count.
The Archbishop of Canterbury, an old fart who adores to spit out letters.

          Act I: The only one of them.

          Scene I: The Archbishop of Canterbury is a bastard.

[Enter The Archbishop of Canterbury and Lady Capulet]

The Archbishop of Canterbury:
 You are nothing!

          Scene II: Count, Lady Capulet, count.

The Archbishop of Canterbury:
 You are as beautiful as the sum of yourself and a cat!

Lady Capulet:
 Am I worse than the square of the product of the sum of a warm gentle flower and a rose
 and my pretty angel?

The Archbishop of Canterbury:
 If not, let us proceed to Scene VIII.

          Scene III: Fizzing to no end!

The Archbishop of Canterbury:
 Is the remainder of the quotient between yourself and the sum of a happy cow and a
 chihuahua as good as nothing?

Lady Capulet:
 If not, let us proceed to Scene IV. Thou art as handsome as the sum of the sum of
 the sweetest reddest prettiest warm gentle peaceful fair rose and a happy proud kindgom
 and a big roman. Speak thy mind!

 Thou art as fair as the sum of thyself and a honest delicious cute blossoming peaceful
 hamster. Thou art as cunning as the sum of the sum of an embroidered King and a horse
 and thyself. Speak thy mind!

 Thou art as amazing as the sum of the sum of a good happy proud rich hero and a hair and
 thyself! Speak thy mind.

 Speak your mind!

          Scene IV: Milady, there is jazz in thy robe.

The Archbishop of Canterbury:
 Is the remainder of the quotient between yourself and a proud noble kingdom as good as
 nothing?

Lady Capulet:
 If not, let us proceed to Scene V. You are as charming as the sum of the sum of a noble
 cunning gentle embroidered brave mighty King and a big warm chihuahua and an amazing
 pony! Speak your mind!

 You are as prompt as the sum of yourself and a big black sweet animal. You are as noble
 as the sum of the sum of a gentle trustworthy lantern and yourself and a hog. Speak your
 mind!

 You are as bold as the sum of the sum of yourself and a good delicious healthy sweet
 horse and my smooth cute embroidered purse. You are as peaceful as the sum of a flower
 and yourself. Speak your mind.

 Speak your mind!

          Scene V: Buzz me up, Scotty!

The Archbishop of Canterbury:
 Is the remainder of the quotient between yourself and the sum of a gentle happy cow and a
 chihuahua as good as nothing?

Lady Capulet:
 If not, let us proceed to Scene VI. Thou art as handsome as the sum of the sweetest
 reddest prettiest warm gentle peaceful fair rose and a small town. Speak your mind!

 You are as prompt as the sum of yourself and a big healthy peaceful fair rich kingdom.
 You are as loving as the sum of the sum of an embroidered King and a horse and thyself.
 You are as amazing as the sum of yourself and a cute fine smooth sweet hamster. Speak
 your mind!

 You are as prompt as the sum of the sum of yourself and an amazing cunning Lord and a
 hair. Speak your mind.

 Speak your mind!

The Archbishop of Canterbury:
 Let us proceed to Scene VII.

          Scene VI: Output or die!

The Archbishop of Canterbury:
 Open your heart!

          Scene VII: Oh, to jump the line.

Lady Capulet:
 You are as handsome as the sum of a proud noble rich kingdom and a rural town. Speak your
 mind! You are as gentle as the sum of the sum of yourself and a green mistletoe and my
 father. Speak your mind!

The Archbishop of Canterbury:
 We must return to Scene II.

          Scene VIII: Goodbye, cruel world!

[Exeunt]

So, after my struggle with SPL here, I felt like I had to do at least one submission with it on any challenge. And this is it.

So, what's all this then?

So, first, we declare the variables we're going to use throughout the program, which must come from Shakespeare plays. Fed up of Romeo, Juliet, Ophelia and Othello, I went up with The Archbishop of Canterbury and Lady Capulet. Their descriptions, as well as the Acts'/Scenes' titles, are disgarded by the parser, so you can put there pretty much anything you like.

So, let's make some king of translation to something a little less gibberishy.

Act I, Scene I

Begin
Lady Capulet = 0;

Act I is pretty straightforward: we initialize our variable with 0.

Act I, Scene II

Lady Capulet += 1;
if(Lady Capulet < Math.pow((2*2*1+1)*(2*1),2))
continue;
else
goto Scene VIII;

We increment Lady Capulet's value and compare it with 100 (yes, that whole sentence serves solely to get the number 100); if it's not smaller, we jump to Scene VIII (the end); otherwise, we continue on to the next Scene.

Act I, Scene III

if(Lady Capulet % (2+1) == 0)
continue;
else
goto Scene IV;
The Archbishop of Canterbury = 2*2*2*2*2*2*1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2*2*2*2*1;
The Archbishop of Canterbury += 2*1+1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2*2*2*1+1;
System.out.print((char)The Archbishop of Canterbury);
System.out.print((char)The Archbishop of Canterbury);

First, we see if the modulus of the division by 3 is 0; if it's not, we jump to Scene IV; if it is, we begin doing arithmetic operations and storing them on the Archieperson, outputting them in character form once we find the one we're looking for. Yes, in the end, the idea is to get Fizz.

Act I, Scene IV

if(Lady Capulet % (2*2) == 0)
continue;
else
goto Scene V;
The Archbishop of Canterbury = 2*2*2*2*2*2*1+2*2*1+2*1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2*2*1;
The Archbishop of Canterbury += 2*2*1+(-1);
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2*2*2*1+2*2*2*1;
The Archbishop of Canterbury += 1;
System.out.print((char)The Archbishop of Canterbury);
System.out.print((char)The Archbishop of Canterbury);

First checks if the modulus of the division by 4 is 0, then continues as the same scene as before, for Jazz.

Act I, Scene V

if(Lady Capulet % (2*2+1) == 0)
continue;
else
goto Scene VI;
The Archbishop of Canterbury = 2*2*2*2*2*2*1+2*1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2*2*2*2*1;
The Archbishop of Canterbury += 2*1+1;
The Archbishop of Canterbury += 2*2*2*2*1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*2+1;
System.out.print((char)The Archbishop of Canterbury);
System.out.print((char)The Archbishop of Canterbury);
goto Scene VII;

Functions like the previous two, checking if the modulus of the division by 5 returns 0, then attempts to write Buzz; the only difference is that, in the end, we skip a Scene.

Act I, Scene VI

System.out.print(Lady Capulet);

To reach this Scene, the number assumed by Lady Capulet must not have been neither Fizz nor Jazz nor Buzz; so, we output it in numeric form.

Act I, Scene VII

The Archbishop of Canterbury = 2*2*2*1+2*1;
System.out.print((char)The Archbishop of Canterbury);
The Archbishop of Canterbury += 2*1+1;
System.out.print((char)The Archbishop of Canterbury);
goto Scene II;

So, this is the only way I found to jump to the next line: output, first, a CR, then a LF; then, we return to Scene II, to that we can continue with the program.

Act I, Scene VIII

End.

Straightforward enough.

I'm still trying to see if I could show this running online, but I can't find an online compiler - the one I know doesn't seem to combine well with any program except the one already loaded, or maybe there's some kind of problem with the interface between the keyboard and the chair...

Update 1:

After mathmandan's comment, I edited the order of Jazz's and Buzz's scenes. It had to be done.

JavaScriptDRY && OO

In the lack of DRY solutions not using modulus/division I wrote it.
Also it's an exercise in OO (yes, I know there's no real OO with JS)

You can see it running at JSFiddle

//FizzJazzBuzz
var zzClass = function(){

    this.divisor;
    this.word;
    this.count;
};

zzClass.prototype = {
    isZZ : function(){
        if (this.count == this.divisor)
        {
            this.count = 1;
            return this.word;
        }
        else
        {
           this.count++;
           return '';
        }
    }
}

function initZZ(w,d)
{
    var x = Object.create(zzClass.prototype
       , { divisor :{ value : d }, word: { value : w } }
     );

     x.count = 1;

     return x;
}

// Declare array of ZZ's
var arrZZ = [
    initZZ('Fizz',3),
    initZZ('Jazz',4),
    initZZ('Buzz',5)
    ]

var phrase = '';

for (var i = 1; i < 101; i++)
{
    phrase = '';

    for (var j=0; j<arrZZ.length; j++)
    {
        phrase = phrase + arrZZ[j].isZZ();
    }

    if (phrase == '') phrase = i;

    console.log(phrase);
}

We presume using a simple conditional and a variable to count when to print is "cheaper" than using modulus or division. An efficient way to calculate a minimum common multiple