text:
maximum subarray variant
Problem
There is a circular track containing fuel pits at irregular intervals. The total amount of fuel available from all the pits together is just sufficient to travel round the track and finish where you started. Given the the circuit perimeter, list of each fuel pit location and the amount of fuel they contain, find the optimal start point on the track such that you never run out of fuel and complete circuit.
Sample Input
(location, fuel)

(0/100, 6)
(2,16)
(18,1)
(30,45)
(84,5)
(92,27)

circuit length - 100, total fuel-100

Most of the simplifying assumptions are obvious, but what do you mean by "optimal"? And given that whatever you mean I can construct an input which doesn't have a unique answer, how should that be handled?

"optimal" means a choosing a start point X such that you can finish journey and again reach back X, without failing in the middle due to fuel outage. You can run out of fuel after crossing a few pits, if calculation isn't done properly. In case of multiple answers, list all.

If the "total amount of fuel available from all the pits together is just sufficient to travel round the track and finish where you started" then there is either one or zero solutions. The one solution would be to visit every fuel pit in sequential order. This problem is embarrassingly trivial.

Rescinded. I see what you're talking about. I agree with Peter Taylor though, I think by "optimal" you mean "only".

Start with an arbitrary amount of fuel at any point in the circuit and plot the cumulative amount of fuel as you travel around the circuit, allowing it to go negative if necessary. The minima of the graph are the possible starting positions.

You have some sample input data, and expected output data. Or is it enough if our program prints "solved!"? Would a typical problem look like: '0,0,2,0,0,4,0,0,7,0,8,0,0,0,0,0,0,0,0,0,1,0' where every step costs 1 unit, and numbers higher 0 mean that you get n units there? With the last element of the array connected to the first - not easily displayable in the comments.

O(n^2) solution is straightforward. Visit each fuel pit and try to ascertain if can be valid start point. But this would need 2 nested for loops. I am looking for an optimized O(n) solution which would visit each node exactly once. (code length no bar)

So what is the challenge then? If two solutions are both O(n), how do you determine which one is better? Also, does it matter what the input is?

@JoelCornett The challenge is to get the most optimized solution, and verify it from profiling. Input can be anything which covers all test cases, but to be fair all solutions needs to be profiled against same input.

JavaScript 140 chars
For the first solution, I assume that the fuel pits are provided in order order of location around the track and in the form:
var fuelPitInfo = [
    {
       location: 2,//The location from some point on the track
       fuelDistance: 1//The distance you can travel with the fuel from this stop
    },
    ..
]

Thus, a potential non code-golfed JavaScript function to calculate a working starting location is as follows (test fiddle):
function calculateStartingLocation(trackLength, fuelPitInfo) {
    for(i=0;;i++){
        var fuelPit = fuelPitInfo[i];
        var remainingFuelDistance = fuelPit.fuelDistance;
        for(j=i+1;;j++){
            var nextFuelPit = fuelPitInfo[j = j % fuelPitInfo.length];
            if (i == j) return fuelPitInfo[i].location;
            remainingFuelDistance -= (nextFuelPit.location - fuelPit.location + trackLength) % trackLength;
            if (remainingFuelDistance < 0) break;
            remainingFuelDistance += nextFuelPit.fuelDistance;
            fuelPit = nextFuelPit;
        }
    }
}

And the code-golfed function version (140 chars) is as follows (assuming location is replaced with l and fuelDistance is replaced with d in the provided fuelPitInfo object) (test fiddle):
function a(b,c){for(i=0;e=c[i],f=e.d;i++){for(j=i+1;g=c[j=j%c.length];){if(i==j++)return c[i].l;f-=(g.l-e.l+b)%b;if(f<0)break;f+=g.d,e=g;}}}

+1 briguy, please add a small explanation to your code, and also worst case complexity.

@jerrymouse:  Sure.  You start at a fuel pit, only consider one direction around the track (if there is enough fuel to make it one way, there is enough to make it the other), and then check that you can make it to each fuel pit in order.  You try the next fuel pit if you fail, or return the location of a valid starting fuel pit if not.  This is O(n^2), and I wrote it to be concise rather than efficient, because it was before your comment that you wanted the "most optimized" solution, and because pre-mature performance optimization is almost always a bad idea ;)

D (98 chars)
the input is a int array with the amount of fuel with 0 if there is no fuel there
int f(int[] a){
    for(int s,r=-1,i=0;;i++){
        if(r+a.length==i)
            return r;
        if(--s<0){
            r=i;s=0;
        }
        s+=a[i%$];
    }
}

I start at index 0 with 0 fuel and whenever s falls below 0 I set that spot as my new start and reset s to 0
if there is a solution you will find it in O(n) time or loop forever

+1 ratchet, please add a small explanation to your code, and also worst case complexity. Please format code to be more verbose..

Python, 183
import sys
f=[map(int,_.split()) for _ in open(sys.argv[1])]
l=len(f)
s=[]
for i in range(l):
\tu,d=zip(*(f[i:]+f[:i]))
\tif all(sum(u[:j])<sum(d[:j])for j in range(l+1)):s+=[i]
print s

This program takes input in the form of a file consisting of N lines, where N is the number of fuel depots. Each line contains integers A and B, where A is the amount of fuel at the depot, and B is the distance to the next fuel depot. Example:
7 5
6 7
4 3

Output is the string representation of a list containing the indices of the fuel depots that are valid starting points. In this case, it outputs:
[0, 2]

Meaning that starting at either fuel depot 0, or fuel depot 2 will allow the vehicle to make it all the way around the circle.

+1 joel, please add a small explanation about how your code works, and also worst case complexity.

APL, 48 chars
{i/⍨{∧/0≤-\,m⊖⍨⍵-1}¨i←⍳↑⍴m←⍵[;2],⍪2-⍨/⍵[;1],100}

I'm not sure what the conditions are for this golf, but I wrote a straightforward O(n²) solution.
Explanation
This function accepts a matrix with the positions and amounts of fuel, with the condition that the length is 100 and that the first pit is at position 0:
      p
 0  6
 2 16
18  1
30 45
84  5
92 27

The first operation is to take the first column, append 100 at the end, and take the differences of each pair of values, to get the distances between each pair of pits:
      d←2-⍨/p[;1],100
      d
2 16 12 54 8 8

Then it builds a new matrix with the amounts of fuel in the first column and the distances in the second:
      m←p[;2],⍪d
      m
 6  2
16 16
 1 12
45 54
 5  8
27  8

Then it enumerates the naturals from 1 up to the number of rows (pits) and selects those which pass a given test:
      i←⍳↑⍴m
      ({ . . . }¨i)/i

The test is to rotate the rows of the matrix by the index amount minus 1, so let's say if we want to start from the 3rd pit, it rotates 2 rows from the top to the bottom:
      r←(3-1)⊖m
 1 12
45 54
 5  8
27  8
 6  2
16 16

Then it flattens the elements of the matrix in row-major order and it scans their alternating sum. Scanning means to compute the alternating sum of just 1, 2, 3… up to all the elements of the vector:
      a←-\,r
      a
1 ¯11 34 ¯20 ¯15 ¯23 4 ¯4 2 0 16 0

We can see that by starting from the 3rd pit the tank is first filled up to 1, then drained down to -11, then filled up to 34, and so on. The next step is to ascertain whether all the numbers are ≥0, which in this case they are not:
      ∧/0≤a
0

If they did, the starting position would be included in the resulting set of good starting positions. And that's all.

As somebody mentioned, one could probably compute this alternating sum just once and use the minima as starting positions. I'll do it as a second version.


text:
List of primes under a million
This is my first code golf question, and a very simple one at that, so I apologise in advance if I may have broken any community guidelines.
The task is to print out, in ascending order, all of the prime numbers less than a million. The output format should be one number per line of output.
The aim, as with most code golf submissions, is to minimise code size. Optimising for runtime is also a bonus, but is a secondary objective.

It's not an exact duplicate, but it is essentially just primality testing, which is a component of a number of existing questions (e.g. http://codegolf.stackexchange.com/questions/113, http://codegolf.stackexchange.com/questions/5087 , http://codegolf.stackexchange.com/questions/1977 ). FWIW, one guideline which isn't followed enough (even by people who should know better) is to pre-propose a question in the meta sandbox http://meta.codegolf.stackexchange.com/questions/423 for criticism and discussion of how it can be improved before people start answering it.

Ah, yes, I was worried about this question being too similar to the plethora of prime number-related questions already around.

In all those solutions that spell out "1000000", why not run to 999999 instead of 1000000, saves a byte.  Everyone knows that 1000000 is not prime.

@GlennRanders-Pehrson Because 10^6 is even shorter ;)

A few years back I submitted an IOCCC entry that prints primes with only 68 characters in C -- unfortunately it stops well short of a million, but it might be of interest to some: http://computronium.org/ioccc.html

@ɐɔıʇǝɥʇuʎs How about 1e6 :-D

Python 3, 45 bytes
k=P=1
while k<1e6:P%k>0==print(k);P*=k*k;k+=1

Try it online!
By the time the loop reaches testing k, it has iteratively computed the squared-factorial P=(k-1)!^2. If k is prime, then it doesn't appear in the product 1 * 2 * ... * (k-1), so it's not a factor of P. But, if it's composite, all its prime factors are smaller and so in the product. The squaring is only actually needed to stop k=4 from falsely being called prime.
More strongly, it follows from Wilson's Theorem that when k is prime, P%k equals 1. Though we only need that it's nonzero here, it's useful in general that P%k is an indicator variable for whether k is prime.
Thanks to @Sisyphus for 1 byte with P%k>0==print(k) using chained operator short-circuiting in place of P%k and print(k).

You can save a byte doing P%k>0==print(k) instead of P%k and print(k).

@Sisyphus Great find, and on an answer that's had many eyes on it! Well worth an outgolfing bounty. Is there an answer of yours I can bounty for this? You could also post this improvement as an answer here, or post an answer here in another language.

I've posted a Julia answer, since I'd prefer the improvement stays in your (highly visible) post (and you did 99% of the work with Wilson's theorem!).

Mathematica, 17 24
Just for comparison:
Prime@Range@78498

As noted in a comment I failed to provide one prime per line; correction:
Column@Prime@Range@78498

Prime~Array~78498 also 17 :)

Would be nine bytes in mthmca, if that were to be released.

That violates the condition of one prime per line of output. Prefixing with Print/@ and terminating with ; to prevent output of a long list of Nulls fixes that, at the cost of 8 extra characters.

@celtschk I don't know if I missed or disregarded that five years ago.

Well, I definitely missed that it was from five years ago :-)

C, 61 chars
Almost exactly the same as this one (the question is almost exactly the same too).
n=2;main(m){n<1e6&&main(m<2?printf("%d\n",n),n:n%m?m-1:n++);}

Got SEG-FAULT after printing 881

@Manav, perhaps you compiled without optimizations. It relies on a good optimizer, which will remove the recursion.

Yes adding -O3 to gcc solved the problem!!

This method is insane. I love it.

I can get you to 57 bytes n=2;main(m){n<1e6&&main(m<2?printf("%d\n",n),n:m-++n%m);}

Since n%m?m-1:n++ can be shortened to m-++n%m. Subtracting the conditional while nesting the increment in the conditional logic itself removes the need for the ternary operation! :D

Looks nice, but unfortunately 13 is prime and 33 isn't.

MATLAB (16) (12)
Unfortunately, this outputs on a single line:
primes(1000000)

but that is solved by a simple matrix transpose:
primes(1000000)'

and I can cut out some characters by using exponential notation (as suggested in the comments):
primes(1e6)'

Using 1e6 instead of 1000000 helps here too.

@orion That would make it 11 characters

@Axoren that does not include the ' at the end

Bash (37 chars)
seq 2 1e6|factor|sed 's/.*: //g;/ /d'

(60 chars)
seq 2 1000000|factor|sed -e 's/[0-9]*: //g' -e '/^.* .*$/ d'

on my computer (2.0 GHz cpu, 2 GB ram) takes 14 seconds.

This can be improved to:
seq 2 1000000|factor|sed 's/[0-9]*: //g;/^.* .*$/ d'

yes you're  right. I wrote my sed command clean, not golfed :P

This can also further be improved to: seq 2 1000000|factor|sed 's/[0-9]*: //g;/ /d'

I was applying this improvement before I saw your comment ;)

awk is faster and shorter in filtering this: seq 2 1000000|factor|awk '!$3&&$0=$2' – 37 characters. Or if you filter out the 1 case with awk, but the code's length is the same: seq 1000000|factor|awk 'NF==2&&$0=$2'.

Yes, that awk script is about 25% faster :)

seq 1e6|factor|awk '$0=$2*!$3' is a bit shorter.

seq, factor and sed are external programs, this may as well be c p where c is a symlink to cat and p is a text file with primes up to a million... can you do it with shell builtins?

@technosaurus seq and factor are in coreutils, so it's legitimate. sed is also pretty ubiquitous.
coreutils can be treated like a built-in. Bash without coreutils is like C++ without the STL.

J, 21 characters
1[\p:i.(_1 p:1000000)

which can be shortened to
1[\p:i.78498

if you know how many primes there are below 1000000.

Using enfile items, ,., instead of 1[\ to save a character. Remove the unnecessary parenthesis, and use exponential notation: 1e6.

Came up with this: ,.i.&.(p:^:_1)1e6 Not shorter (after applying @Omar 's suggestions) but I found the use of under interesting.

Bash, 30 bytes
Since saeedn won't act on my suggestion – which is both shorter and faster than his approach – I thought I'd post my own answer:
seq 1e6|factor|awk '$0=$2*!$3'

How it works
seq 1e6

lists all positive integers up to 1,000,000.
factor

factors them one by one. For the first ten, the output is the following:
1:
2: 2
3: 3
4: 2 2
5: 5
6: 2 3
7: 7
8: 2 2 2
9: 3 3
10: 2 5

Finally,
awk '$0=$2*!$3'

changes the entire line ($0) to the product of the second field (the first prime factor) and the logical negation of the third field (1 if the is one prime factor or less, 0 otherwise).
This replaces lines corresponding to prime numbers with the number itself and all other lines with zeros. Since awk only prints truthy values, only prime number will get printed.

awk '$0=$2*!$3' is awksome cool!

PowerShell, 47 44 bytes
Very slow, but the shortest I could come up with.
$p=2..1e6;$p|?{$n=$_;!($p-lt$_|?{!($n%$_)})}

PowerShell, 123 bytes
This is much faster; far from optimal, but a good compromise between efficiency and brevity.
 $p=2..1e6;$n=0
 while(1){$p=@($p[0..$n]|?{$_})+($p[($n+1)..($p.count-1)]|?{$_%$p[$n]});$n++;if($n-ge($p.count-1)){break}}
 $p

Ruby 34
require'prime';p Prime.take 78498

Python 3.x: 66 chars
for k in range(2,10**6):
 if all(k%f for f in range(2,k)):print(k)

More efficient solution: 87 chars
Based on the Sieve of Eratosthenes.
p=[];z=range(2,10**6)
while z:f=z[0];p+=[f];z=[k for k in z if k%f]
for k in p:print(k)

Haskell, 51
mapM print [n|n<-[2..10^6],all((>0).rem n)[2..n-1]]

You can change mapM_ to mapM, return value won't be printed, and this is Code Golf. ;)

why are there extra spaces after print and in (> 0)?

You can replace 999999 with 10^6. And please update your byte count - 63 can't possibly be right.

Bash, 37
Will golf more, if I can...
Most of this is trying to parse factor's awkward output format.
seq 1e6|factor|grep -oP "(?<=: )\d+$"

Takes 5.7 or so seconds to complete on my machine.
(It just happened that my post was the first to go on the second page of answers, so nobody is going to see it...)
Old solution
This is longer and slower (takes 10 seconds).
seq 1e6|factor|egrep ':.\S+$'|grep -oE '\S+$'

Wow - I never came across factor before, but there it is right there in coreutils!

Shave off one character: seq 1e6|factor|grep -oP "(?<=: )\d+$" with a perl-grep lookbehind

@DigitalTrauma how does that work

-P enables perl-style regexes.  (?<=: ) is a positive lookbehind for the string ": ".  Basically this says that ": " must come before what matches \d+$, but is not actually part of the match, so the -o option just gives us one matching number after the colon, i.e. just gives numbers where there is only one factor, i.e. prime.

@DigitalTrauma added

Ruby 50 41
require'mathn'
p (2..1e6).select &:prime?

No need for .to_a, as Enumerable already includes select. You can also use the shorthand notation for Symbol#to_proc to shorten it further: p (2..1e6).select &:prime? (1 is not prime)

@Ventero thanks a lot! I didn't know about the Symbol#to_proc. I gotta pay more attention to the shortcuts Ruby offers.

Shorter version require'prime';p Prime.take 78498.

@ŁukaszNiemier Great! I think that's so different that you can post it as a separate answer.

Good use of some good ol' country boy mathn'

Shorter version (29 bytes) without lib: p(2..1e6).select{_1/1||_1/_1}

APL, 15
p~,p∘.×p←1↓⍳1e6

My interpreter ran into memory problems, but it works in theory.

How? Can you give a deskription?

You need a ⍪ in front to make one number per line, and you don't need the ,.

@RasmusDamgaardNielsen ⍳ are the first integers. 1↓ drops the first one. p← assigns to p. p∘.×p makes a multiplication table. p~ removes from p whatever is on the right. (, isn't needed, it ravels the table into a list.)

Perl, 49 bytes
Regular expression kung fu :)
for(1..1E6){(1x$_)=~/^(11+?)\1+$/ or print"$_\n"}

Ungolfed version:
for(1 .. 1_000_000) {
    (1x$_) =~ /^(11+?)\1+$/ or print "$_\n";
}

It hasn't even made 10% progress while I type this post!
Source for the regex: http://montreal.pm.org/tech/neil_kandalgaonkar.shtml

inspired me to write a perl6 version. also, 1000000 can be written 10**6

Also, 1000000 can be written 1E6

Always was a favorite regex of mine, but you need to remember that it fails spectacularly once you get to higher numbers - because of the fact that it's converting huge numbers into unary. This regex might not work for finding primes in the hundreds of thousands and beyond, depending on one's configuration of the language (and your machine.)

Julia, 11
primes(10^6)

It looks like built ins are getting upvotes, plus I needed more words for longer answer.

J (15 or 9)
I can't believe this beat Mathematica (even if it's just a single by 2 chars)
a#~1 p:a=:i.1e6

Or:
p:i.78498

... The output format should be one number per line of output. That's why my answer begins with 1[\ .

gs2, 5 bytes
Encoded in CP437:
∟)◄lT

1C 29 pushes a million, 11 6C is primes below, 54 is show lines.

C, 91 88 85 82 81 80 76 72 characters
main(i,j,b){for(;i++<1e6;b++&&printf("%d\n",i))for(j=2;j<i;)b=i%j++&&b;}

The algorithm is terribly inefficient, but since we're doing code-golf that shouldn't matter.

you can shorten it easily:
main(i,j,b){for(;i++<1e6;b++&&printf("%d\n",i))for(j=2;j<i;)b=i%j++&&b;} or some idea like this (since I actually didn't compile it)

How is i sure to be 0? I think that, if you provide any argument, it'll fail. Also, I think j will have some sort of type error. Not sure for b though.

GolfScript, 22/20 (20/19) bytes
n(6?,:|2>{(.p|%-.}do:n

At the cost of speed, the code can be made two bytes shorter:
n(6?,:|2>.{|%2>-}/n*

If the output format specified in the edited question is disregarded (which is what many of the existing answers do), two bytes can be saved in the fast version and one can be saved in the slow one:
n(6?,:|2>{(.p|%-.}do
n(6?,:|2>.{|%2>-}/`

This will print an additional LF after the primes for the fast version, and it will print the primes as an array for the slow one.
How it works
Both versions are implementations of the sieve of Eratosthenes.
The fast version does the following:

Set A = [ 2 3 4 … 999,999 ] and | = [ 0 1 2 … 999,999 ].
Set N = A[0] and print N.
Collect every N-th element from | in C. These are the multiples of N.
Set A = A - C.
If A is non-empty, go back to 2.

n(6?   # Push "\n".pop() ** 6 = 1,000,000.
,:|    # Push | = [ 0 1 2 … 999,999 ].
,2>    # Push A = [ 2 3 4 … 999,999 ].
{      #
  (    # Unshift the first element (“N”) of “A”.
  .p   # Print “N”.
  |%   # Collect every N-th element from “A” into a new array, starting with the first.
  -    # Take the set difference of “A” and the array from above.
  .    # Duplicate the set difference.
}do    # If the set difference is non-empty, repeat.
:n     # Store the empty string in “n”, so no final LF will get printed.

The slow version works in a similar fashion, but instead of successively removing multiples of the minimum of “A” (which is always prime), it removes multiples of all positive integers below 1,000,000.
Competitiveness
In absence of any built-in mathematical functions to factorize or check for primality, all GolfScript solutions will either be very large or very inefficient.
While still far from being efficient, I think I have achieved a decent speed-to-size ratio. At the time of its submission, this approach seems to be the shortest of those that do not use any of the aforementioned built-ins. I say seems because I have no idea how some of the answers work...
I've benchmarked all four submitted GolfScript solutions: w0lf's (trial division), my other answer (Wilson's theorem) and the two of this answer. These were the results:
Bound     | Trial division     | Sieve (slow)       | Wilson's theorem | Sieve (fast)
----------+--------------------+--------------------+------------------+----------------
1,000     | 2.47 s             | 0.06 s             | 0.03 s           | 0.03 s
10,000    | 246.06 s (4.1 m)   | 1.49 s             | 0.38 s           | 0.14 s
20,000    | 1006.83 s (16.8 m) | 5.22 s             | 1.41 s           | 0.38 s
100,000   | ~ 7 h (estimated)  | 104.65 (1.7 m)     | 35.20 s          | 5.82 s
1,000,000 | ~ 29 d (estimated) | 111136.97s (3.1 h) | 3695.92 s (1 h)  | 418.24 s (7 m)

Is the "slow" sieve just a Sieve of Eratosthenes?

Both are. The slow version is just an awful implementation.

NARS2000 APL, 7 characters
⍸0π⍳1e6

Welcome to Programming Puzzles & Code Golf!

Golfscript 26 25 24
Edit (saved one more char thanks to Peter Taylor):
10 6?,{:x,{)x\%!},,2=},`

Old code:
10 6?,{.,{)\.@%!},,2=*},`

This code has only theoretical value, as it is incredibly slow and inefficient. I think it could take hours to run.
If you wish to test it, try for example only the primes up to 100:
10 2?,{:x,{)x\%!},,2=},`

You can save a character by replacing \; with *. (You can also get much faster for the current character count by finding the first divisor rather than all of them: `10 6?,2>{.),2>{1$%!}?=},``

@PeterTaylor Thanks, using multiplication there is a very neat trick.

There's one more char saving with a variable: replace ., with :x, and \.@ with x\  (whitespace is because of escaping issues with MD in comments) and remove *.

@PeterTaylor good one, thanks! I've edited my code.

GolfScript, 25 (24) bytes
!10 6?,2>{.(@*.)@%!},n*\;

If the output format specified in the edited question is disregarded, one byte can be saved:
!10 6?,2>{.(@*.)@%!},`\;

This will print the primes as an array (like many other solutions do) rather than one per line.
How it works
The general idea is to use Wilson's theorem, which states that n > 1 is prime if and only if

!     # Push the logical NOT of the empty string (1). This is an accumulator.
10 6? # Push 10**6 = 1,000,000.
,2>   # Push [ 2 3 4 … 999,999 ].
{     # For each “N” in this array:
  .(  # Push “N - 1”.
  @   # Rotate the accumulator on top of the stack.
  *   # Multiply it with “N - 1”. The accumulator now hold “(N - 1)!”.
  .)  # Push “(N - 1)! + 1”
  @   # Rotate “N” on top of the stack.
  %!  # Push the logical NOT of “((N - 1)! + 1) % N”.
},    # Collect all “N” for which “((N - 1)! + 1) % N == 0” in an array.
n*    # Join that array by LF.
\;    # Discard the accumulator.

Benchmarks
Faster than trial division, but slower than the sieve of Eratosthenes. See my other answer.

CJam - 11
1e6,{mp},N*

1e6, - array of 0 ... 999999
{mp}, - select primes
N* - join with newlines

Isn't CJam more recent than this question?

@PeterTaylor oh, yes it is

Java, 110 bytes
void x(){for(int i=1;i++<1e6;)System.out.print(new String(new char[i]).matches(".?|(..+?)\\1+")?"":(i+"\n"));}
Using unary division through regex as a primality test.

Nice approach. Never seen that prime-regex before. +1 from me. Although, using a nested for-loop for prime-checking is slightly shorter. :)

Julia 1.x, 38 bytes
2:1e6 .|>i->0∉i.%(2:i-1)==println(i)

Try it online!
Since the other Julia answer was posted, primes is no longer in the standard library. We use a couple of features:

∉ costs 3 bytes but is shorter than in(...).
We use the map syntax f.x over map(f,x).
We can broadcast % using .%.
Floating point can exactly represent everything up to 1e6, no problems there.
We use a == short circuiting trick.

F#, 100 94 bytes
let p n=
    let rec c i=i>n/2||(n%i<>0&&c(i+1))
    c 2
for n in 1..1000000 do if p n then printfn "%i" n
let p n={2..n-1}|>Seq.forall(fun x->n%x<>0)
{2..1000000}|>Seq.filter p|>Seq.iter(printfn "%i")

QBASIC, 75 bytes
FOR I=2 TO 1e6
    FOR J=2 TO I^.5
        IF I MOD J=0 THEN:GOTO X
    NEXT
    ?I
X:NEXT

I could have saved a character by going with FOR J = 2 TO I/2 but the run time was seriously slow. Runs at a much saner speed by only going to Sqrt I.

R, 45 43 characters
for(i in 2:1e6)if(sum(!i%%2:i)<2)cat(i," ")

For each number x from 2 to 1e6, simply output it if the number of x mod 2 to x that are equal to 0 is less than 2.

The first number produced by this code is 1, but 1 is not a prime.

Mathematica 25
Assuming you don't know the number of primes less than 10^6:
Prime@Range@PrimePi[10^6]

J, 16 chars
1]\(#~1&p:)i.1e6

Without the output format requirement, this can be reduced to 13 chars:
(#~1&p:)i.1e6

1]\ just takes the rank 1 array of primes, turns it into a rank 2 array, and puts each prime on its own row -- and so the interpreter's default output format turns the one line list into one prime per line.
(#~ f) y is basically filter, where f returns a boolean for each element in y. i.1e6 is the range of integers [0,1000000), and 1&p: is a boolean function that returns 1 for primes.

Bash (433643)
My (not so clever) attempt was to use factor to factor the product.
factor ${PRODUCT}

Unfortunately with large numbers the product is of course huge.  It also took over 12 hours to run.  I decided to post it though because I thought it was unique.
Here is the full code.
If it was primes under six it would be reasonable.
  factor 30

Oh well, I tried.

+1 This answer is truly diabolical. Not quite precomputed result (it saves quite a bit of characters), and much much more terrible to compute :) It's quite possibly also an example that makes the optimized factor perform much worse than the basic trial division algorithm.

NARS2000 APL - 9 characters
¯2π⍳2π1e6

Quite a boring answer.
Short explanation:
¯2 π  ⍝ generate the Nth prime for N
⍳     ⍝ in the range 1 to
2 π   ⍝ the number of primes less than or equal to
1e6   ⍝ a million

This is sinister black magic.

@professorfish I assume I should add an explanation?

yessssssss (putting in extra sssss because of char limit_)

You need ⍪ for the proper output (and btw, ¯2π⍳78498 is much simpler).

Commodore 64 Basic, 55 characters
1F┌I=2TO10^6:F┌J=2TOI/2:IF(I/J=INT(I/I))G┌3
2N─:?I
3N─I

PETSCII substitutions: ┌ = SHIFT+O, ─ = SHIFT+E
Incredibly slow: first, because the algorithm is extremely inefficient (it tries dividing by every value less than half the candidate number), second, because the Commodore 64 is slow, and third, because Commodore Basic does all its math in emulated floating-point on an 8-bit CPU.
Theoretical solution, 82 characters
1M=10^6:D╮S(M):F┌I=2TO1000:F┌J=I^2TOMST─I:S(J)=-1:N─:N─:F┌I=2TOM:IF(N┌S(I))T|:?I
2N─

╮ = SHIFT+I, ┌ = SHIFT+O, ─ = SHIFT+E, | = SHIFT+H
If this program could run on an actual Commodore 64, it would be much faster than the above.  However, it can't: the sieve alone would take 5,000,007 bytes out of the 38,911 bytes a C64 has available for Basic programs.  Note the use of -1 instead of 1 when denoting composite values in the array: C64 Basic doesn't have a true boolean negation; NOT performs a two's complement instead.

I think that should be INT(I/J) not I/I. Btw. that´s 56 bytes; and 56 characters (the last line needs a RETURN as well so it gets recognized). 1F┌I=2TO10^6:F┌J=2TOI/2:IF(I/J!=INT(I/I))N─:?I and 2N─I is four characters shorter and six bytes smaller. Nice approach though.

Oh and for those that think that integer varibales would be faster: They´re not. Commodore Basic transforms integer values to float for calculations.

HPPPL, 90 89 chars
(HP Prime Programming Language), for the HP Prime color graphing calculator.
export p()begin local i;for i from 2 to 1e6 do if isprime(i)=1 then print(i) end;end;end;

Output to the terminal is quite slow on the Prime, so the program takes quite a while to run. Printing out all primes using the emulator takes about 88 seconds on my i5 2410M laptop.
As my google account is messed up, I have to start all over again with a new account... so be it. My photo and name are the same as before ;)
You can try out the program with the free HP Prime emulator available here:
http://www.hp-prime.de/en/category/13-emulator

APL (Dyalog), 15 chars
⍪(⊢~∘.×⍨)1↓⍳1E6

Try it online! (only goes until one thousand as TIO does not allot enough memory for a million)
⍳1E6 first million ɩntegers
1↓ drop one
(…) apply the following tacit function:
 ⊢ the argument (all the numbers 2…1000000)
 ~ except those that are in
 ∘.×⍨ the multiplication table (using the argument as both vertical and horizontal axis)
⍪ table (makes list into column)

Vim, 34 bytes
6@=9<CR>o<Tab>0<Esc>V{g<C-A>dj=:g/\v^(<Tab><Tab>+)\1+</d<CR>
This is a direct adaptation of my top solution to Prime Numbers. The difference is... here I have to go up to a million. This forces a cool tactic to put 999999 into the readahead, but it also makes this solution impossible to run. You won't even get past the setup making the number array, because you'd need to fill more than half a terabyte of RAM (without overhead). And if you ever got to the regex algorithm... well, it sucks. You'd never finish.
This solution requires :set autoindent noexpandtab, which you might have set already, might not. It also requires computer hardware that doesn't exist.

6@=9<CR>: Cool trick to write 999999 in 5 bytes. Integer 9 gets evaluated into the expression register as text. That "macro" is run 6 times.
o<Tab>0<Esc>: Make N (999,999) lines of zeroes, with stair-step indent. This is kind of like what happens when you paste in insert mode without doing :set paste.
V{g<C-A>: Visual increment to turn the 0s into a list of numbers 1-999,999. Conveniently leaves cursor on top.
dj: Remove the blank (zero) and 1 lines.
=:: Vim users rarely think of the : command as an operator, but it is one (a charwise operator, surprisingly). Runs the = out to where the : command would move the cursor (top to bottom in this case).
\v^(<Tab><Tab>+)\1+<: Regex that matches a composite number of tabs. If you haven't, watch the VimCast episode, which covers an old version of this solution. The :g//d will delete those lines. The cursor will end on the last remaining line, which will act as the operator for = to remove all indent.

Vim, 36 bytes (actually runs)

6@=9<CR>O0<Esc>V{g<C-A>:%norm~V$EkdYo@0D@.<C-O>@.<CR>d

This :normal macro is a proper sieve of Eratosthenes that cleans up after itself. I actually ran this out to 1,000,000. Took 10-15 minutes. The algorithm is quite good, but the data structure (array of lines in Vim) comes with a big toll. I wrote about it in more detail a long time ago.

PHP, 55 53 51 bytes
for($n=1;1e6>$i=$n++;$i||print"$n
")while($n%$i--);

Run with -nr or try it online. (TiO only runs to 10K; 1M would exceed the time limit.)
The outer loop runs $n from 1 to 1 million.
The inner loop is the primality test: loops $i down from $n-1 until $i is a divisor of $n.
If that divisor is 1, $n is a prime and will be printed in the post-condition of the outer loop.

FORTRAN 90, 80 bytes
DO I=2,1E2;D=1;DO J=2,I**.5;IF(MOD(I,J)==0)D=0;ENDDO;IF(D==1)PRINT*,I;ENDDO;END

This is the same as below, but in a newer and less rigorous version.

FORTRAN 77, 104 95 bytes
      DOI=2,1E6;D=1;DOJ=2,I**.5;IF(MOD(I,J).EQ.0)D=0;
      ENDDO;IF(D.EQ.1)PRINT*,I;ENDDO;END

Works with gfortran. Not sure if the DO I=... and DO J=... works without spaces in other compilers.
(Modification: program name supressed; I just learned that it's optional!)

Python, 75
print filter(lambda n:n==2 or all(n%i for i in range(2,n)),range(15485864))

Not terribly efficient though, it actually gives me a out of memory error in Jython.
Here's a (slightly) more efficient version:
import math
print [2]+filter(lambda n:all(n%i for i in xrange(3,int(math.sqrt(n))+1,2)),xrange(3,15485864,2))

This version took approximately 8 minutes to run.

quite a big variety of speeds here, one of my answers took 4.5 seconds

Scala, 58
2 to 1000000 map{x=>if(2 to x/2 forall(x%_!=0))println(x)}

or
2 to 1000000 filter{x=>2 to x/2 forall(x%_!=0)}map println

Giving last prime number can save one character.

Haskell, 65 chars
main=print[x|x<-[2..999999::Int],null[i|i<-[2..x-1],mod x i==0]]

Nice.  Could you save a few by removing the ::Int ?

Octave, 12, 11
primes(1e6)

Write 1000000 as 1e6

1e6 is even shorter ;)

Befunge-98, 119 characters
Because if it can be done, it can be done in Befunge! Probably not optimal. Works in 98 but not 93 because of the difference in how many bits a cell can store.
2.300p210pv>a,00g:.2+00>p"d"::**v
>00g1-10g`!|Prime Get> ^|p012!`\<
| %g01g00 <>10g1+10pv  v<
>00g:2+00#^        #<^#<@

C#, 70
Enumerable.Range(1,1e6).Where(n=>Enumerable.Range(2,n).All(x=>x%n!=0))

You're not going to see much here though for a LONG time...

There are several reasons why this is wrong. (1) You cannot implicitly convert from a double 1e6 to an int, but int is required by Range. (2) The inner Range must take at most n-2 terms, otherwise you will test n % n which is clearly 0. (3) You write x%n when you want n%x. Fixing these issues, something like this will work: Enumerable.Range(2,999999).Where(n=>Enumerable.Range(2,n-2).All(x=>n%x!=0)) However, this still does not output the numbers; the requirement was one per line.

PHP - 72 bytes
<?for($i=1;$i++^999999;print$d?~ı.$i:'')for($d=$j=2;$j<$i&&$d=$i%$j++;);

Hexdump:
0000000 3c 3f 66 6f 72 28 24 69 3d 31 3b 24 69 2b 2b 5e
0000010 39 39 39 39 39 39 3b 70 72 69 6e 74 24 64 3f 7e
0000020 f5 2e 24 69 3a 27 27 29 66 6f 72 28 24 64 3d 24
0000030 6a 3d 32 3b 24 6a 3c 24 69 26 26 24 64 3d 24 69
0000040 25 24 6a 2b 2b 3b 29 3b
0000048

Kinda slow, could be optimised (for 6 bytes) by division-checking until the square root of each number only, like so:
<?for($i=1;$i++^999999;print$d?~ı.$i:'')for($d=$j=2;$j<sqrt($i)&&$d=$i%$j++;);

PARI/GP, 26 bytes
Simple solution:
forprime(p=2,1e6,print(p))

Less-efficient solutions, one per line:
prodeuler(p=2,1e6,print(p));
apply(n->print(n),primes(78498));
apply(n->print(n),primes([2,1e6]));

Javascript es6 66 bytes
I was surprised to not see JS in here so I thought I'd put in a word for her
//takes about 19 minutes to run on my work pc
for(i=2,l=[];i<1e6;++i)l.every(a=>i/a%1)&&l.push(console.log(i)|i)

You can save a byte by incrementing in the compare for(i=1,l=[];++i<1e6;)

MATL, 5 bytes
1e6Zq

Explanation:
1e6   % push 10000 to stack
   Zq % primes up to top-of-stack number

Javascript, 74 73 bytes
saved one byte thanks to Martin Ender
()=>{for(i=0;i<1e6;i++)!/^.?$|^(..+)\1+$/.test('1'.repeat(i))&&alert(i);}

Tests all numbers under 1 million against a regex. Regex Explanation

Jelly, 7 bytes
10*6ÆRY

Try it online!
10*6    # One million in scientific notation (10^6 = 1,000,000).
    ÆR  # List of primes less than one million.
      Y # Join the list with newlines.

Welcome to PPCG!

I improved the formatting and added in a Try It Online link. Also 5 bytes

@cairdcoinheringaahing not sure if it was in the syntax at the time, but you could replace 10*6 with ȷ6 to save a byte.

Python 2; 67 Bytes
n,p=3,[2]
while n<1e5:exec'print n;p+=[n]'*all(n%x for x in p);n+=2

Checks current number against all previous primes, and if not divisible by any of them, prints number and adds to list
The advantage of the while loop compared to other methods is that python will allow direct comparison against a number of the form "1e5", rather than having to use a long form or convert it to an int
Still takes a long time to run

05AB1E, 6 bytes
6°ÅPε,

Try it online!
Explanation:
6°ÅPε,
6°       Push 1000000 to stack (10^6)
  ÅP     List of all primes < 1000000
    ε,   Print each element of the list

You can save a byte changing ε, to » (join by newlines; after which the result is implicitly output).

Perl 6, 27 bytes
grep(&is-prime,^)>>.say

Try it online!
Filters all the primes from 0 to a million minus 1 and then prints.

Japt -R, 6 bytes
L³õ fj

Test it
L³õ fj
L          :100
 ³         :Cubed
  õ        :Range [1,L³]
    f      :Filter
     j     :  Prime

Vyxal, 4 bytes
k4'æ

Try it Online!
k4   # 1m
  '  # 1...^ filtered by
   æ # is prime?

Thunno N, \$ 4 \log_{256}(96) \approx \$ 3.29 bytes
Z6gN

Attempt This Online!
Note: this is very slow (it times out on ATO), so here's a version which prints the primes up to 1000: Attempt This Online!
Explanation:
Z6    # Push 10**6 (1000000)
  g   # Filter (range of ^) for:
   N  #  Primes
      # N flag joins by newlines
      # Implicit output

C (111)
x=1000000,s[1000000],j;main(i){while(++i<x)for(j=2*i;j<x;j+=i)
s[j]=1;for(i=1;++i<x;)if(!s[i])printf("%d\n",i);}

C (112)
x=1000000,s[1000000],j;main(i){while(++i<x)for(j=2*i;j<x;j+=i)
s[j]=1;i=1;while(++i<x)if(!s[i])printf("%d\n",i);}

C (113, over 25% faster)
x=1000,s[1000000],j;main(i){while(++i<x)for(j=i*i;j<x*x;j+=i)
s[j]=1;i=1;while(++i<x*x)if(!s[i])printf("%d\n",i);}

C (ungolfed)
#include <stdio.h>
int sieve[1000000];
int main(void) {
    int i, j;
    for (i = 2; i < 1000; i++)
        for (j = i * i; j < 1000000; j += i)
            sieve[j] = 1;
    for (i = 2; i < 1000000; i++)
        if (!sieve[i])
            printf("%d\n", i);
    return 0;
}

i=1;while(++i<E) can be improved to for(i=1;++i<E;). for(j=2*i;j<x;j+=i)s[j]=1; can be improved to for(j=1;++j<x;)s[j*i]=1;

Thanks. For your second improvement, though, considering that j would no longer be a direct index to the sieve, wouldn't comparing against x cause the program to significantly overrun the array?

Fair point. One big improvement still possible, though: use a single loop. Can't think how I missed it earlier.

As in, using one loop in total, or replacing the first pair of loops with one loop, resulting in two loops? I don't think the former is possible, as it'd mean printing while the sieve is in an incomplete state.

Sure it's possible. The part of the sieve up to i is complete.

If you moved the declaration of s inside the loop you could use x instead of 1000000, I think you could save a character or two even taking the additional int and ; into account.

Can't you do x=1000000,s[x]? I'm not an expert in C though.

Also, instead of s[j]=1;for(i=1..., do s[j]=i=1;for(...

You can probably just use 1e6 rather than 1000000 in most contexts. It's a floating-point number rather than an integer, but it tends to get implicitly converted.

C - 67
$ cat x.c
main(p,t){for(p=1;t=2,++p<1e6;t<p||printf("%d\n",p))while(p%t++);}
$ wc -c x.c
67 x.c
$ gcc -O3 x.c -o x
x.c: In function ‘main’:
x.c:1: warning: incompatible implicit declaration of built-in function ‘printf’
$ ./x | wc -l
78498

It's sloooooow... don't ask... :-D
I got an even shorter variant (54 bytes) but unluckily it prints the biggest prime first. ;-(
Maybe it fits in a different code golf... someday... ;-)

Clojure - 95 bytes
This is a simple, unoptimised function which prints the primes.
(defn p[](doseq[i(range 2 1e6):when(every? false?(map #(=(mod i %)0)(range 2 i)))](println i)))

Now, I wanted to create something nice too, so here is a function that creates a lazy infinite list of primes.
(defn primes
  ([]
    (concat [2 3] (primes 5)))
  ([n]
    (lazy-seq
      (first
        (for [i     (range)
              :let  [i (+ i n)]
              :when (every? false? (map #(= (mod i %) 0)
                                        (range 2 (Math/sqrt i))))]
          (cons i (primes (+ i 2))))))))

Matlab (12)
Pretty simple=)
primes(1e6)'

So simple that there is already http://codegolf.stackexchange.com/a/6274/21348

Oh, didn't see that one, but I have to say that mine is way shorter=)

Java, 183 characters
import java.util.stream.*;
class P{public static void main(String[]a){
IntStream.range(1,1000000).filter(i->!IntStream.range(2,i).anyMatch(j->i%j==0)).forEach(System.out::println);
}}

Performance is not optimal, but code is well readable. For faster computation could be code extended to use parallel streams:
import java.util.stream.*;
class P{public static void main(String[]a){
IntStream.range(1,1000000).parallel().filter(i->!IntStream.range(2,i).anyMatch(j->i%j==0)).forEachOrdered(System.out::println);
}}

I think you can remove some of the newlines.

Java - 101 characters
Ungolfed version:
for(int i=3, j; i < 1000000; i++) {
    for(j = 2; j < i / 2; j++)
        if (i % j ==0)
            break;
    System.out.printf(i % j != 0 ? i + "%n" : "");
}

Golfed version:
for(int i=3,j;i<1000000;i++){for(j=2;j<i/2;j++)if(i%j==0)break;System.out.printf(i%j!=0?i+"%n":"");}

@Martin Büttner Oups. Fixed it.

IDK, if that is an accepted format in Codegolf, you have to wrap it into a function, a lambda or a program. It helps other people to test your code faster and gives everyone using the same language a fair playing ground.

Perl6 - 47
for 1..10**6 {(1 x$_)~~/^(11+?)$0+$/ or say $_}

credit to Gowtham's perl solution

1000000 better written as 10**6
print "$_\n" became say $_
=~ became ~~
needed to add whitespace in front of the x operator

you can use superscript version of 106 > 10⁶
so you can shorten range from 1..106 to ^10⁶

you can move the for on the right side and it becomes 41 chars

(1 x$_)~~/^(11+?)$0+$/ or say $_ for ^10⁶

You could also use .say instead of say $_.

Dart - 75 chars
Loop based version:
main(i,j){for(i=2;i<1e6;i++)l:{for(j=2;j<i;j++)if(i%j<1)break l;print(i);}}

It's much faster if you change j<i to j*j<=i, but not shorter!
Alternative List based version (107 chars)
Not going to win any records without a shorter way to generate the list.
main(p,q){p=new List.generate(999998,(x)=>x+2);while(!p.isEmpty){print(q=p[0]);p.removeWhere((x)=>x%q<1);}}

Ungolfed
    main(p,q) {
      p = new List.generate(999998, (x) => x + 2);
      while (!p.isEmpty) {
        print(q = p[0]);
        p.removeWhere((x) => x%q < 1);
      }
    }

Bacchus, 34 bytes
\n[2..1E6]a(Öp:a(·=1.Öw)?),·¨

Explanation:
\n            Prepare the output to be one in each line

[2..1E6]      Generates an array from 2 to 1000000

:a            Push the array to the stack

(),·¨         For each element on the array we previously pushed to the stack

Öp:a          If current element of the for-each loop is Prime push 1 to the stack. Otherwise, push 0.

(·=1.Öw)?     If last pushed element is 1 then print current element of the for each loop.

Most of the code is used to output each prime in different lines. Otherwise a much shorter code (10 bytes) would be
[2..1E6]p#

LiveScript - 71 bytes
I was goofing around, trying to golf Sieve of Eratosthenes. I'm quite happy with the result. It uses prelude.ls.
x=1e6;[2 to x]|>unfoldr ([x]:l)->|l>[]=>[console.log<|x,l|>filter (%x)]

It outputs to the console. You can try the code in http://livescript.net - I recommend using lower limit than 1e6, because it gets slow at those numbers and probably hangs your browser for a while. I couldn't find a way to stop LS from inlining [2 to 1e6], so I had to creae a var for it.
Just for the sake of it, the original function I mangled the first one from:
p=->[2 to it]|>unfoldr ([x]:l)->|l>[]=>[x,l|>filter (%x)]

JS, 100 67 57
By xem and subzey
Execute this in the browser's console or nodeJS.
Short version: 57b. (it's very long to end: ~ 20 min)
for(i=1;1e6>++i;p&&console.log(i))for(p=j=i;j-->2;)p*=i%j

Faster version, 100b (ends in ~ 1 min)
p=[];for(i=2;1E6>i;i++)for(t=0,j=i;1E6>j;j+=i)t&&(p[j]=1),t=1;for(i=2;1E6>i;i++)p[i]||console.log(i)

Prolog - 129
Not a very short variant, but reasonably fast. A simple implementation of the Sieve of Eratosthenes.
:-initialization m.
F+S+X:-G is F,(G=<1e6,X=G;G<1e6,(G+S)+S+X).
m:-assert(i-1),2+1+I,\+i-I,write(I),nl,I*I+I+J,assert(i-J),1=0;!.

Invocation:
time swipl -qf ./prime.pl < /dev/null | wc -l

78498

real    0m3.646s
user    0m3.468s
sys     0m0.264s

Readable:
:- initialization(main).

between2(From, _, X) :-
    X is From,
    X =< 1000000.
between2(From, StepSize, X) :-
    Y is From,
    Y < 1000000,
    between2(Y + StepSize, StepSize, X).

main :-
    assert(stroke(1)), % shorter than ":-dynamic stroke/1."
    between2(2, 1, I),
    \+ stroke(I),
    write(I), nl,
    between2(I*I, I, J),
    assert(stroke(J)),
    fail.
main.

Perl, 75
map{my($a,$b)=($_,0);for(2..$a-1){$a%$_==0&&$b++}$b||print"$a\n"}(2..10**6)

Pyth - 14 12 chars
Fkr2^T6IqlPk1k
Thanks so much to @FryAmTheEggman for removing two chars from filter and ![1:] instead of ==1. As you probably can guess I learned Pyth literally yesterday. :)
jbf!tPTtU^T6

Omg I actually beat Mathematica builtins. Its very simple it just loops through 2 to a million and uses trick that prime numbers have one number in thier prime factorization which pyth happens to have a function for.
jb:    Join with \n as sperator
f:     filter by
!tPT:  not tail of prime factorization of loop variable(tail would be falsey if len 1 so then negate)
tU^T6:  filter through range 2-million

It does take a verrrrrry long time to run, but if you want to just see it run, you can change the 6 to a 2 for primes under hundred.

Using pyth's filter function is a tad shorter: jbf!tPTtU^T6. This also saves a char by checking len(prime_factors(n)[1:])>0, which could also be added to your code: I!tPk. (This works because an empty list is False, and a list of any other length is True) Good luck with Pyth ;)

Jagl Alpha 1.2 - 14 bytes
Not competing, language is younger than question
1e6r{m}%{PZp}/

Prints on separate lines.

Is this language younger than the question?

Yes, I am not competing. Clarified in the answer @githubphagocyte

@githubphagocyte :)

Ruby 37 32
(2..1e6).map{|x|p x if x.prime?}

yeah that makes so much sense. THanks :)

Actually, I can't find any documentation of prime?. Have you tested this?

yeah it works great. Here: http://ruby-doc.org/stdlib-1.9.3/libdoc/prime/rdoc/Integer.html#method-i-prime-3F

This only works if the Prime module is loaded. You need to require 'prime' otherwise you get NoMethodError: undefined method \prime?' for 2:Fixnum`

T-SQL, 141
Assuming a resultset is valid output, here's code that works with SQL Server 2008 R2.  It uses a table to store previously found primes.  The table is initialized with 2, and all odd integers greater than that are checked against the contents of the table at the point in time of the check.  Runtime and efficiency obviously were not concerns....
DECLARE @ INT=3SELECT 2 p INTO # l:IF NULL=ALL(SELECT 1FROM # WHERE @%p=0)INSERT # VALUES(@)SET @+=2IF @<1e6GOTO l SELECT p FROM # ORDER BY p

Sage, 28 bytes
for i in primes(1e6):print i

Try it online

@FryAmTheEggman It's Python 2

Pyth, 9 bytes
V^T6IP_NN

Explanation:
V starts a for loop from 0 to the next number, keeping N as the value
T = 10 and so ^T6 = 10^6 = 1000000
I is if, P_N checks if N is prime and returns True or False based on the result.
The final N is just to print it.

I'm new to Pyth so it's likely not the best solution. Any suggestions are welcome!

Java 8, 100 97 92 bytes
o->{for(int i=1,n,j;i++<1e6;){for(n=i,j=2;j<n;n=n%j++<1?0:n);if(n>1)System.out.print(n);}}

-3 bytes by thanks to @Nevay.
-5 bytes by converting Java 7 to Java 8.
I know there are already a few other Java answers. I didn't knew which to choose to put the comment on with my golfed method, so I decided to post this separate answer. Not to mention it's slightly or a lot shorter than any of the other current Java answers so far.
Explanation:
Try it here.
o->{                          // Method with empty unused parameter and no return-type
  for(int i=1,n,j;            //  Initialize some integers
      i++<1e6;){              //  Loop (1) from 2 through 1,000,000 (exclusive)
    for(n=i,j=2;              //   Set some integers
        j<n;                  //   Inner loop (2) from 2 through `n` (exclusive)
      n=                      //    Change `n` to:
        n%j++<1?              //     If `n` is divisible by `j`:
         0                    //      Change `n` to 0 (which means it isn't a prime)
        :                     //     Else:
         n                    //      Leave `n` unchanged
    );                        //   End of inner loop (2)
    if(n>1)                   //   If `n` is larger than 1, which means it's a prime:
      System.out.println(n);  //    Print `n` + new-line
  }                           //  End of loop (1)
}                             // End of method

You can use if(n>1)System.out.println(n); instead of System.out.print(n>1?n+"\n":""); to save 3 bytes.

PHP, 100 95 bytes
It works by iterating 1,000,000 times and then using this regular expression on a unary number to check if it's prime. It's not the smallest PHP solution submitted, but thought I'd submit it just so it's here.
for($i=0;$i<=1e6;$i++)if(preg_match('/^1?$|^(11+?)\1+$/',str_repeat("1",$i))==0)echo$i.PHP_EOL;

Matchu explains how the regular expression works - https://stackoverflow.com/a/3296068/3000179
First 50: https://eval.in/746404

Can you remove the space between for($i=0;$i<=1e6;$i++) and everything else?

@CalculatorFeline yep, thanks!

Great algorithm! 28 bytes shorter: while(++$i<1e6)preg_match('/^1?$|^(11+?)\1+$/',$s.=1)||print"$i\n"; (not tested). Save one more byte with a literal newline. Have you tried ereg instead of preg_match? That would save another 8 bytes, shrinking your solution to 58 bytes.

Ohm, 3 bytes (CP437)
Non-competitive, obviously, but I don't think anyone will mind since this question is almost 5 years old ;)
6°P

Tcl, 104 bytes
set i 2
time {set p 1;set j 2;while \$j<$i {if $i%$j==0 {set p 0};incr j};if $p {puts $i};incr i} 999998

Try it online!
Unfortunately I could not find an online Tcl interpreter which does not time out running it.

Tcl, 110 bytes
set i 2
time {set p 1;set j 2;while \$j<$i {if $i%$j==0 {set p 0;break};incr j};if $p {puts $i};incr i} 999998

Try it online!

tcl, 115
set i 2
time {set p 1;set j 2;while \$j<$i {if ![expr $i%$j] {set p 0;break};incr j};if $p {puts $i};incr i} 999998

demo

tcl, 201
My still not golfed answer:
for {set i 2} {$i<$1000000} {incr i} {
    set p 1
    for {set j 2} {$j<$i} {incr j} {
        if {[expr $i%$j] == 0} {
            set p 0
            break
        }
    }

    if $p {puts $i}
}

demo

102

100

94 - note my previous bytecounts should be 2 longer since i lowered loop limit

88

05AB1E, 7 bytes
Since there is not yet an answer in 05AB1E.
T6mGNp–

Try it online!

Why is the input for this 22?

@carusocomputing There is no reason for that... removed it

Pyth, 12 bytes
V^T6IqlPN1N
Explanation
V^T6 - For loop using looping variable N in range 0 to 10 ^ 6
IqlPN1 - If len(prime_factors(n)) == 1
N - implicity print n (if it is prime)
Try running the code here: https://pyth.herokuapp.com/?code=V%5ET6IqlPN1N&debug=0
Note that this seems to take too long to run on the online interpreter, so  try replacing V^T6 with V^T3, which will run (and clearly if it can print primes up to 1,000, it will work with 1,000,000)

Welcome to PPCG!

Pyt, 9 bytes
78497ǰƖřᵽ

Try it online!

78498ǰƖřᵽ
78497      - push 7, 8, 4, 9, and 7 on the stack
    ǰ      - join everything on stack w/no delimiters
     Ɩ     - casts to int
      ř    - construct range from 78498 to 1 ([1,2,3,..., 78497, 78498])
       ᵽ   - push xth prime for every item in list

Doesn't meet the timeout rq on tio, but it would work, you can try it with lower numbers the reason for 78498 is that that is the 0 indexed prime under a million

You can save a byte (or two) and get it to not time out on tio: 6ᴇřĐṗ*žÁ. The Á is only to make the output match the format specified in the question, and can be removed if the output can be an array.

I feel like that's different enough to post as your own answer, but if you don't want to, I'll update.

I'll post it as a separate answer

C (gcc) 65 bytes
j;f(i){for(;++i<1e6;)for(j=2;!printf("%d\n"+(i>j)*3,i)&&i%j++;);}

Try it online! ( stops at 1000 )

59 bytes

Pyt, 8 bytes
6ᴇřĐṗ*žÁ

Try it online!
Explanation:
6ᴇ            Push 1000000
ř             Push [1,2,...,999999,1000000]
Đ             Duplicate top of stack
ṗ             Is each element prime (pushes array of booleans)
*             Multiply top two on stack element-wise
ž             Remove all zeros
Á             Push contents of array onto stack
              Implicit print

Rockstar, 128 bytes
X's1
while X-999999
let X be+1
let D be X
P's1
while P and D-2
let D be-1
let M be X/D
turn up M
let P be X/D aint M

if P say X

Try it here (Code will need to be pasted in) - Extremely inefficient; knock a few 9s off the second line to have it complete in a sane amount of time.

Factor + math.primes, 22 bytes
1e6 primes-upto stack.

Try it online!

1e6 primes-upto Get a list of primes up to a million
stack. Prettyprint each element of a sequence, one per line

C (gcc), 59 bytes
i;main(n){for(;n<1e6;i||printf("%d ",n))for(i=n++;n%i--;);}

Try it online! (upto 1000)

CellTail, 165 bytes
I=-1;O=N;N,-1,N:N,(1,1,1),N;999999..,N,N:N,N,N;A,(a,a,b),N:N,a,a+1;A,(a,b,0),N:N,(a+1,2),N;A,(a,b),N:N,(a,b,a%b),N;A,(a,b,c),N:N,(a,b+1,a%(b+1)),N;a,N,N:N,(a,1,a),N;

Should eventually produce the correct output, will take a very long time though.
Try it online
Try it online, numbers up to 1000 so it will actually complete in a few minutes

Arturo, 34 bytes
loop 1..1e6=>[if prime?<=&->print]

Try it

Python, 68
print[a for a in range(2,999999)if all(a%b for b in range(2,a/2+1))]

Sadly, there's no hope in seeing it terminate within any reasonable time frame...

Haskell, 126 chars, Using Sieve of Eratosthenes
import Data.Set
g i n m|i>n=[]|member i m=g(i+1)n m|1<2=i:g(i+1)n(fromList[i*i,i*i+i..n]`union`m)
main=print$g 2(10**6)empty

Run quite fast on my machine.
% ghc primeList1.hs -O
[1 of 1] Compiling Main             ( primeList1.hs, primeList1.o )
Linking primeList1 ...

% time ./primeList1 >/dev/null
./primeList1 > /dev/null  5.04s user 0.05s system 99% cpu 5.100 total

Ruby, 94 (optimized for speed, 2.655 secs)
(a=[*2..n=1e6]).each{|p|next if !p
break if p*p>n
(p*p).step(n,p){|m|a[m]=nil}}
puts a.compact

Ran in 2.655 seconds on my machine, which is pretty good considering how slow Ruby is.
Here's how I timed it:
t = Time.now

(a=[*2..n=1e6]).each{|p|next if !p
break if p*p>n
(p*p).step(n,p){|m|a[m]=nil}}
puts a.compact

puts Time.now - t

It takes a ridiculously long time to output to stdout, so I did sieve.rb > sieve.txt (on Windows).

(M)AWK - 104 103 100 98 97 87
BEGIN{for(n=2;n<1e6;){if(n in L)p=L[n]
else print p=n
for(N=p+n++;N in L;)N+=p
L[N]=p}}

Old:
The 'x' file:
BEGIN{for(n=2;n<1e6;){if(n in L){p=L[n]
del L[n]}else print p=n
for(N=p+n++;N in L;)N+=p
L[N]=p}}

The size:
$ wc -c x
97 x

The run (counting output lines instead of wasting space here) on a Thinkpad T60/T5500@1.6GHz in powersave mode (1 GHz clock, Debian6):
$ time mawk -f x | wc -l
78498

real    0m3.894s
user    0m3.820s
sys     0m0.072s

But since this won't be the shortest solution, speed is no matter.
The algorithm is a reorganized sieve method.
I have not seen this method elsewhere up to now and the local name is "floating sieve of erathosthenes" (FSOE) until I know better.

Groovy - 65 chars
This feels like cheating, but... Output confirmed against other solutions (i.e. 'probable prime' is accurate for such small values)
n=new BigInteger(1);78498.times{println n=n.nextProbablePrime()}

The code uses the fact that there are 78498 primes that fit the requirement.

C# & LinqPad 71
As usual directly executable in LinqPad
for(int i=0;++i<1e6;){for(int b=1;++b<i;)if(i%b==0)goto a;i.Dump();a:;}

Takes about 7 minutes on my computer.

Perl, 35
use ntheory":all";print_primes(1e6)

Fast and small vs. the usual golf horrifically slow regex.  I used this earlier for 39 characters:
use ntheory":all";say for@{primes(1e6)}

Golfscript, 55
{.2<{}{:l;1{).l\%}do}if}:r;10 6?,{..r={" "+print}{}if}%

Old code:
{:q-2:r\,{1+}%{q\%0={1r+:r}{}if}%;;r}:f 1000000,{f!},\;(;n*

WARNING.
This program uses an extremely slow algorithm, it takes ~15 seconds for it to display the 1000 first primes and the time grows exponentially. If you want to use it, change the 1000000 in the code to something lower.

><> (Fish), 54 51 bytes
11+:aa*:\/&~!
:**=?;2&\
:v?=&:&:<^!?%&+1:&
.\:nao90

There's Befunge but no ><>, so I thought "might as well". Uses the ever so slow trial division.

Smalltalk - 22 characters
Integer primesUpTo:1e6

The dialect is Smalltalk/X; other dialects have the same or a similar method in Integer.
Exec. time (measured with: "Time millisecondsToRun:[...]" is 90ms on my somewhat older (2010) 2.6Ghz Mac.
Evaluating "(Integer primesUpTo:1e6) size" returns: 78498

Ruby, 118 117 bytes
n=999984;t=true;a=[t]*n;(2..Math.sqrt(n).round).each{|i|a[i]&&(i..n/i).each{|j|a[j*i]=!t}};(2..n).each{|i|a[i]&&p(i)}

Run Time:
0.53s user 0.13s system 92% cpu 0.714 total

Swift 2, 79 bytes
Utilises the Sieve of Eratosthenes.
var r=[Int](2..<Int(1e6));while r.count>0{print(r[0]);r=r.filter{$0%r[0] != 0}}

Notes:

Solution without the sieve needs two extra bytes.
Takes ~14 mins on i5 3.5 GHz; or ~40 secs if compiled with optimisations.
Use -O flag with swiftc to turn on optimisations.

Molecule (v6+), 19 bytes
0{1+_p?~}u1000000L

Explanation:
0{1+_p?~}u1000000L
0{1+_p?~}          Push 0, add a code block.
         u1000000  Push one million.
                 L Repeat the code block 1000000 times.

Oracle SQL 11.2, 139 bytes
WITH v AS(SELECT LEVEL i FROM DUAL CONNECT BY LEVEL<=:1)SELECT a.i FROM v a, v b GROUP BY a.i HAVING:1-2=SUM(SIGN(MOD(a.i,b.i)))ORDER BY 1;

Pyth, 9 bytes
V^T6IP_NN

Try it online!
Explanation:
V   : Iterate over all numbers from 0 to ...
^T6 : 10^6
I   : If ...
P_N : number is prime ...
N   : print number

Java 107 Bytes, 26 minutes, naive approach
y->{int i=1,j,n,r=0;for(j=2,n=1000000;(r+=++i>=j?1:0)!=n;j+=j%i==0?i=1:0)System.out.print(i>=j?j+"\n":"");}

ungolfed
                y->{
                int i=1,j,n,r=0;
                for(j=2,n=1000000;
                    (r+=((++i>=j)?1:0))!=n;
                    j+=((j%i==0)?i=1:0)) {
                    System.out.print(i>=j?j+"\n":"");
                }
                }

Worstcase Runtime is O(n) divisons for primes as it tests everything in [2,i[ and looks if anything divides i and prints it if it's divisorless or continues if a divisor is found. n*O(n) would make it O(n^2), but due to distribution of divisors and primes, it is something along O(n^2/log(n))+O(n*log(n)) divisons. In practice this takes something along 26 minutes apparently.
Java ungolfed 1601 Bytes, adaptive wheel sieve, 1.6 seconds
public class Sieve {
    ArrayList<Integer> primes = new ArrayList<>();
    ArrayList<Integer> candidates = new ArrayList<>();
    int target = Integer.MAX_VALUE;
    int product = 1;
    int nextEvolve = 0;
    int multiplier = 1;
    int iteration = 0;
    boolean evolve = true;
    Sieve(int n) {
        this.candidates.add(1);
        this.target = n;
    }
    int next() {
        final int toTest = this.product*this.multiplier+this.candidates.get(this.iteration);
        //System.out.println("try: "+toTest+" p:"+this.product+" m:"+this.multiplier+" i:"+this.iteration);
        for(int i = this.nextEvolve; i < this.primes.size() && toTest/this.primes.get(i)>=this.primes.get(i); ++i) {
            if(toTest%this.primes.get(i)==0) {
                ++this.iteration;
                if((this.iteration%=this.candidates.size())==0) {
                    ++this.multiplier;
                }
                return this.next();
            }
        }
        this.primes.add(toTest);
        ++this.iteration;
        if((this.iteration%=this.candidates.size())==0) {
            ++this.multiplier;
            if(this.evolve && this.multiplier%this.primes.get(this.nextEvolve)==0) {
                if(this.target/this.product<toTest) {
                    this.evolve = false;
                }else {
                    final int size = this.candidates.size();
                    for(int i = 1; i < this.primes.get(this.nextEvolve); i++) {
                        for(int j = 0; j < size; j++) {
                            if((i*this.product+this.candidates.get(j))%this.primes.get(this.nextEvolve)!=0) {
                                this.candidates.add(i*this.product+this.candidates.get(j));
                            }
                        }
                    }
                    this.product*=this.primes.get(this.nextEvolve);
                    this.multiplier=this.multiplier/this.primes.get(this.nextEvolve);
                    ++this.nextEvolve;
                }
            }
        }
        return toTest;
    }
    public static void main(String[] args) {
        try {
            System.in.read();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        final Sieve s = new Sieve(1_000_000);
        for(int prime = s.next(); prime < 1_000_000; prime = s.next()) {
            System.out.println(prime);
        }
    }
}

Java golfed 883 Bytes, 16 seconds
class S{ArrayList<Integer> p=new ArrayList<>(),c=new ArrayList<>();int t,q,n,m,i;boolean e=true;S(int n){this.c.add(1);this.t=n;q=m=1;n=i=0;}int next(){int toTest=this.q*this.m+this.c.get(this.i);for(int i=this.n;i<this.p.size();++i)if(toTest%this.p.get(i)==0){++this.i;if((this.i%=this.c.size())==0)++this.m;return this.next();}this.p.add(toTest);++this.i;if((this.i%=this.c.size())==0){++this.m;if(this.e && this.m%this.p.get(this.n)==0){if(this.t/this.q<toTest) this.e=false;else{int size=this.c.size();for(int i=1;i<this.p.get(this.n);i++)for(int j=0;j<size;j++)if((i*this.q+this.c.get(j))%this.p.get(this.n)!=0)this.c.add(i*this.q+this.c.get(j));this.q*=this.p.get(this.n);this.m=this.m/this.p.get(this.n);++this.n;}}}return toTest;}public static void main(String[] args){S s=new S(1_000_000);for(int prime=s.next();prime<1_000_000;prime=s.next()){System.out.println(prime);}}}

Stata, 21 bytes
primes 1000000, clear

This is (obviously) a built-in command...

ASMD, 7 bytes
W(i|P?p

Explanation:
W        # Push 1,000,000
 (       # Begin range loop (0 -> 999,999)
  i      # Push counter variable
   |     # Duplicate
    P?p  # If prime, print
       . # Implicit end range loop

Ruby, 60 bytes
for n in 0..1e6
if('1'*n)!~/^1?$|^(11+?)\1+$/
puts n
end
end

see here for explanation

Python 2 (PyPy), 86 bytes
for i in range(2,int(1e6)):
	if all([i%j!=0 for j in range(2,int(i**0.5)+1)]): print i

Try it online!

Stax, 7 bytesCP437
ç►╪(Æ;Ç

Run and debug online!
Explanation
Uses the unpacked version to explain.
wi|6QVM<
w           loop
 i          loop index `i`
  |6        the `i`th prime
    Q       print and keep on stack
     VM<    while the printed number is less than one million

Microscript II, 18 bytes
6E_s{ls1+v;(lP)}*h

Requires the latest version of the interpreter due to a bug in how the previous version handled addition with null values (although in retrospect it might work even in the previous version if you change ls1+ to 1sl+).
Approximate pseudocode translation:
x=0
Repeat 10⁶ times:
    x=x+1
    if x is prime:
        print x
End

MathGolf, 5 bytes
►rg¶n

Try it online.
Explanation:
►     # Push 1000000
 r    # Pop and push a list in the range [0,1000000)
  g   # Filter it by:
   ¶  #  Is it a prime?
    n # Join with newline delimiter
      # (after which the entire stack is output implicitly as result)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

authors: 鼎点娱乐代理--平台总代

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Play a perfect game of Mu Torere
Background
Mu Torere is a game that is one of only two known to be played by the Maori people of New Zealand before European influence. This makes it a very unique game in that it has an "objective winning criterion" and rules of play that are different from most other games in existence.
Gameplay:
The board is an octagon. There are connections between each adjacent vertex, and there is a center node that is connected to all of the vertices. At any point in time, eight of the nine nodes are occupied by stones. At the start, there are four white stones and four black stones that are each take up one half of the octagon, with the center node empty. Black moves first.
Each turn, a player can move one of his stones along one of the 16 edges from one node to the empty node. A stone can only be moved from an outer node to the center node if the stone is next to an opponent's stone.
A player loses when he is unable to make a legal move, which occurs when there is no edge connecting a stone to the empty node.

Here is a website that explains the rules (with a diagram) and offers some analysis.
The Challenge
Your challenge is to write the shortest program that can play a perfect game of Mu Torere against a human opponent. Your program should be able to display and update the game board, make moves and receive moves from a human opponent. Most importantly, it should play a perfect game.
Perfect Game?
Yes, perfect game. I've been doing some game analysis, and I found that the game lasts for an infinite amount of time if played perfectly by both sides. This means that your program should never lose. Also, your program should be able to force a win whenever the human opponent makes a mistake that allows the program to force a win. As for how your program finds the perfect move, this is up to you.
Details
After each move (and at the start of the game), your program should print the game board. However you choose to display the board, it must show all of the nodes and be fully connected (all 16 connection lines should be drawn with no crossed lines). At the start, the board should have the correct starting position. One way of accomplishing this is by making the game board a square.
w-w-w
|\|/|
b-o-w
|/|\|
b-b-b

The two colors are black and white, or dark/light. The board must show which nodes are occupied by which player's pieces, such as marking them with a "b" or "w", and which node is vacant. Participants are encouraged (but not required) to make the game board more graphical, rather than plain text.
Your game board should have a numbering system that gives each node a unique number. You may choose to number the board any way you like, but it should be explained in your answer or by the program.
The square board can be numbered as follows:
1-2-3
|\|/|
4-5-6
|/|\|
7-8-9

The human is the first to move. His input will be a single number. This will be the number of the node where the moved stone currently is. If I wanted to move a stone from node 4 to an empty node 5, I will type a 4. The 5 is implied as it is the only empty node.
Assume that the human will always make a legal move.
After the human makes his move, an updated board should be printed. After your program decides on a legal move, it should print another updated board, and then wait for the human to enter another move.
Your program should terminate once it has won.
Notes
Standard code golf rules apply, no accessing external files, etc., etc. Also, I'm going to impose a flexible time limit of 15 seconds (on a reasonable machine) for your program to make each of its moves. As stated, this game has the possibility to form infinite loops, and I don't want a depth-first search getting into an infinite loop.

Great challenge. Only "If the human inputs an illegal move, then your program should wait and allow him to input a different move." seems a bit un-golf-ish to me: can't we just leave the behaviour undefined in case of illegal inputs?

I threw that requirement in at the last minute, and I guess it would be okay if we were to eliminate it. That just makes it harder for the human, who is already doomed to not win. :)

It's not that hard to always enter a legal move... By the way, after fairly detailed analysis I think it's unnecessary to search more than 1.5 moves ahead. Whether that approach is the shortest is another question.

The linked website isn't available anymore, it would be better to change it into a link to an archived version.

Ruby, 390 chars
o=->s,c{f=s=~/o/;[*0..8].select{|t|s[t]==c&&(t<1||(t+6)%8+1==f||t%8+1==f||f<1&&(s[(t+6)%8+1]!=c||s[t%8+1]!=c))}.map{|t|k=s*1;k[f]=c;k[t]=?o;k}}
v=->s,c,h{f=o[s,c];f==[]?0:h<1?1:2-f.map{|t|v[t,c>?b??b:?w,h-1]}.min}
q=->g{puts"1-2-3\n|\\|/|\n8-0-4\n|/|\\|\n7-6-5\n".tr"0-8",g;$>.flush}
q[g="obbbbwwww"]
(g.tr!?o,?b;g[gets.to_i]=?o;q[g];q[g=o[g,?w].sort_by{|q|v[q,?w,5]}[-1]])while v[g,?b,5]>0

An implementation in ruby which directly calculates the game tree (which takes quite some code) and thus always plays optimally. The board positions are spiraling outwards as shown in the following figure:
1 - 2 - 3
| \ | / |
8 - 0 - 4
| / | \ |
7 - 6 - 5

bash and friends (463 447 chars)
t(){ tr 0-8a-i $b$b
}
p(){ t<<E
0-1-2
|\|/|
3-4-5
|/|\|
6-7-8

E
}
g(){ b=`tr $x$e $e$x<<<012345678|t`
p
e=$x
}
b=bbbbowwww
e=4
m=0
p
while [ $m != 5 ]&&read x;do
g
m=0
for y in {0..8};do
s=0
S=05011234
grep -E "w.*($y$e|$e$y)"<<<${b:$y:1}30125876340142548746>/dev/null&&for p in wow.\*/ww wow.\*/w bbo.\*/b obb.\*/b www wbw .
do
((s++))
tr $y$e $e$y<<<3012587630/4e|t|grep $p>/dev/null&&break
done
s=${S:$s:1}
[ $s -gt $m ]&&m=$s x=$y
done
g
done

Human plays as b, computer as w. Board position is numbered as in the here doc at the top. It turns out that the heuristics to play a perfect game are surprisingly simple.
On the other hand, losing down the interesting path is quite hard. http://ideone.com/sXJPy demonstrates the shortest possible suicide against this bot. Note that the extra 0 at the end is to test that it breaks out of the loop correctly.

NB I could save one character by making the read x compulsory, but that would make testing quite frustrating. I could also save a character by removing the blank line after the board, but...

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Tower of hanoi solver
For reference as to what the tower of Hanoi is, either Google it or look on the Wikipedia page.
Your code should be able to do 2 things, and they are the following:

Accept user input that specifies the number of discs at the starting point of the Hanoi tower
Create output in a fashion of your choosing (so long as it is somehow logical) to show the solution to the tower puzzle.

An example of logical output would be the following (using a 4 disc start):
L1L2C1L1R-2R-1L1L2C1C-1R-2C1L1L2C1
L represents the left peg, C represents the center peg and R represents the right peg and the numbers are how far to move the disk on that peg and in what direction. Positive numbers represent the number of pegs moving towards the rightmost peg (because the disks start on the leftmost peg).
The rules to tower of Hanoi are simple:

Only one disk may be moved at a time.
Each move consists of taking the upper disk from one of the pegs and sliding it onto another peg, on top of the other disks that may already be present on that peg.
No disk may be placed on top of a smaller disk.

The disks start on the leftmost peg, largest on the bottom, smallest on the top, naturally.

Do we need to solve arbitrarily big towers, or is there some limit we can assume, like 10, 100, 1k, 1M discs?

@userunknown if I were you, I wouldn't worry too much about extraordinarily large numbers, but I'll say that the highest number of disks that your program can handle should only be limited by the computer's memory capacity or its call stack limit (kind of the same thing I guess, since memory is a pretty general term). Don't let arbitrarily high numbers scare you when submitting your code, though; if your solution is creative but can only handle so many disks, I for one would still give you credit.

Well, my idea was a pretty inefficient solving algorithm, and if the limit is, was the program can handle, it would be fine. But I had a look at the solutions so far, and realized, that I would play in a completely different league.

Husk, 5 bytes
↑≠⁰İr

Try it online!
Each n in the output represents moving disk n to the next available peg (wrapping cyclically).
Explanation
   İr   The ruler sequence [0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, ...]
↑       Take while...
 ≠⁰     ... not equal to the input.

Python, 76 chars
def S(n,a,b):
 if n:S(n-1,a,6-a-b);print n,a,b;S(n-1,6-a-b,b)
S(input(),1,3)

For instance, for N=3 it returns:
1 1 3  (move disk 1 from peg 1 to peg 3)
2 1 2  (move disk 2 from peg 1 to peg 2)
1 3 2  (move disk 1 from peg 3 to peg 2)
3 1 3  ...
1 2 1
2 2 3
1 1 3

I know  I am a bit late to the game but this shaves 13 chars: https://tio.run/##K6gsycjPM/r/PyU1TSFYI08n0dZQJ8nWWNOKSyEzTSHPCiima6iTqGOmm6ibpGldUJSZV6KQqJNkDZEAC@skaf4P1jDV/G/6HwA

Perl - 54 chars
for(2..1<<<>){$_--;$x=$_&-$_;say(($_-$x)%3,($_+$x)%3)}

Run with perl -M5.010 and enter the number of discs on stdin.
Output format:
One line per move, first digit is from peg, second digit is to peg (starting from 0)
Example:
02 -- move from peg 0 to peg 2
01
21
02
10
12
02

Save 5 chars by removing the braces. $x=--$_&-$_,say(($_-$x)%3,($_+$x)%3)for 2..1<<<>

GolfScript (31 25 24 chars)
])~{{~3%}%.{)3%}%2,@++}*

With thanks to Ilmari Karonen for pointing out that my original trs/permutations could be shortened by 6 chars. By decomposing them as a product of two permutations I managed to save one more.
Note that factoring out the 3% increases length by one character:
])~{{~}%.{)}%2,@++}*{3%}%

Some people have really complicated output formats. This outputs the peg moved from (numbered 0, 1, 2) and the peg moved to. The spec doesn't say to which peg to move, so it moves to peg 1.
E.g.
$ golfscript hanoi.gs <<<"3"
01021201202101

No doubt the same logic in sed is even shorter, but my sed abilities aren't up to it.

You can do it in 25 chars: ])~{.{3^3%}%2,@{2\-}%++}*

Perl, 75 79 chars
Totally stealing Keith Randall's output format:
sub h{my($n,$p,$q)=@_;h($n,$p^$q^h($n,$p,$p^$q),$q*say"@_")if$n--}h pop,1,3

Invoke with -M5.010 for the say.
(I think this can be improved if you can find a way to make use of the function's return value instead of just suppressing it.)

[stock "just use say" recommendation]

Okay -- but wouldn't I have to include the cost of enabling 5.10 features against my char count?

You would—but it's free. Just make a note of how to invoke your program so that people not fluent in perl invocation specifics can give it a shot anyway.

Thanks for the link; I was looking for that sort of thing earlier.

SML, 63
fun f(0,_,_)=[]|f(n,s,t)=f(n-1,s,6-s-t)@[n,s,t]@f(n-1,6-s-t,t);

call function f(n,s,t) with:

n number of disks
s starting point
t goal point

Scala,92 88 87 chars
def?(n:Int,a:Int,b:Int){if(n>0){?(n-1,a,a^b)
print(n,a,b);?(n-1,a^b,b)}};?(readInt,1,3)

Output format
Say number of disk=3 then,
(1,1,3)(2,1,2)(1,3,2)(3,1,3)(1,2,1)(2,2,3)(1,1,3) (disk number,from peg, to peg)
                                                   \---------------------------/
                                                            Move 1              ... Move n

Nice use of xor.

Bash (64 chars)
t(){ tr 2$1 $12 <<<$s;};for((i=$1;i--;))do s=`t 1`01`t 0`;done;t

Posting this one despite being more than twice the length of the GolfScript one because I like the reuse of t to serve as echo $s.

C, 98 92 87 chars
Implements the most trivial algorithm.
Output is in the form ab ab ab where each pair means "move the top disc from peg a to peg b".
EDIT: Moves are now encoded in hex - 0x12 means move from peg 1 to peg 2. Saved some characeters.
EDIT: Reads the number from stdin, rather than parameter. Shorter.
Example:
% echo 3 | ./hanoi
13 12 32 13 21 23 13
n;
h(d){n--&&h(d^d%16*16,printf("%02x ",d,h(d^d/16))),n++;}
main(){scanf("%d",&n);h(19);}

Can someone explain the syntax of the body of function h() - particularly the apparent two arguments in its recursive call (d^d%16*16 and printf(...)), and the last operation apparently hanging off the end. Based on my knowledge, that function has two syntax errors, but I already know it builds (after including stdio) and executes correctly.

It's possible to pass more parameters than the function wants. Their values go nowhere. h(x,printf(...)) is simply a way to call printf before h is called. The last n++ is made after the inner h returns. It's used to undo the initial n--.

Thanks, that makes sense (the purpose of n++ was evident). Why isn't there a semicolon preceeding n++ instead of a comma, or does it make a difference?

@Griffin, Actually ; would be the same here. , is often useful (e.g. if(x)a,b; replaces if(x){a;b;}), but has no advantage here.

Jelly, 5 bytes
2*Ṗọ2

Try it online!
0 move the smallest disk one space to the right (wrapping back to the start if necessary)
1 move the second-smallest disk to the only other legal column
2 move the third-smallest disk to the only other legal column
etc.
Algorithm
We can see the solution of the Towers of Hanoi problem recursively; to move a stack of size n from A to B, move a stack of size n-1 from A to C, then the disk of size n from A to B, then move a stack of size n-1 from B to C. This produces a pattern of the following form (in the output format used by this program):
0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2 …

We can observe that this sequence is A007814 on the OEIS. Another possible definition of the sequence is "the kth (1-based) element of the sequence is the number of zeroes at the end of the number k when it's written in binary". And that's what the program here is calculating.
Explanation
First, we calculate the number of moves in the solution, 2n-1. It turns out to be shortest to actually calculate one extra move and discard it later, so this is 2*, i.e. 2 to the power of something. (The only input we've taken so far is the command line argument, so that gets used by default.)
Next, we use Jelly's builtin for calculating the number of zeroes at the end of a number in base b; that's ọb. As we're calculating in binary, it's ọ2. All we need to do is to apply this builtin to the numbers from 1 to 2n-1 inclusive.
There are two simple ways to iterate over a range of numbers in Jelly, € and R, and my earlier attempts at this problem used one of these. However, in this case, it's possible to go slightly shorter: Ṗ, when given a number as input, will let you do an iteration that stops one element short (in general, Ṗ is a builtin used to process all but one element of something). That's exactly what we want in this case (because 2* generates one too many elments), so using it to link 2* and ọ2 into 2*Ṗọ2 gives us a 5-byte solution to the problem.

Awk, 72 chars
function t(n,a,b){if(n){t(n-1,a,a^b);print n,a,b;t(n-1,a^b,b)}}t($0,1,3)

Output format is same as Keith Randall's one.
awk -f tower.awk <<< "3"
1 1 1
2 1 1
1 1 1
3 1 3
1 1 1
2 1 3
1 1 3

Bash script, 100 96 chars
t(){ [[ $1<1 ]] && return
t $(($1-1)) $2 $(($2^$3))
echo $@
t $(($1-1)) $(($2^$3)) $3
}
t $1 1 3

Output format is same as Keith Randall's one.
1 1 3
2 1 2
1 3 2
3 1 3
1 2 1
2 2 3
1 1 3

Edit: Saved 4 chars by peter's comment.

You can add the spaces and save a few chars by echoing $@

@PeterTaylor: Good point. let me update it.

J, 23 bytes
binary numbers solution
2&(+/@:~:/\)@#:@i.@^~&2

This solution uses the binary counting method described in this video.
Which is to say, I generate the binary digits from 1 up to 2^n, then take infixes of length 2 and compare each bit to the corresponding bit of the previous number, and check if they're unequal.  The number of unequal bits is the output for that move.
Output, eg, for 3 disks, where smallest disk is labeled 1:
1 2 1 3 1 2 1

1 means "move the smallest disk one peg right, looping back to the first peg if needed"
n, for all other n, means "move disk n to a legal peg" (there will always be exactly one)
Try it online!
recursive solution
((],[,])$:@<:)`]@.(1=])

Same output as the above solution, but the logic here makes the recursive nature of the problem clearer.
Visualizing it as a tree also emphasizes this point:
              4
             / \
            /   \
           /     \
          /       \
         /         \
        /           \
       /             \
      3               3
     / \             / \
    /   \           /   \
   /     \         /     \
  2       2       2       2
 / \     / \     / \     / \
1   1   1   1   1   1   1   1

Try it online!

the coincidental nature of submitting your answer over 5 years after the original question was posed within the same hour that I returned to review the answers to this question I submitted over 5 years ago… wow. +1

R, 73 bytes
Putting R on the map. Inspired by [Keith Randall's answer][1] with simplified input, print only end and start peg to save 2 bytes. Also 0-indexed pegs.
f=function(n,s=0,e=2){if(n){f(n-1,s,3-s-e)
print(c(s,e))
f(n-1,3-s-e,e)}}

Try it online!

APL (Dyalog Classic), 19 bytes
3|(-⍪0 1⍪2∘-)⍣⎕,⍨⍪⍬

Try it online!
output is a 2-column matrix of ints in {0,1,2} - from peg, to peg

K (ngn/k), 23 bytes
{3!x{-x,(,0 2),1+x}/()}

Try it online!

JavaScript (ES6), 45b
h=(n,f,a,t)=>n?h(--n,f,t,a)+f+t+h(n,a,f,t):''

e.g. calling h(4, 'A', 'B', 'C') (move 4 discs from peg A to peg C using auxiliary peg B)
returns 'ABACBCABCACBABACBCBACABCABACBC' (move a disc from peg A to peg B, move a disc from peg A to peg C, move a disc from peg B to peg C, etc.)

Nice. I wonder whether the f,a,t parameters should have defaults included in the function definition? Otherwise submissions could include arbitrary data in additional args. I’m a newbie though, so someone more experienced should advise.


text:
Write the shortest program that generates the most compiler warnings and errors
The challenge:
Write a very short program that, when compiled, creates the most amount of compiler warnings and errors. It can be written in any programming language.
Scoring:
The score is determined by this equation: errors_and_warnings_length/code_length. Highest score wins.
Example:
The C# program class is 5 chars long and generates 3 warnings, which is a score of (1/5)*3 = 0.6.
EDIT:
Because of some confusion, programs have to be at least 1 char long. Otherwise it would get a score of infinity.

While I like the concept, I find the metric a little worrisome. What compiler? What settings (especially with regard to warnings)? I mean gcc -Wall -pedantic is very different from plain ol gccis different fromtcc` is presumably different from some other c compiler.

Just get a compiler in Russian, or German, you get some LONG errors(no pun intended)

I'd love to see answers in languages other than C/C++.

I would've liked it if the challenge was to generate as many different errors as possible

Ahem. Otherwise its score would be undefined.

On a related note, here's a link to the grand C++ error explosion competition
http://tgceec.tumblr.com/post/74534916370/results-of-the-grand-c-error-explosion

GCC, score 2200 / 36 ≈ 4.5 × 1058
#include __FILE__
#include __FILE__

I have not actually finished compiling this code, but based on testing and simple mathematics, it should produce a total of 2200 #include nested too deeply errors.
Of course, the program is trivially extensible.  Adding a third line brings the score up to 3200 / 54 ≈ 4.9 × 1093.  Four lines give 4200 / 72 ≈ 3.6 × 10118, and so on.

Very clever answer. +1

Very clever I agree, but I'd count that as 1 error ("nested too deeply"), not a separate error for each line of the backtrace.

Wow, very clever. Looks like we got a very clear winner!

@Kevin: Just to be clear, it should produce that error 2²⁰⁰ times, once for each possible path by which the nesting limit can be reached.  The fact that each error also includes 200 lines of backtrace just makes the output even more verbose.

Hmm. I could swear when I tried it last night gcc bailed after 1 error, but it appears to be running printing more now.  Objection withdrawn. Incidentally, is 200 from the c standard?

@Kevin: I've no idea, but that's what the limit seems to be for GCC.

@Kevin Per http://gcc.gnu.org/onlinedocs/gcc-4.8.2/cpp/Implementation-limits.html : "We impose an arbitrary limit of 200 levels [of nested #include], to avoid runaway recursion. The standard requires at least 15 levels."

... and it's a good thing I don't hack on GCC anymore or I would feel I had to find some way to detect this scenario and bail out earlier. ;-)

C, 0 characters - Score=(1/0)*1=Infinity

generates 1 error:
/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status

Note: http://ideone.com/xdoJyA

1/0 is undefined, not "infinity".

@Frank, that depends on the number system.

Fitting answer to this question.

+1 Even if 1/0 is undefined, it's demonstrably larger than one divided by any larger number.  0 takes the cake.

@jnm2 not sure about that. 1/0 is undefined and, although right side approaches +infinity, that doesn't make 1/0 defined at all.

Limit doesn't say a whole lot about the value in the point. That only holds true if the function is continuous in that point. Take for example the sign function.

Not to mention, @jnm2, by your logic 1/0 also is demonstrably smaller than 1 divided by any smaller number than 0. Making it 1/-1 = -1 > 1/0 > 1 = 1/1 ?

Note that you can turn the link error into a compiler error. Using gcc's -pedantic switch wil give you: empty.c:1: warning: ISO C forbids an empty translation unit.

Since the domain is positive, I think what I said makes sense.  Theory is fun but I think we need some common sense here.  The most compiler errors for the least amount of code, remember.  The limit is obvious.

1.0/0.0 = +INF, at least according to IEEE 754 :)  So you just have to do the calculation in floating point.

A zero-sized C code was accepted as the winner in the IOCCC, as the shortest self-replicating program, so it's a good precedence to accept it here. (the rules were, as usually, changed after that submission, but it still counts)

In Maths, 1/0 is infinity and it is 0/0 which is undefined.

I've modified the rules. Sorry, but your program is disqualified. +1 for the idea, though.

@manojlds Incorrect. The limit is, in some cases, +infinity. However imagine the limit of 1/(-(x^2)) when approaching zero, suddenly it's 1/0 = -infinity. And what about 1/sgn(x)? Now the limit coming from the positive side is +1 and the limit from the negative side is -1.

@WardMuylaert what you say is right, sgn(x) matters, but in this case x is the number of characters of code, which cannot be negative, so the limit must come from +1 side. Also, when I wrote infinity there all that was on my head was 1/10 < 1/1 < 1/0.1 < 1/0.01 < 1/0.001 <.....<1/0. :P

1/0=∞ in arithmatic on the real projective line. So like it was said before, this is just a matter of the number system you are using.

GCC, score 5586.6 (and more if needed)
179 chars, 1000003 warnings/errors (using -Wall)
#define E a,a,a,a,a,a,a,a,a,a
#define D E,E,E,E,E,E,E,E,E,E
#define C D,D,D,D,D,D,D,D,D,D
#define B C,C,C,C,C,C,C,C,C,C
#define A B,B,B,B,B,B,B,B,B,B
_(){A,A,A,A,A,A,A,A,A,A}

This can be extended arbitrarily, of course. For example, using 10 #defines instead of 5 and a length of 20 "calls" instead of 10 would lead to a score of about (20**10)/(179*4) = 14301675977.65 (and would take quite some time to run ;)

Using #define X(A) A,A,A,A,A,A,A and X(X(X(X(X(X(A)))))) you can duplicate code much faster.

An application of the billion laughs attack, nice.

GCC twice, 86
22 chars, 1898 errors+warnings on my system.
I'm sure this approach can be much improved, by choosing longer files with shorter names.
#include</usr/bin/gcc>

/usr/bin/gdb is significantly larger (5.5M vs 760K), but /vmlinuz at 5.6M might be your best bet.

HQ9++, 1 (limit of (n+29)/n)
The following emits the warning Warning: this is not a quine for each Q in the code.
QQQQQ...Q
Warning: this is not a quine

Small is good, right?  Hmm...

FWIW, this is a joke.  If that wasn't obvious.

As far as jokes go, this is a good one. +1

C, .727
11 chars, 5 errors, 3 warnings, (1/11)*8 = .727273
m(;){@,x}2

cc -g -Wall    er.c   -o er
er.c:1: error: expected declaration specifiers or '...' before ';' token
er.c:1: warning: return type defaults to 'int'
er.c: In function 'm':
er.c:1: error: stray '@' in program
er.c:1: error: expected expression before ',' token
er.c:1: error: 'x' undeclared (first use in this function)
er.c:1: error: (Each undeclared identifier is reported only once
er.c:1: error: for each function it appears in.)
er.c:1: warning: left-hand operand of comma expression has no effect
er.c:1: warning: control reaches end of non-void function
er.c: At top level:
er.c:1: error: expected identifier or '(' before numeric constant

I count 5 errors, plus 3 warnings

I suppose you're right. I was counting the "error:" and "warning:" strings.

I think you win if we only count different errors/warnings.

If -Werror is used on the command line, warnings are promoted to errors.  And also, which C compiler used will affect the number of reported errors (or if -Werror is available, etc.)  One might argue the command line length for invocation might be counted as part of the "program" length... and each compiler version on each platform is a separate category.  :-)

NASM, score 63/40 * 2^32 ≈ 2.905 * 10^19
%rep 1<<32
%rep 1<<32
!
%endrep
%endrep

Will output c.asm:3: error: label or instruction expected at start of line 2^64 times. Again this is easily extensible to much bigger outputs.

C++98 (211 bytes) g++-5 (Ubuntu 5.2.1-23ubuntu1~12.04) 5.2.1 0151031
I wanted to see how well I could do in C++ without using the preprocessor at all. This program produces 2,139,390,572 bytes of output, most of which is a single error message.
template<int i,class S,class T>struct R{typedef R<i,typename R<i-1,S,S>::D,typename R<i-1,S,S>::D>D;};template<class S,class T>struct R<0,S,T>{typedef S D;};void f(){R<27,float,R<24,int*const*,int>::D>::D&E=4;}

me@Basement:~/src/junk$ ls -l a.C
-rw-rw-r-- 1 me me 211 Apr 27 21:44 a.C
me@Basement:~/src/junk$ g++-5 a.C -fmax-errors=1 2>a.C.errors.txt
me@Basement:~/src/junk$ ls -l a.C.errors.txt
-rw-rw-r-- 1 me me 2139390572 Apr 27 22:01 a.C.errors.txt

Ungolfed:
template <int i, class S, class T>
struct R {
    typedef R<i, typename R<i-1,S,S>::D, typename R<i-1,S,S>::D> D;
};
template <class S, class T>
struct R<0, S, T> {
    typedef S D;
};
void f() {
    R<27, float, R<24, int*const*, int>::D>::D &E = 4;
}

This program works by defining a recursive struct template R which holds a typedef D containing two copies of R. This results in an type name which grows exponentially, which is printed out in full in the error message. Unfortunately, g++ seems to choke while attempting to print an error message longer than (1<<31) bytes. 2,139,390,572 bytes was the closest I could get to the limit without going over. I'm curious if anyone can adjust the recursion limits and parameter types 27, float, 24, int*const* to get closer to the limit (or find a compiler which can print an even longer error message).
Excerpts from the error message:
a.C: In function ‘void f()’:
a.C:1:208:  error:  invalid  initialization  of non-const reference of type
‘R<27, float, R<24, R<23, R<22, R<21, R<20, R<19, R<18, R<17, R<16, R<15,
R<14,  R<13, R<12, R<11, R<10, R<9, R<8, R<7, R<6, R<5, R<4, R<3, R<2, R<1,
int* const*, int* const*>, R<1, int* const*, int* const*> >, R<2, R<1, int*
const*,  int*  const*>,  R<1, int* const*, int* const*> > >, R<3, R<2, R<1,
int* const*, int* const*>, R<1, int* const*, int* const*> >, R<2, R<1, int*
const*,  int* const*>, R<1, int* const*, int* const*> > > >, R<4, R<3, R<2,
R<1, int* const*, int* const*>, R<1,
...
int*  const*,  int*  const*>  > > > > > > > > > > > > > > > > > > > > > > >
>::D& {aka R<27, R<26, R<25, R<24, R<23,  R<22,  R<21,  R<20,  R<19,  R<18,
R<17,  R<16,  R<15,  R<14, R<13, R<12, R<11, R<10, R<9, R<8, R<7, R<6, R<5,
R<4, R<3, R<2, R<1, float, float>, R<1, float, float> >, R<2,  R<1,  float,
float>,  R<1,  float, float> > >, R<3, R<2, R<1, float, float>, R<1, float,
float> >, R<2, R<1, float, float>, R<1, float, float> > > >, R<4,
...
, R<1, float, float>, R<1, float, float> > >, R<3, R<2, R<1, float, float>,
R<1, float, float> >, R<2, R<1, float, float>, R<1, float, float> > > > > >
>  >  >  >  >  >  > > > > > > > > > > > > > > >&}’ from an rvalue of type
‘int’
    template<int    i,class   S,class   T>struct   R{typedef   R<i,typename
R<i-1,S,S>::D,typename  R<i-1,S,S>::D>D;};template<class  S,class  T>struct
R<0,S,T>{typedef                         S                         D;};void
f(){R<27,float,R<24,int*const*,int>::D>::D&E=4;}

                                                        ^
compilation terminated due to -fmax-errors=1.

2,139,390,572 bytes / 211 bytes = 10,139,291.8

This is why I always use STLfilt... Welcome to PPCG! This is a great first submission!

Unfortunately it seems I misunderstood the challenge; it seems submissions are scored by the number of error messages, not the byte count. Obviously my 1 error entry is not very competitive. Perhaps my answer should be moved here

Rust, 206 chars, 220+2 errors, score 5090, tunable.
macro_rules! e {
    ($e:expr, $($es:expr),+) => {
    compile_error!(stringify!($e, $($es),+));
        e! { $(a + $es),+ }
        e! { $(b + $es),+ }
    };
}
e! {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

And you can actually see it finish compilation, in about 3 minutes for me:
error: could not compile `a` due to 1048578 previous errors

Like the C #include __FILE__ example above, it is tunable, but

if you want to go beyond 2256, you need to set #![recursion_limit = "9999999"]
rustc will OOM long before you can reach that
longer expressions mean slower execution, so the more errors you want, the slower they will be printed

What I actually wanted to do is implement the Péter's variant of the Ackermann function. But I don't quite grok macros well enough to do that with the unary encoding. Anyone help?

SmileBASIC, 1/1 = 1
A

Generates the error Syntax Error in 0:1

SB only ever generates one error at a time, so this is really the only answer you can make.