text:
Generate a right triangle
In this challenge, you must take two numbers (separated by a space) as input and output an ASCII right triangle, made up of xs.
The first number will be the width and height of the triangle you should output. The second number will be which corner the right angle will be in. The corners are numbered 1 to 4, starting in the top left and going in English reading order:
1    2

3    4

For example (inputs and their respective triangle outputs):
INPUT | 3 1 | 3 2 | 3 3 | 3 4
------+-----+-----+-----+----
 OUT- | xxx | xxx | x   |   x
 PUT  | xx  |  xx | xx  |  xx
      | x   |   x | xxx | xxx

Your program's output must match these examples exactly for their respective inputs.
The input will always be valid: the first number will be an integer ≥1, and the second number will be 1, 2, 3, or 4.
This is code-golf; shortest code (in character count) wins.

APL (30)
{' x'[1+(⍎⍵⌷'⌽+⍉⊖')≤/¨⍳2⍴⍺]}/⎕

Explanation:

{...}/⎕: reduce given function over the input (so if the input has 2 numbers, just calls the function with those two numbers, ⍺ being the left number and ⍵ the right number)
≤/¨⍳2⍴⍺: Make an ⍺-by-⍺ coordinate matrix and set those positions where the X coordinate is not greater than the Y coordinate, giving a bitfield.
(⍎⍵⌷'⌽+⍉⊖'): select a transformation function given by ⍵ to put the triangle right-side-up.
' x'[1+...]: add one to the bitfield, and use the result as an index into the string ' x', so putting space for 0 and x for 1.

The more APL I read, the more I realize APL is a parsing nightmare.  Wouldn't it have to actually evaluate the (⍎⍵⌷'functions') part before it decides how to interpret the whole statement? Consider for example 1+(⍵⌷'12+')|40.  It wouldn't even know if | is monadic or dyadic before ⍎ing that parenthesized portion.
The whole abstract syntax tree changes depending on the evaluation.

I meant 1+(⍎⍵⌷'12+')|40...will not let me edit.

@protist: Fun fact: f ← { [ } does not give an error! f 1÷0 gives... a domain error! (because of the division by zero). Only when you call the function like f 123 you get syntax error. Behold: http://imgur.com/jtmdi4B

By all the gods!!!! That breaks my heart a little.  I have been playing with writing APL interpreters some, and that demonstrates a great evil in the current implementations. hahaha

It almost seems like functions are put in place routinely by some sort of ugly macro-expansion-like process.  It would somewhat indicate in-place text expansion.

@protist: Yeah, I was rather surprised too when I discovered that the ⍎⍵⌷ thing works. When I wrote this, I thought J-style gerunds would come in very handy and on a whim I tried this. Luckily I don't actually use APL for any "real" programming. The way it works, it's actually impossible to parse a function without knowing what its formal parameters are - so that means it actually has to reparse the function every time you call it!

@protist: This of course is mitigated by the fact that this only holds for functions that contain ⍎, and those would have to do parsing on each call anyway. Though considering { [ } is not a syntax error I don't think it actually does that optimization.

Ruby, 116 115 109 96
I shall start with my own solution.
i=gets.split
s=i[0].to_i
(i[1]<?3?s.downto(1):1..s).map{|x|t=?x*x
puts /2|4/=~i[1]?t.rjust(s):t}

I just know that I'll get beat by a 30 character GolfScript solution almost instantly :P
Thanks to minitech for shaving off 19 characters (wow)!

Instead of ==0, you can use <1. ?x*x saves another character. Also, puts i[1]%2<1?t.rjust(s):t} would do the trick, right?

Hmm… you have spaces around the ?? Is that necessary? Also, I think you can do the same thing with the r=.

@minitech It is necessary - the leading space because otherwise it parses 1? as a single token, and the trailing space because otherwise it parses as ?t (which is equivalent to 't'). How do you propose restructuring the r part?

Did you try it? Under which version of Ruby? Works fine for me on 2.0.

@minitech Odd, it didn't work before and now it does :P Thanks

You can get it down to 99: https://gist.github.com/minitech/6334130

@minitech Wow, thanks! You're amazing at code golf :P

Oops, and of course one more with .map &:to_i :D Also, thanks!

Keep it as a string and abuse ord to shave off… one more character: https://gist.github.com/minitech/6334130/revisions

Regular expressions for… one more! puts /2|4/=~i[1]?…

GolfScript (34 33 chars)
~\:^,{)' x'^*$>^<0(2$?%}%\(2&(%n*

It's a shame that the corners aren't numbered in rotation, because that would allow a more elegant approach of building one array and then rotating it n times:
~\:^,{)' x'^*$>^<}%{-1%zip}@)*n*

C# - 195
using System;class P{static void Main(string[]a){int G=int.Parse(
a[0]),O=int.Parse(a[1]),L=O<3?0:G+1,F=O<3?-G:1;G=O%2>0?-G:G;for(;
F<L;F++)Console.Write("{0,"+G+"}\n","".PadRight(F<0?-F:F,'x'));}}

Formatted:
using System;
class P
{
    static void Main(string[] a)
    {
        int G = int.Parse(a[0]),
            O = int.Parse(a[1]),
            L = O < 3 ? 0 : G + 1,
            F = O < 3 ? -G : 1;

        G = O % 2 > 0 ? -G : G;

        for(; F < L; F++)
            Console.Write("{0," + G + "}\n", "".PadRight(F < 0 ? -F : F, 'x'));
    }
}

Input has to be space-delimited, not comma separated.

@Doorknob: The screenshot is from a test program where I chose to show the input with a comma. The input actually is space delimited when you execute the program, although the point is moot because all C# console applications receive input as an array of strings.

Mathematica 122 (104?)
g@s_ := ({w, p} = ToExpression@StringSplit@s;
   Array[If[Switch[p, 1, # <= (w + 1 - #2), 2, # <= #2, 3, # >= #2, 4, # > (w - #2)],
   "X", ""] &, {w, w}]) // Grid

GraphicsGrid[{{g["12 1"], g["12 3"]}}]

Under a liberal interpretation of "output", the following (104 chars) will work.
f@s_ := ({w, p} = ToExpression@StringSplit@s;
  Graphics[Polygon@Delete[{{w, 0}, {0, 0}, {w, w}, {0, w}}, p], Axes -> True])

f["50 4"]

If input in the form of a list were permitted, the following (75 chars) would suffice:
f[{w_, p_}] :=
 Graphics[Polygon@Delete[{{w, 0}, {0, 0}, {w, w}, {0, w}}, p], Axes -> True]

Technically this is against the rules :P

What rule does it violate?

The input/output chart thingy I put. The 122 char one is good though. I edited the question to clarify

Oops. I thought the chart was simply an example.

I just placed the ASCII art version in first place.

Golfscript, 39 36 35 characters
~\:y,{' '*'x'y*+y<0~2$?%}%-1@2>?%n*

live demo: http://golfscript.apphb.com/?c=OyczIDInCn5cOnkseycgJyoneCd5Kit5PC0xIDIkPyV9JS0xQDI%2BPyVuKgo%3D
too bad it's not 30 characters as requested

Replacing 1${-1%}* with -1 2$?% and \2>{-1%}* with \2>-1\?% will net you 2 characters.

@Volatility thanks, incorporated

@Volatility -1 2 can be written 0~2

And for another char we have to restructure a bit more: ~(\:y,{{>'x '=}+y,%0~2$?%}%\2&(%n*

J, 59 55 42 38 37 36 characters
If it's permitted to have the input at the end of the program:
(|:@|.@]^:([:|[+_7*2<[)[:[\'x'$~])~/

If not (for an extra 3 characters):
t=.(|:@|.@]^:([:|[+_7*2<[)[:[\'x'$~])~/

Usage:
   (|:@|.@]^:([:|[+_7*2<[)[:[\'x'$~])~/3 4
  x
 xx
xxx

or
   t 3 4
  x
 xx
xxx

I think this could be a fair bit shorter since most of the characters are brackets and caps to keep it in an implicit style.
Edit
Using a gerund and the agenda verb has chopped off a few characters, but there's still too many caps in there for my liking.
Edit 2
That's a bit more like it. Dumping the agenda for a list of how many rotations are required gets rid of most of the extra brackets and a few caps.
Edit 3
Got rid of the last extraneous cap and a pair of brackets in the process. Need to find a cheaper way of encoding the number of rotations required.
Edit 4
Use prefix instead of suffix to chop off a character. Enables a different way of creating the list which doesn't save any characters. Bugger.
Edit 5
Using a formula to chop off another character. Still feel this bit could be shorter.

Python 106 Characters
w,d=map(int,raw_input().split())
for e in range(1,w+1)[::d/3*2-1]:print('%'+'-+'[d%2]+str(w)+'s')%('*'*e)

Python 3, 91
Based on Abhijit's answer.
Modified the creation of the output string to avoid the sum of strings and the ugly 1s in the range.
Python 3 gets rid of the raw_ in raw_input, but makes necessary to use // for integer divison and to add parantheses for print, so that saves only one character.
w,d=map(int,input().split())
for e in range(w)[::d//3*2-1]:print('%*s'%(w-d%2*2*w,'x'*-~e))

Kitten, 140
def s{><replicate}
getLine{' 'neChar}span{readInt fromSome}toBoth->{w n}
w 0 if(n 2>){><}..
{<>w>< -{'X's}{' 's}both if(n 2%0=){><}cat say}each

Ungolfed:
getLine
{' ' neChar} span
{readInt fromSome} toBoth
->{ width corner }

width 0
if (corner 2 >):
  swap
..

{ ->index
  'X' index replicate
  ' ' (width index -) replicate
  if (corner 2 % 0 =):
    swap
  cat say
} each

Evidence that I need to implement overloading and flesh out the standard library.

source: Stack Exchange

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

sort: votes


text:
Simple chess bot
Inspired by this
Implement simple chess bot (with console or GUI) that has following features:

[Pseudo-]graphically showing the board;
Accepting user moves and making their own moves;
Playing by basic chess rules (not doing illegal moves);
Making at least minimally reasonable moves (no random moves, a player making random valid moves against the bot should lose most times).

In general, implement something like "SedChess" (linked above) in minimum number of bytes.
Optional:

Advances rules like castling, stalemate detection, en passant, etc;
Checking validity of user inputs;
Analysing more than 1 move in depth;

Limitations:

No networking;
No dependance on chess-specific libraries (unless they are included in the language and language's standard library) or programs;
No lame tricks like showing two boards and requesting user play two games (with himself).

Do you think anyone can compete with this?

Nice. Maybe somebody want to try more languages for this problem.

You describe a major undertaking, not a puzzle.

There are other major undertakings like golfing an x86 emulator here.

This looks rather like an extension of Calculate all legal moves, which so far has no submissions. If you want anyone to attempt an answer, you might be better off restricting the question to the half which that one doesn't cover - i.e. estimating a board's value.

@PeterTaylor Which btw was solved already here ;-) Unfortunately no one tried another solution in either question.

@ugoren Yes I do believe so. I beat that chess bot in a match of chess.

See also: http://codegolf.stackexchange.com/questions/37251/chess-tournament

This one posted by ugoren doesn't recognize checkmate or castling or en passant.

@ugoren You can't castling :/ But else, nice bot for a 1k bytes!

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


text:
Create sets with a Goldbach-like property
Goldbach's conjecture states that every even number > 4 is the sum of two prime numbers.  Although this conjecture is not yet proven, similar results have been proven for other series of numbers.  For example, every even number can be written as the sum of two practical numbers.
The Challenge
Given a number N, return a set of positive integers such that every even number in the interval [4,N] can be written as the sum of two numbers in the set.  Furthermore, the set generated must contain as few elements as possible, otherwise this challenge would be trivial.
Shortest answer wins.
Detailed Example
For N=24, one possible output is {2,4,8,10,12}.  This is because it contains the fewest number of elements possible (5).  Also, every even number {4,6,8,... 24} can be written as the sum of exactly two of the members of the set.
4=2+2
6=2+4
...
12=8+4
14=10+4
...
24=12+12

Examples
Here are some examples.  There may be many valid outputs for each input, but only a few are listed.
4:{2}
6:{2,4} or {1,3}
9:{2,4}  #pay attention to how the odd number is handled
10:{2,4,6} or {2,3,5}
12:{2,4,6}
24:{2,4,8,10,12}
26:{1,3,7,11,13}

I asked a question at Math.SE about the mathematical details of this problem: http://math.stackexchange.com/questions/476081/how-can-i-find-the-smallest-set-such-that-all-even-integers-4xn-can-be-writt

GolfScript (53 chars)
~2/),3>[2][1 3]]({2*:x;{:S{x<},{x\-S+.&}/}%}/{,}$0=n*

A major speed optimisation results from a bit of duplicate-trimming, at a cost of 3 chars:
~2/),3>[2][1 3]]({2*:x;{:S{x<},{x\-S+.&$}/}%.&}/{,}$0=n*

NB Let f(2n) be the size of the optimal set for [4..2n]. Then f(2n) <= f(2n+2) <= f(2n) + 1. The first inequality is obvious from the definition; the second is easily seen by taking any optimal set S_{2n} for [4..2n] and taking the union with {n+1}, or indeed with {2n+2-x} for any x in S_{2n}.
This suggests a greedy algorithm, which the first revision of this answer implements. However, that greedy algorithm turns out to be incorrect. The unique optimal set for [4..20] is {2,4,8,10}, which is not a subset of either of the two optimal sets for [4..26]: {1,3,7,11,13} and {2,4,8,12,14}.
My current solution assumes that every optimal set will contain only odd numbers or only even numbers. I haven't proven this, but given that odd + even = odd a set which mixes parities is wasting possible pairs.

{2,3,5} is optimal set for 10, but contains both odd and even numbers

@EgorSkriptunoff, true, but there are also two all-odd and two all-even sets for the same score. {even, odd, odd} can produce 4 numbers, so can't get beyond 10, whereas {2,4,8} and {2,4,6} are solutions for 12.  If you look at four-element sets then a 2-2 split in parity limits to 6 pairs (so up to 14); a 3-1 split limits to 7 pairs (up to 16); a 4-0 split limits to 10 pairs, and {2,4,8,10} achieves 9 (up to 20). The further you go, the more disadvantage there is to mixing parities.

J block, 106 characters
f=.3 :0
n=.0
while.1
do.for_z.>,{n#<>:i.y
do.if.0=$(+:2+i.<:<.-:y)-.+/~z
do.z
return.end.end.n=.>:n
end.
)

As usual for J programs, very memory hungry. The algorithm is as simple as can be: for each length n, for each combination z of n values, if that combination covers the whole set, return that combination.
Ruby, 116 112 characters
f=->x{0.upto(x){|n|(1..x).to_a.combination(n){|z|return z if
[]==4.step(x,2).to_a-z.flat_map{|i|z.map{|j|i+j}}}}}

(whitespace insignificant)
Ruby version of the algorithm, built-in deduplication, much more memory-efficient due to the use of enumerators in place of arrays (though J seems to optimise this somewhat), surprisingly not much larger than the J version.
results:
 4-5 :[2]
 6-9 :[2, 4]
10-13:[2, 4, 6]
14-21:[2, 4, 8, 10]
22-29:[2, 4, 8, 12, 14]
30-39:[2, 4, 8, 12, 16, 18]
40-45:[2, 4, 6, 12, 18, 20, 22]

upto(1/0.0)? It's trivial to prove that upto(x) is pessimistic.


text:
Build the busiest beaver in x86 machine code in 32 bytes or less
Your task is to write a program in x86 machine language (any version you like) that will run through as many instructions as possible and then halt, using a maximum of 32 bytes of code and starting with zeroed-out registers.
You can assume anything about the random-access memory you like, as long as it's in a usable format for the x86 machine.

There are pretty small busy beaver Turing machines whose halting behavior is unknown (http://en.wikipedia.org/wiki/Busy_beaver#Known_values). What happens when someone implements one of them?

There are a few details that could be filled in here. Do we have a stack set up for us? How big is it? Is the program free to access memory? If so, how much of it? Do we have read-write access to all 4 GB? If so, can we pick where our program is located?

You can assume anything about the memory you want, I guess, as long as the actual registers are all zeroed out at the beginning of the code's execution. (Will this cause problems? I'm not terribly experienced with machine language.)

Can we assume that the processor is in real mode and/or protected mode? Because if we can assume protected mode, that opens up a bunch of other questions about the Global Descriptor Table and the paging table, etc etc. Given those issues, it might be better to just enforce real-mode, which means much less memory available. Unless we can assume unreal mode, which I realize now I was implicitly assuming that I was in. But in any case, this should probably be explictly called out in the problem description.

2524224 instructions
My program:
_start:
        mov     bl, _end
        stc
iloop:  adc     [bx], al
        inc     bx
        jnz     iloop
        jnc     _start
        a32
        loop    _start
        hlt
_end:

(Technical note: this is written for nasm. The a32 is nasm's syntax for the alternate address-size prefix byte. For masm, you would replace the a32 with defb 0x67.)
For clarity, here's the listing output:
 1                  _start:
 2 0000 B310                mov     bl, _end
 3 0002 F9                  stc
 4 0003 1007        iloop:  adc     [bx], al
 5 0005 43                  inc     bx
 6 0006 75F9                jnz     iloop
 7 0008 73F4                jnc     _start
 8 000A 67                  a32
 9 000B E2F1                loop    _start
10 000D F4                  hlt
11                  _end:

The program assumes that the processor is in real mode, and that the program is located at the bottom of a 64k segment of memory which is otherwise initialized to all-bits-zero. Its design is simple: treat the memory as a single giant unsigned integer, and increment it through all possible values, until it rolls back around to all-zeroes. Repeat this 232 times. Then halt.
The innermost loop (lines 4‒6) is responsible for incrementing the huge integer. Each iteration adds zero or one to a single byte, depending on whether there was a carry out of the previous byte. Note that every byte in the huge integer is accessed, whether or not it has changed, so this loop always iterates 216 - 14 times.
By the way, in case you were wondering, this code illustrates the reason why the x86 inc/dec instructions don't affect the carry flag: just to simplify this sort of multi-byte carry pattern. (This pattern came up more often back in the days of 8-bit microprocessors, when the original 8080 instruction set was defined.)
Line 7 causes the incrementing process to repeat until a one is carried out of the last byte, indicating that the huge integer has been reset to all-bits-zero. This takes a long time.
Lines 8‒9 mark the outermost loop, and causes this process to repeat 232 times, until the ecx register rolls around to zero. This is effectively equivalent to adding another 32 bits to the giant integer.
It would be possible to add another outer loop and do this again using (say) the edx register, and then maybe using esi and edi for even more repetitions. However, it's not worth doing. The instructions to increment and loop require four bytes. Those four bytes are taken away from the giant integer. So we lose 32 bits on the RAM counter, just to add 32 bits via a register: it ends up being a wash. The only reason ecx is an exception is that it has a specialized loop instruction that fits into only three bytes. Thus the program trades 24 bits for 32, a tiny but still positive gain of 8 bits.
It's not too hard to directly calculate the number of instructions that the program executes before it halts. However, there's a much simpler way to estimate this number. The program modifies all of its memory, less the 14 bytes that contain the program, and the bx and ecx registers. This adds up to 216 - 14 + 2 + 4 = 65528 bytes, for a total of 524224 bits. The shortcut involves realizing that, in the process of running, every single possible pattern of 524224 bits appears exactly once. For the RAM and the ecx register this is easy to see, since the program increments through every single value. For bx this is a little less obvious, since it's being changed at the same time as the value in memory is being updated. However, one can show that, given the program's structure, if a complete bit pattern were to actually appear twice, then the program would have to be in an infinite loop. Since this is not the case, each bit pattern must ultimately be visited only once. (The complete proof is left as an exercise to the reader, naturally.)
Since every possible bit pattern appears in the course of the program, the program must execute at least 2524224 instructions, which is approximately equal to 1.4 × 10157807. (The acutal number is very slightly higher, because of the jump instructions, but the difference at this magnitude is negligible.)
Obviously, this could be significantly improved by using more than 64k of RAM. I'm holding off on the next version of the code until I figure out exactly how much RAM can be accessed.

Isn't that 17 instructions (34 bytes)? Or am I missing something?

@JoeZ. inc is 1 byte (if you don't assemble it in 16 bit mode)

Oh. So this program would actually be 25 bytes long?

Yes, it's 25 bytes

Sorry, I should have been more explicit. I added the listing output so as to avoid ambiguity.

you should be able to use the 4 bytes of ECX in fewer than 4 bytes of code. How long is LOOP NOP?

~2^(2^67) instructions
(at&t syntax)
start:
    movq    $0x1a,%rax
    stc
loop:
    adcb    %cl,(%rax)
    incq    %rax
    jnz     loop
    jnc     start
    hlt

Disassembled, 26 bytes:
start:
0000000000000000    movq    $0x0000001a,%rax
0000000000000007    stc
loop:
0000000000000008    adcb    %cl,(%rax)
000000000000000a    incq    %rax
000000000000000d    jne loop
0000000000000013    jae start
0000000000000019    hlt

Similar to breadbox's solution, but there's no reason to stop at 16 bits of address.  My code uses x86-64 and assumes we have 2^64 bytes of memory and we use all but the memory holding the code as a giant counter.

movq $0x1a,%rax => subq $-X,%eax and stc can be omitted


text:
Find a set of 10 numbers such that all pairs have a different GCF
The set of ten numbers below:
223092870
17237308840522
1075474925835771
12574206406402195
79458974087499419
265057843710517649
466012798920390527
926434345611831877
1390237791335182649
2336970054109245767

has the property that no two pairs of numbers have the same greatest common factor. (In this case, the greatest common factor of each pair of numbers is actually a distinct prime.)
Your task is to find the set of 10 positive integers with the smallest sum that satisfy this property.
For reference, the sum of the above ten numbers is 5 477 838 726 638 839 246 (≈5.48×1018).

What's the score? The sum, then post time?

The lowest currently posted sum wins, and if there is an exact tie, then earliest posted time is the tiebreaker.

recently posted? The oldest one with a given sum should be the winner.

I corrected that. Sorry for the confusion :\

This question appears to be off-topic because it's a pure maths puzzle, not a programming puzzle. In principle it can be solved with pencil and paper.

I suppose I intended it to be something more like a Project Euler puzzle, which often requires the use of a computer to calculate.

@PeterTaylor Irrelevant. Many questions here are like this, for example one of mine - Collatz Conjecture. The point is to do it in short code. Voted to Leave Open in the queue.

@Doorknob, that question is different because a) it takes input, so an actual program is required; b) it's a code golf, so an actual program is required. Nothing in the statement of this question requires you to answer with a program, just the set of numbers.

Regardless of that, people have still been using code in order to find answers to the question, and they've posted it here.

If this question is going to stay open (and it currently appears that it will), you should at least fix it to specify the legal numbers. At present it asks for the set of integers with a given property which has minimal sum. Take any valid answer in non-negative integers and multiply by any negative integer to get a valid answer; since the negative integer chosen is unbounded, the sum can be arbitrarily low.

Changed it to positive integers.

Sum: 11835
[1920, 1792, 1440, 1344, 1280, 1080, 1008, 810, 756, 405]

To verify, a table of the gcd values for each pair:
     | 1920 | 1792 | 1440 | 1344 | 1280 | 1080 | 1008 |  810 |  756
-----+------+------+------+------+------+------+------+------+-----
 405 |   15 |    1 |   45 |    3 |    5 |  135 |    9 |  405 |   27
 756 |   12 |   28 |   36 |   84 |    4 |  108 |  252 |   54 |
 810 |   30 |    2 |   90 |    6 |   10 |  270 |   18 |
1008 |   48 |  112 |  144 |  336 |   16 |   72 |
1080 |  120 |    8 |  360 |   24 |   40 |
1280 |  640 |  256 |  160 |   64 |
1344 |  192 |  448 |   96 |
1440 |  480 |   32 |
1792 |  128 |

Implementation Details
Update: Massive performance gain c/o @PeterTaylor, as is so often the case.

For a set S of length n matching the problem description, each element of S must have at least n-1 divisors (including 1 and the value itself), as each must participate in exactly n-1 unique gcd. Only values with this property are considered.
The algorithm for the number of divisors takes the following form:
If i is a positive integer with the prime factorization p0e0·p1e1…pnen, then the number of divisors of i is equal to (e0+1)·(e1+1)…(en+1). When counting divisors, only primes of the set [2, 3, 5, 7] are used; i.e. only those divisors which are 7-smooth are counted.
The search algorithm begins with the largest value of the set, and then searches recursively for each next smaller value. When the current search space has been exhausted, the next larger value with enough divisors is added to the list.
Note: while this is guaranteed to find the set with the smallest maximum value, it is not necessarily the optimal solution to this problem. A counter-example for n=6:
[120, 112, 90, 84, 80, 45] (531) vs. [162, 108, 81, 72, 48, 16] (487).
The memoization of the gcd function results in a significant performance gain. By the time the third or fourth term is reached, most of the gcds have already been calculated, and need only to be looked up. Additionally, the first iteration is performed outside of the gcd function itself, which increases look-up collision.
for ... else is something of a Python oddity. The else block will only be evaluated if the for loop terminates properly, i.e. not by break. I use this for short-circuiting upon duplicate gcds.
The length of the set, n, is provided as input via stdin.

Implementation
from time import time

num_vals = input()

def memoize(func):
  class memodict(dict):
    def __call__(self, *args):
      return self[args]
    def __missing__(self, key):
      ret = self[key] = func(*key)
      return ret
  return memodict()

@memoize
def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

def divisors(n):
  divs = 1
  for i in 2,3,5,7:
    exp = 1
    while n%i == 0:
      n /= i
      exp += 1
    divs *= exp
  return divs

def next_val(n):
  while True:
    n += 1
    d = divisors(n)
    if d >= num_vals-1: return n

vals = []

def f(n, end, nums, factors):
  if n<1:
    return nums
  index = n-1
  for i in vals[n-1:end]:
    index += 1
    new_factors = set()
    for j in nums:
      v = gcd(i, j%i)
      if v in factors or v in new_factors:
        break
      new_factors.add(v)
    else:
      ret = f(n-1, index, nums + [i], factors | new_factors)
      if ret: return ret

def g(n):
  global vals
  val = 0
  while len(vals) < n:
    val = next_val(val)
    vals += [val]
  index = n-1
  while True:
    ret = f(n-1, index, [val], set())
    if ret: return ret
    val = next_val(val)
    vals += [val]
    index += 1

t1 = time()
v = g(num_vals)
print sum(v), v
print time() - t1

Solutions and approximate runtime for n ∈ [2, 10]:
3 [2, 1]
0.00s

11 [6, 3, 2]
0.00s

43 [18, 12, 9, 4]
0.00s

149 [54, 36, 27, 24, 8]
0.05s

531 [120, 112, 90, 84, 80, 45]
0.07s

1143 [240, 224, 180, 168, 160, 126, 45]
0.34s

2601 [480, 448, 360, 336, 320, 270, 252, 135]
2.32s

5445 [960, 896, 720, 672, 640, 540, 504, 378, 135]
2m 2.4s

11835 [1920, 1792, 1440, 1344, 1280, 1080, 1008, 810, 756, 405]
36m 6s

The optimal solution up to n=6 uses only the primes 2 and 3. (You find all of them except n=6: {16, 48, 72, 81, 108, 162} scores 487). Your sets for n=7 and n=8 are also optimal, and your sets for n=9 and n=10 are those which I calculated manually for four-prime sets, but which I haven't proven optimal. It's a big jump from 7 to 11, so four-prime sets probably hold the crown for a while more.

If you change the return to yield in g(n), you can have it keep searching for possible solutions past the first one. So far I've tried it up to 8 (can't keep my computer running long enough before going to bed to try the others), but besides the 487 solution for n=6, so far no other "sub-minimal" solutions have popped up.

Sum: 58025
(ruby)
(0..9).map{|i|(2**i)*(3**(9-i))}

Gives
[19683, 13122, 8748, 5832, 3888, 2592, 1728, 1152, 768, 512]

Don't think it can get much better than that.

@JoeZ. In fact, I think this may be provably optimal.

@primo I promise you an upvote if you post a proof of optimality.

@JanDvorak happily, I seem to have been mistaken. The pattern breaks as early as n = 4. Compare [27, 18, 12, 8] with [30, 15, 10, 6].

Then the search is on to find another set for which this holds.

Actually for n = 3, this gives [9, 6, 4] but we can do better using [2, 3, 6]. Edit: now that I see primo's program, it can find that also as the smallest for n = 3

FWIW, this is almost optimal for the problem when limited to two primes. It can be improved by special-casing the extrema: (0..n-1).map{|i|(2**(i==n-1?n-2:i))*(3**(i==0?n-2:n-1-i))}

Sum: 132251618166478572 (≈1.32×1017)
As a reference last-place answer, I will post the Python code I used to generate the initial set of numbers in the question:
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61,
          67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137,
          139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197]

numbers = [1] * 10

primefactor = 0

for a in range(10):
    for b in range(a+1, 10):
        numbers[a] *= primes[primefactor]
        numbers[b] *= primes[primefactor]
        primefactor = primefactor + 1

# can't use "sum" because it produces weird values.
numbertotal = 0
for i in numbers:
    numbertotal += i

print numbers, numbertotal

Essentially what this does is take every prime number from 2 to 197 (the first 10C2 = 45 primes), and multiplies them to a unique pair of numbers. That way, any pair of numbers will only have that one prime that was assigned to it as a common factor.
This was done mostly as a proof that there do exist sets of numbers with the property required in the question - as you can see, the value it generated is far from optimal.
Modifying this code to shuffle the primes around randomly before multiplying them results in smaller numbers being created. With multiple trials, I found the following set of numbers:
1268193027813141
2224904691135063
4714631150921614
7005966291691742
9288794198034215
9315429894689005
12630588322608113
13006064536029667
23545741081119313
49251304972436699

whose sum is 132251618166478572, as above.


text:
Simultaneous equations
With equations that have more than one unknown, simultaneous equations can be used in solving for them. This challenge will only deal with linear equations with two unknowns, to make things as elementary as possible.
The program should take two lines of input from stdin, each containing a linear equation with two unknowns (x and y). Output should be in the form x=<x-value>, y=<y-value>, where the angled bracketed text should be replaced by the appropriate value. Non-integer values can be outputted in either decimal point form rounded to at least 3 decimal places or until the fraction terminates (eg. 1/2 would be 0.5 not 0.500), or simplest (improper, not mixed) fraction form (as all results will be rational). If the equations are unsolvable (ie are parallel but not equivalent), output Unsolvable. If the equations are equivalent and would therefore have an infinite number of solutions, output Degenerate.
The use of external modules is not allowed. Also, any library functions that solve equations (this applies especially to Mathematica) are not allowed.
Each equation in the input will be in general form, with no whitespace. If a coefficent or the constant term is 0, the whole term will not appear, and if a coefficient is ±1, only the pronumeral will appear.
Test cases:
Input:                 Input:                 Input:                 Input:
7x+4y-8=0              4x+3y+32=0             x-y=0                  2x+5y-1=0
x-8y+1=0               x-4=0                  x-y+5=0                2x+5y-1=0
Output:                Output:                Output:                Output:
x=1, y=1/4 (or 0.25)   x=4, y=-16             Unsolvable             Degenerate

This is once again code-golf, so shortest code wins.

See also the Diophantine version.

Python 3, 250
I reuse the code for parsing the input for each of the "coefficients" of x, y, and "=" by putting it into a string and multiplying it the right number of times.
For the "coefficient of =" case to work (absence means 0, not 1, like for x and y), the last "0" of the input has to be thrown away (and then magic takes over...).
Makes heavy use of short circuiting in logic expressions, and of False==0.
Uses Python's feature of leaving off trailing zeros of floats (finding out if the solution is an integer is still necessary).
exec((("R=input()[:-1];"+"*_,R=I,*_=R.split(%r);%s=R!=I and int(I in'+-'and I+'1'or I);"*3)*2)%tuple("xXyY=Cxxyy=c"))
d,u,v=X*y-Y*x,C*y-c*Y,X*c-x*C
print(d and"x=%s, y=%s"%(u%d and-u/d or-u//d,v%d and-v/d or-v//d)or"UDnesgoelnvearbaltee"[u==v==0::2])

"UDnesgoelnvearbaltee"[u==v==0::2] might be one of the neatest little Python tricks I've ever seen. Kudos for that.

Python 2 - 497
def i(x):return-1 if x=="-"else int(x)if x else 1
def g(a,b):return g(b,a%b) if b else a
r=raw_input
u=r()[:-2]
v=r()[:-2]
t=u==v
a=u.find("x")
a,u=0 if a<0 else i(u[:a]),u[a+1:]
b=u.find("y")
b,u=0 if b<0 else i(u[:b]),u[b+1:]
e=-i(u) if u else 0
c=v.find("x")
c,v=0 if c<0 else i(v[:c]),v[c+1:]
d=v.find("y")
d,v=0 if d<0 else i(v[:d]),v[d+1:]
f=-i(v) if v else 0
x,y,z=e*d-f*b,a*f-c*e,a*d-b*c
m,n=g(x,z),g(y,z)
print"Degenerate"if t else"x=%d/%d, y=%d/%d"%(x/m,z/m,y/n,z/n)if z else"Unsolvable"

Sorry - I just realised I typed Unsolveable in the test cases wrong. It should be Unsolvable. Edited now.

It's okay, it doesn't seem like a misspelled word.

I tried this and got Degenerate for x=0,y=0, which is wrong.

I see it now, testing for equality after modifying the string, how dumb

Python 2, 244 chars
import re
def P():e=re.sub(r'(\d)(x|y)',r'\1*\2',raw_input()[:-2]);x=y=0.;c=eval(e);x=1;a=eval(e)-c;x,y=y,x;return a,eval(e)-c,c
a,b,c=P()
d,e,f=P()
D=a*e-d*b
X=b*f-c*e
print'x=%g, y=%g'%(X/D,(c*d-a*f)/D)if D else'UDnesgoelnvearbaltee'[X==0::2]

Throws some * characters in the right place, then evaluates the LHS on various combinations of x,y in {0,1} to derive the coefficients.  Then it does the standard determinant computations to find the solution.


text:
Too Fast, Too Fourier: FFT Code Golf
Implement the Fast Fourier Transform in the fewest possible characters.
Rules:

Shortest solution wins

It can be assumed that the input is a 1D array whose length is a power of two.

You may use the algorithm of your choice, but the solution must actually be a Fast Fourier Transform, not just a naive Discrete Fourier Transform (that is, it must have asymptotic computation cost of \$O(N \log N)\$)

the code should implement the standard forward Fast Fourier Transform, the form of which can be seen in equation (3) of this Wolfram article,

$$F_n = \sum_{k=0}^{N-1}f_ke^{-2\pi ink/N}$$

Using an FFT function from a pre-existing standard library or statistics package is not allowed.  The challenge here is to succinctly implement the FFT algorithm itself.

This is underspecified. At the very least you need to define the normalisation factors, and you also ought to be aware that any ambiguity will be wilfully misinterpreted. E.g. is "Implement" satisfied by the answer "FFT (3 chars): it's in the standard library"? Some test cases would be good too.

Does it matter about the order of the output elements, i.e. do we need to implement bit reversed unscrambling or can we leave the output in scrambled order ?

See the edits to the rules.  The output should be a list/array with values ordered according to the indices in the standard DFT expression, referenced above.

VTC as no IO requirements mentioned.

Can you post some example inputs and outputs so we can test our implementations?

Title should have been "Fast and Fourier-s" (Fast and Furious).

Where are the tests cases?

Instead of point to the page fft O(n^2) why not point to the page fast Fourier transform with O(n*log_2(n))

If the problem for fft is the speed why not use some other tag and not "codegolf" tag? I not had identified the problem where this fft is slow... Can someone give some input where this fft functions are slow?

Mathematica, 95 bytes
Another implementation of the Cooley–Tukey FFT with help from @chyaong.
{n=Length@#}~With~If[n>1,Join[+##,#-#2]&[#0@#[[;;;;2]],#0@#[[2;;;;2]]I^Array[-4#/n&,n/2,0]],#]&

Ungolfed
FFT[x_] := With[{N = Length[x]},
  If[N > 1,
    With[{a = FFT[ x[[1 ;; N ;; 2]] ],
          b = FFT[ x[[2 ;; N ;; 2]] ] * Table[E^(-2*I*Pi*k/N), {k, 0, N/2 - 1}]},
      Join[a + b, a - b]],
    x]]

I think #[[;;;;2]]==#[[1;;N;;2]] and [[2;;;;2]]==[[2;;N;;2]].

101 characters：With[{L=Length@#},If[L>1,Join[+##,#-#2]&[#0@#[[;;;;2]],#0@#[[2;;;;2]]E^(-2I*Pi(Range[L/2]-1)/L)],#]]&

Nice, you can condense another anonymous function inside it without conflicting with the recursive one. Also learned that Part fills in missing indices. We can take it further using Unicode.

J, 37 bytes
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#

An improvement after a few years. Still uses the Cooley-Tukey FFT algorithm.
Saved 4 bytes using eπi = -1, thanks to @Leaky Nun.
Try it online!
Usage
   f =: _2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#
   f 1 1 1 1
4 0 0 0
   f 1 2 3 4
10 _2j2 _2 _2j_2
   f 5.24626 3.90746 3.72335 5.74429 4.7983 8.34171 4.46785 0.760139
36.9894 _6.21186j0.355661 1.85336j_5.74474 7.10778j_1.13334 _0.517839 7.10778j1.13334 1.85336j5.74474 _6.21186j_0.355661

Explanation
_2&(0((+,-)]%_1^i.@#%#)&$:/@|:]\)~1<#  Input: array A
                                    #  Length
                                  1<   Greater than one?
_2&(                            )~     Execute this if true, else return A
_2                            ]\         Get non-overlapping sublists of size 2
    0                       |:           Move axis 0 to the end, equivalent to transpose
                          /@             Reduce [even-indexed, odd-indexed]
                       &$:               Call recursively on each
                   #                     Get the length of the odd list
                i.@                      Range from 0 to that length exclusive
                    %#                   Divide each by the odd length
             _1^                         Compute (-1)^x for each x
           ]                             Get the odd list
            %                            Divide each in that by the previous
       +                                 Add the even values and modified odd values
         -                               Subtract the even values and modified odd values
        ,                                Join the two lists and return

See also, this: http://blog.ndpar.com/2014/10/11/dft-j/

Python, 166 151 150 characters
This uses the radix-2 Cooley-Tukey FFT algorithm
from math import*
def F(x):N=len(x);t=N<2or(F(x[::2]),F(x[1::2]));return N<2and x or[
a+s*b/e**(2j*pi*n/N)for s in[1,-1]for(n,a,b)in zip(range(N),*t)]

Testing the result
>>> import numpy as np
>>> x = np.random.random(512)
>>> np.allclose(F(x), np.fft.fft(x))
True

2 things: it's typically best to use from x import*, and sum(([x for x in y] for y in z),[]) is longer than [x for y in z for x in y].

Thanks - that saves 15 characters! 11 more and it's a tweet.

Oh, that's definitely possible.  Often when you find one improvement, an old one becomes a stumbling block.

Python 3: 140 134 113 characters
Short version - short and sweet, fits in a tweet (with thanks to miles):
from math import*
def f(v):
 n=len(v)
 if n<2:return v
 a,b=f(v[::2])*2,f(v[1::2])*2;return[a[i]+b[i]/1j**(i*4/n)for i in range(n)]

(In Python 2, / is truncating division when both sides are integers. So we replace (i*4/n) by (i*4.0/n), which bumps the length to 115 chars.)
Long version - more clarity into the internals of the classic Cooley-Tukey FFT:
import cmath
def transform_radix2(vector):
    n = len(vector)
    if n <= 1:  # Base case
        return vector
    elif n % 2 != 0:
        raise ValueError("Length is not a power of 2")
    else:
        k = n // 2
        even = transform_radix2(vector[0 : : 2])
        odd  = transform_radix2(vector[1 : : 2])
        return [even[i % k] + odd[i % k] * cmath.exp(i * -2j * cmath.pi / n) for i in range(n)]

Shortened to 113 bytes using e^(-2j * pi * i / n) = (-1)^(2 * i / n) = (1j)^(4 * i / n)

@miles Very impressive observation, thank you! Having repeatedly implemented DFTs for over a decade, I got obsessed with sin/cos/exp and forgot that simple powers of i can be used. I edited my answer to incorporate the new insight and credit you.

e^(-2j * pi * i / n) = (-1)^(2 * i / n) = (1j)^(4 * i / n) Should be
e^(2j * pi * i / n) = (-1)^(2 * i / n) = (1j)^(4 * i / n)?

@Hunaphu On what basis do you say that? The standard DFT formula uses -2j. The inverse DFT uses +2j.

Sorry, I was not commenting your code (which I have no reason to question) but the statement e^(-2j * pi * i / n) = (-1)^(2 * i / n) which is false.

@Hunaphu Oh, I think you're right. But notice that in my short code, I divide by 1j**(i*4/n), whereas in my long code I multiply by cmath.exp(i * -2j * cmath.pi / n). The division effectively negates the exponent.

That was what I suspected, but I wanted to study your code and was unsure of that part. Thanks for an interesting answer!

R: 142 133 99 95 bytes
Thanks to @Giuseppe for helping me shaving down 32 36 bytes!
f=function(x,n=sum(x|1),y=1:(n/2)*2)`if`(n>1,f(x[-y])+c(b<-f(x[y]),-b)*exp(-2i*(y/2-1)*pi/n),x)

An additional trick here is to use the main function default arguments to instantiate some variables.
Usage is still the same:
x = c(1,1,1,1)
f(x)
[1] 4+0i 0+0i 0+0i 0+0i

4-year old version at 133 bytes:
f=function(x){n=length(x);if(n>1){a=Recall(x[seq(1,n,2)]);b=Recall(x[seq(2,n,2)]);t=exp(-2i*(1:(n/2)-1)*pi/n);c(a+b*t,a-b*t)}else{x}}

With indentations:
f=function(x){
    n=length(x)
    if(n>1){
        a=Recall(x[seq(1,n,2)])
        b=Recall(x[seq(2,n,2)])
        t=exp(-2i*(1:(n/2)-1)*pi/n)
        c(a+b*t,a-b*t)
        }else{x}
    }

It uses also Cooley-Tukey algorithm. The only tricks here are the use of function Recall that allows recursivity and the use of R vectorization that shorten greatly the actual computation.
Usage:
x = c(1,1,1,1)
f(x)
[1] 4+0i 0+0i 0+0i 0+0i

Four years later, and we get it down to 101 bytes. Not 100% sure why you used Recall as it's a named function already, but hey, it's easy to golf in hindsight! :) +1, very nice.

Yes Recall is now unnecessary, indeed. I noticed that a few months ago but was too lazy to change it :) I'll modify it.

Very nice! I squeezed another 4 bytes out!, putting this on par with Mathematica.

Thanks! I thought about putting y up there but didn't notice it could be use for the exp(...) part as well.

Python, 134
This borrows heavily from jakevdp's solution, so I've set this one to a community wiki.
from math import*
F=lambda x:x*(len(x)<2)or[a+s*b/e**(2j*pi*n/len(x))for s in(1,-1)for n,(a,b)in
enumerate(zip(F(x[::2]),F(x[1::2])))]

Changes:
-12 chars: kill t.
def F(x):N=len(x);t=N<2or(F(x[::2]),F(x[1::2]));return ... in zip(range(N),*t)]
def F(x):N=len(x);return ... in zip(range(N),F(x[::2]),F(x[1::2]))]

-1 char: exponent trick, x*y**-z == x/y**z  (this could help some others)
...[a+s*b*e**(-2j*pi*n/N)...
...[a+s*b/e**(2j*pi*n/N)...

-2 char: replace and with *
...return N<2and x or[
...return x*(N<2)or[

+1 char: lambdaize, killing N
def F(x):N=len(x);return x*(N<2)or[a+s*b/e**(2j*pi*n/N) ... zip(range(N) ...
F=lambda x:x*(len(x)<2)or[a+s*b/e**(2j*pi*n/len(x)) ... zip(range(len(x)) ...

-2 char: use enumerate instead of zip(range(len(
...for(n,a,b)in zip(range(len(x)),F(x[::2]),F(x[1::2]))]
...for n,(a,b)in enumerate(zip(F(x[::2]),F(x[1::2])))]

I think that this is no longer a fast fourier transform, though... by "killing t" you added in some unnecessary calculations which move it from O[N log(N)] to O[N^2]

It appears that I cannot downvote my own post.  You are correct, I exchanged the loop order and killed the performance.  I will leave this up for now, in case I find a way to fix it.

101 bytes with f=lambda x:x*(len(x)<2)or[u+v/1j**(4*i/len(x))for i,(u,v)in enumerate(zip(f(x[::2])*2,f(x[1::2])*2))]

You can replace for s in(1,-1)for with for s in 1,-1for or even, if order does not matter, for s in-1,1for.

C, 259
typedef double complex cplx;
void fft(cplx buf[],cplx out[],int n,int step){
if(step < n){
fft(out, buf,n, step * 2);
fft(out+step,buf+step,n,step*2);
for(int i=0;i<n;i+=2*step){
cplx t=cexp(-I*M_PI*i/n)*out[i+step];
buf[i/2]=out[i]+t;
buf[(i+n)/2]=out[i]-t;
}}}

The problem is, such implementations are useless, and straightforward algorithm is MUCH faster.

You can remove some more whitespace to get a lower amout of characters, for example the step < n can be changed into step<n and the step * 2 can be changed into step*2.

all the variables and functions and typedefs should have one-letter names to save a lot of chars

You had someone suggest a bunch of improvements for this. Take a look at them here: http://codegolf.stackexchange.com/review/suggested-edits/17119

You can remove all newlines, newlines are useless in C

@TùxCräftîñg Not all newlines are useless. They are needed for directives like #include, #define, #if, etc.

Matlab, 128 118 107 102 101 94 93 bytes
EDIT6: thanks @algmyr for another byte!
function Y=f(Y);
n=numel(Y);
k=2:2:n;
if k;
   c=f(Y(k-1));
   d=f(Y(k)).*i.^(2*(2-k)/n);
   Y=[c+d;c-d];
end

EDIT5: Still getting shorter:) thanks to @sanchises
function Y=f(Y)
n=numel(Y);
k=2:2:n;
if k;
   c=f(Y(k-1));
   d=f(Y(k)).*(-1).^((2-k)/n);
   Y=[c+d;c-d];
end

EDIT4: Yay, -1 character more (could aslo have done without the k):
function Y=f(Y)
n=numel(Y);
if n>1;
   k=2:2:n;
   c=f(Y(k-1));
   d=f(Y(k)).*(-1).^((k/2-1)*2/n)';
   Y=[c+d;c-d];
end

EDIT2/3: Thanks for @sanchises for further improvements!
function Y=f(Y)
n=numel(Y);
if n>1;
   c=f(Y(1:2:n));
   d=f(Y(2:2:n)).*(-1).^(-(0:n/2-1)*2/n).';
   Y=[c+d;c-d];
end

EDIT: Could make some improvements, and noticed that the scaling constant is not required.
This is the expanded version, character count is valid if you remove the newlines/spaces. (Works only for column vectors.)
function y=f(Y)
n=numel(Y);
y=Y;
if n>1;
   c=f(Y(1:2:n));
   d=f(Y(2:2:n));
   n=n/2;
   d=d.*exp(-pi*i*(0:n-1)/n).';
   y=[c+d;c-d];
end

Tip: you can combine the two d= lines into one: m=n/2;d=f(Y(2:2:n)).*exp(-pi*i*(0:m-1)/m).';. Furthermore, consider changing y=f(Y) to Y=f(Y) and remove line 3 (and promise you'll never do that outside of code-golf)

Oh thanks! Does function Y = f(Y) have any disadvanteages other than unreadability?

Well, MATLAB will never complain about a return value, even if Y is never changed. It is slightly faster though, so I guess it isn't so bad after all for some purposes (i.e. a function that almost never changes the input variable)

Now, for shaving off more: m=n/2 could be removed, and instead m replaced by n/2 and n*2 respectively. And then, I strongly believe, the program is as short as could be in MATLAB.

Yay, finally under 100=) thanks!

Your believe was wrong, I could strip one more character! =P

Always happy to be proven wrong :) Although, I'm afraid you'll have to recount... I'm counting 102 characters in your latest version.

You're right, we've still got 2 characters to go. EDIT: one more to go=)

I know this is very old, but I just realized that this can still be golfed. Instead of if n>1, you can do if k if you move the definition of k outside the if statement. Furthermore, you can change ((k/2-1)*2/n)' to ((2-k)/n) (note the absence of the conjungate operator).

Since this is necroposted already, why not another improvement? By default the variable i is the imaginary unit, so (-1).^((2-k)/n) can be written as i.^(2*(2-k)/n) saving 1 character.

Yeah, why not? Thanks a lot! :)

And then, I strongly believe, the program is as short as could be in MATLAB. – Sanchises Mar 8 '15 at 21:05 Famous last words...

Jelly, 31 30 28 26 bytes
LḶ÷$N-*×,N$+ḷF
s2Zß€ç/µ¹Ṗ?

This uses the Cooley-Tukey radix-2 recursive algorithm. For an un-golfed version, see my answer in Mathematica.
Try it online or Verify multiple test cases.
Explanation
LḶ÷$N-*×,N$+ḷF  Helper link. Input: lists A and B
L               Get the length of A
   $            Operate on that length
 Ḷ                Make a range [0, 1, ..., length-1]
  ÷               Divide each by length
    N           Negate each
     -          The constant -1
      *         Compute -1^(x) for each x in that range
       ×        Multiply elementwise between that range and B, call it B'
          $     Operate on that B'
         N        Negate each
        ,         Make a list [B', -B']
            ḷ   Get A
           +    Add vectorized, [B', -B'] + A = [A+B', A-B']
             F  Flatten that and return

s2Zß€ç/µ¹Ṗ?  Main link. Input: list X
         Ṗ   Curtail - Make a copy of X with the last value removed
          ?  If that list is truthy (empty lists are falsey)
       µ       Parse to the left as a monad
s2             Split X into sublists of length 2
  Z            Transpose them to get [even-index, odd-index]
   ß€          Call the main link recursively on each sublist
     ç/        Call the helper link as a dyad on the sublists and return
             Else
        ¹      Identity function on X and return

C (gcc), 188 186 184 183 bytes
#define d(a,b,c)f(a,b,c,1,0)
f(a,b,c,n,k)_Complex*a,*b;{_Complex z[c];*b=*a;if(n<c)for(f(a,z,c,n*2),f(a+n,z+n,c,n*2);k<c;k+=n*2)b[k+c>>1]=z[k]*2-(b[k/2]=z[k]+z[k+n]/cpow(1i,2.*k/c));}

Try it online!
Slightly golfed less
#define d(a,b,c)f(a,b,c,1,0)
f(a,b,c,n,k)_Complex*a,*b;{
  _Complex z[c];
  *b=*a;
  if(n<c)
    for(f(a,z,c,n*2),f(a+n,z+n,c,n*2);k<c;k+=n*2)
      b[k+c>>1]=z[k]*2-(b[k/2]=z[k]+z[k+n]/cpow(1i,2.*k/c));
}

Pari/GP, 76 characters
X(v)=my(t=-2*Pi*I/#v,s);vector(#v,k,s=t*(k-1);sum(n=0,#v-1,v[n+1]*exp(s*n)))

Usage
X([1,1,1,1])
%2 = [4.000000000000000000000000000, 0.E-27 + 0.E-28*I, 0.E-28 + 0.E-27*I, 0.E-27 + 0.E-28*I]

Isn't this the naive DFT? (ie theta(N^2))

APL(NARS), 58 chars, 116 bytes
{1≥k←≢⍵:⍵⋄(∇⍵[y∼⍨⍳k])(+,-)(∇⍵[y←2×⍳t])×0J1*t÷⍨2-2×⍳t←⌊k÷2}

test
  f←{1≥k←≢⍵:⍵⋄(∇⍵[y∼⍨⍳k])(+,-)(∇⍵[y←2×⍳t])×0J1*t÷⍨2-2×⍳t←⌊k÷2}
  f 1 1 1 1
4J0 0J0 0J0 0J0
  f 1 2 3 4
10J0 ¯2J2 ¯2J0 ¯2J¯2
  f 1J1 2 ¯2J1  9
10J2 3J7 ¯12J2 3J¯7
  f 5.24626,3.90746,3.72335,5.74429,4.7983,8.34171,4.46785,0.760139
36.989359J0 ¯6.211855215J0.3556612739 1.85336J¯5.744741 7.107775215J¯1.133338726 ¯0.517839J0
  7.107775215J1.133338726 1.85336J5.744741 ¯6.211855215J¯0.3556612739

Octave, 109 103 101 100 bytes
f(f=@(f)@(x,n=rows(x)){@(d=f(f)(x(k=2:2:n)).*i.^((k*2-4)/n)')[d+(c=f(f)(x(k-1)));c-d],x}{1+(n<2)}())

Try it online!
Ooooo do my eyes bleed from this recursive accursed lambda. Large parts of this were lifted from @flawr's answer.
f(                                          % lambda function
  f=@(f)                                    % defined in its own argument list,
                                            % accepts itself as parameter (for recursion)
    @(x,n=rows(x)){                         % calls another lambda,
                                            % 2nd parameter is just to define a variable
      @(d=f(f)(x(k=2:2:n)).*i.^((k*2-4)/n)')% 1/4 of FFT (argument just defines a variable)
        [d+(c=f(f)(x(k-1)));                % 2/4 of FFT
         c-d                                % 4/4 of FFT
        ],                                  % This is in a @()[] to inhibit evaluation
                                            % unless actually called
      x                                     % FFT of length 1
    }{1+(n<2)}                              % if len(x)==1, return x
                                            % else return [d+c;c-d]
  ()                                        % this is probably important too
)

I don't understand what you did but I like it a lot.

Axiom,  259, 193, 181, 179 bytes
L(g,n,f)==>[g for i in 1..n|f]
h(a)==(n:=#a;n=1=>a;c:=h(L(a.i,n,odd? i));d:=h(L(a.i,n,even? i));n:=n/2;t:=1>0;v:=L(d.i*%i^(-2*(i-1)/n),n,t);append(L(c.i+v.i,n,t),L(c.i-v.i,n,t)))

Even if h(a) could pass all the test and would be ok as entry for this 'competition'
one has to call h() or hlp() thru fft() below, for checking arguments.
I don't know if this software can be ok because i only had seen what other wrote, and search
the way it could run in Axiom for return some possible right result. Below ungolfed code with few comments:
-- L(g,n,f)==>[g for i in 1..n|f]
-- this macro L, build one List from other list, where in g, there is the generic element of index i
-- (as a.i, or a.i*b.i or a.i*4), n build 1..n that is the range of i, f is the condition
-- for insert the element in the list result.

hlp(a)==
    n:=#a;n=1=>a
    -- L(a.i,n,odd? i)  it means build a list getting "even indices i of a.i as starting from index 0" [so even is odd and odd is even]
    -- L(a.i,n,even? i) it means build a list getting "odd  indices i of a.i as starting from index 0"
    c:=hlp(L(a.i,n,odd? i));d:=hlp(L(a.i,n,even? i))
    n:=n/2;t:=1>0
    v:=L(d.i*%i^(-2*(i-1)/n),n,t)
    append(L(c.i+v.i,n,t),L(c.i-v.i,n,t))

-- Return Fast Fourier transform of list a, in the case #a=2^n
fft(a)==(n:=#a;n=0 or gcd(n,2^30)~=n=>[];hlp(a))

(5) -> h([1,1,1,1])
   (5)  [4,0,0,0]
                                    Type: List Expression Complex Integer
(6) -> h([1,2,3,4])
   (6)  [10,- 2 + 2%i,- 2,- 2 - 2%i]
                                    Type: List Expression Complex Integer
(7) -> h([5.24626,3.90746,3.72335,5.74429,4.7983,8.34171,4.46785,0.760139])
   (7)
   [36.989359, - 6.2118552150 341603904 + 0.3556612739 187363298 %i,
    1.85336 - 5.744741 %i, 7.1077752150 341603904 - 1.1333387260 812636702 %i,
    - 0.517839, 7.1077752150 341603904 + 1.1333387260 812636702 %i,
    1.85336 + 5.744741 %i,
    - 6.2118552150 341603904 - 0.3556612739 187363298 %i]
                                      Type: List Expression Complex Float
(8) -> h([%i+1,2,%i-2,9])
   (8)  [10 + 2%i,3 + 7%i,- 12 + 2%i,3 - 7%i]
                                    Type: List Expression Complex Integer

in the few i had seen h() or fft() would return exact solution, but if the simplification
is not good as in:
(13) -> h([1,2,3,4,5,6,7,8])
   (13)
                    +--+                                   +--+
        (- 4 + 4%i)\|%i  - 4 + 4%i             (- 4 - 4%i)\|%i  - 4 + 4%i
   [36, --------------------------, - 4 + 4%i, --------------------------, - 4,
                    +--+                                   +--+
                   \|%i                                   \|%i
            +--+                                   +--+
    (- 4 + 4%i)\|%i  + 4 - 4%i             (- 4 - 4%i)\|%i  + 4 - 4%i
    --------------------------, - 4 - 4%i, --------------------------]
                +--+                                   +--+
               \|%i                                   \|%i
                                    Type: List Expression Complex Integer

than it is enought change the type of only one element of list, as in below writing 8. (Float)
for find the approximate solution:
(14) -> h([1,2,3,4,5,6,7,8.])
   (14)
   [36.0, - 4.0000000000 000000001 + 9.6568542494 923801953 %i, - 4.0 + 4.0 %i,
    - 4.0 + 1.6568542494 92380195 %i, - 4.0, - 4.0 - 1.6568542494 92380195 %i,
    - 4.0 - 4.0 %i, - 4.0 - 9.6568542494 923801953 %i]
                                      Type: List Expression Complex Float

I wrote it, seen all other answers because in the link, the page it was too much difficult so I don't know if this code can be right. I'm not one fft expert so all this can (it is probable) be wrong.

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


text:
Generate a grid of sums
Generate a 7 by 7 grid, filled with random numbers. However, in cells with an odd row and column number (starting at 0), you must use the sum of the surrounding cells. Here's a small example with a 3 by 3 grid (sum-square bolded):
2 2  2
2 16 2
2 2  2
And here's an example 7 by 7 grid:
6 5  4 3  7 2  5
6 43 3 50 8 43 8
4 7  8 8  9 3  1
4 36 1 43 6 40 5
3 3  6 1  4 7  5
4 35 3 45 9 42 1
2 6  8 6  8 5  3
Rules

Numbers that are not sums must always be between 1 and 9 inclusive.
Grid must be randomly generated. For each non-sum, every digit must have an equal chance of appearing, regardless of which cell it is in.
Numbers must be aligned. This means that either the first or last digit of each number in a column must line up vertically. (You may assume that the middle numbers will always be two digits.)
Surrounding cells includes diagonals. Therefore, each sum square will have eight numbers surrounding it, which you must add.
Shortest code wins, since this is code-golf.

Does it have to be the first digit that lines up? i.e. can it be the last?

@Volatility I suppose right align would work. edited

What if a language doesn't have a random number generator?

APL, 53 49 43 42 40 39 36
I managed to replicate J's ;. in APL, and used Gareth's approach, saving 13 chars.
{×5⌷⍵:5⌷⍵⋄+/⍵}¨3,⌿3,/×∘?∘9¨∘.∨⍨9⍴0 1

Sample run:
      {×5⌷⍵:5⌷⍵⋄+/⍵}¨3,⌿3,/×∘?∘9¨∘.∨⍨9⍴0 1
9  9 6  1 7  5 6
7 55 5 39 9 54 9
9  8 2  1 8  1 9
2 43 8 41 6 42 5
7  3 4  4 8  3 2
2 29 1 26 2 35 8
6  4 2  3 2  3 7

Explanation:

∘.∨⍨9⍴0 1 generates a bit mask.
×∘?∘9¨ multiplies each bit by a random value from 1 to 9 inclusive, generating a masked grid of random numbers.
3,⌿3,/ uses what can only be described as hackery to return all 3 by 3 overlapping boxes in the masked array. These are also flattened in the process.
{×5⌷⍵:5⌷⍵⋄+/⍵}¨ iterates over the array, assigning each element to ⍵. For each iteration, it takes the fifth (middle, remembering that APL indexing is 1-based), and returns its sign. In this case this is equivalent to testing if the number is greater than 0. If this returns 1 (for true), then return that element. Otherwise, return the sum of the elements in the flattened 3 by 3 box. It uses the :⋄ ternary operator, which is the equivalent of ?: in many languages.

Uh-oh. Looks like I'm going to have to find more character savings. :-S

@Gareth well, look what we have here. I'm back in the lead :P

NOOOOOOOOOO!!!!!!! :-(

J, 63 61 59 55 52 51 49 47 39 37 characters
3 3(4&{+4{*|+/)@,;._3(**1+?)+./~9$0 9

With thanks to Volatility for his 10 character saving.
Explanation (each step will have different random numbers...):
Generate the mask for generating the random numbers (uses $:
   9 9$9$0 9
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0
0 9 0 9 0 9 0 9 0

Now we have a hook. This is actually a happy accident from when I was whittling down an earlier version. It was meant to be transpose |: and OR +. with the original. It made sense since I was using ones and zeroes at the time, but now I have nines and zeroes. It just so happens that it works in the same way with the GCD meaning of +.. Lucky for me. :-)
   (+.|:)9 9$9$0 9
0 9 0 9 0 9 0 9 0
9 9 9 9 9 9 9 9 9
0 9 0 9 0 9 0 9 0
9 9 9 9 9 9 9 9 9
0 9 0 9 0 9 0 9 0
9 9 9 9 9 9 9 9 9
0 9 0 9 0 9 0 9 0
9 9 9 9 9 9 9 9 9
0 9 0 9 0 9 0 9 0

So, now that we have a grid of 9s and 0s we want to generate some random numbers. ? generates a random number from 0 up to (but not including) a given number. Given a list it will generate one random number in this way for each member of the list. So in this case it will generate a number from 0 to 8 for every 9 in the table and a floating point number from 0 to 1 for each 0.
   ?(+.|:)9 9$9$0 9
 0.832573 7 0.926379 7 0.775468 6 0.535925 3  0.828123
        7 0        5 5        4 3        4 5         4
0.0944584 2 0.840913 2 0.990768 1 0.853054 3  0.881741
        3 8        7 0        8 3        3 4         8
 0.641563 4 0.699892 7 0.498026 1 0.438401 6  0.417791
        6 8        7 5        2 3        6 6         3
 0.753671 6 0.487016 4 0.886369 7 0.489956 5  0.902991
        3 4        7 8        1 4        8 0         8
0.0833539 4 0.311055 4 0.200411 6 0.247177 5 0.0464731

But we want numbers from 1 to 9 not 0 to 8. So we add 1.
   (1+?)(+.|:)9 9$9$0 9
 1.4139 4  1.7547 7 1.67065 4 1.52987 1 1.96275
      2 8       2 4       3 9       6 9       9
1.15202 7 1.11341 5  1.0836 1 1.24713 2 1.13858
      9 3       3 2       4 7       3 8       6
1.06383 9 1.67909 4 1.09801 8  1.4805 6  1.0171
      9 5       5 5       9 5       9 4       3
1.22819 1 1.85259 4 1.95632 6 1.33034 3 1.39417
      4 2       5 1       3 7       2 5       6
1.06572 5  1.9942 5 1.78341 5 1.16516 6 1.37087

This is very nice but we've lost the zeroes that I want, so we'll multiply it by the original mask after turning all the nines into ones. I do this by checking if the value is greater than 1. That gives us: (1&<*1+?).
There are a couple of things going on here:

We've created a fork which allows us to pack a lot of work into very few characters.
We've bonded (&) the 1 to the < verb.

So all combined the (1&<*1+?) is generating random numbers, and zeroing all the numbers which where generated by zeroes in the original grid.
   (1&<*1+?)(+.|:)9 9$9$0 9
0 3 0 2 0 7 0 1 0
9 5 2 7 7 1 4 5 7
0 6 0 8 0 3 0 1 0
4 8 7 5 9 7 7 9 4
0 9 0 6 0 9 0 9 0
6 1 2 1 4 6 8 9 4
0 3 0 8 0 6 0 6 0
2 5 2 2 2 2 3 9 3
0 9 0 3 0 5 0 3 0

The next bit is the (in my opinion, anyway :-) clever bit.
The cut ;. verb has a form x u;._3 y which cuts the input into boxes described by x, and then applies the verb u to them. In this case we have 3 3(4&{++/*0=4&{)@,;._3.

The 3 3 is describing the boxes we want - 3x3.
The (4&{++/*0=4&{)@, is a verb train which describes what we want to do to each box.

To demonstrate the ;. verb I'll use < to show each box:
   3 3(<);._3(1&<*1+?)(+.|:)9 9$9$0 9
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│0 8 0│8 0 7│0 7 0│7 0 4│0 4 0│4 0 3│0 3 0│
│9 1 3│1 3 2│3 2 3│2 3 8│3 8 5│8 5 5│5 5 9│
│0 6 0│6 0 1│0 1 0│1 0 2│0 2 0│2 0 4│0 4 0│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│9 1 3│1 3 2│3 2 3│2 3 8│3 8 5│8 5 5│5 5 9│
│0 6 0│6 0 1│0 1 0│1 0 2│0 2 0│2 0 4│0 4 0│
│7 1 6│1 6 7│6 7 1│7 1 2│1 2 1│2 1 6│1 6 1│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│0 6 0│6 0 1│0 1 0│1 0 2│0 2 0│2 0 4│0 4 0│
│7 1 6│1 6 7│6 7 1│7 1 2│1 2 1│2 1 6│1 6 1│
│0 7 0│7 0 5│0 5 0│5 0 9│0 9 0│9 0 7│0 7 0│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│7 1 6│1 6 7│6 7 1│7 1 2│1 2 1│2 1 6│1 6 1│
│0 7 0│7 0 5│0 5 0│5 0 9│0 9 0│9 0 7│0 7 0│
│7 9 9│9 9 7│9 7 1│7 1 9│1 9 4│9 4 9│4 9 5│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│0 7 0│7 0 5│0 5 0│5 0 9│0 9 0│9 0 7│0 7 0│
│7 9 9│9 9 7│9 7 1│7 1 9│1 9 4│9 4 9│4 9 5│
│0 3 0│3 0 2│0 2 0│2 0 7│0 7 0│7 0 9│0 9 0│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│7 9 9│9 9 7│9 7 1│7 1 9│1 9 4│9 4 9│4 9 5│
│0 3 0│3 0 2│0 2 0│2 0 7│0 7 0│7 0 9│0 9 0│
│3 1 6│1 6 1│6 1 7│1 7 6│7 6 8│6 8 9│8 9 9│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│0 3 0│3 0 2│0 2 0│2 0 7│0 7 0│7 0 9│0 9 0│
│3 1 6│1 6 1│6 1 7│1 7 6│7 6 8│6 8 9│8 9 9│
│0 9 0│9 0 3│0 3 0│3 0 4│0 4 0│4 0 3│0 3 0│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Some things to notice:

The boxes overlap - the second and third columns in the top left box are the first and second in the box to the right of it.
There are 7x7 boxes. That's why we had a 9x9 grid initially.
Each place we require a sum has a 0 at the box's centre.

Now we just need to either pass the value at the centre back (if it's non-zero) or sum the numbers in the 3x3 box (if the centre is zero).
To do this we need easy access to the centre number. , helps here. It turns the 3x3 grid into a list of 9 items with the centre number at number 4.
4&{ will use { to pull out the centre value and then compare it with 0: 0=4&{. This returns a 0 or 1 for true or false, which we then multiply by the sum +/. If it was zero at the centre we now have our sum as required. If it was not we have zero, so to finish off we just add the centre value 4&{+.
This gives the verb train (4&{++/*0=4&{)@,
   3 3(4&{++/*0=4&{)@,;._3(1&<*1+?)(+.|:)9 9$9$0 9
2  6 9  3 7  9 7
3 47 6 51 5 49 5
3  9 9  6 6  2 8
7 48 6 47 1 37 5
5  4 5  7 7  2 6
5 35 3 49 8 51 9
1  6 6  6 7  4 8

Does your one line of code do all that, including generate the random numbers? Reassure me. Just finding it hard to believe.

Yep, hard as it may be to believe. The random bit is done by the ?. I'll change the explanation to reflect the newest version.

@DavidCarraher Most verbs in J are either 1 or 2 characters so 47 characters can pack in a lot of work.

The cutting of a 9x9 box into 7x7 overlapping squares is definitely the clever bit. In less than 10 minutes I've been able to apply it to beat my current GolfScript implementation by 7.5%.

Oh well, looks like it's back to the drawing board for me.

@Volatility Only a couple of characters in it... :-)

I've conceded defeat, so I've decided to golf this piece of work. 8 chars can be saved if (1&<*1+?)(+.|:)9 9$9$0 9 is replaced by (**1+?)+./~9$0 9. It uses a much shorter grid generator, and replaces 1&< with monadic *, which are equivalent in this case.

@Volatility Wow, excellent!

You can use 4&{+4{*|+/ instead of 4&{++/*0=4&{ to save 2 chars.

Tour de force !

Ruby (135 characters)
a=(0..48).map{rand(9)+1}
([0,0,j=8]*3).each{|l|a[j]=[0,1,6,7,8].inject{|s,e|s+a[j+e]+a[j-e]};j+=l+2}
a.each_slice(7){|r|puts"%-3s"*7%r}

Sample output
2  1  6  9  4  5  1
9  34 4  37 2  31 3
7  2  3  1  8  1  7
5  42 4  40 2  47 9
3  9  9  4  9  4  7
3  44 4  41 2  47 4
6  9  1  5  7  6  8

Breakdown
It's not too obvious how this works, so here's a quick breakdown. NOTE: You can probably skip some of these steps and jump to shorter versions more quickly, but I think it's educational enough to see different ways I shaved off characters, especially by spotting patterns in literals to turn 2-digit numbers into 1-digit versions.
Naive version
Unlike the other Ruby solutions that rely on a two-dimensional array, you can (eventually) get a shorter version by starting with a 1-dimensional array and working with offset values, since the patterns repeat.
ary=(0..48).map { rand(9) + 1 }

offsets = [-8,-7,-6,-1,1,6,7,8]

3.times do |i|
  [8,10,12].each do |j|
    ary[j + 14*i] = ary.values_at(*offsets.map { |e| j+14*i + e }).inject(:+)
  end
end

ary.each.with_index do |e,i|
  $> << ("%-3s" % e)
  $> << ?\n if i % 7==6
end

The key principle here is that we're working at index positions 8, 10, 12, just offset by multiples of 14. Positions 8, 10 and 12 are the centers of the 3x3 grids that we're summing up. In the sample output, 34 is position 8, 42 is position 8 + 14*1, etc. We replace position 8 with 34 by positions offset from position 8 by [-8,-7,-6,-1,1,6,7,8] — in other words 34 = sum(ary[8-8], ary[8-7], ..., ary[8+8]). This same principle holds for all the values of [8 + 14*i, 10 + 14*i, 12 + 14*i], since the pattern repeats.
Optimising it
First, some quick optimisations:

Instead of 3.times { ... }, and calculating j + 14*i each time, "inline" the positions [8,10,12,22,24,26,36,38,40].
The offsets array is used once, so replace the variable with the literal.
Replace do ... end with {...} and switch around the printing to $> << foo. (There's a trick here involving puts nil and () == nil.)
Shorter variable names.

The code after this is 177 characters:
a=(0..48).map{rand(9)+1}
[8,10,12,22,24,26,36,38,40].each{|j|a[j]=a.values_at(*[-8,-7,-6,-1,1,6,7,8].map{|e|j+e}).inject(:+)}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

For the next reduction, note that the inject doesn't need the offsets array to be in order. We can either have [-8,-7,-6,-1,1,6,7,8] or some other ordering, since addition is commutative.
So first pair up the positives and the negatives to get [1,-1,6,-6,7,-7,8,-8].
Now you can shorten
[1,-1,6,-6,7,-7,8,-8].map { |e| j+e }.inject(:+)

to
[1,6,7,8].flat_map { |e| [j+e, j-e] }

This results in
a=(0..48).map{rand(9)+1}
[8,10,12,22,24,26,36,38,40].each{|j|a[j]=a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+)}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

which is 176 characters.
Shift by 8 and move to differences
The two-character literal values seem like they can be shortened away, so take [8,10,12,22,24,26,36,38,40] and shift everything down by 8, updating j at the start of the loop. (Note that +=8 avoids needing to update the offset values of 1,6,7,8.)
a=(0..48).map{rand(9)+1}
[0,2,4,14,16,18,28,30,32].each{|j|j+=8;a[j]=a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+)}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

This is 179, which is bigger, but the j+=8 can actually be removed.
First change
[0,2,4,14,16,18,28,30,32]

to an array of differences:
[2,2,10,2,2,10,2,2]

and cumulatively add these values to an initial j=8. This will eventually cover the same values. (We could probably skip straight to this instead of shifting by 8 first.)
Note that we'll also add a dummy value of 9999 to the end of the differences array, and add to j at the end, not the start of the loop. The justification is that 2,2,10,2,2,10,2,2 looks awfully close to being the same 3 numbers repeated 3 times, and by computing j+difference at the end of the loop, the final value of 9999 won't actually affect the output, since there isn't a a[j] call where j is some value over 10000.
a=(0..48).map{rand(9)+1}
j=8
[2,2,10,2,2,10,2,2,9999].each{|l|a[j]=a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+);j+=l}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

With this differences array, the j+=8 is now just j=8, of course, since otherwise we'd repeatedly add 8 too many. We've also changed the block variable from j to l.
So since the 9999 element has no effect on the output, we can change it to 10 and shorten the array.
a=(0..48).map{rand(9)+1}
j=8
([2,2,10]*3).each{|l|a[j]=a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+);j+=l}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

This is 170 characters.
But now the j=8 looks a bit clunky, and you can save 2 characters by shifting [2,2,10] down by 2 to conveniently get an 8 you can use for assignment. This also needs j+=l to become j+=l+2.
a=(0..48).map{rand(9)+1}
([0,0,j=8]*3).each{|l|a[j]=a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+);j+=l+2}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

This is 169 characters. A round-about way to squeeze 7 characters, but it's neat.
Final tweaks
The values_at call is actually sort of redundant, and we can inline an Array#[] call. So
a.values_at(*[1,6,7,8].flat_map{|e|[j+e,j-e]}).inject(:+)

becomes
[1,6,7,8].flat_map{|e|[a[j+e],a[j-e]]}.inject(:+)

You can also spot that flat_map + j+e/j-e + inject can be reduced to a more direct summation with an initial 0 in the array.
This leaves you with 152 characters:
a=(0..48).map{rand(9)+1}
([0,0,j=8]*3).each{|l|a[j]=[0,1,6,7,8].inject{|s,e|s+a[j+e]+a[j-e]};j+=l+2}
a.map.with_index{|e,i|$><<"%-3s"%e<<(?\nif i%7==6)}

Finally:

map.with_index can become each_slice.
Change the printing approach.

135:
a=(0..48).map{rand(9)+1}
([0,0,j=8]*3).each{|l|a[j]=[0,1,6,7,8].inject{|s,e|s+a[j+e]+a[j-e]};j+=l+2}
a.each_slice(7){|r|puts"%-3s"*7%r}

You can replace each with map for one byte.

Python, 132
This doesn't technically satisfy the rules, because the last digits of each number are aligned rather than the first. But I thought I'd share anyway:
import numpy
G=numpy.random.randint(1,10,(7,7))
G[1::2,1::2]=sum(G[i:6+i:2,j:6+j:2]for i in[0,1,2]for j in[0,1,2]if i&j!=1)
print G

Sample output:
[[ 8  9  8  3  8  5  8]
 [ 6 53  4 45  8 53  8]
 [ 8  2  8  1  5  3  8]
 [ 2 40  6 34  1 32  7]
 [ 4  1  9  1  3  3  2]
 [ 4 35  7 35  6 31  1]
 [ 1  7  2  5  2  8  6]]

GolfScript (79 78 72 70 68 66 65 60 chars)
56,{13%5<,~9rand)}%9/`{>3<zip`{>3<(*(+(\{+}*or' '}+7,%n}+7,/

NB This contains a literal tab, which Markdown may well break.
The clever bit is due to Gareth: see his J solution.
Online demo

Mathematica, 108
s=#-1;;#+1&;g=1+8~RandomInteger~{7,7};Column/@
ReplacePart[g,{i_?EvenQ,j_?EvenQ}:>g〚s@i,s@j〛~Total~2-g〚i,j〛]

For prettier output Column/@ can be replaced with TableForm@ at a cost of 2 characters.

Very, very clever.Grid[ReplacePart[    g, {i_?EvenQ, j_?EvenQ} :>      g[[s@i, s@j]]~Total~2 - g[[i, j]]]\[Transpose]] gives a cleaner output and saves a couple of characters iff you count Transpose as a single character, which it is in Mathmatica. Btw, Wolfram's OneLinerSubmission template counted 106 characters, 105 with the one character Transpose.

@DavidCarraher Thanks. The char count is due to unnecessary newline and :> being one symbol, although it's in the private use area of unicode. One could even remove the transpose, since the validity summation rule holds even after transposition. But it seems Grid doesn't align the entries without further options (v8)

Grid centers the numbers within columns. Technically, that would not satisfy the challenge, but it does look better than having a list appear in the displayed table.

Very nice.  I just spend considerable time creating the same thing, only I used Part and Tuples.  Posting soon.

You could save two characters with this: p=2|4|6;Column/@ReplacePart[g,{i:p,j:p}:>g[[s@i,s@j]]~Total~2-g[[i,j]]]

R: 114 characters
a=array(sample(1:9,49,r=T),c(7,7))
for(i in 2*1:3){for(j in 2*1:3)a[i,j]=sum(a[(i-1):(i+1),(j-1):(j+1)])-a[i,j]}
a

First line create a 7 by 7 array filled with randomly chosen numbers from 1 to 9 (uniform distribution with replacement, hence r=T which stands for replace=TRUE). Second line, compute sums of 3 by 3 grids, substract center and replace it with the result. Third line print the resulting grid (by default, matrix and array columns are right aligned).
Example output:
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    8    5    6    4    3    2    2
[2,]    1   37    6   41    7   38    8
[3,]    5    3    3    3    9    4    3
[4,]    4   31    3   41    3   44    9
[5,]    3    5    5    9    6    7    3
[6,]    3   32    2   40    4   37    5
[7,]    8    2    4    1    9    1    2

J, 67 65 bytes
A naïve and verbose solution in J. It is a straightforward implementation of the task.
(+/^:_"2((,&.>/@(<:,],>:)"0)&.>m){0 m}a)(m=.{;~1 3 5)}a=.>:?7 7$9

First I create a 7 x 7 array of integers between 1 and 9. In fact J's ? verb generates numbers up to its argument, that's why we need to increment each element, >: in J
a=.>:?7 7$9

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

I prepare a mask to be used for zeroing of the odd row/col cells, a pairs of odd row/column indices:
m=.{;~1 3 5
┌───┬───┬───┐
│1 1│1 3│1 5│
├───┼───┼───┤
│3 1│3 3│3 5│
├───┼───┼───┤
│5 1│5 3│5 5│
└───┴───┴───┘

The Catalogue verb { combines items from the atoms inside the boxed list
┌─────┬─────┐
│1 3 5│1 3 5│
└─────┴─────┘

to form a catalogue, the 3x3 table of the pairs above
Then I prepare a table of row/col indices to be used for selection of each of the 3x3 subarrays.
s=.(,&.>/@(<:,],>:)"0)&.>m
┌─────────────┬─────────────┬─────────────┐
│┌─────┬─────┐│┌─────┬─────┐│┌─────┬─────┐│
││0 1 2│0 1 2│││0 1 2│2 3 4│││0 1 2│4 5 6││
│└─────┴─────┘│└─────┴─────┘│└─────┴─────┘│
├─────────────┼─────────────┼─────────────┤
│┌─────┬─────┐│┌─────┬─────┐│┌─────┬─────┐│
││2 3 4│0 1 2│││2 3 4│2 3 4│││2 3 4│4 5 6││
│└─────┴─────┘│└─────┴─────┘│└─────┴─────┘│
├─────────────┼─────────────┼─────────────┤
│┌─────┬─────┐│┌─────┬─────┐│┌─────┬─────┐│
││4 5 6│0 1 2│││4 5 6│2 3 4│││4 5 6│4 5 6││
│└─────┴─────┘│└─────┴─────┘│└─────┴─────┘│
└─────────────┴─────────────┴─────────────┘

For each pair in the m array I make a pair of triplets, centered around each number of the m pair:
        ┌─────┬─────┐
 1 3 -> │0 1 2│2 3 4│
        └─────┴─────┘

These pairs of triplets are used by the J From verb {, which can select multiple rows and columns simultaneously. 0 1 2 / 2 3 4 means that I select rows 0, 1 and 2 together with columns 2, 3 and 4, thus selecting the second 3x3 subarray on the top.
Finally, I can use the 7x7 array and the masks to achieve the task:
First I use m as a mask to set the corresponding elements to 0:
0 m}a

Then I take all the 3x3 subarrays using s as a selector and find their sums:
+/^:_"2 s{0 m}a

Then I put these numbers back into the starting array.
 (+/^:_"2 s{0 m}a)m}a

2  8 7  4 4  5 1
4 39 4 39 6 36 9
3  8 3  6 5  3 3
6 44 6 40 7 42 1
7  7 4  4 5  9 9
2 36 6 43 2 46 9
2  2 6  8 8  1 3

Try it online!

APL (Dyalog Unicode), 32 31 30 bytesSBCS
-1 byte thanks to @jslip
|a-m×+/+/⊢⌺3 3⊢a←?9⌈m←∘.⍱⍨2|⍳7

Try it online!

∧/¨~ -> ⍱/¨

@jslip Ah, de Morgan's laws. Thanks :)

Ruby, 207
I shall present my solution first (as I always do):
a=Array.new(7){Array.new(7){rand(9)+1}}
s=[-1,0,1]
s=s.product s
s.slice!4
r=[1,3,5]
r.product(r).map{|x|u=0
s.map{|y|u+=a[x[0]+y[0]][x[1]+y[1]]}
a[x[0]][x[1]]=u}
puts a.map{|x|x.map{|y|y.to_s.ljust 3}.join

Ruby, 150 characters
v=(a=0..6).map{a.map{rand(9)+1}}
(o=[1,3,5]).map{|i|o.map{|j|v[i][j]=0
(d=[0,-1,1]).map{|r|d.map{|c|v[i][j]+=v[i+r][j+c]}}}}
puts v.map{|r|"%-3d"*7%r}

if the left justification requirement justification is just that ljust would have to be used... well, no. I love Ruby's formatting capabilities.
Do not use Array.new(7){...}. (0..6).map{...} is both shorter and more readable and you get an assignable range for free.
Line #3 inspired by Doorknob's solution.

GolfScript, 87 chars
49,{.1&\7/1&!|9rand)*}%.7/{[..1>@0\+]zip{{+}*}%);}:^%zip{^~}%]zip{.0=!=}%{'  '+3<}%7/n*

There are too many zips in there... (see online)
3  9  9  3  3  9  8
6  46 2  50 3  39 8
7  3  7  2  4  7  3
8  33 9  51 8  49 5
4  3  9  9  3  9  2
1  45 9  41 6  33 2
4  3  6  1  6  1  4

J, 58/64/67 characters
0j_1":(7$0,:7$0 1){"0 1 |:>v;v-~7 7{.0,.0,3+/\"1]3+/\v=.1+?7 7$9

While the specification requires the numbers to be left-aligned, there is no requirement to use the decimal notation, so I guess this is valid output:
1.0e0 8.0e0 9.0e0 6.0e0 2.0e0 9.0e0 6.0e0
6.0e0 3.9e1 8.0e0 4.0e1 2.0e0 3.8e1 4.0e0
1.0e0 4.0e0 2.0e0 8.0e0 3.0e0 9.0e0 3.0e0
2.0e0 2.4e1 5.0e0 4.1e1 9.0e0 4.7e1 8.0e0
1.0e0 3.0e0 6.0e0 5.0e0 3.0e0 5.0e0 7.0e0
4.0e0 3.0e1 1.0e0 2.3e1 1.0e0 3.1e1 1.0e0
6.0e0 5.0e0 4.0e0 2.0e0 1.0e0 5.0e0 8.0e0

If right alignment instead of left alignmnent is acceptable, we're at 58 characters
(7$0,:7$0 1){"0 1 |:>v;v-~7 7{.0,.0,3+/\"1]3+/\v=.1+?7 7$9

J's ": (format) has three formatting modes:

right-aligned with n digits or with shrink-wrap (default display)
left-aligned scientific notation with n digits and m characters total
shrinkwrap boxed display with (left/center/right)-(top/middle/bottom) alignment (below, 69 characters)

The most verbose but also most versatile and the only one able to produce the output as per the example is the 8!:2 formatting foreign, which takes a formatting string as its left argument. Also 67 characters:
'l3.'8!:2(7$0,:7$0 1){"0 1 |:>v;v-~7 7{.0,.0,3+/\"1]3+/\v=.1+?7 7$9

Here is the boxed format:
 0 0":<"0(7$0,:7$0 1){"0 1 |:>v;v-~7 7{.0,.0,3+/\"1]3+/\v=.1+?7 7$9

 ┌─┬──┬─┬──┬─┬──┬─┐
 │2│6 │5│7 │5│7 │6│
 ├─┼──┼─┼──┼─┼──┼─┤
 │8│40│4│35│9│49│6│
 ├─┼──┼─┼──┼─┼──┼─┤
 │6│7 │2│2 │1│9 │6│
 ├─┼──┼─┼──┼─┼──┼─┤
 │8│41│9│35│3│45│7│
 ├─┼──┼─┼──┼─┼──┼─┤
 │3│1 │5│6 │7│8 │4│
 ├─┼──┼─┼──┼─┼──┼─┤
 │7│37│4│45│6│48│8│
 ├─┼──┼─┼──┼─┼──┼─┤
 │8│4 │5│4 │8│1 │6│
 └─┴──┴─┴──┴─┴──┴─┘

Perl, 117 characters
print$_,++$j%7?$":$/for map{++$i/7&$i%7&1?
eval join"+",@x[map{$i+$_,$i-$_}1,6,7,8]:" $_"}@x=map{1+int rand 9}$i--..48

This is one of those Perl scripts where all but one of the for loops have been collapsed into map calls so that everything can be done in a single statement. Global variables also make some important appearances in this one. I guess what I'm trying to say here is, this program is a bit gross.
Wait, it gets worse: There's a known bug in the script! It has less than a one-in-a-million chance of getting triggered, though, so I haven't gotten around to fixing it yet.

Don't hold out on us, what is the bug?

Bonus points to the first person who spots it!

Mathematica, 106 / 100
I came up with something very similar to ssch's code, before seeing it.  I am borrowing his idea of using Column.  With ASCII only, 106:
s=#-1;;#+1&
a=8~RandomInteger~{7,7}+1
a[[##]]=a[[s@#,s@#2]]~Total~2-a[[##]];&@@@{2,4,6}~Tuples~2
Column/@a

With Unicode characters (as used by ssch), 100:
s=#-1;;#+1&
a=8~RandomInteger~{7,7}+1
a〚##〛=a〚s@#,s@#2〛~Total~2-a〚##〛;&@@@{2,4,6}~Tuples~2
Column/@a

Powershell, 149 148 bytes
-1 byte thanks to @AdmBorkBork. It's cool!
$i=-1
($a=(,1*8+0,1*3)*3+,1*7|%{$_*(1+(Random 9))})|?{++$i;!$_}|%{6..8+1|%{$_,-$_}|%{$a[$i]+=$a[$i+$_]}}
-join($a|%{if(!(++$i%7)){"
"};'{0,3}'-f$_})

Explanation:
$i=-1                       # let $i store -1
($a=                        # let $a is array of random numbers with zero holes
    (,1*8+0,1*3)*3+,1*7|    # the one-dimension array equals
                            # 1 1 1 1 1 1 1
                            # 1 0 1 0 1 0 1
                            # 1 1 1 1 1 1 1
                            # 1 0 1 0 1 0 1
                            # 1 1 1 1 1 1 1
                            # 1 0 1 0 1 0 1
                            # 1 1 1 1 1 1 1
    %{                      # for each element
        $_*(1+(Random 9))   # multiply 0 or 1 element to random digit from 1 to 9
    }                       # now $a stores values like (* is a random digit from 1 to 9)
                            # * * * * * * *
                            # * 0 * 0 * 0 *
                            # * * * * * * *
                            # * 0 * 0 * 0 *
                            # * * * * * * *
                            # * 0 * 0 * 0 *
                            # * * * * * * *
)|?{++$i;!$_                # calc index $i and passthru values == 0 only
}|%{                        # for each zero value cell with index $i
    6..8+1|%{               # offsets for the surrounding cells
                            #  .  .  .
                            #  .  x +1
                            # +6 +7 +8
        $_,-$_              # add the mirror offsets
                            # -8 -7 -6
                            # -1  x +1
                            # +6 +7 +8
    }|%{                    # for each offset
        $a[$i]+=$a[$i+$_]   # add surrounding values to the cell
    }
}
                            # display the $a
-join(
    $a|%{                   # for each value of $a
        if(!(++$i%7)){"`n"} # line break for each 7 cells
        '{0,3}'-f$_         # formatted value of $a with width = 3 char and align right
    }
)                           # join all values to string

You can get rid of a byte (a newline) by encapsulating your $a assignment in parens and moving the next line up to make one big line -- ($a=(,1*8+0,1*3)*3+,1*7|%{$_*(1+(Random 9))})|?{++$i;!$_}|%{6..8+1|%{$_,-$_}|%{$a[$i]+=$a[$i+$_]}}

No. It doesn't work. The array must be fully populated before $a[$i+$_]. So here are two steps. I had several attempts to encapsulate in one pipe. :)

It doesn't work if you don't place parens around the assignment. With ($a=(,1*8+0,1*3)*3+,1*7|%{$_*(1+(Random 9))}), $a is fully populated before the next pipeline instance. It should work (at least, it does for me).

Excel VBA, 74 bytes
VBE immediate function that outputs to [B2:H9].
[B2:H9]="=IF(ISODD(ROW()*COLUMN()),SUM(A1:C1,A2,C2,A3:C3),INT(RAND()*8)+1)

Sample Output

Mathematica 142  151 172   179
Code
z = (m = RandomInteger[{1, 9}, {7, 7}]; s = SparseArray; o = OddQ; e = EvenQ; i = {1, 1, 1};
(m + ArrayPad[ListCorrelate[{i, i, i}, m] s[{{i_, j_} /; o@i \[And] o@j -> 1}, {5, 5}], 1]
- 2 m s[{{i_, j_} /; e@i \[And] e@j -> 1}, {7, 7}]) // Grid)

Usage
z

You have 0s; the rules say 1-9

Thanks. I corrected the data and pics. The functions remain unchanged.

Also, the numbers are not aligned as specified in the question.

Mathematica's wordiness (or, more accurately, insistence on using big words) becomes apparent.

Julia 0.6, 127 (89) bytes
x=rand(1:9,7,7);[x[i,j]=sum(!(0==k==l)*x[i+k,j+l]for k=-1:1,l=-1:1)for i=2:2:7,j=2:2:7]
Base.showarray(STDOUT,x,1<1;header=1<1)

Try it online!
89 bytes using native display, which might be admissible if additional lines can be printed:
7×7 Array{Int64,2}:
6   6  8   2  3   2  3
7  44  5  33  4  23  5
3   8  1   9  1   3  2
4  41  2  37  5  22  2
7   8  8   8  3   4  2
9  53  6  44  7  36  3
7   7  1   9  2   6  9

Java 10, 262 260 248 239 bytes
v->{int a[][]=new int[7][7],i=49,j,k;for(;i-->0;)a[i/7][i%7]+=Math.random()*9+1;var r="";for(;++i<7;r+="\n")for(j=0;j<7;r+=(k=a[i][j])>9|j++%2<1?k+" ":k+"  ")if(i*j%2>0)for(a[i][j]=k=0;k<9;k++)a[i][j]+=k!=4?a[i+k/3-1][j+k%3-1]:0;return r;}

-12 bytes thanks to @ceilingcat.
Explanation:
Try it here.
v->{                        // Method with empty unused parameter and String return-type
  int a[][]=new int[7][7],  //  Integer-matrix with 7x7 zeroes
      i=49,j,k;             //  Index integers (`i` starting at 49)
  for(;i-->0;)              //  Loop `i` in the range (49, 0]:
    a[i/7][j%7]+=Math.random()*9+1;
                            //   Fill the current cell with a random 1..9 integer
  var r="";                 //  Result-String, starting empty
  for(;++i<7;               //  Loop `i` in the range [0, 7):
      r+="\n")              //    After every iteration: append a new-line to the result
    for(j=0;j<7;            //   Inner loop `j` in the range [0, 7):
        r+=                 //     After every iteration: append the result-String with:
           (k=a[i][j])>9    //      If the current number has 2 digits,
           |j++%2<1?        //      or it's an even column (indices 0/2/4/6)
            k+" "           //       Append the current number appended with one space
           :                //      Else:
            k+"  ")         //       Append the current number appended with two spaces
      if(i*j%2>1)           //    If both indexes `i` and `j` are odd
        for(a[i][j]=k=0;    //     Reset both the current item and index `k` to 0
            k<9;k++)        //     Inner loop `k` in the range [0, 9):
          a[i][j]+=         //      Sum the item at location `i,j` with:
           k!=4?            //       If `k` is not 4 (the current item itself)
            a[i+k/3-1][j+k%3-1]
                            //        Sum it with the numbers surrounding it
           :                //       Else:
            0;              //        Leave it the same by adding 0
  return r;}                //  Return the result-String

@ceilingcat Thanks! And I've been able to save a few more bytes with var instead of String and +=Math.random()*9+1; instead of =(int)(Math.random()*9+1);. It's actually pretty useful for you to visit all my old answers, haha! :D

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


text:
Basic Calculator with GUI
I recently had to add a small basic calculator to a project. I wrote a quick dirty one, but it seemed small enough to check with you people out here ;)
Just out of curiosity & an appetite to get surprised for some real hacky solutions, try and beat this one :
CODE (JS/JQUERY):
function scalcy() {
    var b="", p=parseFloat,t,i;
    return $("<div>").append("789/456*123-.0=+".split("").map(function(i){
        return $("<button/>").text(i).width(32).height(32).click(function(){
        b = (!p(i=$(this).text())? b.replace(/\D+$/,""): b) + i;
        t.val(((!(i.match(/[.\d]/))? (b=eval(b.slice(0,-1))+i+"").slice(0,-1):
                p(b.match(/[.\d]+/g).pop()) || 0) + "").slice(0,8));
    })})).prepend(t=$("<input/>").width(123).click(function(){
        this.value=b="0";})).width(130);
}

Screenshot (in chrome): (DEMO)

Considerations: Better the UI & lesser the bugs, the better.
Minimum Functionalities:

Supports floating point arithmetic (/*-+),
Reset feature,
Continuous Operation (like working on with the last result)

Note:

Use any language & library, but please not a library call like new
calculator().
Forking the above code itself is most welcome.

Additional Notes:

A graphical UI is obviously considered better than not having any at all.
I'd suggest to have a look at this challenge (for inspiration): Create a GUI Piano.

What is the objective winning criteria? How do you measure how great a UI is?

Basically the calculator should look like the calculator we all know, some buttons & a textbox (like the image above). No sacrifices to be made on that..

I don't like to duplicate UI things (and support only the new one). I have thoose buttons on my keyboard, which don't work on your solution.

well you see, most of the above code is after the GUI part. It's equivalent to me capturing the keyboard & passing it to the eval (in your case expr).

Well you see, it is not on the list of minimal functionalities.

there you go, added.

Congratulations, you just made a chamelion question that invalidated a previously valid answer.

Well I thought adding that would have given undue advantages to languages with no possibilities. Either ways, you win if no one else does, which seems more likely :)

@loxxy Maybe no one else attempts a question which is not well-specified and has no objective winning criterion. Reading and following the comments usually generates better questions and also more interest in solving them.

This snippet on the link provided does not work on Safari 5.1.9 (Snow Leopard 10.6.8) .

@JohannesKuhn There you go. Nothing invalidates your answer now. My bad for the edit earlier, sorry.

I'll just leave this here, and quietly slip out the door...

This is off-topic. It should be in the Code Review section of Stack Exchange.

Tcl/Tk, 100
pack [entry .e -textv e] -f both -e 1
bind . <Return> {catch {expr $e} e}
bind . <Escape> {set e {}}

Buttons are not required, so leave them alone.
The GUI is great. So simple that you can finally focus on the task that you try to do.

I'm not familiar with the language, so I need to ask: This isn't using a text-based interface, as opposed to graphical one?

Tk is a graphical toolkit. Yes, it has a window and so on. Just no buttons :P

Upvoted for strict interpretation of rules... one of my favorite games on this site.

I am not familiar with the language as well, but I see it is very much possible to write a gui based calcy, but would require more code, though: http://wiki.tcl.tk/1270

Tried here and works fine :)

Failed outgolf: 118

You only save 12 characters (bind <>) for in exchange for the lmap and list formating. Yes, this trade of isn't worth it most of the time.

Outgolfed: 106

Nice work. Yeah. I should bind to the toplevel instead. Saves a few chars.

Also tried to do sthg like https://tio.run/##BcGxDsIgFAXQ3a@4Iaw0cTdu/oArMtDnNTVUJPRpagjfjueorGOUKAmeWesPE@GUu37BAPfA/NYFjjge1lcsSLhSPzXfcNkkFkLQjOdeKiyDgWnddLT5me@YcLLpDC9RZYHfqCCshNDH@AM but it caused memory over-allocation. There are syntax subtle details on tcl I still fail to grasp!

I got an other idea. catch takes an additional parameter, and sets the result to this. Saves a few chars.


text:
Preferential Voting
Australia (and many countries) has a perferential voting system,
where voters, number the candidates from 1 - n, where n is the number of candidates,
in order of preference.
Until a candidate gets a absolute majority of votes, the number 1 votes for the candidate with minimum count of number 1 votes, are redistributed to their next preference.
Full detail can be found at http://www.eca.gov.au/systems/single/by_category/preferential.htm, under the The Full Preferential Count
Implement a system that takes in a array of voting slips.
where a voting slip is a array, where each index is a candidate ID, and the element at that index is the voters preference number for that candidate.
Eg:
for a 3 candidates with, 7 voting slips, input could be:
    votes =
   2   1   3
   1   2   3
   3   2   1
   1   3   2
   1   2   3
   2   3   1
   3   2   1

You may take this input in your languages preferred 2D array like data structure.
Example function: (matlab)
function winningParty = countVotes (votes)
    [nVotes, nParties] = size(votes)

    cut = zeros(1,nParties) % no one is cut at the start
    while(max(sum(votes==1))<=0.5*nVotes) %while no  one has absolute majority
        [minVotes, cutParty] = min(sum(votes==1) .+ cut*nVotes*2)                           %make sure not cut twice, by adding extra votes to cut party

        votes(votes(:,cutParty)==1,:)--; % reassign there votes

        cut(cutParty) = true;
        votes

    end
    [winnersVotes, winningParty] = max(sum(votes==1))

Output:
octave:135> countVotes(votes)
nVotes =  7
nParties =  3
cut =

   0   0   0

minVotes =  1
cutParty =  2
votes =

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

winnersVotes =  4
winningParty =  1
ans =  1 %This is the only line i care about

EDIT:
In cases of tie for lowest portion of primary share, either  can be removed.
There can be no tie for winning candidate. Winner must have strictly greater than 50% of votes.

Assuming sufficient response: I will select the winner, when the Austrian Election results are confirmed.

The external link describes multiple systems, and it's ambiguous as to which one you want people to implement. 2. Neither the post nor the external link describes what happens when multiple candidates tie for last place. 3. A test case is a lot more useful when it includes the expected output as well as the input.

To highlight Peter Taylor's point, the following shows many systems for preferential voting. http://www.stat.uchicago.edu/~lekheng/meetings/mathofranking/ref/saari.pdf Saari's book, the Geometry of Voting, goes into more detail.

The title says Australia but your first comment says Austria ? You know they are two different countries, right ? One has kangaroos and the other has lederhosen.

comment should say Australia. Typo

I have added the example output.
I had thought that the example program would be surficent to clear up any ambiguity as to how preferential voting (as I want it implemented) works.  II'll add more a proper description.

Your example program probably is sufficient for those people who own a copy of matlab. For the rest of us, an actual sample of output is surprisingly helpful.

Ok, thanks for the tip. breadbox

Just to clarify, if the vote count was odd (eg 7), would "absolute majority" be 4 or 5 votes, since with floor division it would be 4, but otherwise it would be 5?

For purposes of this, consider a absolute majority of a odd number of votes to be Ceil(numVotes)/2.
So a absolute majority of 7 would be 4.

Reference implementations can sometimes clear up ambiguities (if they're written in a transparent pseudocode), but when the issue is one of apparent failure to take into account corner cases the existence of a reference implementation which doesn't explicitly take them into account doesn't help. And when, as in your clarification, there's freedom to choose between three or more different approaches to the corner case, a reference implementation which only implements one of them is misleading.

mm fair call, Peter.

Python 3, 173 146 Python 2, 125(see below)
Original version, 173:
C=sorted(S[0]);C[-1]=0
while C:
 v={i:sum(i==min(C,key=s.__getitem__)for s in S)for i in C};c=max(C,key=v.get);C.remove(min(C,key=v.get))
 if v[c]*2>len(S):C=print(v[c],c+1)

Expects input in this form:
S=[
   [2,   1,   3],
   [1,   2,   3],
   [3,   2,   1],
   [1,   3,   2],
   [1,   2,   3],
   [2,   3,   1],
   [3,   2,   1],
   ]

and prints number of votes and the winning candidate:
4 1

Commented version:
# create a list of the (still available) candidates;
# these will be used as indexes and therefore have to start at 0 instead of 1
C=sorted(S[0]);C[-1]=0
# start a loop with some condition that's easily stoppable later
while C:
    # for each slip s, find the (still available) candidate with the best vote; count these for each (still available) candidate
    v={i:sum(i==min(C,key=s.__getitem__)for s in S)for i in C}
    # find the candidate with the highest number of votes
    c=max(C,key=v.get)
    # remove the candidate with the lowest number of votest
    C.remove(min(C,key=v.get))
    # somebody with more than 50 % of the votes (=slips) already?
    if v[c]*2>len(S):
        # if yes, then print votes and candidate number
        # (the print function returns None, which makes the condition of the loop fail)
        C=print(v[c],c+1)

EDIT After clarification of output by OP:
C=sorted(S[0]);C[-1]=0
while C:v={i:sum(i==min(C,key=s.__getitem__)for s in S)for i in C};c=max(C,key=v.get);C.remove(min(C,key=v.get))
print(c+1)

(The loop runs to exhaustion of candidates, which is no problem, because the number of votes is not neeeded.)
EDIT 2, newest version, Python 2, 125:
Python 2 range yields a list, which is shorter than the construction I had to use for Python 3.
Also, c need not at all times be the candidate with tho most votes -- it's only important at the end. At the end, there is only one candidate left, so c just has to be some candidate (I use C[0]), because that must be the right one at the end.
That means that the name v is use only once. Replacing that usage with the definition of v saves some more characters.
C=range(len(S[0]))
while C:c=C[0];C.remove(min(C,key={i:sum(i==min(C,key=s.__getitem__)for s in S)for i in C}.get))
print c+1

You just need to return the winning party.
The actual number of votes they end up with is not required.

GolfScript, 37 characters
.0=,({.0={`{\0==}+1$\,,}$1>`{&}+%}*0=

Input (on stack) is a list of votes where elements can be e.g. numbers or strings. Example:
[
  ["Bernard" "Archibald" "Chris"]
  ["Archibald" "Bernard" "Chris"]
  ["Chris" "Bernard" "Archibald"]
  ["Archibald" "Chris" "Bernard"]
  ["Archibald" "Bernard" "Chris"]
  ["Bernard" "Chris" "Archibald"]
  ["Chris" "Bernard" "Archibald"]
]

.0=,({.0={`{\0==}+1$\,,}$1>`{&}+%}*0=

# => either Archibald or Bernard (because of tie)

"where a voting slip is a array, where each index is a candidate ID, and the element at that index is the voters preference number for that candidate." You have it the other way round. You have Index= Preference, Element = candidate ID.
idk if this was intentional, or not (thinking on it, it is in someways a better format for the data, since it intrinsially stops people putting two choices at preference 1)