text:
programmers from all languages, write this with as few code as possible
i've been dabbling with a hypothetical language... now, i want to add a feature/mechanism that can easily format data in as few codes as possible.
now, i need to compare my hypothetical language feature with how it's going to be written in other languages. in particular, would it have lesser code? so i just decided i would have a sample problem and see how this is coded in different languages. problem is, i'm only familiar with C-like languages (C/C++, Java, C#, J#,.. ), Python and some Perl.
so could you guys help me out and write codes, as short as possible (no pseudo code) in different languages for the problem below. be as clever as you want and don't even think of efficiency. we're looking more of how we can describe what needs to be accomplished as short as possible. very declarative. or maybe there's already a languages that does this very well??
transform this:
((a0, a1, a2), (b0, b1, b2), (c0, c1, c2))

to this:
(a0, (b0, c0)), (a1, (b1, c1)), (a2, (b2, c2))

the parenthesization just denotes nested arrays or list, whichever way you want to look at it. also, there are no types, so don't have to worry about that.

Welcome to Programming Puzzles & Code Golf! This site is for programming contests / challenges, not general programming questions. For those, you may want to try [so], but be sure to read their help center before posting this there to make sure that your question will be on-topic. Thanks!

It can be tricky to find a home for a question. e.g. Stack Overflow typically looks for specific programming questions; I'm a bit surprised that this Q doesn't qualify, but this site wants puzzles. Consider http://cstheory.stackexchange.com/ or http://programmers.stackexchange.com/ . The latter is very good for "white-boarding" ideas.

I think this is the best place to ask this question.

I think this question is not asked well enough to be answered. The specification for what has to be done is pretty much non-existent.

@IngoBürk But it's still pretty clear what's being asked.

It should be reworded to have the emphasis on the challenge and have the context placed in note at the end.

Python
The language feature you're describing is typically known as zip. Assuming the array is named a:
zip(a[0],zip(*a[1:]))

Sample usage:
a = (('a0', 'a1', 'a2'), ('b0', 'b1', 'b2'), ('c0', 'c1', 'c2'))
print zip(a[0],zip(*a[1:]))

Output:
[('a0', ('b0', 'c0')), ('a1', ('b1', 'c1')), ('a2', ('b2', 'c2'))]

If the last two values of each don't need to be in a list:
zip(*a)

would suffice.

it was so long ago since i coded in python... and so little did i know of its library that i've never seen "zip" before... i'll soon look into the documentation for this. and by "soon look into", i mean look into it after a few days (that's just how i roll)... but there certainly are things i could pick up from this. thnx.

any other inputs?? guys?

Python 3
I know you already have a Python answer, but here's some code that can be easily translated to other languages:
tup = [[a0, a1, a2], [b0, b1, b2], [c0, c1, c2]]
end = []

for j in range(len(tup[0])):
    end.append([tup[0][j]])
    end[j].append([])
    for i in range(1, len(tup)):
        end[j][1].append(tup[i][j])

...And since you've tagged this as code-golf I've golfed my code from 206 characters to 157:
t=[[a0,a1,a2],[b0,b1,b2],[c0,c1,c2]]
e=[];l=len;r=range
for j in r(l(t[0])):
 e.append([t[0][j]]);e[j].append([])
 for i in r(1,l(t)):e[j][1].append(t[i][j])

no offense, but nested loops? that is just typical programming.

maybe you've mistaken it to be opposite day, today, coz i said short and clever.

^ just keeping the whole thread alive and going. no real offense intended.

now, any other inputs??


text:
Take a break to make a snake!
Our classic snake has developed an inbalance of growth hormones. To make matters worse, his tail is frozen in place! Given directional input as specified in Figure 1, write a program to determine where he will grow.

Figure 1. Directional input.
Program specifications

Read the input character by character on STDIN.
After reading a character, output the snake to STDOUT. Please include a blank line in between each time you print a snake.
The snake consists of <>v^ and a head. The head of the snake may be any round character of your choosing, such as o, 0, O, or ☺.
Any combination of wasd is valid for input.
Your program should not assume the input is within a certain length.
The snake can pile on top of itself, overwriting <>v^. See examples for snake growing mechanics.
Trailing whitespace is okay, but your snake must look correct.

Scoring
This is code-golf. Your score is the number of characters in your program. Lowest score wins!
Example snakes:
Input: ddddssaassdddddww
Output:
>>>>v
    v
  v<<  ☺
  v    ^
  >>>>>^

Input: dddsssaaawww
Output:
☺>>v
^  v
^  v
^<<<

Input: dddsssdddddasddddwww
Output:
>>>v
   v       ☺
   v       ^
   >>>>v<  ^
       >>>>^

Input: dddwwdddssssaaaaaaaaawww
Output:
      >>>v
☺     ^  v
^  >>>^  v
^        v
^<<<<<<<<<

Input: ddddssssaawwddddd
Output:
>>>>v
    v
  >>>>>☺
  ^ v
  ^<<

Input: dddddssaawwwwddddd
Output:
   >>>>>☺
   ^
>>>^>v
   ^ v
   ^<<

Input:
ddddaaaasssssdddddddddddwwwwwaaaasssssdddddddddddwwwwwwwwwwsssssaaaasssssdddddddwwwwwddddssaaaasssddddaaaassssssssssdddwwwwwwwddddswaaaassssddaasssaaaaaaaaaawwwwddddssssaaaaaaaaaaawwwwddddsssssssssaaaa

Output:
                  v
                  v
                  v
                  v
                  v
v<<<<  v<<<<  v<<<<  >>>>v
v      v   ^  v   ^  ^   v
v      v   ^  v   ^  v<<<<
v      v   ^  v   ^  v
v      v   ^  v   ^  v
>>>>>>>>>>>>>>>>>>>>>v<<<<
                     v
                     v
                     v  v<<<<
                     v  v   ^
                     v  v
       >>>>v  >>>>v  v  v
       ^   v  ^   v  v  v<<
       ^   v  ^   v  v  v
       ^   v  ^   v  v  v
       ^<<<v<<<<<<<<<<<<<
           v
           v
           v
           v
       O<<<<

Very nice. But... WTH is a "code gofl"?

I'd get rid of the bonus as it is way too easy to create your own snake and input string.

@JanDvorak rotfl my bad.

@BetaDecay done.

Also, does the snake start in a random position on the top line?

@BetaDecay the snake starts at the top left corner, but if the input causes the snake to grow farther up or to the left then the whole snake shifts so it can still be printed. Does that make sense?

@chilemagic is leading whitespace OK?

@JanDvorak Your snake should be flush to the left like the examples.

Why isn't there a path to the top of the d in the code golf example though?

@BetaDecay it's hidden  behind the downwards path

@JanDvorak Where the snake start off originally then? It's supposed to start in the top left corner, so why isn't there a path near the top left corner? Does the plane automatically scale to fit the path?

@BetaDecay the plane scales. In the code golf example it started at the top left of the c, but since the d is taller it moves down.

I guess an @ is a valid head? It doesn't save me code, but I think it looks nice.

@JanDvorak yeah @ is valid!

If my language of choice cannot read a single character at a time, can I assume that there's one character per line? 2. Does the plane have a maximum width/height?

@Dennis I'd rather say it's fair to assume there's one line of input only

As for #2, anything above 80 characters will probably confuse the console. It shouldn't confuse you, though.

are extraneous leading lines OK?

@JanDvorak a few leading lines (<5) would be fine.

@Dennis you can assume there is one character per line. There is no maximum width/height, but you can assume you won't overflow 32 bit integers and stuff like that.

I'm confused. I went with the examples and printed the entire snake in its final state. But reading the bullet points, it sounds like I have to print the snake after every character. Which one is it? Everyone seems to assume printing the final snake is fine.

@IngoBürk I wanted the snake to be printed after every character and have the program accept one character at a time. I don't think I made that clear enough in the question so I'm willing to accept either way. You can just print the final snake.

@chilemagic Thanks! If both are acceptable you should probably clarify this in the question.

@chilemagic I think it's time to start marking the winner, don't you think? ;)

@IngoBürk I love that you included the gifs in your answer! Since this is code-golf, I believe the winner is Jan Dvorak but I haven't tested his solution yet. I will mark it soon! The question is almost a month old.

@chilemagic Yes, I didn't win despite my animation efforts. But that's okay. ;)

In order to make it happen on early Sinclair machines (ZX80 and ZX81) could my snake consist of <>VA instead please?

Ruby, 207 characters
b=[];x=y=0;gets.chars{|c|b[y]||=[];b[y][x]={?\n=>->{?0},?w=>->{y>0?y-=1:b=[[]]+b;?^},?a=>->{x>0?x-=1:b.map!{|r|[' ']+r};b[y][1]=?<},?s=>->{y+=1;?v},?d=>->{x+=1;?>}}[c][]};puts b.map{|r|r.map{|c|c||' '}.join}

Ungolfed:
b=[]  #board
x=y=0 #position
gets.each_char{|c|
  b[y] ||= []
  b[y][x] = {
    "\n" => lambda{0},
    "w"  => lambda{if y>0 then y-=1 else b=[[]]+b; "^"},
    "a"  => lambda{if x>0 then x-=1 else b.map!{|r|[' ']+r}; b[y][1]="<"},
    "s"  => lambda{y+=1; "v"},
    "d"  => lambda{x+=1; ">"}
  }[c].call}
puts b.map{|r|r.map{|c|c||' '}.join}

(the lambda for a writes back because the row the assignment above writes to is no longer on the board)

ECMAScript 6 Javascript (399 401 431)
Has to be run in a browser supporting ECMAScript 6 due to the arrow functions.
Here are fiddles which have been altered to run in any (common) browser by not using arrow functions. They also print to a textarea instead:

Normal
Animated

Golfed Version
i=prompt(),v=[],c=0,x=[0],y=[0],s='unshift',k='slice',t='sort',h=[0,-1,0,1,0]
while(c<i.length){m='wasd'.indexOf(i[c++]);v[s]('^<v>'[m]);x[s](x[0]+h[m]);y[s](y[0]+h[m+1])}f=(a,b)=>a-b
q=x[k]()[t](f)[0],e=x[k]()[t]((a,b)=>b-a)[0],w=y[k]()[t](f)[0],o=[]
while((i=y.pop())!=null){i-=w;j=x.pop()-q;t=(o[i]||Array(e+1-q).join(" ")).split("");t.splice(j,1,v.pop()||"@");o[i]=t.join("")}alert(o.join("\n"))

Animated GIF:
One of the OP's examples:

The example from Stretch Maniac:

Ungolfed
Here is a (slightly) ungolfed version from sometime before I started really golfing it down:
var input = prompt(),
    values = [],
    c = 0,
    x = [0],
    y = [0],
    s = 'unshift';
while (c < input.length) {
    var mapped = 'wasd'.indexOf(input[c++]);
    values[s]('^<v>'[mapped]);
    x[s](x[0]+[0, -1, 0, 1][mapped]);
    y[s](y[0]+[-1, 0, 1, 0][mapped]);
}

var minX = x.slice().sort(function (a,b){return a-b})[0];
var maxX = x.slice().sort(function (a,b){return b-a})[0];
var minY = y.slice().sort(function (a,b){return a-b})[0];

var output = [];
while((i=y.pop())!=null) {
    i-=minY;
    j=x.pop()-minX;
    t=(output[i]||Array(maxX+1-minX).join(" ")).split("");
    t.splice(j,1,values.pop()||"@");
    output[i]=t.join("");
}

console.log(output.join("\n"));

The gifs are very cool. Are they made automatically, by a script you've written?

Thanks! With the power of Google I just looked up how to make a gift from a screen recording in Ubuntu. It just uses a screen recorder and convert. Pretty easy :)

(gif, not gift)

sed, 71
s/w/\^\x1B[D\x1B[A/g
s/a/<\x1B[2D/g
s/s/v\x1B[B\x1B[D/g
s/d/>/g
s/$/@/

Golfscript, 165 126
' '*"\33[":e{e'D'}:-{[e'C'+'<'--]]}:a{[-+'>']]}:d{[e'B'+'^'-e'A']]}:w{[e'A'+'v'-e'B']]}:s{][\[}:+7{;}*''\~[e'H'e'J']\'@'e'20H'

Same approach as my previous answer, but correctly positioning the cursor before and afterwards. I'm pretty proud of the approach to cursor positioning -- basically, it first runs the snake in reverse, without printing out characters.

Can you add an example call? echo "dddddssaawwwwddddd" | sed -e 's/w/\^\x1B[D\x1B[A/g' -e 's/a/<\x1B[2D/g' -e 's/s/v\x1B[S\x1B[D/g' -e 's/d/>/g' -e 's/$/@/' doesn't give the correct output for me.

Your prompt after executing is probably overwriting part of the snake. Paste the snake directly into stdin instead of piping, or add a few \ns after the @ so your prompt goes elsewhere.

This might fail if the snake goes up or left of the board.

@tomsmeding Yeah, I might expand it to deal with that. Language aside, though, I really think ANSI control sequences are the way to go for shorter code.

Java - 646
Might as well be the first one!
I bet you all can beat this.
un(sort of)golfed
import java.util.*;
public class Snake{
    public static void main(String[]a) {
        int x,y,minX,minY,maxX,maxY;
        x=y=minX=maxX=minY=maxY=0;
        List<Integer>xs,ys=new ArrayList<Integer>();
        xs=new ArrayList<Integer>();
        List<Character>p=new ArrayList<Character>();
        for(int b=0;b<a[0].length();b++){
            int newX=x,newY=y;
            switch(a[0].charAt(b)){
            case'a':newX--;p.add('<');break;
            case's':newY++;p.add('v');break;
            case'd':newX++;p.add('>');break;
            case'w':newY--;p.add('^');break;
            }
            xs.add(x);ys.add(y);
            x=newX;y=newY;
            if(x<minX){minX=x;}
            if(x>maxX){maxX=x;}
            if(y<minY){minY=y;}
            if(y>maxY){maxY=y;}
        }
        char[][]c=new char[maxY-minY+1][maxX-minX+1];
        for(int i=0;i<xs.size();i++)c[ys.get(i)-minY][xs.get(i)-minX]=p.get(i);
        c[y-minY][x-minX]='@';
        for(char[]k:c){for(char l:k){System.out.print(l);}System.out.println();}
    }
}

Smaller -
import java.util.*;class S{public static void main(String[]a){int x,y,o,z,s,u;x=y=o=s=z=u=0;List<Integer>j,t=new ArrayList<Integer>();j=new ArrayList<Integer>();List<Character>p=new ArrayList<Character>();for(int b=0;b<a[0].length();b++){int e=x,r=y;switch(a[0].charAt(b)){case'a':e--;p.add('<');break;case's':r++;p.add('v');break;case'd':e++;p.add('>');break;case'w':r--;p.add('^');break;}j.add(x);t.add(y);x=e;y=r;if(x<o)o=x;if(x>s)s=x;if(y<z)z=y;if(y>u)u=y;}char[][]c=new char[u-z+1][s-o+1];for(int i=0;i<j.size();i++)c[t.get(i)-z][j.get(i)-o]=p.get(i);c[y-z][x-o]='@';for(char[]k:c){for(char l:k){System.out.print(l);}System.out.println();}}}

input - dddsssdddwwwwaaaaaaaassssssssssddddddddddddddddd
v<<<<<<<<
v >>>v  ^
v    v  ^
v    v  ^
v    >>>^
v
v
v
v
v
>>>>>>>>>>>>>>>>>@

input - dddsssdddddasddddwww
>>>v
   v       @
   v       ^
   >>>>v<  ^
       >>>>^

my personal favorite - dwdwdwddaasassdddddwdwdwddsdswawaasassdddddddwdwdwddsdswawaasassddddwwwwwwwssssssdsdddwwwwddaassddaassddddsssdddwdwdwddaasasassddddwwwwssssssssasasaaawdwwdwddwwdddddddwdwdwddsdswawaasassddddddddddwwdwwwwaasssassdsdddddddwdwdwwwwasasssssssssssdwwwwwwwddd
                    v
                    v
                    v
                    v   v<<
   v<<   v<<     v<<v   v
  v<    v< ^<   v< ^v   v<<                        v<<     v<
 >v    >v   ^  >v   >v  v                          v ^    v<^
>^>>>>>^>>>>>>>^>>>>^>>>>>>>v    v<v               v ^    v ^
                            v   v< v       v<<    v< ^    v ^
                            v  v<  v      v< ^<   v >^    v>^
                            >>>v   v     >v   ^   >v^     v>>>@
                               >>>>>>>>>>^>>>>>>>>>>>>>>>>v^
                                  ^v                      v^
                                >>^v                      v^
                               >^  v                      v^
                               ^  v<                      v^
                              >^ v<                       v^
                              ^<<<                        >^

619 bytes

C# 607
namespace System{using B=Text.StringBuilder;class P{static void Main(){var f=new Collections.Generic.List<B>(){new B("O")};int w=1,r=0,c=0;for(Action R=()=>f[r].Append(' ',w-f[r].Length+1);1>0;){var key=Console.ReadKey(1>0).KeyChar;if(key=='w'){f[r][c]='^';if(--r<0)f.Insert(r=0,new B());R();f[r][c]='O';}if(key=='a'){f[r][c]='<';if(--c<0){foreach(var s in f)s.Insert(c=0,' ');w++;}R();f[r][c]='O';}if(key=='s'){f[r][c]='v';if(++r>f.Count-1)f.Add(new B());R();f[r][c]='O';}if(key=='d'){f[r][c]='>';if(++c>w++)foreach(var s in f)s.Append(' ');R();f[r][c]='O';}Console.WriteLine(string.Join("\n",f)+"\n");}}}}

"Ungolfed" with whitespace (this will not be kept in sync with the golfed version):
namespace System
{
    using B = Text.StringBuilder;
    class P
    {
        static void Main()
        {
            var f = new Collections.Generic.List<B>() { new B("O") };
            int w = 1, r = 0, c = 0;
            Action R = () => f[r].Append(' ', w - f[r].Length + 1);
            while (true)
            {
                char key = Console.ReadKey(1>0).KeyChar;
                if (key == 'w')
                {
                    f[r][c] = '^';
                    if (--r < 0) { f.Insert(0, new B()); r = 0; }
                    R();
                    f[r][c] = 'O';
                }
                if (key == 'a')
                {
                    f[r][c] = '<';
                    if (--c < 0)
                    {
                        foreach (var s in f)
                            s.Insert(0, ' ');
                        w++;
                        c = 0;
                    }
                    R();
                    f[r][c] = 'O';
                }
                if (key == 's')
                {
                    f[r][c] = 'v';
                    if (++r > f.Count - 1) f.Add(new B());
                    R();
                    f[r][c] = 'O';
                }
                if (key == 'd')
                {
                    f[r][c] = '>';
                    if (++c > w++)
                    {
                        foreach (var s in f)
                            s.Append(' ');
                    }
                    R();
                    f[r][c] = 'O';
                }

                Console.WriteLine(string.Join("\n", f) + "\n");
            }
        }
    }
}

Python 3: 259 Bytes
x=y=0
b,p,r={},(0,-1,0,1),range
while 1:
 d='wasd'.index(input());b[(x,y)]='^<v>'[d];x+=p[d];y-=p[~d];b[(x,y)]='☺';l,m=([k[i]for k in b]for i in(0,1))
 for j in r(min(m),max(m)+1):print(''.join(b[(i,j)]if(i,j)in b else' 'for i in r(min(l),max(l)+1)))
 print()

I decided to store the snake in a dict, with coordinates for the keys. Then find and iterate over the output range, substituting blank spaces.
x = y = 0
board = {}
while 1:
    d = 'wasd'.index(input())
    board[(x, y)] = '^<v>'[d] # body
    x += (0, -1, 0, 1)[d]
    y -= list(reversed((0, -1, 0, 1)))[d]
    board[(x,y)] = '☺' # head

    xs, ys= ([coord[dim] for coord in board] for dim in(0, 1))
    for j in range(min(ys), max(ys)+1):
        print(''.join(board[(i,j)] if (i,j) in board else ' '
                      for i in range(min(xs), max(xs)+1)))
    print()

PS.
My first Golf :)
Let me know if my answer is inappropriate

Using O instead of ☺ saves you 2 bytes. ☺ is a red herring.

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ ☺ wasn't actually counted as 3 bytes.

@MartinEnder It must be, the default encoding is UTF-8. I had a feeling it wasn't counted. I have a feeling it was accidental and must be immediately fixed by Gilly.

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Well technically, the answerer is free to use any encoding supported by their interpreter (and I'm pretty sure some ASCII-compatible code page contains that character) but that's beside the point. I'm saying the byte count is already the same as that of using O, so I wouldn't worry about it. It's clear from the code that it would still work for any other character but using ☺ lets you conveniently run the test cases from the challenge without changes.

@MartinEnder Python uses UTF-8, proved by its ability to support unicode strings. To enable this functionality, the first or second line must be #coding=utf-8. Note that #coding=utf-16 does not work. Hence ☺ must be counted as 3.

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ No part of this is true. Python 3 uses whatever encoding is defined by the system as the source code encoding, as well as for the default of str.encode and bytes.decode. The magic comment #coding=utf-8 is ignored in Python 3.

Yes I naively just used the string length rather than the actual size, ignoring encoding. If you'd really like @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ I can modify the answer to use a 0. By the way, what is the "standard" way to measure your submission length? So I know for next time.

Python 2.7 - 274 bytes
x,y,m,d,r=0,0,{},(0,-1,0,1),range
for c in raw_input():b='wasd'.index(c);m[(x,y)]='^<v>'[b];x+=d[b];y-=d[~b];m[(x,y)]='@';l,n=([k[h] for k in m] for h in (0, 1))
for j in range(min(n),max(n)+1):print(''.join(m[(i,j)] if (i,j) in m else ' 'for i in range(min(l),max(l)+1)))

Ungolfed version
x,y,matrix,delta = 0,0,{},(0, -1, 0, 1)
for c in raw_input('Command: '):
    d = 'wasd'.index(c)
    matrix[(x, y)] = '^<v>'[d]
    x += delta[d]
    y -= list(reversed(delta))[d]
    matrix[(x, y)] = '@'
xs, ys = ([xy[i] for xy in matrix] for i in (0, 1))
for j in range(min(ys), max(ys)+1):
    print(''.join(matrix[(i, j)] if (i, j) in matrix else ' '
                  for i in range(min(xs), max(xs)+1)))

Welcome to Programming Puzzles & Code Golf! According to the rules outlined in our help center, all solutions to challenges should be a serious contender for the winning criteria in use. For example, an entry to a code golf contest needs to be golfed.

I'm added the byte count for you, but there's quite a lot of unnecessary spaces in there which you might want to remove.

Thanks guys, I made the necessary changes to my first entry. Any extra advice will be greatly appreciated.

I really golfed it.

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ That just prints SyntaxError: invalid syntax.

@Dennis Hrm... unusual behavior, try replacing 0,1 with (0,1) removing the space and see if that helps (HELP: Line number would be appreciated!)

05AB1E, 35 34 30 28 bytes
.•₃º•"<>v^"©‡0ªÐUĀ>sŽO^®XkèΛ

Uses 0 as head of the snake.
-4 bytes thanks to @Grimy.
Try it online (no test suite for all test cases at once, because there is no way to reset the Canvas, so outputs would overlap..).
Explanation:
.•₃º•          # Push compressed string "adsw"
     "<>v^"    # Push string "<>v^"
           ©   # Save it in variable `r` (without popping)
            ‡  # Transliterate the (implicit) input-string,
               # replacing all "adsw" with "<>v^" respectively
               #  i.e. "ddddssaassdddddww" → ">>>>vv<<vv>>>>>^^"
0ª             # Convert the string to a list of characters, and append a 0 (for the head)
               #  → [">",">",">",">","v","v","<","<","v","v",">",">",">",">",">","^","^","0"]
  Ð            # Triplicate this list of characters
   U           # Pop and store one of the three lists in variable `X`
   Ā           # Trutify each character ("0" remains 0; everything else becomes 1)
    >          # And then increase each integer by 1
               #  → [2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1]
  s            # Swap the two lists on the stack
      ®Xk      # Get the index of each character of variable `X` in variable `r` ("<>v^")
               #  i.e. [">",">",">",">","v","v","<","<","v","v",">",">",">",">",">","^","^","0"]
               #   → [1,1,1,1,2,2,0,0,2,2,1,1,1,1,1,3,3,-1]
   ŽO^   è     # And use those to index into the compressed number 6240
               #  → [2,2,2,2,4,4,6,6,4,4,2,2,2,2,2,0,0,0]
Λ              # Use the Canvas builtin with these three lists

See this 05AB1E tip of mine (sections How to compress strings not part of the dictionary? and How to compress large integers?) to understand why .•₃º• is "adsw" and ŽO^ is 6240.
As for a brief explanation of the Canvas builtin Λ and its three arguments:
First argument: length(s): the sizes of the lines we want to draw. Since we have to keep in mind overlapping, we use size 2 for every character, and an additional 1 for the head of the snake.
Second argument: string(s): the characters we want to display. Which are the characters in this case, appended with the head-character of the snake.
Third argument: direction(s): the directions these character-lines of the given length should be drawn in. In general we have the directions [0,7] which map to these directions:
7   0   1
  ↖ ↑ ↗
6 ← X → 2
  ↙ ↓ ↘
5   4   3

Which is why we have the integer 6240 for the directions \$[←,→,↓,↑]\$ respectively.
See this 05AB1E tip of mine for a more detailed explanation about the Canvas builtin Λ.

I might have missed something, but I don't think γ is needed at all. This seem to work just fine.

@Grimy Thanks, it indeed does; nice alternative approach with the list of 2s and 1 for the head! And I've been able to save 2 more bytes based off your program.

Thanks! I am currently at 23, though that's a significantly different approach, so I might make it its own answer if that's fine by you.

@Grimy That indeed is quite a different approach than mine, so feel free to post it. I was indeed kinda expecting some unicode conversion and modulo might make this shorter than the transliterate, but I'm quite honestly pretty bad with those kind of magic integer/string conversions. :)

Perl - 394
Not the shortest, but it beats Javascript, C# and Java at least.
use List::Util qw(min max);sub c{()=$_[0]=~/$_[1]/g}%l=(a,['<',-1,0],d,['>',1,0],w,['^',0,-1],s=>['v',0,1]);($s,$x,$y,$w,$h)=($ARGV[0],0,0,max(c($s,a),c($s,d)),max(c($s,w),c($s,'s')));@s=split'',$s;map$x=min($x,$i+=$l{$_}[1]),@s;$i=0;map$y=min($y,$i+=$l{$_}[2]),@s;$x=abs $x;$y=abs $y;map{$m[$y][$x]=$l{$_}[0];$x+=$l{$_}[1];$y+=$l{$_}[2]}@s;$m[$y][$x]='o';map{map{print$_||' '}@$_;print"\n"}@m

Some tricks:

Warnings and strict not turned on to allow barewords and not declaring variables before using them
Thin commas instead of fat commas to save a few characters
Not setting initial values for variables when not necessary
Leaving out semi-colons when possible
Defining arrays and hashes not as references to avoid having to use ->
Allowing width, height to be larger than necessary to avoid having to calculate them accurately (which would take extra code)

Things that hurt:

No built-in way to count number of characters in a string (might have been longer anyway)
No built-in min/max functions, thus need to waste 27 characters to import library that does it (less than defining our own)

C - 273 bytes - with Interactive Input!
#define F for(i=w*w
*g,*G,x,i,j,w,W,u;main(w){putch(1);F;j=-~getch();g=G){if(!(x%w&&~-~x%w&&x/w&&x/w^~-w)){W=w+6;G=calloc(W*W,4);F-1;u=i%w+i/w*W-~W*3,i==x?x=u:8,i;)G[u]=g[i--];free(g);w=W;}G[x]="<^X>v"[j%=7];G[x+=1-G[x]%3+W*(!!j-j/2)]=1;F;i;)putch(i--%W?G[i]?G[i]:32:10);}}

The field is printed each time a character is entered and grows if the snake's head nears the edge. I don't know how portable it is--someone on the Internet said getch() doesn't work on non-Windows platforms. Hard to say whether ASCII 1 will look like a smiley face either.
The golfed version is quite annoying as there is no way to gracefully exit the program. Control-C doesn't work for me. On the other hand, the ungolfed version terminates if a character other than 'w', 'a', 's', or 'd' is entered.
So-called "ungolfed":
#define SMILEYFACE 1
int main()
{
    int o;
    int w = 1;
    int *g = 0, *g2;
    int c, n;
    int x = 0;
    for( putch(SMILEYFACE);c = getch(); ) {
        if(c!='w'&&c!='a'&&c!='s'&&c!='d')
            return 1;
        if(!(x%w) | !(~-~x%w) | !(x/w)  | !(x/w-~-w) ) {
            int wnew = w + 4;
            int off = 2;
            g2 = calloc(wnew*wnew,sizeof(int));
            for(n = w*w; --n; )
                g2[ n%w+off + (n/w+off)*wnew ] = g[n];
            free(g);
            g = g2;
            x = (x/w+off)*wnew + x%w + off;
            w = wnew;
        }
        int i = -~c%7;
        g[x] = "<^X>v"[i];
        int dx = 1-g[x]%3 + w * (!!i-i/2);
        x += dx;
        g[x] = SMILEYFACE;
        for(o = w*w; o; )
            putch(o--%w?g[o]?g[o]:32:10);

    }
    return 0;
}

05AB1E, 23 bytes
Ç7%DÉ+D"^>>v"ºsè0ªDĀ>rΛ

Try it online!
Explanation:
                      # implicit input (eg: "wasd")
Ç                     # codepoints (eg: [119, 97, 115, 100])
 7%                   # modulo 7 (eg: [0, 6, 3, 2])
   DÉ+                # plus itself modulo 2 (eg: [0, 6, 4, 2])
# This is the list of directions that will be passed to 05AB1E's canvas function, Λ.
# 0 means up, 6 left, 4 right, 2 down.

 "^>>v"º              # "^>>v", horizontally mirrored (namely "^>>vv<<^")
D       sè            # index into this with a copy of the list of directions
          0ª          # append "0"
# This is the list of strings that will be drawn.

D                     # duplicate the list of strings
 Ā                    # truthify (maps letters to 1, 0 stays 0)
  >                   # increment each
# This is the list of lengths to draw.

r                     # reverse the stack because Λ takes arguments in the opposite order
 Λ                    # draw!

source: Stack Exchange

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

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

sort: votes


text:
A Decent Decade
This is a short one:

Only once in American history has there been a decade in which four of the years were prime numbers.

Your program has to output the decade after 1776 where four its years were primes. This is code golf so the shortest code wins.
The output must be like so:
1710s

or
1980s

Note: The answer must be calculated and not explicitly hardcoded into your program.

what exactly counts as "hardcoding the answer"? What is our program allowed to know? Maybe you should ask us to find the first such decade after a given year.

I know you know about the sandbox, so why don't you use it? A question which has been edited at least twice in the 15 minutes since it was posted would clearly have benefitted from it.

@Peter I thought I would be a simple enough question to go and post it.

@BetaDecay [tag:constant-output] [tag:code-golf]s which aren't [tag:kolmogorov-complexity] golfs are always problematic.

I nearly always think my question ideas are clear and worthwhile, but I still post them in the sandbox first. Very few of them get any further... It saves a lot of confusion.

CJam, 24 bytes
1770{A+_A,f+{mp},,4<}g's

At the cost of two extra bytes, this program can be modified to calculate the first decade containing four prime years after (not containing) a user-defined year:
liA/A*{A+_A,f+{mp},,4<}g's

Example runs
$ cjam <(echo "1770{A+_A,f+{mp},,4<}g's"); echo
1870s
$ cjam <(echo "liA/A*{A+_A,f+{mp},,4<}g's") <<< 1776; echo
1870s
$ cjam <(echo "liA/A*{A+_A,f+{mp},,4<}g's") <<< 1870; echo
2080s
$ cjam <(echo "liA/A*{A+_A,f+{mp},,4<}g's") <<< 2080; echo
3250s
$ cjam <(echo "liA/A*{A+_A,f+{mp},,4<}g's") <<< 3250; echo
3460s

How it works
li                          " Read an integer “Y” from STDIN.                 ";
  A/A*                      " Execute “Y = Y / 10 * 10”.                      ";
      {             4<}g    " While the result of the loop is less than four: ";
       A+                   " Execute  “Y += 10”.                             ";
         _A,f+              " Push [ Y Y+1 Y+2 Y+3 Y+4 Y+5 Y+6 Y+7 Y+8 Y+9 ]. ";
              {mp},,        " Compute the number of primes in that range.     ";
                        's  " Push 's'.                                       ";

Python - 105 103 87
Iterating over ith primes using sympy's prime function:
import sympy
p=sympy.prime
for i in range(275,305):
 if p(i)>p(i+3)-9:print`p(i)-1`+'s'

Alternative solution iterating over years from 1780 to 2010 and counting primes per decade:
r=range
for d in r(1780,2010,10):
 if sum(all([y%i>0for i in r(2,y)])for y in r(d,d+10))>3:print`d`+'s'

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


text:
Multiply all numbers in a string
Winner: Chilemagic, a massive 21 bytes!
You may continue to submit your answer, however you can no longer win. Original post kept:

Your goal is to find all numbers in a string, and multiply each one individually by a value input by the user

You will not need to worry about decimals
The user will input a number and a string
The user must type the number and string at some point, however the method the program reads it does not matter. It can be with stdin, reading a text file, etc, however the user must press the 9 button on their keyboard (for example) at some point
Anything that can compile and run is acceptable

Example:
Sentence input: This 1 is22a 3352sentence 50
Number input: 3
Output: This 3 is66a 10056sentence 150

This contest ends on September 6th, 2014 (7 days from posting).
This is a code-golf, so the shortest code wins

Any number is to be multiplied. I updated my example.

I don't understand the significance or use of "press the 9 button" in your challenge.  How or where does it apply in the example given?

If the number to be multiplied by is 9, the user must press the 9 key at some point.

@Darren He's basically saying that you can't hardcode the number.

Can we make assumptions about the size of the numbers involved, particularly the possibility of overflow?  Depending on the results of the above, do we treat "-1234" as "-" followed by 1234 or as -1234?

Is it acceptable to output the number 0 as an empty string? I assume not, but I figured I should make sure.

@Alchymist There isn't any difference between these two cases if the factor is positive.

What are the restrictions if any on what programming language can be used?

@x-code Any language.

To add to @IlmariKaronen's question: What to do with leading zeroes as in "Bond is agent 007" -> "Bond is agent 21" or "Bond is agent 0021" or "Bond is agent 021" or ...?

agent 007 should give agent 025, because, you see, 007 is octal.  :-)

@FUZxxl There is a difference if there can be numeric overflow

@Alchymist That's a point. We can assume by common code-golf rules that the input data will only contain numbers of reasonable size.

Update - Perl - 17
s/\d+/$&*$^I/ge

15 characters + 2 for -i and -p flags.
We can use the -i flag to input a file extension, but since we aren't reading any files, we can use it to get the number and it the variable $^I will get assigned to it.
Run with:
perl -e'print"This 1 is22a 3352sentence 50"' | perl -i3 -pe's/\d+/$&*$^I/ge'

Perl - 21
Updated as per @Dennis's comment.
$n=<>;s/\d+/$&*$n/ge

Run with -p flag.
Example run:
perl -e'print"This 1 is22a 3352sentence 50\n3"' | perl -pe'$n=<>;s/\d+/$&*$n/ge'

Explanation:
$n=<>; read in the number
-p prints the output
s/\d+/$&*$n/ge Read the input with <> and search for one or more digits and replace them with the digits times the number. g is global, e is eval the replace potion of the s///. $& contains what was matched and it multiplied by the number, $n.
You can read more about s/// in perlop and more about Perl regexes in perlre.
Another solution:
@F.Hauri pointed out you can also use the s switch to assign the $n variable to 4. I'm not sure how many characters this counts as but I'll leave it here:
perl -spe 's/\d+/$&*$n/ge' -- -n=4 <<<'This 1 is22a 3352sentence 50'

I think you could save a few more characters by using <>=~ instead of _$=<>;. Also could you please explain what the s part of the regex means, for us novices?

@Tal String.

@Mew I'm pretty sure it's for "substitution"

@MartinBüttner Probably. I need to learn perl. I only ever saw it used on strings, so that's where I picked that up.

It is for "substitution". It can also be m, which stands for "match".

You don't need the trailing semicolon, that'll save you a character

Right tool for the task.

If you use $& instead of $1, you can shorten (\d) to \d. 2. If you use the -p switch and change the input order, you can drop say<>=~ and r.

Changing the inner $n to ($n.=<>) saves a byte.

@primo I think that is the same length.

@chilemagic indeed, I miscounted.

You may use -s switch, to whipe $n=<> out: perl -spe 's/\d+/$&*$n/ge' -- -n=4 <<<'This 1 is22a 3352sentence 50' (do render: This 4 is88a 13408sentence 200)

JavaScript (ES6) - 48 44 chars
Thanks to @bebe for saving one character. Update: 8/Mar/16, removed another four characters
b=(p=prompt)();p(p().replace(/\d+/g,y=>y*b))

Ungolfed:
var sentence = prompt(),
    num = parseInt(prompt(), 10); // base 10

sentence = sentence.replace(/\d+/g, digit => digit * num);

alert(sentence);

43 chars:
(p=prompt)(p(b=p()).replace(/\d+/g,y=>y*b))

b=(p=prompt)();p(p().replace(/\d+/g,y=>y*b))

Requires number input first and then sentence.
Cut one char more here thanks @bebe again!

you don't need to parse number input

@bebe Of course! I didn't notice! Thanks a lot!

(p=prompt)(p(b=p()).replace(/\d+/g,y=>y*b)) another one (but this asks for multiplier first)

@bebe Thanks for this too!

Python 2 (79)
import re
n=input()
s=input()
print re.sub('\d+',lambda x:`int(x.group())*n`,s)

Sample run

Input:

$ python mult.py
3
"This 1 is22a 3352sentence 50"

Output:

This 3 is66a 10056sentence 150

Online demo: http://ideone.com/V6jpyQ

Brilliant. I guess re.sub is the method Beta Decay and I (the other two Python submissions) were trying to reimplement. It would have been so easy... Something else that I've learned! ;)

@Falko re.sub aside, you've done an excellent job at golfing the string replace logic

@Falko I agree, re.sub is exactly the thing I wanted!

Python 2 - 126
import re
n=input()
s=input()
for i in list(re.finditer('\d+',s))[::-1]:s=s[:i.start()]+`int(i.group())*n`+s[i.end():]
print s

First input: integer n.
Second input: string s (with quotation marks, e.g. "abc42").

CJam, 47 33 30 bytes
q_A,sNerN%\[_A,s-Ner~](f*]zs1>

Reads the number and the string (in that order and separated by a single space) from STDIN.
Try it online.
Example run
$ cjam multiply.cjam <<< '7 N0 R3GUL4R 3XPR35510N5 1N CJ4M M4K3 M3 4 54D P4ND4'
N0 R21GUL28R 21XPR248570N35 7N CJ28M M28K21 M21 28 378D P28ND28

How it works
q                                 " Read from STDIN (“Q”) and push a second copy.         ";
  A,s                             " Push “0123456789” (thanks, @aditsu).                  ";
 _   NerN%                        " Replace digits with linefeeds and split at linefeeds. ";
          \ _A,s-Ner              " Replace non-digits with linefeeds.                    ";
                    ~             " Evaluate the resulting string.                        ";
           [         ]            " Collect the results in an array.                      ";
                      (f*         " Multiply all other integers by the first.             ";
                         ]z       " Interleave the elements of both arrays.               ";
                           s1>    " Flatten the result and discard the leading space.     ";

This is the weirdest piece of code ever!!!

@Bludream: This isn't even the weirdest code I've written. :P

Hmm, 3 * 7 = 27?

lol, yeah voted for both. Though These are not going to make world a better place. How on earth programming languages who are supposed to be readable turned into this??

@aditsu: Splitting vs iterating, the battle continues. :P

Wow, impressive.. and you didn't even use my A,s to get the digits

@aditsu: Nice trick. I skipped that part when I read your answer. Can I borrow it?

No need to ask :p

Bash+coreutils, 38 bytes
eval echo `sed "s/[0-9]\+/$\[$1*&]/g"`

Reads input string from STDIN and multiplier as a command-line parameter.
Output:
$ ./multstr.sh 3 <<< "This 1 is22a 3352sentence 50"
This 3 is66a 10056sentence 150
$

Interesting idea, but this will work only if the string doesn't any contain characters that are special to Bash... This is an example of a string I wouldn't try: 1 D4R3 Y0U: ; rm -rf /

@Dennis yes that is a rather unfortunate caveat

C# in LINQPad, 124
Straightforward. Please use CTRL+2 in LINQPad (Language: C# Statements).
var s=Console.ReadLine();var k=int.Parse(Console.ReadLine());new Regex("\\d+").Replace(s,t=>""+int.Parse(t.Value)*k).Dump();

If the multiplier is given as first input parameter, it can be done in 116 characters:
var k=int.Parse(Console.ReadLine());new Regex("\\d+").Replace(Console.ReadLine(),t=>""+int.Parse(t.Value)*k).Dump();

EDIT:
Thanks to Abbas's comment below, this can even be golfed more by using Regex static method, rather than instantiate it:
var k=int.Parse(Console.ReadLine());Regex.Replace(Console.ReadLine(),"\\d+",t=>""+int.Parse(t.Value)*k).Dump();

Nice one, code-golf in C# isn't easy! I don't want to get rep on your effort so I'll provide you a tip instead of posting my own answer: use the static Regex.Replace(string, string, string) instead of new Regex("...").Replace(...); Here's the short multiplier-first version: var k=int.Parse(Console.ReadLine());Regex.Replace(Console.ReadLine(),"\\d+",t=>""+int.Parse(t.Value)*k).Dump();. In both versions this saves another 5 characters, getting you on 119 for the long version and 111 for the multiplier-first version

Thanks for the tip, however, I decided not to change my original answer, such that others will be able to learn what-not-to-do from me, and what-to-do from you - regarding C# Regex Golfing.

I understand you but you could also add my tip in your answer as an edit. Users tend to read this more than they will a list of comments with tips.

Sure. The answer was edited.

Mathematica 71 61
With 10 chars saved thanks to Martin Buttner.
Spaces in code are for readability.
f is a function in which s is the input string and n is the number to multiply discovered string numbers by.
 StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &

Examples
 s="This 1 is22a 3352sentence 50"

Integer
StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &@@{s, 3}

"This 3 is66a 10056sentence 150"

Rational number
StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &@@{s, -7.13}

"This -7.13 is-156.86a -23899.8sentence -356.5"

Complex Number
StringReplace[#, a : DigitCharacter .. :> ToString[#2 FromDigits@a]] &@@{s, -5 + 3 I}

"This -5 + 3 I is-110 + 66 Ia -16760 + 10056 Isentence -250 + 150 I"

I don't know Mathematica. But in your examples all numbers and words are separated by spaces. Does it work for numbers directly attached to letters as well, like "abc42"?

For StringReplace it makes no difference whether there are spaces.  I used the examples originally given by Chiperyman.

I switched to the updated example. (I had used the example given earlier by Chiperyman.) For StringReplace it makes no difference whether there are spaces.

Cobra - 171
use System.Text.RegularExpressions
class P
    def main
        a=int.parse(Console.readLine?'')
        print Regex.replace(Console.readLine,'\d+',do(m as Match)="[int.parse('[m]')*a]")

Python 3 - 141
I don't think I can golf this any more...
import re
n=input()
f=input()
o=''
p=0
for i in re.finditer('\d+',f):o+=f[p:i.start()]+str(int(i.group())*int(n));p=i.end()
o+=f[p:]
print(o)

Example:
3     # This is input
h3110 # This is input
h9330 # This is output

10
hello100 hello100
hello1000 hello1000

Unfortunately this approach does not work. For n=2 and s="1 2" it yields 4 4, since replace modifies the first number twice. That's the same problem I'm facing right now with Python 2... ;)

@Falko I've managed to fix the problem, although making my code longer in the process

Oh, well done! Just some minor remarks: m=input() saves you nothing. And x=int is actually 2 bytes longer than calling int(...) twice.

Ruby 40
a,b=$*
p a.gsub(/\d+/){|s|s.to_i*b.to_i}

Input from stdin.
Example run:
$ ruby mult.rb "This 1 is22a 3352sentence 50" 3
"This 3 is66a 10056sentence 150"

Online demo: http://ideone.com/4BiHC8

Lua: 73 69 characters
r=io.read
s=r()n=r()s=s:gsub("%d+",function(m)return m*n end)print(s)

Sample run:
bash-4.3$ lua -e 'r=io.read;s=r()n=r()s=s:gsub("%d+",function(m)return m*n end)print(s)' <<< $'This 1 is22a 3352sentence 50\n3'
This 3 is66a 10056sentence 150

You can golf it a bit more by putting everything on one line, and smooshing instructions next to ")". Like "s=r()n=()" is perfectly fine.

Doh, and I read Tips for golfing in Lua just a couple of weeks ago. :( Thank you, @AndoDaan.

JavaScript, ES6, 43 characters
This is my first attempt at golfing!
(p=prompt)(p(n=p()).replace(/\d+/g,y=>y*n))

Run this in latest Firefox's Console. The first input is the number and the second input is the string from which the numbers are to be multiplied with the first input number.
The final prompt lists the output.

Pretty nice JS Golf for a first timer!

Many other answers could be shorter if number was read first. That was is much easier.

@manatwork - Yeah, but the question does not give any preference on the order, so I think it should be fine.

Correct. This is a lack of the question itself. Personally I preferred to handle input in string+number order in my answers to keep them comparable with the others.

Vyxal s, 8 bytes
⁽±Ḋƛ⌊⁰*∨

Try it Online!

flex(-lexer) (94 89 characters)
 int m;main(c,v)char**v;{m=atoi(*++v);yylex();}
%%
[0-9]+ {printf("%d",m*atoi(yytext));}

Ungolfed version which doesn't segfault if you forget the command-line argument (not much longer):
%{
#define YY_DECL int y(int m)
%}
%option noyywrap noinput nounput
%%
[0-9]+ {printf("%d",m*atoi(yytext));}
%%
int main(int argc, char** argv) {
  return (argc > 1) ? y(atoi(argv[1])) : 1;
}

Compile with:
flex -o m.c m.l
cc -o m m.c -lfl

or:
flex --noyywrap -o m.c m.l
cc -o m m.c

Eg:
$ ./m 163
This 1 is22a 3352sentence 50
This 163 is3586a 546376sentence 8150

Groovy - 124
Scanner s=new Scanner(System.in)
def x=s.nextLine()
def n=s.nextInt()
x=x.replaceAll(/\d+/,{it->it.toInteger()*n})
println x

Click on the title to see the runnable example
Examples Tried:

This 1 is22a 3352sentence 50
  3
  This 3 is66a 10056sentence 150

This 1 is22a 3352sentence 50
  42
  This 42 is924a 140784sentence 2100

Perl - 48 chars
$n=<>;print/\d/?$_*$n:$_ for(<>=~/(\d+)|(\D+)/g)

Read a number on the first line, then read a sentence and break it into chunks of either digits or non digits. Print the non digits as they are, and the numbers get multiplied.

CJam - 35
li:X;lN+{_sA,s-,{])\_!!{iX*}*oo}*}/

Try it at http://cjam.aditsu.net/
Sample input:
7
CJ4M W1LL H4V3 R3GUL4R 3XPR35510N5 L4T3R

Sample output:
CJ28M W7LL H28V21 R21GUL28R 21XPR248570N35 L28T21R

Explanation:
The program goes through each character, collecting the digits on the stack, and for each non-digit it first prints the collected number (if any) multiplied by the numeric input, then prints the character.
li:X; reads the numeric input and stores it in X
lN+ reads the string and appends a newline (it helps with trailing numbers)
{…}/ for each character in the string
- _s copies the character and converts to string
- A,s-, removes all the digits and counts the remaining characters; the result will be 0 if the character was a digit or 1 if not
- {…}* executes the block if the count was 1 (i.e. non-digit); for digits it does nothing, so they remain on the stack
-- ] collects the characters from the stack into an array (i.e. a string); the characters are any digits from the previous iterations, plus the current character
-- )\ separates the last item (the current character) and moves it before the (remaining) string
-- _!! copies the string and converts it to a boolean value - 0 if empty, 1 if not
-- {…}* executes the block if the string was not empty, i.e. we had some digits before the current non-digit character
--- iX* converts the string to integer and multiplies by X
-- o prints the top of the stack - either the multiplied number or the empty string if we didn't have a number
-- o (the 2nd one) prints the new top of the stack - the current non-digit character

That's a much saner approach.

J - 63 char
Program reads in the number, and then the sentence.
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1

Explained by explosion:
;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
                                                         1!:1]1  NB. read sentence
                                         e.&'0123456789'         NB. is digit? bool vector
                                      i=.                        NB. save to i
                                 2  /\                           NB. between adjacent chars:
                                  ~:                             NB.  true if not equal
                               1,                                NB. pad to sentence length
 (                         ;.1~                         )        NB. cut the sentence
                ^:(0{i)                                          NB. if cut is digits:
  *&.".                                                          NB.  multiply as number
       &(1!:1]1)                                                 NB.  with user input
;                                                                NB. rejoin sentence

If we get to use J's PCRE library and make the sentence come first, we can knock this down to 54 characters:
;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1

Explained by explosion:
                                                1!:1]1  NB. read in sentence
                         '\d+'(rxmatches       )        NB. all /\d+/ matches
                              (          rxcut])        NB. cut by those matches
 _2                     \                               NB. on each nonmatch-match pair:
   (               &.>)/                                NB.  take the match
     *&.".                                              NB.  multiply as number
          &(1!:1]1)                                     NB.  by user input
   (,                 )                                 NB.  prepend nonmatch
;                                                       NB. rejoin sentence

J is bad at this, what can I say. It's a inconvenient because J's so nonimperative.
Some examples:
   ;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
3
This 1 is22a 3352sentence 50
This 3 is66a 10056sentence 150
   ;(*&.".&(1!:1]1)^:(0{i)(<@);.1~1,2~:/\i=.e.&'0123456789')1!:1]1
100
N0 R3GUL4R 3XPR35510N5 1N J M4K35 M3 54D ALS0
N0 R300GUL400R 300XPR3551000N500 100N J M400K3500 M300 5400D ALS0
   0!:0 <'system\main\regex.ijs'  NB. this is usually preloaded by J on startup anyway
   ;_2(,*&.".&(1!:1]1)&.>)/\'\d+'(rxmatches rxcut])1!:1]1
TH4T'5 M4RG1N411Y B3TT3R
0
TH0T'0 M0RG0N0Y B0TT0R

Haskell (161)
Golfed
main=do{n<-getLine;l<-getContents;let{g c(t,s)|c>'/'&&c<':'=(c:t,s)|t/=""=([],c:(show.(*(read n)).read$t)++s)|True=(t,c:s)};putStr.tail.snd.foldr g("","")$' ':l}

Ungolfed
modify :: (Show a, Read a) => (a -> a) -> String -> String
modify f = show . f . read

main=do
  number <- fmap read $ getLine    -- get number
  l <- getContents                 -- get input

  -- if the current character is a digit, add it to the digits
  -- if the current character isn't a digit, and we have collected
  --    some digits, modify them and add them to the string
  -- otherwise add the current characters to the string

  let go current (digits , string)
        | current `elem` ['0'..'9'] = (current : digits, string)
        | not (null digits)         = ([], current:(modify (*number) digits) ++ string)
        | otherwise                 = (digits, current:string)

  -- since the result of `go` is a pair, take the second value,
  -- remove the head (it's a space, in order to convert digits at the start)
  -- and print it
  putStr . tail . snd . foldr go ("","")$' ':l

Unfortunately, Haskell doesn't have a Regex library in its Prelude.

nice golfing ; you could have deleted the outermost {} for a gain of 1 char. also, I just posted this Haskell solution with 70 bytes: http://codegolf.stackexchange.com/questions/37110/multiply-all-numbers-in-a-string/38216#38216

Japt, 9 bytes
r"%d+"_*V

Try it

Python 89
import re,sys
j,n,s=sys.argv
print re.sub('(\d+)',lambda m:str(int(m.group())*int(n)),s)

eg:
# python numberstring.py 3 '1shoop da2 w007p!'
3shoop da6 w21p!

Rebol - 117
n: do input d: charset"0123456789"parse s: input[any[b: some d e:(e: insert b n * do take/part b e):e | skip]]print s

Ungolfed:
n: do input
d: charset "0123456789"

parse s: input [
    any [
        b: some d e: (e: insert b n * do take/part b e) :e
        | skip
    ]
]

print s

Python - 142
import re
s=raw_input()
i=int(raw_input())
print ''.join([x[0]+str(int(x[1])*i) for x in filter(None,re.findall('(\D*)(\d*)',s)) if x[0]!=''])

Java 218
Someone had to do java.  The input string are 2 token on the command line.
java M 'This 1 is22a 3352sentence 50' 3
public class M{
    public static void main(String[]a) {
        int m=new Integer(a[1]),n=0,b=0;
        String s="";
        for(char c:a[0].toCharArray()){
            if(c<48|c>57)s=b>(b=0)?s+m*n+c:s+c;
            else n=b*n+c-38-(b=10);
        }
        System.out.println(b>0?s+m*n:s);
    }
}

According to my test, the if condition works with bitwise | too, which is 1 character shorter.

Thanks.  Code updated.  (It is actually still a boolean or, just without evaluation shortcut).

GNU Awk: 86 characters
s{n=split(s RS,a,/[^0-9]+/,d);while(++i<n)printf"%s%s",a[i]==""?"":a[i]*$1,d[i]}{s=$0}

Sample run:
bash-4.3$ awk 's{n=split(s RS,a,/[^0-9]+/,d);while(++i<n)printf"%s%s",a[i]==""?"":a[i]*$1,d[i]}{s=$0}' <<< $'This 1 is22a 3352sentence 50\n3'
This 3 is66a 10056sentence 150

PHP - 75/115 68/109
Two versions, newer php versions can do this:
echo preg_replace_callback("/\d+/",function($m){return$m[0]*$f;},$s);

Older php versions: I did not count the newline, added those for readability.
function a($s){echo preg_replace_callback("/\d+/",b,$s);}
function b($i){global$f;return$i[0]*$f;}
a($s,$f);

Example input+output
$s = "ab11cd22"; // string
$f =  3; // -> output: ab36cd69
$f = -2; // -> output: ab-24cd-46

Kinda difficult, the words 'function' and 'preg_replace_callback' take up a lot of chars.
The space after global and return arent needed if followed by a $var (-2 chars)

No need to put \d in character class (-2 chars); no need to enclose the function in double quotes (-2 chars); you have to properly terminate the statement inside the function with semicolon (+1 char). By the way, \d in double quoted string should be written as \\d, so better change the quotes to single quotes.

Thanks. Started with [0-9], changed 0-9 to \d. Wasnt sure about the quotes around the function, I cant test that one, my local php's version doesnt allow it.

The double quotes work fine (at least for me) :)

C (142 134 characters)
main(a,b)char**b;{char*c=b++[2],*d="0123456789";for(;*c;c+=strspn(c
,d))write(1,c,a=strcspn(c,d)),dprintf(1,"%d",atoi(*b)*atoi(c+=a));}

Newline inserted for enhanced legibility. Pass the factor as the first, the string as the second command line option. This implementation requires the dprintf function which is part of POSIX.1 2008 and might not be available on Windows. Here is the unminified source:
/*
 * Multiply all numbers in a string by a number.
 * http://codegolf.stackexchange.com/q/37110/134
 * Solution by user FUZxxl
 */

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

extern int
main(int count, char **argv)
{
    char *str = argv++[2], *digits = "0123456789";

    while (*str) {          /* as long as we have not reached the end */
        count = strcspn(str, digits);
        write(1, str, count);

        dprintf(1, "%d", atoi(*argv) * atoi(str += count));
        str += strspn(str, digits);
    }
}

Improvements

142 → 134: Use strspn and strcspn instead of looping over the string.

Clojure - 141 140 128 chars
I'm a Clojure newbie, but FWIW:
(let[[a b]*command-line-args*](println ((fn[s n](clojure.string/replace s #"\d+"#(str(*(read-string %)(read-string n)))))a b)))

Sample run:
bash$ java -jar clojure-1.6.0.jar multstr.clj "This 1 is22a 3352sentence 50" 3
This 3 is66a 10056sentence 150

Ungolfed (ugly but hopefully somewhat easier to read):
(let [[a b] *command-line-args*]
    (println ( (fn [s n]
                    (clojure.string/replace
                        s
                        #"\d+"
                        #(str (* (read-string %) (read-string n)))))
                    a b)))

Two answer: perl + bash
Pure bash (~262)
First, there is an not so short pure bash version (no fork, no external binaries)!
mn () {
    if [[ $1 =~ ^(.*[^0-9]|)([0-9]+)([^0-9].*|)$ ]]; then
        local num=${BASH_REMATCH[2]} rhs="${BASH_REMATCH[3]}";
        mn "${BASH_REMATCH[1]}" ${2:-3} l;
        echo -n "$[num*${2:-3}]$rhs";
    else
        echo -n "$1";
    fi;
    [ "$3" ] || echo
}

Let's show:
mn "This 1 is22a 3352sentence 50" 42
This 42 is924a 140784sentence 2100

(Which is a totally improbable sentence)
Perl little obfuscated (for fun only)
This version (based on @Chilemagic's answer) is not shorter, but designed as a totem script:

cat <<eof >mn.pl

#!/usr/bin/perl          -sp
                      eval eval'"'
                      .('['^'(')
           .'/\\'.'\\'.('`'|'$').'+'.'/\\$\&'
                        .'*\\$'
                      .('`'|'.').'/'
                      .('`'|"'")
                      .('`'|'%').'"'

eof
  chmod +x mn.pl

Sample run:
./mn.pl -n=2 <<<$'This 1 is22a 3352sentence 50\n21.'
This 2 is44a 6704sentence 100
42.

Haskell, 70
too bad I'm too late IMHO this is pretty good for this specific question and language. the other Haskell solution here is 161 characters..
[]%n=""
s%n=f s(reads s)n
f _((a,b):_)n=show(a*n)++b%n
f(x:s)_ n=x:s%n

this works by using the reads function which parses a string Partially. for example, reads "34abc" = [(34, "abc")]. this obviously makes it perfect for this challenge.
usage:
*Main> " This 1 is22a 3352sentence 50"%3
" This3 is66a10056sentence150"


text:
Two-Many Outputs
The Challenge
I present to you another spy vs. spy challenge pitting obfuscators versus crackers. In this case, however, the datum to be protected is not an input but an output.
The rules of the challenge are simple. Write a routine with the following specifications:

The routine may be written in any language but may not exceed 320 bytes.
The routine must accept three 32-bit signed integers as inputs. It can take the form of a function that accepts 3 arguments, a function that accepts a single 3-element array, or a complete program that reads 3 integers from any standard input.
The routine must output one signed 32-bit integer.
Over all possible inputs, the routine must output between 2 and 1000 (inclusive) unique values. The number of unique values a routine can output is called its key.

As an example, the C program
int foo( int i1, int i2, int i3 ) {
    return 20 + (i1^i2^i3) %5;
}

has a key of 9, since it (hopefully) can only output the nine values 16,17,18,19,20,21,22,23, and 24.
Some additional limitations are as follows:

The routine must be fully deterministic and time-invariant, returning identical outputs for identical inputs. The routine should make no call to pseudorandom number generators.
The routine may not rely on "hidden variables" such as data in files, system variables, or esoteric language features. For example, routines should generally not refer to constants unless the constants are clearly defined in the code itself. Routines that rely on compiler quirks, outputs from mathematically undefined operations, arithmetic errors, etc. are also strongly discouraged. When in doubt, please ask.
You (the coder) must know precisely how many unique outputs the routine can produce, and should be able to provide at least one input sequence that produces each output. (Since there can potentially be hundreds of unique outputs, this set would only ever be requested in the event your key is contested.)

Since this problem bares far less resemblance to classical encryption than the previous one, I expect it will be accessible to a broader audience.
The more creative, the better.
The Scoring
The shortest non-cracked submission(s) per byte count will be declared the winner(s).
If there's any confusion, please feel free to ask or comment.
The Counter-Challenge
All readers, including those who have submitted their own routines, are encouraged to "crack" submissions. A submission is cracked when its key is posted in the associated comments section. If a submission persists for 72 hours without being modified or cracked, it is considered "safe" and any subsequent success in cracking it will be ignored for sake of the contest.
Only one cracking attempt per submission per reader is permitted. For example, if I submit to user X: "your key is 20" and I'm wrong, user X will disclaim my guess as incorrect and I will no longer be able to submit additional guesses for that submission.
Cracked submissions are eliminated from contention (provided they are not "safe"). They should not be edited. If a reader wishes to submit a new routine, (s)he should do so in a separate answer.
A cracker's score is the number of submissions (either compliant or not) (s)he cracks. For crackers with identical counts, the ranking is determined by total byte count across all cracked submissions (the higher, the better).
The cracker(s) with the highest score(s) will be declared the winners along with the developers of the winning routines.
Please do not crack your own submission.
Best of luck. :)
Leaderboard
Last Updated Sept 2, 10:45 AM EST
Immovable Barriers (non-cracked submissions):

CJam, 105 [Dennis]

Unstoppable Forces (crackers):

Dennis [Java, 269; C, 58; Mathematica, 29]
Martin Büttner [Java, 245]

May I suggest [cops-and-robbers] as the tag for these challenges? I think it's a fairly established name for such games in security and it will probably provoke more interest then [adversarial].

Sure. I'll change it now.

What kind of output is acceptable? STDOUT, return, etc...

Both stdout and a simple return are acceptable.

Your example is incorrect; its signature is 9.  %5 can return anything from -4 to 4, inclusive.

I forgot about that. I'll correct the example. Thanks for the heads up.

I've made an attempt to crack a key, but the answer was edited since the original post was invalid. Does that mean I get to try again?

@Dennis I would be fine with you trying again. It was my fault that it was messed up.

@COTO Your example still doesn't have a key of 5. -2^31 is an edge case, since abs() doesn't work on it.

burbles lips OK. Third time's the charm.

CJam, 105 bytes
1q~]4G#b2A#md"M-k^XM-WHM-n^GM-0%M-uwM-gM-^XeM-kM-^VO^Ph,M-^MM-^PM-qM-!M-8M-AM-OM-~tM-^FM-cM-h^AM-0M-0M-lM-@M-^[MF=M-^Z^SM-1M-KM-T2M-9M-UmSM-N
M-8M-^^M-n$4M-^M^SM-x M-OM-^@^?"256b@D#Y256#%2+md!A3#*)%)%

The above uses caret and M notation, since it contains unprintable character. After converting the byte stream into an integer (256b), the following code gets executed:
1q~]4G#b2A#md
12313030820310059479144347891900383683119627474072658988524821209446180284434934346766561958060381533656780340359503554566598728599799248566073353154035839
@D#Y256#%2+md!A3#*)%)%

You can try this version online in the CJam interpreter.
How it works
This submission uses number theory instead of obfuscation. The program will return 0 for almost all inputs. From the few inputs that result in a non-zero output, a secret modulus is derived that is applied to the 10 least significant bits of the third integer.
The most efficient way of solving this challenge (that I can think of) would be factorizing the 512 bit integer, which I hope won't be achievable in 72 hours.
" Prepend 1 to the numbers read from STDIN and convert the resulting array into an integer
  (“N”) by considering them digits of a base 2**32 number.                                 ";

1q~]4G#

" Compute “N / 1024” and “N % 1024”.                                                       ";

2A#md

" Push a carefully selected 512 bit semi-prime (“S”).                                      ";

12313030820310059479144347891900383683119627474072658988524821209446180284434934346766561958060381533656780340359503554566598728599799248566073353154035839

" Compute P = (N / 1024) ** 13 % 2 ** 256 + 2.                                             ";

@D#Y256#%2+

" Compute “S / P” and “S % P”.                                                             ";

md

" Compute “M = (S / P) % (1000 * !(S % P) + 1) + 1”.

  “M” is the key if P is a divisor of S; otherwise, “M == 1”.                              ";

!A3#*)%)

" Compute the final output: “N % 1024 % M”.                                                ";

%

Example run
$ base64 -d > outputs.cjam <<< MXF+XTRHI2IyQSNtZCLrGNdI7gewJfV355hl65ZPEGgsjZDxobjBz/50huPoAbCw7MCbTUY9mhOxy9QyudVtU84KuJ7uJDSNE/ggz4B/IjI1NmJARCNZMjU2IyUyK21kIUEzIyopJSkl
$ wc -c outputs.cjam
105 outputs.cjam
$ LANG=en_US cjam outputs.cjam < outputs.secret; echo
1
$ LANG=en_US cjam outputs.cjam <<< '1 2 3'; echo
0

You're just too darn good with the encryption stuff. ;)

"This submission uses number theory instead of obfuscation." Looks at code "Hmm, right."

Java - 269
Thanks for everyone's patience, this should now be fixed.
shortened:
int a(int a,int b,int c){double d=180-360.0/(int)(Math.abs(Math.sin(a*60))*50+2),e=180-360.0/(int)(Math.abs(Math.cos(b*60))*50+2),f=180-360.0/(int)(Math.atan2(c*60, a*60)*51+2);if(Math.abs(d+e+f-360)<.1)return Integer.valueOf((int)d+""+(int)e+""+(int)f);else return 1;}

Not shortened:
int a(int a, int b, int c) {
    double d = 180 - 360.0 / (int) (Math.abs(Math.sin(a * 60)) * 50 + 2);
    double e = 180 - 360.0 / (int) (Math.abs(Math.cos(b * 60)) * 50 + 2);
    double f = 180 - 360.0 / (int) (Math.atan2(c * 60, a * 60) * 51 + 2);
    if (Math.abs(d + e + f - 360) < .1)
        return Integer.valueOf((int) d + "" + (int) e + "" + (int) f);
    else
        return 1;
}

You can save four characters by changing double e,f,d=...;e=...;f=...; to double d=...,e=...,f=...;

@Ypnypn Thanks! added to golfed version.

Here goes nothing: 98

Just from bruteforcing... 110?

@MartinBüttner: Thanks, fixed.

@StretchManiac For some negative inputs, I will get a java.lang.NumberFormatException. Anyway, during my bruteforce, I used this formula instead for a bit of optimization: ((int)d*1000000+(int)e)*1000+(int)f.

I don't think this will work, because you'll get - inside your number during concatenation (I believe that's what bitpwner is talking about). I think you can golf this down though, by not casting 360 to double but by using 360.0 instead (or maybe 360., not sure if that works in Java).

So, @bitpwner and I both guessed wrong?

@StretchManiac as long as your answer has not been cracked, you should probably just fix it (with an edit).

I get 121 outputs, but I'm not entirely sure of it.

@MartinBüttner that is incorrect.

Second attempt (with explicit permission): 122

@Dennis nice job! (That's it)

If it wasn't for @MartinBüttner, I would have answered 121 as well. Then I found out that, on very rare occasions, Math.abs(Math.sin(a*60)) ==  1.0. The first positive a that satisfies the condition is 152,073,634... -- +1 for making me learn Java.

@Dennis Not bad! Did you just brute force that? Odd that this doesn't happen for cos as well then.

@MartinBüttner: Math.cos(0) == 1.0. I initially guessed the possible values of the trigonometric functions. Since I got 121 as the key, I ran a brute-force search to check if the sine could return 1 as well.

@Dennis Whoops, totally forgot about that... odd that I still got 121 without considering cos return 1.0 then.

Okay something's odd. Allowing for cos == 1.0 I get 122. also allowing for sin == 1.0 I get 123.

@MartinBüttner: I get 51 possible values for d and e, 160 for f. These are the 122 solutions they generate: http://pastebin.com/dX5ieFDw

@Dennis In that case, you're forgetting 1 and your answer is incorrect as well ;) (123 being correct... someone come along and grab the cracking score...). And I guess Stretch Maniac didn't account for sin == 1.0 when he said that 122 is correct.

Let us continue this discussion in chat.

Sorry about me getting the wrong answer. To make up for it I made an explanation of the right answer here. I actually really enjoyed making this :)

A Sampler
Not an official entry of course, and the character count is too high, but I figure if anyone wants a mind-numbing challenge, they can try to determine how many unique outputs the following function produces (given three inputs as described in the OP):
function z(y,_,$){M=[];N=[];O=[];C=1792814437;P=72;r=t=0;(f=function(a,k,L){if(k<a.length){for(L=a[k],a[k]=0;a[k]<L;a[k]++)f(a,k+1)}else
if(!t){f([P-1,P-1],0,++t);N=M;while(t<2*P){s=!(t&1);f([P,P,P,P],0,++t);r=r||(s?0:t);t&1&&(N=O);O=[]}}else
((t<2)&&(((d=P*a[0]+(P+1)*a[1]+P)<(P<<6))&&(M[d]=(((y^~_)>>a[0])+((_^~$)>>(a[0]-32)))&1),((a[1]<P-a[0])&&
(M[a[1]+(P+1)*a[0]]=(($^C)>>a[0]+16-a[1])&1))||1))||((t&1)&&((O[P*a[2]+a[3]]|=M[a[1]+P*a[2]]&N[P*a[0]+a[3]]&&
!(a[0]-a[1]))||1))||(s|=N[(a[0]+1)*a[1]+a[3]]);})([],0,0);return r;}

In fact, I'm so confident that it's uncrackable, I'll award anyone who cracks it the "Supreme Unstoppable Force of Nature Award".
Because really, they deserve it.

You should put up a bounty for it!

@Orby That would be nice, but it's hard to award a bounty to a comment.

I added some indentation to this.

@COTO is this challenge still on?

@SohamChowdhury: Absolutely. If you figure it out, I'll expound your victory in the OP. If not, let me know and I'll post the solution.

Java - 245
Cracked by Martin Büttner
int a(int[]_$){return $($($_(_$[0],0)))+$_(_$[1],1)*11+$($($_(_$[1+1],0)))*(1+1);}int $_(int $,int $_){int OO=0,o=1,O=1;for($=$<0?-$:$;++O*O<=$;OO+=$%O<1?O:0,o+=$%O<1?1:0,$/=$%O<1?O--:1);return $_>0?o:OO+$;}int $(int $){return(int)Math.sqrt($);}

Feed the input as an int array: a(new int[]{1,2,3}). I'm not expecting it to go 72 hours, but have fun with it.
Here it is with line breaks, to make it a bit more readable:
int a(int[]_$){return $($($_(_$[0],0)))+$_(_$[1],
1)*11+$($($_(_$[1+1],0)))*(1+1);}int $_(int $,int
$_){int OO=0,o=1,O=1;for($=$<0?-$:$;++O*O<=$;OO+=
$%O<1?O:0,o+=$%O<1?1:0,$/=$%O<1?O--:1);return $_>
0?o:OO+$;}int $(int $){return(int)Math.sqrt($);}

Just from bruteforcing... 90?

@bitpwner Nope, sorry.

I deobfuscated it a bit: http://pastebin.com/8pvvfFYB (I hope I didn't make any mistakes while replacing variable names.)

Okay, here is my attempt: 965?

@MartinBüttner Correct. Thanks for the obfuscated version :D

C, 58 bytes (Cracked)
A simple one:
f(a,b,c){return(long long)a*b*c-0x1d21344f8479d61dLL?0:a;}

7 (-15485867, -1299721, -104287, 0, 104287, 1299721, 15485867).

That was fast :)

Mathematica, 29 bytes, Key: 715, Cracked by Dennis
This is just a fixed version of my initial answer, which didn't work for non-positive inputs.
f=Plus@@Mod[NextPrime@#,240]&

Takes a list of integers like
f[{1,2,3}]

I found 349 unique outputs.  The range was from 3 to 717.

@PhiNotPi Wrong. (I double-checked)

Well, I found my mistake and the right answer.  Too late though.

If the stuff I pieced together from the Mathematica documentation and WolframAlpha is correct, the key is 715 (3 ... 717).

@Dennis Correct.

Mathematica looks like a nice language, but it's either too darn expensive or I'm too darn cheap...

@Dennis Yay for student licenses! Let's hope that there will be some decent open source implementations of Wolfram Language in the not so distant future. (Actually, you could just buy a Raspberry Pi, that's probably cheaper.)

207 characters, in C/C++, not yet obfuscated:
int x(int a, int b, int c) {
    int d, e, f;
    for (int i=0; i!=1<<31; ++i) {
        d=10*(b-a);
        e=a*(28-c)-b;
        f=a*b-2.7*c;
        a += d;
        b += e;
        c += f;
    }
    return ((a%5+5)*10+(b%5+5))*10+c%5+5;
}

Just trying my luck... 729.

@bitpwner Damn, I was just gonna say that. :D ... If that's wrong, that's the upper bound though.

This is not a valid submission. All assignments inside the loop may result in signed integer overflow, which has undefined behavior.


text:
SPOF Picture Hanging
Objective
I have a nice picture that I want to hang on my wall. And I want it to hang there in a spectacular way, so I chose to hang it on n nails where n is any positive integer.
But I'm also indecisive, so if I change my mind, I don't want a lot of trouble taking the picture down. Therefore, removing any one of the n nails should make the picture fall down. Did I mention that there is no friction in my house?
Can you help me?
Rules

Your program must read the number n from stdin and print to stdout (or your language's equivalents).
The output must be the solution according to the output specification without any other trailing or leading characters. However, trailing whitespace and/or newlines is acceptable.
You must use exactly n nails.
Assuming a friction-less world, your solution must fulfill the following conditions:

Hanging the picture as described by your solution, the picture must not fall down.
If any one of the nails is removed, the picture must fall down.

Standard loopholes apply. In particular, you may not make requests to, e.g., the verification program to brute-force solutions.

Note that 4.2 already implies that all n nails must be involved.
Output Specification

All nails are named from left to right with the position they are in, starting at 1.
There are two fundamental ways to put the string around a nail: clockwise and counter-clockwise. We denote a clockwise step with > and a counter-clockwise step with <.
Everytime the string is put around a nail, it comes out on top of the nails, so skipping nails means the string will go across the top of the intermediate nails.
Every solution must start on nail 1 and end on nail n.
The output must consist of a sequence of steps wherein a step is a combination fo the nail's name and the direction in which to put the string around it.

Example Output
Here is an example output for n=5 and n=3:
1>4<3<2>4>5<          # n=5, incorrect solution
1>2<1<2>3<2<1>2>1<3>  # n=3, correct solution

And here is a visual representation of the incorrect solution for n=5 (awsumz gimp skillz)

The correct solution for n=1 is simply 1> or 1<. For multiple nails, there can be different solutions. You must only output one since this is part of your score.
Verification
You can verify whether a solution is correct here: www.airblader.de/verify.php.
It uses a GET request, so you can call it directly if you want. For example, if foo is a file containing a solution on each line, you can use
cat foo | while read line; do echo `wget -qO- "www.airblader.de/verify.php?solution=$line" | grep "Passed" | wc -l`; done

If you believe a solution is correct but the verifier marks it as incorrect, please let me know!
Edit: And if your output is so long that a GET request won't cut it, let me know and I'll make a POST request version. :)
Scoring
This is code-golf. The score is the number of bytes of your source-code in UTF-8 encoding, e.g., use this tool. However, there is a potential bonus for every submission:
Run your program for all n in the range [1..20] and add the length of all outputs up to determine your output score. Subtract your output score from 6291370 to get the number of bonus points that you may deduct from your byte count to get your overall score. There is no penalty if your output score is higher than this number.
The submission with the lowest overall score wins. In the unlikely case of a tie, the tie breakers are in this order: higher bonus points, lower byte count, earlier submission date.
Please post both the individual parts (byte count, bonus points) of the score and the final score, e.g., "LOLCODE (44 - 5 = 39)".

Do > and < always guarantee that the string loops over the top of the nail? If so, can you post an example of a valid output for n>1? Also - what is the output for an input of n with no solutions?

The string will always pass once over the nail, otherwise this nail would effectively not be involved. But it isn't a "full" loop as that would make it impossible (compare how 1> is drawn in the picture). And there is no n where no solution is possible. A valid solution for n=2 is 1>2<1<2>.

I'm not sure I understand how that would fall. Wouldn't the string be wound like this?

It's hard to explain in words. If you have some string, try it out :) or at least draw it with enough space. I might be able to make a little animation tomorrow if it's still hard to visualize. For today I'm afraid I'll have to say goodnight. ;) edit: just saw you drew it. Yes that is correct. Imagine carefully what happens if a nail is removed. Again, I'll make a small animation tomorrow otherwise.

(one attempt in words: if 2 is removed, the entire right side can fall down freely. The loop that went around it can now be pulled across the top of 1 and then the entire string is free)

Gotcha. Same with nail 1.

Exactly :)  Glad you understood. I know it's tricky to imagine but magical to see in action (which due to friction only works for a few nails). I'll still make that animation tomorrow so other people might understand better.

Could you please check the following string for 11 nails? The site says it fails on nail 2, but I did it by hand and it worked, and the algorithm that generated it passed all the tests before 11. 1>2>1<2<3>4>5>4<5<3<5>4>5<4<2>1>2<1<4>5>4<5<3>5>4>5<4<3<6>7>8>7<8<6<8>7>8<7<9>10>11>10<11<9<11>10>11<10<7>8>7<8<6>8>7>8<7<6<10>11>10<11<9>11>10>11<10<9<3>4>5>4<5<3<5>4>5<4<1>2>1<2<4>5>4<5<3>5>4>5<4<3<2>1>2<1<9>10>11>10<11<9<11>10>11<10<6>7>8>7<8<6<8>7>8<7<10>11>10<11<9>11>10>11<10<9<7>8>7<8<6>8>7>8<7<6<

Is the length of 1>2<1<2> counted as 4 or 8?

To make sure i understand the notation, is 5>4>3>2>1> on 5 nails just a big loop around them all?

I think more examples for the notation would be better

@xnor Ah, crap. The script fails for n > 10. I'll have to fix it tonight. In the meantime it should be safe to assume that your script is correct if it works for n < 10. Sorry about that. The length of 1> is 2, so all characters count.

@proudhaskeller No, except for 5 it would loop around all nails once. You can put it like this: In every step, the string will pass over the top of the nail once. If it was a big loop, it would not pass over the top of the first four nails. I can add more examples later.

"Every solution must start on nail 1 and end on nail n. ... You can verify whether a solution is correct here" I'm not sure, but I think it's a bug in the verifier that it accepts 4>2>4<2<3>1>3<1<2>4>2<4<1>3>1<3<.

@PeterTaylor Yes, the verifier doesn't check for this restriction yet at all. I'll add that as well.

@xnor I fixed the verifier. It successfully detects your solutions for n=11 and n=20.

@PeterTaylor,xnor But fixing the verifier to check for the requirement Peter pointed out, your solutions fail again. Sorry. I love how short your output is, but it has to start and end with the first and last nail. Don't want my picture to look weird on the wall! :)

GolfScript (51 67 bytes + (7310 7150 - 6,291,370) = -6,284,153)
~,{.,({.,.[1]*{(\(@++}@((*1=/{C}%.~+2/-1%{~'<>'^}%*}{[~)'>']}if}:C~

This is based on Chris Lusby Taylor's* recursive commutator construction, better expounded in Picture-Hanging Puzzles, Demaine et al., Theory of Computing Systems 54(4):531-550 (2014).
Outputs for the first 20 inputs:
1>
1>2<1<2>
1>2<1<2>3<2<1>2>1<3>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>
1>2<1<2>3<2<1>2>1<3>5<4>5>4<3<1>2<1<2>3>2<1>2>1<4>5<4<5>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>7<5>6<5<6>7>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>7<6<5>6>5<7>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>
1>2<1<2>3<2<1>2>1<3>5<4>5>4<3<1>2<1<2>3>2<1>2>1<4>5<4<5>9<8>9>8<6>7<6<7>8>9<8<9>7<6>7>6<5<4>5>4<1>2<1<2>3<2<1>2>1<3>4>5<4<5>3<1>2<1<2>3>2<1>2>1<6>7<6<7>9<8>9>8<7<6>7>6<8>9<8<9>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>10<9>10>9<7>8<7<8>9>10<9<10>8<7>8>7<6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<7>8<7<8>10<9>10>9<8<7>8>7<9>10<9<10>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>7<5>6<5<6>7>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>7<6<5>6>5<7>11<10>11>10<8>9<8<9>10>11<10<11>9<8>9>8<7<5>6<5<6>7>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>7<6<5>6>5<7>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<8>9<8<9>11<10>11>10<9<8>9>8<10>11<10<11>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>13<12>13>12<9>10<9<10>11<10<9>10>9<11>12>13<12<13>11<9>10<9<10>11>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>11<10<9>10>9<11>13<12>13>12<11<9>10<9<10>11>10<9>10>9<12>13<12<13>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>14<13>14>13<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>13>14<13<14>12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>14<13>14>13<12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<13>14<13<14>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>15<13>14<13<14>15>14<13>14>13<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>13>14<13<14>15<14<13>14>13<15>12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>15<13>14<13<14>15>14<13>14>13<12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<13>14<13<14>15<14<13>14>13<15>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>16<15>16>15<13>14<13<14>15>16<15<16>14<13>14>13<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>13>14<13<14>16<15>16>15<14<13>14>13<15>16<15<16>12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>16<15>16>15<13>14<13<14>15>16<15<16>14<13>14>13<12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<13>14<13<14>16<15>16>15<14<13>14>13<15>16<15<16>
1>2<1<2>3<2<1>2>1<3>5<4>5>4<3<1>2<1<2>3>2<1>2>1<4>5<4<5>9<8>9>8<6>7<6<7>8>9<8<9>7<6>7>6<5<4>5>4<1>2<1<2>3<2<1>2>1<3>4>5<4<5>3<1>2<1<2>3>2<1>2>1<6>7<6<7>9<8>9>8<7<6>7>6<8>9<8<9>17<16>17>16<14>15<14<15>16>17<16<17>15<14>15>14<10>11<10<11>13<12>13>12<11<10>11>10<12>13<12<13>14>15<14<15>17<16>17>16<15<14>15>14<16>17<16<17>13<12>13>12<10>11<10<11>12>13<12<13>11<10>11>10<9<8>9>8<6>7<6<7>8>9<8<9>7<6>7>6<1>2<1<2>3<2<1>2>1<3>5<4>5>4<3<1>2<1<2>3>2<1>2>1<4>5<4<5>6>7<6<7>9<8>9>8<7<6>7>6<8>9<8<9>5<4>5>4<1>2<1<2>3<2<1>2>1<3>4>5<4<5>3<1>2<1<2>3>2<1>2>1<10>11<10<11>13<12>13>12<11<10>11>10<12>13<12<13>17<16>17>16<14>15<14<15>16>17<16<17>15<14>15>14<13<12>13>12<10>11<10<11>12>13<12<13>11<10>11>10<14>15<14<15>17<16>17>16<15<14>15>14<16>17<16<17>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>10<9>10>9<7>8<7<8>9>10<9<10>8<7>8>7<6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<7>8<7<8>10<9>10>9<8<7>8>7<9>10<9<10>18<17>18>17<15>16<15<16>17>18<17<18>16<15>16>15<11>12<11<12>14<13>14>13<12<11>12>11<13>14<13<14>15>16<15<16>18<17>18>17<16<15>16>15<17>18<17<18>14<13>14>13<11>12<11<12>13>14<13<14>12<11>12>11<10<9>10>9<7>8<7<8>9>10<9<10>8<7>8>7<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>7>8<7<8>10<9>10>9<8<7>8>7<9>10<9<10>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<11>12<11<12>14<13>14>13<12<11>12>11<13>14<13<14>18<17>18>17<15>16<15<16>17>18<17<18>16<15>16>15<14<13>14>13<11>12<11<12>13>14<13<14>12<11>12>11<15>16<15<16>18<17>18>17<16<15>16>15<17>18<17<18>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>7<5>6<5<6>7>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>7<6<5>6>5<7>11<10>11>10<8>9<8<9>10>11<10<11>9<8>9>8<7<5>6<5<6>7>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>7<6<5>6>5<7>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<8>9<8<9>11<10>11>10<9<8>9>8<10>11<10<11>19<18>19>18<16>17<16<17>18>19<18<19>17<16>17>16<12>13<12<13>15<14>15>14<13<12>13>12<14>15<14<15>16>17<16<17>19<18>19>18<17<16>17>16<18>19<18<19>15<14>15>14<12>13<12<13>14>15<14<15>13<12>13>12<11<10>11>10<8>9<8<9>10>11<10<11>9<8>9>8<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>7<5>6<5<6>7>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>7<6<5>6>5<7>8>9<8<9>11<10>11>10<9<8>9>8<10>11<10<11>7<5>6<5<6>7>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>7<6<5>6>5<7>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<12>13<12<13>15<14>15>14<13<12>13>12<14>15<14<15>19<18>19>18<16>17<16<17>18>19<18<19>17<16>17>16<15<14>15>14<12>13<12<13>14>15<14<15>13<12>13>12<16>17<16<17>19<18>19>18<17<16>17>16<18>19<18<19>
1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>20<19>20>19<17>18<17<18>19>20<19<20>18<17>18>17<13>14<13<14>16<15>16>15<14<13>14>13<15>16<15<16>17>18<17<18>20<19>20>19<18<17>18>17<19>20<19<20>16<15>16>15<13>14<13<14>15>16<15<16>14<13>14>13<12<11>12>11<9>10<9<10>11>12<11<12>10<9>10>9<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>9>10<9<10>12<11>12>11<10<9>10>9<11>12<11<12>8<7>8>7<5>6<5<6>7>8<7<8>6<5>6>5<1>2<1<2>4<3>4>3<2<1>2>1<3>4<3<4>5>6<5<6>8<7>8>7<6<5>6>5<7>8<7<8>4<3>4>3<1>2<1<2>3>4<3<4>2<1>2>1<13>14<13<14>16<15>16>15<14<13>14>13<15>16<15<16>20<19>20>19<17>18<17<18>19>20<19<20>18<17>18>17<16<15>16>15<13>14<13<14>15>16<15<16>14<13>14>13<17>18<17<18>20<19>20>19<18<17>18>17<19>20<19<20>

NB I think that the longer answers will fail the online test because it uses GET rather than POST and URLs are not guaranteed to be handled correctly if they're longer than 255 chars.
There are two tweaks on the standard construction:

In order to ensure that it finishes on the last nail, I actually form the commutator [x_1, x_2^-1] instead of [x_1, x_2].
Following xnor's example, I don't split 50-50. It turns out that to balance it so the larger numbers are used less frequently** the ideal split is according to A006165. I'm using David Wilson's observation to calculate it.

* No relation, as far as I'm aware.
** Well, within the same recursive commutator approach. I'm not claiming to have solved the open problem of proving it optimal.

About URL: Yes, I thought about that. So far nothing came up, so I decided to leave it to allow scripting the check more easily.

Also +1 just for the reference. I didn't know a paper on this existed, but always suspected it might!

@IngoBürk, it's quite a recent paper, so I assumed that it was that which gave you the idea. Interesting to know that it wasn't.

I learned about this puzzle about 6 years or so ago when I was visiting the math faculty of the university on an "open day" kind of thing, the year before I started studying mathematics. Loved it eversince!

Python 2 (208 bytes + (7230 - 6,291,370) = -6,283,932)
def f(a,b):
 if a<b+2:return[a]
 m=(a+b+1)/2
 while all(8*x!=2**len(bin(x))for x in[a-m,m-b]):m+=1
 A=f(a,m);B=f(m,b)
 return[-x for x in A+B][::-1]+B+A
print"1<1>"+"".join(`abs(x)`+"<>"[x>0]for x in f(input(),0))

The function f recursively makes an answer by combining half-solutions as A^{-1}*B^{-1}*A*B, represents inverses by negation. f(a,b) is a solution for the numbers in the half-open interval [a,b).
Edit: To comply with the requirement to start with 1 and end with n, I flipped the order to always end with n by using reversed intervals, and simply append "1<1>" to the beginning.
Edit: Saved 136 symbols in output by rounding the other way in picking intervals, causing intervals with larger numbers (and so likelier to have two digits) to be shorter.
Edit: Saved 100 symbols by splitting the intervals unevenly so the one with larger numbers is shorter. This doesn't lengthen the number of operations used as long as the lengths never cross powers of 2.
Edit: Reintroduced favorable rounding, -50 symbols, 2+ code chars.
Outputs for 1 through 20:
1<1>1>
1<1>1<2<1>2>
1<1>2<1<2>1>3<1<2<1>2>3>
1<1>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>
1<1>3<2<1<2>1>3>1<2<1>2>5<4<5>4>2<1<2>1>3<1<2<1>2>3>4<5<4>5>
1<1>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>5<6<5>6>
1<1>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>7<6<5<6>5>7>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>7<5<6<5>6>7>
1<1>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>
1<1>5<4<5>4>3<2<1<2>1>3>1<2<1>2>4<5<4>5>2<1<2>1>3<1<2<1>2>3>9<8<9>8>7<6<7>6>8<9<8>9>6<7<6>7>3<2<1<2>1>3>1<2<1>2>5<4<5>4>2<1<2>1>3<1<2<1>2>3>4<5<4>5>7<6<7>6>9<8<9>8>6<7<6>7>8<9<8>9>
1<1>6<5<6>5>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>10<9<10>9>8<7<8>7>9<10<9>10>7<8<7>8>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>5<6<5>6>8<7<8>7>10<9<10>9>7<8<7>8>9<10<9>10>
1<1>7<6<5<6>5>7>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>7<5<6<5>6>7>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>11<10<11>10>9<8<9>8>10<11<10>11>8<9<8>9>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>7<6<5<6>5>7>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>7<5<6<5>6>7>9<8<9>8>11<10<11>10>8<9<8>9>10<11<10>11>
1<1>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>
1<1>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>13<12<13>12>11<10<9<10>9>11>9<10<9>10>12<13<12>13>10<9<10>9>11<9<10<9>10>11>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>11<10<9<10>9>11>9<10<9>10>13<12<13>12>10<9<10>9>11<9<10<9>10>11>12<13<12>13>
1<1>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>14<13<14>13>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>13<14<13>14>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>14<13<14>13>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>13<14<13>14>
1<1>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>15<14<13<14>13>15>13<14<13>14>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>14<13<14>13>15<13<14<13>14>15>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>15<14<13<14>13>15>13<14<13>14>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>14<13<14>13>15<13<14<13>14>15>
1<1>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>16<15<16>15>14<13<14>13>15<16<15>16>13<14<13>14>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>14<13<14>13>16<15<16>15>13<14<13>14>15<16<15>16>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>16<15<16>15>14<13<14>13>15<16<15>16>13<14<13>14>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>14<13<14>13>16<15<16>15>13<14<13>14>15<16<15>16>
1<1>9<8<9>8>7<6<7>6>8<9<8>9>6<7<6>7>5<4<5>4>3<2<1<2>1>3>1<2<1>2>4<5<4>5>2<1<2>1>3<1<2<1>2>3>7<6<7>6>9<8<9>8>6<7<6>7>8<9<8>9>3<2<1<2>1>3>1<2<1>2>5<4<5>4>2<1<2>1>3<1<2<1>2>3>4<5<4>5>17<16<17>16>15<14<15>14>16<17<16>17>14<15<14>15>13<12<13>12>11<10<11>10>12<13<12>13>10<11<10>11>15<14<15>14>17<16<17>16>14<15<14>15>16<17<16>17>11<10<11>10>13<12<13>12>10<11<10>11>12<13<12>13>5<4<5>4>3<2<1<2>1>3>1<2<1>2>4<5<4>5>2<1<2>1>3<1<2<1>2>3>9<8<9>8>7<6<7>6>8<9<8>9>6<7<6>7>3<2<1<2>1>3>1<2<1>2>5<4<5>4>2<1<2>1>3<1<2<1>2>3>4<5<4>5>7<6<7>6>9<8<9>8>6<7<6>7>8<9<8>9>13<12<13>12>11<10<11>10>12<13<12>13>10<11<10>11>17<16<17>16>15<14<15>14>16<17<16>17>14<15<14>15>11<10<11>10>13<12<13>12>10<11<10>11>12<13<12>13>15<14<15>14>17<16<17>16>14<15<14>15>16<17<16>17>
1<1>10<9<10>9>8<7<8>7>9<10<9>10>7<8<7>8>6<5<6>5>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>8<7<8>7>10<9<10>9>7<8<7>8>9<10<9>10>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>5<6<5>6>18<17<18>17>16<15<16>15>17<18<17>18>15<16<15>16>14<13<14>13>12<11<12>11>13<14<13>14>11<12<11>12>16<15<16>15>18<17<18>17>15<16<15>16>17<18<17>18>12<11<12>11>14<13<14>13>11<12<11>12>13<14<13>14>6<5<6>5>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>10<9<10>9>8<7<8>7>9<10<9>10>7<8<7>8>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>5<6<5>6>8<7<8>7>10<9<10>9>7<8<7>8>9<10<9>10>14<13<14>13>12<11<12>11>13<14<13>14>11<12<11>12>18<17<18>17>16<15<16>15>17<18<17>18>15<16<15>16>12<11<12>11>14<13<14>13>11<12<11>12>13<14<13>14>16<15<16>15>18<17<18>17>15<16<15>16>17<18<17>18>
1<1>11<10<11>10>9<8<9>8>10<11<10>11>8<9<8>9>7<6<5<6>5>7>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>7<5<6<5>6>7>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>9<8<9>8>11<10<11>10>8<9<8>9>10<11<10>11>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>7<6<5<6>5>7>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>7<5<6<5>6>7>19<18<19>18>17<16<17>16>18<19<18>19>16<17<16>17>15<14<15>14>13<12<13>12>14<15<14>15>12<13<12>13>17<16<17>16>19<18<19>18>16<17<16>17>18<19<18>19>13<12<13>12>15<14<15>14>12<13<12>13>14<15<14>15>7<6<5<6>5>7>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>7<5<6<5>6>7>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>11<10<11>10>9<8<9>8>10<11<10>11>8<9<8>9>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>7<6<5<6>5>7>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>7<5<6<5>6>7>9<8<9>8>11<10<11>10>8<9<8>9>10<11<10>11>15<14<15>14>13<12<13>12>14<15<14>15>12<13<12>13>19<18<19>18>17<16<17>16>18<19<18>19>16<17<16>17>13<12<13>12>15<14<15>14>12<13<12>13>14<15<14>15>17<16<17>16>19<18<19>18>16<17<16>17>18<19<18>19>
1<1>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>20<19<20>19>18<17<18>17>19<20<19>20>17<18<17>18>16<15<16>15>14<13<14>13>15<16<15>16>13<14<13>14>18<17<18>17>20<19<20>19>17<18<17>18>19<20<19>20>14<13<14>13>16<15<16>15>13<14<13>14>15<16<15>16>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>12<11<12>11>10<9<10>9>11<12<11>12>9<10<9>10>4<3<4>3>2<1<2>1>3<4<3>4>1<2<1>2>8<7<8>7>6<5<6>5>7<8<7>8>5<6<5>6>2<1<2>1>4<3<4>3>1<2<1>2>3<4<3>4>6<5<6>5>8<7<8>7>5<6<5>6>7<8<7>8>10<9<10>9>12<11<12>11>9<10<9>10>11<12<11>12>16<15<16>15>14<13<14>13>15<16<15>16>13<14<13>14>20<19<20>19>18<17<18>17>19<20<19>20>17<18<17>18>14<13<14>13>16<15<16>15>13<14<13>14>15<16<15>16>18<17<18>17>20<19<20>19>17<18<17>18>19<20<19>20>

This will get you an amazing (negative) score. I fully expected negative scores. I'll fix the verify script later and check your solutions then.

As pointed out in the comments, this is currently invalid because the output must end with the last nail :(

Oh, I missed that, I'll just append a vestigial n>n< then.

The online checker currently doesn't accept a final nail that's two digits.

I fixed it. I probably should've written some tests for it… :) (edit: the script fails for your n=1 solution now. working on it)

And done! All outputs now run successfully. I'm not PHP expert, but imho PHP was behaving strangely there. Whatever. :)

Very nice idea to split things differently. I was puzzled by the 8 in 8*x!=2**len(bin(x)) until I realised that it compensates for a leading 0b. But a shorter way of doing that test is (x&(x-1))!=0. (I think that the entire loop can be removed too, but I need to think about it).

@PeterTaylor Oh, that's a nice binary trick. Yeah, there's surely a direct arithmetic expression for the highest m so that a-m and m-b have as many bits as with m=(a+b+1)/2. I think there's also optimization to be done in the splitting, with tradeoffs that use more numbers but fewer big ones. A dynamic algorithm could do this optimally. I'm not going to work on this; you're welcome to take it.

C - (199 bytes - 0) = 199
p,n,i;main(int x,char **a){for(n=atoi(a[x=i=1]);i<n;i++)x=x*2+2;int o[x];*o=1;for(x=2;n/x;o[++p]=-x++)for(o[i=(++p)]=x;i;o[++p]=-o[--i]);for(i=0;i<=p;printf("%d%s",abs(o[i]),(o[i]<0)?"<":">"),i++);}

With line breaks:
p,n,i;
main(int x,char **a)
{
    for(n=atoi(a[x=i=1]);i<n;i++)
        x=x*2+2;
    int o[x];
    *o=1;
    for(x=2;n/x;o[++p]=-x++)
        for(o[i=(++p)]=x;i;o[++p]=-o[--i]);
    for(i=0;i<=p;printf("%d%s",abs(o[i]),(o[i]<0)?"<":">"),i++);
}

Probably a fairly naive algorithm given that I don't know that much about knot theory.  Basically just adds the next higher number, then reverses the whole instruction set to unwind it. This would likely much more concise in a language that handles sets better...
The total output length for n in the range [1..20] was 6,291,370 bytes of output (3,145,685 instructions). This was huge enough that I only posted sample outputs for n in the range [1..10].

6,291,370 is exactly the correct number I wanted to post. I accidentally only posted the number for n=20, not the sum of all. I'll have to crank it down to [1..10].

I decided to leave the scoring as is, but drop the requirement to post output. So your score would now be 199 + 0 = 199.