text:
My Robot Has Escaped the Lab!
My robot has short circuited somehow and randomly run off somewhere from my lab!
Luckily, whenever he does this, his shut-down sequence initiates, giving him enough time to randomly turn and run in the direction its facing for five rounds before he switches off. His gyro and accelerometer functions are still relaying the data back to the lab while he is still on.
The data will always come in the form of five sets of two numbers, for example.
12:234,-135:47,-68:230,140:324,127,87
Your mission, golfers is to a) simulate the robot's frantic run and turn sequence by displaying five sets of numbers in the form of a1:d1,a2:d2,a3:d3,a4:d4,a5:d5 where a(n) is the clockwise angle (in degrees) such that -179<=a<=+180 that the robot will turn from its current heading (initially it is at zero heading before it runs amok and turns for the first time), and d(n) is the distance in feet it has run before the next heading change which is such that 0<=d<=500 feet; and b) A calculated heading from the lab (which is also facing a heading of zero), distance in feet (accuracy up to 3 decimal places is strongly encouraged, -5 bytes if you do), and the orientation heading (in degrees) of where my robot it is facing when it has switched off.
Easy example:
Data: 0:1,45:1,90:1,90:1,90:1
Heading: 0
Distance: 1
Orientation: -45

The random turns and distances are just that, random. No set values are to be hard coded, we must see the randomness in action within the code.
Restrictions to randomness: No clock or date based references, we need to see a native random reference within the code. Whenever you run this code, the randomness must present itself with a possibility of showing 1 of 360 possible angles of turning with each turn-run round. So the robot may turn -36 degrees at one turn and may turn +157 degrees the next, followed by another turn of +2 degrees by another turn of -116 degrees and a final turn of +42 degrees on the final turn. At least 360 distinct values must be possible (between -179 to +180 degrees inclusive) with each random angle generation.
Restrictions to distance run: Similarly set, there are 501 possible distances the robot can run, (between 0 and 500 feet inclusive), so I expect the randomness to also be available when determining the robot's running distance. The robot could theoretically run 45, 117, 364, 27 and 6 feet with each of its respective rounds...
The data fed to you will always be in integer values... the robot will turn in integer ranges of degrees, and will run in integer ranges of distance. The output values however, will be floats...
This is code-golf. Shortest code wins... Now go find my robot!
PS: In reference to my "Accuracy up to 3 decimal places", if you can provide the heading (in degrees, to a MINIMUM of 3 decimal places) and a distance in feet (also accurate also to a MINIMUM 3 decimal places) you will get a -5 byte bonus).

All of your examples violate -179<=a<=+180...

@Doorknob Sorry, moment of weakness... Examples have been fixed...

@WallyWest Why -179<=a<=+180? What about -179.00000000...1, which is not -180 nor +180?

@IsmaelMiguel Seriously, dude? -180 degrees results in the same heading as +180 degrees from one's original orientation. -179 <= a <= 180 results in all 360 possible integer headings. If I wanted to go into unknown territory and narrow the field of possible angles accurate to 0.0000...1 of a degree we would be here all day...

@IsmaelMiguel and @OP - I'm probably going to get shot for this, but couldnt you use -180 < a <= +180 as the < sign on its own means less than but not including AFAIK...

@GeorgeH You are correct, but what WallyWest is saying is wrong. "-179 <= a <= 180 results in all 360 possible integer headings" -> this is wrong because there are 361 headings. Or the robot isn't allowed to go to -180º?

@IsmaelMiguel It is allowed to go -180 degrees, because that's exactly the same as 180.

The place is the same, the rotation is different...

Whether you turn -180 or +180 matters not, @IsmaelMiguel. The overall result means you will still be travelling in the same direction...

That is wrong. +180º means an half-turn clockwise. -180º means half-turn anti-clockwise (or counterclockwise, as you prefer). if the range is -179<=a<=+180, the robot can't turn 180º anti-clockwise. Why? He will be stuck at -179º! Maybe that is why he had short circuit...

@Doorknob, I'm spent... you want to have a go explaining to Ismael?

@WallyWest I'm not stupid and I understand what you mean. I'm just saying that the range should be fixed.

@IsmaelMiguel This is my question, I decide the restrictions here... The range for the robot's turning will remain fixed at what it is. -179 degrees to +180 degrees. Case closed; lump it or leave it.

Well, I was just saying the range is wrong. You do what you want. But try not to break another robot ;)

@IsmaelMiguel I agree with your comments 100%. But realise that the OP used degrees and feet, rather than radians and metres. He probably uses 12-hour time too. That probably means that his world view doesn't include half-open ranges. ;-) [Note to other readers: this is maths geek humour, not intended to be condescending per se. Also, I'm speaking as a user, not a moderator.]

@ChrisJester-Young While I appreciate the math geek humor, I intentiionally made the range -179 degrees to +180 degrees as I didn't want to make this easy for anyone. I didn't want them to re-use the "180" when golfing the code. Also as a +180 degree turn results in facing the same direction as turning -180 degrees I thought it unnecessary to double up.
I used degrees rather than radians simply out of choice and used feet rather than metres because it wouldn't have mattered if I chose one or the other. There was going to be no conversion to smaller units... So I went with feet.

I'm not clear whether the input degrees and distances should be integers or floats, and whether the output headings should be integers too, rounded to the nearest degree, or floats. Are either ok?

@Tobia, let me clarify that in the brief...

@WallyWest: could we please get some clarification about "accuracy up to 3 decimal places is strongly encouraged, -5 bytes if you do"? This part is quite confusing for us...

@MathieuRodic Provided. See postscript.

@WallyWest: sorry, but it is still unclear whether the 3 decimals are a minimum or a maximum...

Perl 6: 188 184 characters - 5 = 180 points
$_=((-179..180).pick=>(^501).pick)xx 5;my$o;$/=([+] .map:{unpolar .value,$o+=.key/($!=180/pi)}).polar;say "Data: {.fmt("%d:%d",",")}
Heading: {$1*$!}
Distance: $0
Orientation: {$o*$!}"

Golf with whitespace:
$_ = ((-179..180).pick => (^501).pick) xx 5;
my $o;
$/ = ([+] .map: {
    unpolar .value, $o += .key / ($!=180/pi)
}).polar;
say "Data: {.fmt("%d:%d", ",")}
Heading: {$1*$!}
Distance: $0
Orientation: {$o*$!}"

Ungolfed:
my &postfix:<°>  = */180*pi; # Deg → Rad
my &postfix:<㎭> = */pi*180; # Rad → Deg

my @data = ((-179..180).pick => (0..500).pick) xx 5;
say "Data: @data.fmt("%d:%d", ",")";

my $cum-angle = 0;
my $complex = [+] @data.map: {unpolar .value, $cum-angle += .key°}
my ($dist, $ang) = $complex.polar;

say "Heading: ",     $ang.㎭;
say "Distance: ",    $dist;
say "Orientation: ", $cum-angle.㎭;

This turns the data into complex numbers with unpolar, puts the sum of them into $complex, and then gets the polar coordinates as $dist, $ang.
The cumulative angle, $cum-angle is collected because the angles are relative to the robot as it moves through the lab and because we need the final angle of the robot in our output.
Sample output:
Data: -73:230,-144:453,-151:274,-52:232,88:322
Heading: -5.33408558001246
Distance: 378.74631610127
Orientation: -332

The only real trick the golf uses is that it (mis)uses all 3 of Perl 6's special variables to good effect:

$! is used for radians ↔ degrees
$_ holds the data, and anything that looks like a lonely .method() actually means $_.method() (except inside the map {…} block, where $_ actually takes on the value of the number pairs that make up the data)
$/ holds what is in the ungolfed version ($dist, $ang). $0 and $1 actually mean $/[0], i.e., $dist, and $/[1], i.e., $ang

Nice! You can still go down from 188 to 184 like this:
$_=((-179..180).pick=>(^501).pick)xx 5;my$o;$/=([+] .map:{unpolar .value,$o+=.key/($!=180/pi)}).polar;say "Data: {.fmt("%d:%d",",")} Heading: {$1*$!} Distance: $0 Orientation: {$o*$!}"

@MathieuRodic Oh, nice find! Thanks! Unfortunately, the space after .map: is mandatory

Oh, I was wrong about the space, cool :)

Ruby, 274 252 249 245 214 211 207 204 202 characters (-5 = 197)
How did PHP beat Ruby in char count?! >:O Must find some way to golf more...
Edit: I beat the PHP answer, but the user who wrote it helped me do it! Go upvote him; he deserves it :-P
Another edit: Gah! He passed me again! You are a very worthy opponent, @MathieuRodic; congratulations, I have to let you win ;-)
P=(M=Math)::PI
puts"Data: #{([x=y=a=0]*5).map{a+=o=rand -179..e=180;x+=M.sin(b=a*P/e)*d=rand 500;y+=d*M.cos b;"#{o}:#{d}"}*?,}
Heading: #{M.atan(y/x)/P*-e+90}
Distance: #{M.hypot x,y}
Orientation: #{a}"

Ungolfed code (and slightly much older version):
data = Array.new(5) { [rand(-179..180), rand(0..500)] }
puts "Data: #{data.map{|x|"#{x[0]}:#{x[1]}"}.join ?,}"
x, y, a = [0] * 3
data.each do |o, d|
    a += o
    x += Math.sin(a * Math::PI / 180) * d
    y += Math.cos(a * Math::PI / 180) * d
end
puts "Heading: #{Math.atan(y / x) / Math::PI * -180 + 90}
Distance: #{Math.sqrt(x * x + y * y)}
Orientation: #{a}"

Sample output:
c:\a\ruby>robotgolf
Data: 94:26,175:332,14:390,159:448,-45:20
Heading: 124.52305879195005
Distance: 279.5742334385328
Orientation: 397

How is the robot facing due north after having turned five random angles?

@WallyWest I was under the impression that the orientation marks the starting angle of the robot, correct? I could make it mark the ending angle for only 3 extra chars.

No, it is always facing due north (heading 0) at the code's execution...
Then it turns, runs, turns, runs, turns, runs, turns, runs, turns and then runs... before it shuts down.
It will need to have the final angle it is facing inthe Orientation section.

@WallyWest Ah, okay, edited. Is it okay if the orientation is not in 0...360, or do we have to do a % 360 on it?

You can save 11 characters by declaring M=Math and P=M::PI and replacing the code accordingly - and one more character by getting rid of the space after the second puts.

and x,y,a=[0]*3 could be x=y=a=0, no?

And move all output to one puts. That would give 252 chars altogether.

I can't believe PHP is beating Ruby either... But for now, it's true :) Also, according to WallyWest, you can remove 5 bytes if your accuracy goes 'up to 3 decimal places'; your program does not validate this condition (most answers on this page did the same mistake).

@Matheiu I doubt that's what the OP meant, so clarification may be needed. I think I'm going to have to let you win this one; I've been pushed to the limits of my golfing skills ;-)

Well, that's how I understood it... after some Googling: http://en.wikipedia.org/wiki/Significant_figures#Rounding_and_decimal_places. Regarding the golf itself, maybe you could use hypot for distance calculation...

@Mathieu It just says "accuracy" and doesn't mention anything else; I assume floating point accuracy would suffice. Thanks; that golf tip worked! +1 to you for that :-D

@Doorknob, %360 is advised... but I'll accept it... especially considering a -180 heading is the same as a 180 heading...

PHP - 238 232 221 212 203 199 characters
for(;$i<5;$h+=$a=rand(-179,181),$x+=cos($b=$a*$k=M_PI/180)*$l=rand(0,501),$y+=$l*sin($b),$d.=($i++?",":"")."$a:$l");echo"Data: $d
Heading: $h
Distance: ".hypot($x,$y)."
Orientation: ".atan2($y,$x)/$k

(test it here: http://ideone.com/dNZnKX)
Non-golfed version:
$k = M_PI / 180;
$h = $x = $y = 0;
$d = "";

for ($i=5; $i--;){
    $h += $a = rand(-179,181);
    $x += ($l = rand(0, 501)) * cos($b = $k * $a);
    $y += $l * sin($b);
    $d .= ($d ? "," : "") . "$a:$l";
}

echo "Data: $d\nHeading: $h\nDistance: " . sqrt($x*$x + $y*$y) ."\nOrientation: " . atan2($y, $x)/$k . "\n";

(test it here: http://ideone.com/1HzWH7)

Looks like Perl just narrowly beat us both at the last minute. :-O

@Doorknob Yup, sorry :)

Definitely. Mouq, you kind of wiped out all our efforts with only 188...

Python - 264 259 256 258 - 5 = 253 characters
from math import*;import random as R;r,k,d=R.randint,pi/180,[];h=x=y=0;exec"a,l=r(-179,180),r(0,500);d+=[`a`+':'+`l`];h+=a;x+=l*cos(k*a);y+=l*sin(k*a);"*5;print('Data: %s\nHeading: %d\nDistance: %.3f\nOrientation: %d'%(','.join(d),h,hypot(x,y),atan2(y,x)/k))

(test it at http://ideone.com/FicW6e)
Ungolfed version:
from math import *
from random import randrange as r

k = pi / 180
h = x = y = 0
d = []
for i in range(5):
    a = r(-179,181)
    l = r(501)
    d += ['%d:%d' % (a, l)]
    h += a
    x += l * cos(k * a)
    y += l * sin(k * a)

print('Data: %s\nHeading: %d\nDistance: %.3f\nOrientation: %f' % (','.join(d), h, sqrt(x*x+y*y), atan2(y,x)/k))

(test it at http://ideone.com/O3PP7T)
NB: many answers include -5 in their title, while their program does not represent the distance with accuracy up to 3 decimal places...

Python 301-5=296
from math import*
r=__import__("random").randint
o=x=y=0
s=[]
for i in[0]*5:a=r(-179,180);d=r(0,500);o+=a;o+=180*((o<-179)-(o>180));n=pi*o/180;x+=d*cos(n);y+=d*sin(n);s+=["%d:%d"%(a,d)]
print"Data: "+",".join(s)+"\nHeading: %d"%degrees(atan(y/x))+"\nDistance: %f"%sqrt(x**2+y**2)+"\nOrientation: %d"%o

Nothing too fancy here, rather verbose. This is one problem for which I am not happy that python's trig functions work in radians.
> python robot.py
Data: 17:469,110:383,-146:240,-78:493,62:1
Heading: -17
Distance: 405.435748
Orientation: -35
> python robot.py
Data: -119:363,89:217,129:321,10:159,-56:109
Heading: -79
Distance: 130.754395
Orientation: 53

Python 2 = 376 319 characters (-5 for distance=314)
import random,math
h=x=y=0
for i in range(5):
    a=random.randint(-179,180)
    d=random.randint(0,500)
    print '%d:%d,'%(a,d),
    h+=a
    if h>180:
        h-=360
    x+=d*math.cos(h)
    y+=d*math.sin(h)
t=math.sqrt(x**2+y**2)
o=math.atan2(y,x)
print
print 'Heading: %d\nDistance: %3f\nOrientation: %d' % (h,t,o)

sample output
-141:245, 56:355, 145:223, -10:80, -38:253,
Heading: 12
Distance: 559.031404
Orientation: -2

Python does trigonometry calculations with radians, not with degrees. Hence, your calculations are probably wrong...

source: Stack Exchange

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

sort: votes


text:
Name the poker hand - 7 cards edition
The Challenge:
In this question: Name the poker hand you had to take a five card poker hand and identify it. This question is similar, with two twists:
First, the output will be in all lower case. This allows for more golfing, as you don't have to worry about the capitalization of flush and straight
high card
one pair
two pair
three of a kind
straight
flush
full house
four of a kind
straight flush
royal flush

Secondly, with the popularity of Texas Hold'em and 7 card stud, we here at code golf should be able to score a seven card poker hand am I right? When scoring a seven card hand, use the five best cards for your hand and ignore the two you don't need.
Reference:
List of poker hands: http://en.wikipedia.org/wiki/List_of_poker_hands
Input (lifted directly from the previous thread)
7 cards from either stdin or commandline arguments.
A card is a two letter string on the form RS, where R is rank and S is suit.
The ranks are 2 - 9 (number cards), T (ten), J (Jack), Q (Queen), K (King), A (Ace).
The suits are S, D, H, C for spades, diamonds, hearts and clubs respectively.
Example of cards
5H - five of hearts
TS - ten of spades
AD - ace of diamonds

Example of input => desired output
3H 5D JS 3C 7C AH QS => one pair
JH 4C 2C 9S 4H JD 2H => two pair
7H 3S 7S 7D AC QH 7C => four of a kind
8C 3H 8S 8H 3S 2C 5D => full house
AS KC KD KH QH TS JC => straight

Notice in the second example there are actually three pairs, but you can only use five cards, so it's two pair. In the fifth example, there are both a three of a kind and a straight possible, but a straight is better, so output straight.
Scoring
This is code-golf, so shortest code wins!
Errata

You may not use external resources.
Ace is both high and low for straights.

Nice; I secretly hoped that someone would pick up the ball. Just wanted to note that I did not have any restrictions on the capitalization in the original question (clarified in a comment), So you could (and most/all did) output "Straight Flush". IMHO capitalized looks better.

You say input (lifted directly from the previous thread) 5 cards. I think you meant to change that to 7.

@steveverrill You can edit posts yourself on stack exchange. Though I did it for you here

Are external resources allowed? There are lookup tables that will allow you to simply look up each card in the hand and get a hand strength.

Can ace be low as well as high for straights?

@NickT: Updated post

Ruby 353
This was based off of Chron's answer from the original question.
This takes input as command line arguments. Basically we just iterate over all combinations of size 5 to get what type of hand it is. Each hand type was modified so that is starts with a number. ("royal flush" -> "0royal 4flush", "high card" -> "9high card"). This allows us to sort strings that were returned. The first string after sorting is the best possible hand. So we print that after removing all numbers from the string.
o,p=%w(4flush 1straight)
f=/1{5}|1{4}0+1$/
puts $*.combination(5).map{|z|s=[0]*13;Hash[*z.map{|c|s['23456789TJQKA'.index c[0]]+=1;c[1]}.uniq[1]?[f,'5'+p,?4,'2four'+a=' of a kind',/3.*2|2.*3/,'3full house',?3,'6three'+a,/2.*2/,'7two pair',?2,'8one pair',0,'9high card']:[/1{5}$/,'0royal '+o,f,p+' '+o,0,o]].find{|r,y|s.join[r]}[1]}.sort[0].gsub(/\d/,'')

Nice. The gsub at the end can just be a sub right?

@bazzargh no it needs to remove all numbers. The code concatenates 4flush with 1straight or 0royal to get "0royal 4 flush" or "1straight 4flush". If we only use sub the 4 wouldn't be removed.

Gives the wrong result for AS QS JS TS 9S 5H 5D. That's gonna cost you a character!

@WumpusQ.Wumbley Hmm this seems to be a bug in the original code. I'll try and figure out what the problem is later.

Haskell 618 603 598 525 512 504 480 464
Cards taken as a line of input. I think I've golfed this to death, but will easily be beaten by ruby etc using the same trick: if you generate all permutations, you get the forward sorts you want to look for straights, plus the reverse sorts you want for testing N of a kind.
import Data.List
m=map
z=take 5
q=m(\x->head[n|(f,n)<-zip"A23456789TJQK"[1..],f==x!!0])
l=m length
v=" of a kind"
w="flush"
y="straight"
c f s p r|f&&r="9royal "++w|f&&s='8':y++" "++w|f='5':w|s||r='4':y|True=case p of 4:_->"7four"++v;3:2:_->"6full house";3:_->"3three"++v;2:2:_->"2two pair";2:_->"1one pair";_->"0high card"
d x=c([5]==l(group$m(!!1)x))(q x==z[head(q x)..])(l$group$q x)$q x==1:[10..13]
k h=tail$maximum$m(d.z)$permutations$words h
main=interact k

Edited to inline "pair" and use number prefixes after seeing @FDinoff's entry, also composed map functions to shave one more char.

You can save yourself a couple characters (about 5 i think) if you get rid of u. "one pair","two pair" is shorter then u=" pair" ... "one"++u,"two++u

yup, I was just making that change after reading your code. Also the number prefix technique saves me another 5

perl (>=5.14), 411 403 400 397 400
Edit: inlined a sub that was only called once, saving 8 chars.
Edit 2: removed a ."" that was left over from an early attempt
Edit 3: instead of a temp variable that preserves the original $_, use one to make it unnecessary. Net gain 3 chars.
Edit 4: fixed failure to detect over-full full house (2x 3-of-a-kind). cost 3 chars.
Not quite a winner, but the straight detector is an interesting concept, I think.
sub
j{join"",sort@_}sub
o{j(map{{A=>10}->{$_},11+index(j(2..9).TJQKA,$_)}$h=~/(.(?=@_))/g)=~/.*(..)(??{j
map$1+$_.'.*',1..4})/?$1:()}$h=$_=<>;if(j(/(\S)\b/g)=~/(.)\1{4}/){$w=$_==19?royal:straight
for
o$f=$1}$_=j(/\b(\S)/g)=~s/(.)\1*/length$&/rge;$k=" of a kind";print$w?"$w flush":/4/?four.$k:/3.*2|[23].*3/?"full house":$f?flush:(o".")?straight:/3/?three.$k:/2.*2/?"two pair":/2/?"one pair":"high card"

Expanded version:
# We'll be doing a lot of sorting and joining
sub j {
  return join "", sort @_;
}

# r() expects $_ to contain a rank, and converts it to a numeric code. The
# code starts at 10 so the numbers will sort correctly as strings, and a list
# of 2 values is returned because A is both 10 and 23. All other ranks have
# undef as the first value and their proper 11..22 value as the second value.
sub r {
  return ({A=>10}->{$_}, 11+index(j(2..9).TJQKA,$_));
}

# Sequence-detector. Factored into a sub because it's run twice; once over
# the ranks in the flush suit to find a straight flush and once over all the
# ranks to find a straight. On successful match, returns the lowest rank of
# the straight (in the 10..23 representation).
# Required parameter: the suit to search, or "." for all suits.
sub o {
  j(map r,$h=~/(.(?=@_))/g)          # The list of ranks, in increasing order,
                                     # with ace included at both ends...
    =~                               # ...is matched against...
  /.*(..)(??{j map$1+$_.'.*',1..4})/ # ...a pattern requiring 5 consecutive
                                     # numbers.
  ?$1:()
  # A note about this regexp. The string we're matching is a bunch of numbers
  # in the range 10..23 crammed together like "121314151619" so you might
  # worry about a misaligned match starting on the second digit of one of the
  # original numbers. But since that would make every pair of digits in the
  # match end with a 1 or a 2, there's no way 5 of them will be consecutive.
  # There are no false matches.
  # Another note: if we have a royal flush and also have a 9 in the same
  # suit, we need to return the T rank, not the 9, which is why the regexp
  # starts with a .*
}

# Read a line into $_ for immediate matching with /.../ and also save it into
# $h because $_ will be clobbered later and we'll need the original string
# afterwards.
$h = $_ = <>;

if(j(/(\S)\b/g) =~ /(.)\1{4}/) { # flush detector: sorted list of all suits
                                 # contains 5 consecutive identical chars
  # $f=$1 comes first, so $f will be true later if there's a flush.
  # Then o() is called with the flush suit as arg to detect straight flush.
  # If there's no straight flush, o() returns the empty list and for loop
  # runs 0 times, so $w is not set. If there is a straight flush, the return
  # value of o() is compared to 19 to detect royal flush.
  $w = ($_==19 ? "royal" : "straight")
    for o($f=$1);
}

$_ =
  j(/\b(\S)/g)                 # Get the sorted+joined list of ranks...
    =~ s/(.)\1*/length $&/rge; # ... and turn it into a list of sizes of
                               # groups of the same rank. The /r flag
                               # requires perl 5.14 or newer.

print
  $w             ? "$w flush" :
  /4/            ? "four of a kind" :
  /3.*2|[23].*3/ ? "full house" :
  $f             ? "flush" :
  (o".")         ? "straight" :
  /3/            ? "three of a kind" :
  /2.*2/         ? "two pair" :
  /2/            ? "one pair" :
                   "high card"

C++, 622 553 chars
four unnecessary newlines added below for clarity.
#include"stdafx.h"
#include"string"
std::string c=" flush",d=" of a kind",e="straight",z[10]={"high card","one pair","two pair","three"+d,e,c,"full house","four"+d,e+c,"royal"+c},
x="CDHSA23456789TJQK";char h[99];int main(){__int64 f,p,t,g,u,v,w,l=1,a=78517370881,b=a+19173960,i,j,q=0;gets_s(h,99);for(i=28;i-->7;){f=p=0;
for(j=7;j--;)if(j!=i%7&j!=(i+i/7)%7){f+=l<<x.find(h[j*3+1])*6;p+=l<<x.find(h[j*3])*3-12;}
v=p&b*2;u=v&v-1;w=p&p/2;g=p*64&p*8&p&p/8&p/64;f&=f*4;t=f&&p==a?9:f&&g?8:p&b*4?7:u&&w?6:f?5:g||p==a?4:w?3:u?2:v?1:0;
q=t>q?t:q;}puts(z[q].c_str());}

Things changed in the golfed version:
Rev 1: Changed all numeric variables to __int64 for single declaration.
Rev 1: Golfed increment and condition of for loops
Rev 0: Changed octal constants to decimal.
Rev 0: Changed if statements to assignments with conditional operator. Rev 1: Rearranged further into a single expression for t. This required new variable v for one of the intermediate values
Rev 0: Deleted verbose output. Only outputs the best overall hand.
 Rev 0: Gave up on compressing the output text (difficult in C because you can't concatenate strings using the + operator.) Writing "flush" only once saved me 12 characters but cost me 15, making me 3 chars worse off overall. So I just wrote it 3 times instead.  Rev 1: used std::string instead of char[] as suggested by FDinoff, making it possible to concatenate with +.
Ungolfed version, 714 noncomment nonwhitespace characters.
Loops through all 21 possible hands that can be made from 7 cards and rejects 2 cards each time. The suit and rank of the five chosen cards are totalised in variables f and p with a different octal digit for each suit/rank. Various bit operations are performed to determine the hand type, which is then stored in t (all 21 possibilities are output in the ungolfed version.) Finally the best possible hand is output.
#include "stdafx.h"
#include "string.h"

char x[] = "CDHSA23456789TJQK", h[99], z[10][99] =
{ "high card", "one pair", "two pair","three of a kind", "straight","flush","full house","four of a kind","straight","royal" };

int main(void)
{
        int i,j,q=0;                  //i,j:loop counters. q:best possible hand of 7 card
        scanf_s("%s/n", &h, 99); getchar();
        for (i = 7; i < 28; i++){

          //f,p: count number of cards of each suit (2 octal digits) and rank (1 octal digit.)
          //t: best hand for current 5 cards. g:straight flag. u,w: flags for pairs and 3's.
          //l: constant 1 (64bit leftshift doesn't work on a literal.)
          //octal bitmasks: a=ace high straight, b=general purpose

            __int64 f=0,p=0,t=0,g,u,w,l=1,a=01111000000001,b=a+0111111110;

           for (j = 0; j < 7; j++){
               if (j != i %7 & j != (i+i/7) %7){

                   f += l << (strchr(x,h[j*3+1])-x)*6;
                   p += l << (strchr(x,h[j*3])-x-4)*3;

                   printf_s("%c%c ",h[j*3], h[j*3+1]);
               }
           }

           w=p&b*2;                          //if 2nd bit set we have a pair
           if (w) t=1;
           u= w & w-1;                       //if there is only one pair w&w-1 evaluates to 0; +ve for 2 pair.
           if (u) t=2;
           w = p & p/2;                      // if 2nd and 1st bit set we have 3 of kind.
           if (w) t=3;
           g = p*64 & p*8 & p & p/8 & p/64;  // detects all straights except ace high. pattern for ace high in a.
           if (g||p==a) t=4;
           f&=f*4;                           //for a flush we want 5 cards of the same suit, binary 101
           if (f) t=5;
           if (u&&w) t=6;                    //full house meets conditions of 2 pair and 3 of kind
           if (p & b*4) t=7;                 //four of a kind
           if (f && g) t=8;                  //straight flush
           if (f && p==a) t=9;               //royal flush
           printf_s("%s %s \n",z[t],t>7?z[5]:"");
           q=t>q?t:q;
        }
        printf_s("%s %s",z[q],q>7?z[5]:"");
        getchar();
}

Ungolfed output

Since you say you are using c++ you could use <string> which does support + for string concatenation. Which then means you could probably use <iostream> and use cout However I don't actually know if any of those would lead to smaller character count.

@FDinoff what I could save: " pair flush flush straight of a kind"=35 chars. Once you add in #include savings are minimal, then you have to consider extra ",=+ and declarations of constants. Also I'm new to C++ and struggling with IDE and compiler settings (it forces me to use scanf_s and printf_s instead of the old "unsafe" versions and the help about fixing it goes round in circles.) cout might help a little, it's on my to do list, but probably for another program. The thing that kills cout for me is using namespace std I don't know if there's a way to avoid writing all that.

You should almost never need printf and scanf since you are using c++. There are other (safer) was to do the same thing. You could use std::cout to get around the using namespace std

@FDinoff thx for the tip. In my latest edit I saved 18 bytes w different string handling: gets_s & puts, plus std::string to concatenate, which means I must convert to char* to output. The golf I posted works with just string or just iostream. Bizarrely I must include both to use <<>> operators with cin/cout & std::strings. Overall, using both #includes works out 5 bytes worse, even though i can declare h as a std::string and avoid a separate char declaration. Predictably, I cant find a list of what's in namespace std in help (or an explanation about the operator.)

@FDinoff I agree, I wouldn't normally use scanf and gets, except for golfing, where programs are pretty unsafe anyway. I could shorten by 5 bytes -s,99 if I could use gets instead of gets_s, but I can't get the compiler to let me. What surprises me is how unsafe C/C++ is in general! A few weeks ago it would have shocked me to find that _int64 x=1<<y gives the wrong answer for y greater than 31. But now I'm just mildly annoyed. Having seen things with array subscripts going out of bounds with no error message, I've got used to it. Is there any way of turning better checking on?

If you had used 1L << 32 (or 1LL) the shift should have worked. 1 is of int type which on your machine was probably only 32 bits. Where long (or long long) would have been the 64 bits that you were expecting. Array's going out of bounds is a logic error and can't always be caught by the compiler (since it does no bounds checking). You might be able to get a decent amount of warning turned on if you used -Wall -Wextra as parameters to your compiler.

JavaScript 600
usage with nodeJS: node code.js "7H 3S 7S 7D AC QH 7C"
function a(o){s="";for(k in o)s+=o[k];return s}
b=process.argv[2]
c={S:0,H:0,D:0,C:0}
v={A:0,K:0,Q:0,J:0,T:0,"9":0,"8":0,"7":0,"6":0,"5":0,"4":0,"3":0,"2":0}
d=b.split(" ")
for(i=d.length;i--;){e=d[i];c[e[1]]++;v[e[0]]++}
c=a(c);v=a(v)
f=g=h=j=k=l=m=false
if((st=c.indexOf(5))!=-1)g=!g
if(v.match(/[1-9]{5}/))h=!h
if(st==0)f=!f
if(v.indexOf(4)!=-1)j=!j
if(v.indexOf(3)!=-1)k=!k
if(n=v.match(/2/g))if(n)if(n.length>=2)m=!m;else l=!l
p=" of a kind"
q="Flush"
r="Straight"
console.log(f&&g?"Royal "+q:h&&g?r+" "+q:j?"Four"+p:k&&(l||m)?"Full House":g?q:h?r:k?"Three"+p:m?"Two pairs":l?"Pair":"High card")

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


text:
Output the first 200 primes using TeX
Write a plain TeX program that lists the first two hundred primes (in base-10 notation). Including external files/resources is not permitted. The output may be to the terminal, the log file, or the actual dvi/pdf file, at your option, but should be easily readable to a human; in particular, there must be some delimiter (comma, space, newline,...) between consecutive primes. e-TeX and pdfTeX primitives are permitted. See this answer for a starting place.
Hard-coding the result is permitted, although I do not expect such an answer to win.
The answer with the lowest byte count wins.

What prevents us from just hard-coding the results? It might even be shorter than some code to generate them.

@Jan Dvorak I guess this post prevents that.

If this wasn't just using TeX, it would be a duplicate.  It is also generally frowned on to limit languages.

@hosch250: That's why I tagged this code-challenge rather than code-golf.

@Jan Dvorak: See edit.

Concerning limiting languages: The point of this post is that programming in TeX is inherently difficult, and adds a significant extra challenge beyond simply producing brief code in a language that was actually designed to be programmed in.

"The answer with the lowest byte count wins." means code-golf. A code challenge is a competition for creative ways to solve a programming puzzle with an objective winning criterion not covered by other scoring tags (e.g. code-golf). http://codegolf.stackexchange.com/tags/code-challenge/info

@ace: I interpreted limiting the language as an additional winning criterion not covered by code-golf. I wanted to use a tag like tex or tex-golf, but did not have the reputation to create one.

Language limitation is not a scoring criterion (which is the primary differentiator of the tags), it's an eligibility criterion. I am keen to see participation on the site broaden to a wider variety of languages, but I don't see language-specific challenges as the best path to that destination. The site is still growing, and when someone who loves language X finds a rich trove of language-agnostic questions to attempt, it is easier for them immediately participate in one that appeals to them.

@Jonathan Van Matre: Your point regarding scoring versus eligibility criteria is well taken. For the other point, there are certain languages (TeX, brainf**k, template metaprogramming, ...) that no one would use for a programming task without a good reason. I'm curious to see how whether this community welcomes questions in which part of the challenge is to use such an otherwise unsuitable language.

176 bytes (plain TeX without e-TeX or pdfTeX)
\let\n\newcount\n~\n\j\n\k2~3\loop\ifnum~<1224{\let\x.\j3\loop\ifnum\j<~\k~\divide\k\j\multiply\k\j\ifnum\k=~\let\x!\fi\advance\j2\repeat\ifx\x., \the~\fi}\advance~2\repeat\end

Algorithm
The algorithm is quite simple. It outputs the first prime number 2 and goes from the next prime number 3 to the 200th prime number 1223.
Each number i is tested, if the odd number is divisible by 3 up to i-1 without even numbers (thanks Howard for the removal of the even numbers).
There is much room for optimizations of the run-time, e.g.:

The inner loop can be aborted, when the first divisor is found, see the comments.
The divisions only need to be done up to sqrt(i).

The result is a paragraph with comma separated numbers:

Ungolfed version
% assign some count registers with short names
\newcount\i
\newcount\j
\newcount\k
% Output first prime number 2
2%
% Start loop with second prime number 3
\i=3 %
\loop
\ifnum\i<1224 % 1223 is 200th prime number
  {% group with curly braces because of the nested \loop
    \let\x=. % \x is changed, if \i is not prime
    % Test for all 2 <= j < i: trunc(i/j)*j == i
    % If true, then j is divisor of i and i is not prime
    \j=3
    \loop
    \ifnum\j<\i
      \k=\i
      \divide\k by \j
      \multiply\k by \j
      \ifnum\k=\i
        \let\x=! % \i is not prime
        % Optimization to break the loop:
        %   \let\iterate\empty
        % Then also \x can be removed: If the loop is not aborted,
        % then \iterate will have the meaning \relax and the
        % test "\ifx\x." can be replaced by "\ifx\iterate\relax".
      \fi
      \advance\j by 2
    \repeat
    \ifx\x.
      , \the\i % output prime number
    \fi
  }%
  \advance\i by 2 % test next odd number
\repeat
\end % end of job

Variant: Output in protocol file, 195 bytes
\let\n\newcount\n~\n\j\n\k~2\def\w{\wlog{\the~}}\w~3\loop\ifnum~<1224{\let\x.\j3\loop\ifnum\j<~\k~\divide\k\j\multiply\k\j\ifnum\k=~\let\x!\fi\advance\j2\repeat\ifx\x.\w\fi}\advance~2\repeat\end

The result is written to the .log file:
This is TeX, Version 3.1415926 (TeX Live 2013) (format=tex 2013.5.21)  11 MAR 2014 18:33
**test
(./test.tex
~=\count26
\j=\count27
\k=\count28
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97
101
103
107
109
113
127
131
137
139
149
151
157
163
167
173
179
181
191
193
197
199
211
223
227
229
233
239
241
251
257
263
269
271
277
281
283
293
307
311
313
317
331
337
347
349
353
359
367
373
379
383
389
397
401
409
419
421
431
433
439
443
449
457
461
463
467
479
487
491
499
503
509
521
523
541
547
557
563
569
571
577
587
593
599
601
607
613
617
619
631
641
643
647
653
659
661
673
677
683
691
701
709
719
727
733
739
743
751
757
761
769
773
787
797
809
811
821
823
827
829
839
853
857
859
863
877
881
883
887
907
911
919
929
937
941
947
953
967
971
977
983
991
997
1009
1013
1019
1021
1031
1033
1039
1049
1051
1061
1063
1069
1087
1091
1093
1097
1103
1109
1117
1123
1129
1151
1153
1163
1171
1181
1187
1193
1201
1213
1217
1223
 )
No pages of output.

Variant: Counting prime numbers, 197 bytes
The following variant also counts the prime numbers to get rid of the "hard-coded" 200th prime number. (I have added this variant at the end, because the question would also allow to hard-code all prime numbers.)
\let\a\advance\let\n\newcount\n\p\n~\n\j\n\k2\p1~3\loop\ifnum\p<200{\let\x.\j3\loop\ifnum\j<~\k~\divide\k\j\multiply\k\j\ifnum\k=~\let\x!\fi\a\j2\repeat\ifx\x., \the~\global\a\p1\fi}\a~2\repeat\end

Most basic improvement (without cost): also step the j loop by 2 instead of one.

@devnull: The question explicitly allows the hard-coding of all prime numbers, thus it is not cheating. However, I have also added a variant that counts prime numbers.

@Howard: Thanks, answer updated.

Oh, jeez! I didn't realize that you're the hyperref guy (besides much more contribution to CTAN).  Thanks for all the great work.  (Besides it's not hard to imagine that there cannot be better answer to this thread :-) )


text:
Determine the critical path
In project management there's a method, called the critical path method, that is used for scheduling activities and for determining which activities' timings are crucial (i.e. critical) and for which activities the schedule offers a timing tolerance.
Your program's task is to order a set of activities chronologically and for each of those activities determine their:

earliest possible start;
earliest possible finish;
latest possible start;
latest possible finish.

Lastly, your program should mark which subsequent activities make up the longest, uninterrupted path; i.e. the critical path.
The input will be the activities by their name, with their duration (in an unspecified time unit) and with the names of the activities they depend on.  For this challenge only so-called finish to start dependencies will be presented as input. In other words: any possibly provided dependencies for a given activity signify that said activity can only start when all the activities, that this activity depends on, have finished. No other forms of dependencies will be presented.
The expected input is in the form of (possibly multiples of):
[F:12;C,B]
Where:

F signifies the activity's name; an uppercase alphabetic character;
12 signifies the duration as a positive integer;
C,B signifies the optional dependencies, as a comma-separated list of activity names.

Here's an example input:
[A:15][B:7][C:9;A,B][D:3;B,C][E:5;C][F:11;D][G:4;D,E,F]
Meaning:
 name | duration | dependencies
------+----------+--------------
    A |       15 |
    B |        7 |
    C |        9 |          A,B
    D |        3 |          B,C
    E |        5 |            C
    F |       11 |            D
    G |        4 |        D,E,F

Your program's output will be an ASCII table, in the exact following form, but filled with different data, depending on the input of course (here I'm using the example input, from above, as input):
 name | estart | efinish | lstart | lfinish | critical
------+--------+---------+--------+---------+----------
    A |      0 |      15 |      0 |      15 |        Y
    B |      0 |       7 |      8 |      15 |        N
    C |     15 |      24 |     15 |      24 |        Y
    D |     24 |      27 |     24 |      27 |        Y
    E |     24 |      29 |     33 |      38 |        N
    F |     27 |      38 |     27 |      38 |        Y
    G |     38 |      42 |     38 |      42 |        Y

Where:

the activities are ordered chronologically ascending by estart (and then arbitrarily);
estart is earliest start;
efinish is earliest finish;
lstart is latest start;
lfinish is latest finish;
critical is a Y/N value, signifying whether this activity belongs to the critical path (i.e. lstart - estart = 0 and lfinish - efinish = 0).

The expected constraints for the input will be:

The activity names will never exceed Z; i.e. the total amount of activities will never exceed 26;
The total duration (i.e. the latest finish of the last activity) will never exceed 9999999 (the width of the lfinish column, with padding);
The number of dependencies, for any given activity, will never exceed 6;
The input will never be inconsistent (e.g. no non-existent dependencies, etc.).

The constraints for your program are:

No use of existing PM/CPM APIs1; you must create the algorithm from scratch.

This is a popularity-contest2; the most elegant solution (or at least, I hope that's what voters will vote for), by popular vote, wins. The winner will be determined 4 days after the submission time of this challenge.

1. If any such API even exists.
2. I want to give the more verbose languages a fair shot at this as well.

Personally, this would be more interesting for me as a code-golf challenge. There is an exact spec with zero variability, and I don't see too many different algorithms one could apply, which makes it perfect to optimize for low char count.

@Claudiu I see where you're coming from, but I just got a little bored with seeing the Js, APLs and GolfScripts coming up on top in every code-golf challenge. I wanted to see the more verbose languages have a decent shot at this as well, and not be discouraged beforehand already. I agree with you though, that there are probably not that many approaches to be taken in this challenge.

GolfScript
A GolfScript solution - just because it can be done.
# Parse input
'['-']'%:I{[.1<\2>';'/(~\{','/{`{\1<=}+I?I?}/}%0]}%

# Determine estart iteratively
{:A{[~{A=~@+\;\;}2$%+$-1=]}%.A=!}do

# Invert dependencies
A{~@+\;\;}%$-1=:M;
[.,,]zip{[~{\~\2=@?0<{;}*}+[A.,,]zip%\:^~;;@^3=M]}%

# Determine lfinish iteratively
{:A{[~{A=~\;\;\-\;}3$%+$0=]}%.A=!}do

# Print results

# Formats numbers (right aligned, 7 chars)
{`"       "\+-7>}:F;

" name | estart | efinish | lstart | lfinish | critical \n"
"------+--------+---------+--------+---------+----------\n"
@{"    "\(" |"@.2=F" | "@.~;@+\;F" |"@.~\;\;\-F" | "@.3=F" |        "@~-\;+!"NY"1/=n}%

Example (online):
> [A:15][B:7][C:9;A,B][D:3;B,C][E:5;C][F:11;D][G:4;D,E,F]

 name | estart | efinish | lstart | lfinish | critical
------+--------+---------+--------+---------+----------
    A |      0 |      15 |      0 |      15 |        Y
    B |      0 |       7 |      8 |      15 |        N
    C |     15 |      24 |     15 |      24 |        Y
    D |     24 |      27 |     24 |      27 |        Y
    E |     24 |      29 |     33 |      38 |        N
    F |     27 |      38 |     27 |      38 |        Y
    G |     38 |      42 |     38 |      42 |        Y

This is like that scene in Chasing Amy when the normally laconic Silent Bob launches into an extended monologue.

Sure  it's epic, but how is it elegant? The only thing that doesn't look like line noise are those two string literals at the end :-)

C#, many many characters.
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
    class Program
    {
        static char[] COLON = { ':' };
        static char[] SEMI_COLON = { ';' };
        static char[] COMMA = { ',' };
        static char[] BRACE = { ']' };

        static void Main(string[] args)
        {
            int step = 0;

            List<Activity> i = new List<Activity>();
            Console.Write("Enter input: ");
            string s = Console.ReadLine().Replace("[", null);
            foreach (string x in s.Split(BRACE, StringSplitOptions.RemoveEmptyEntries))
            {
                string[] y = x.Split(SEMI_COLON);
                Activity n = new Activity(x.Split(COLON)[0], Int32.Parse(y[0].Split(COLON)[1]));
                n.Name = x.Split(COLON)[0];
                n.Dependencies = (y.Length > 1) ? y[1].Split(COMMA).ToList() : new List<string>();
                i.Add(n);
            }

            do
            {
                List<string> d = i.Where(x => x.Done()).Select(y => y.Name).ToList();
                foreach (Activity working in i.Where(x => x.Dependencies.Except(d).Count() == 0 && !x.Done())) working.Step(step);
                step++;
            } while (i.Count(x => !x.Done()) > 0);

            foreach (Activity a in i)
            {
                Activity next = i.OrderBy(x => x.EFinish).Where(x => x.Dependencies.Contains(a.Name)).FirstOrDefault();
                a.LFinish = (next == null) ? a.EFinish : next.EStart;
                a.LStart = a.LFinish - a.Duration;
            }

            Console.WriteLine(" name | estart | efinish | lstart | lfinish | critical");
            Console.WriteLine("------+--------+---------+--------+---------+----------");
            foreach (Activity a in i)
            {
                Console.Write(a.Name.PadLeft(5) + " |");
                Console.Write(a.EStart.ToString().PadLeft(7) + " |");
                Console.Write(a.EFinish.ToString().PadLeft(8) + " |");
                Console.Write(a.LStart.ToString().PadLeft(7) + " |");
                Console.Write(a.LFinish.ToString().PadLeft(8) + " |");
                string critical = (a.LFinish - a.EFinish == 0 && a.LStart - a.EStart == 0) ? "Y" : "N";
                Console.WriteLine(critical.PadLeft(9));
            }
            Console.WriteLine("Hit any key to exit.");
            Console.ReadKey();
        }
    }

    class Activity
    {
        public string Name {get ; set;}
        public int Duration {get ; set;}
        public List<string> Dependencies {get ; set;}
        public int EStart {get ; set;}
        public int EFinish {get ; set;}
        public int LStart { get; set; }
        public int LFinish { get; set; }
        private int steps = 0;

        public Activity(string name, int time)
        {
            EStart = -1;
            EFinish = 0;
            LStart = 0;
            LFinish = 0;
            Name = name;
            Duration = time;
            steps = time;
        }

        public void Step(int count)
        {
            EStart = (EStart == -1) ? count : EStart;
            if (--steps == 0) EFinish = count + 1;
        }

        public bool Done()
        {
            return steps == 0;
        }
    }
}

I would hesitate to call this "the most elegant solution", but it trades the verbosity of C# for ease of parsing input and formatting output (and has Linq).
I basically just loops through all of the activities and increments a time counter if all their dependencies have been completed until all of them are done.  That gives the earliest starts and earliest finishes.  The latest finish for each is simply the earliest start among activities that have it as a dependency, and the latest start is the activity duration minus the latest start.

Haskell, 39 LoC
import Control.Exception.Base (assert)
import Data.List
import Data.Maybe (fromJust)
import Text.Printf

splitBefore x = groupBy (\_ y -> x /= y)

data Activity = Activity {aName :: Char, aLength :: Int, depNames :: [Char]}
                deriving (Eq, Ord, Show)

instance Read Activity where
  readsPrec _ ('[' : aName : ':' : rest1) =
    let [(aLength, rest2)] = reads rest1 :: [(Int, String)]
        (rest3, ']':rest) = span (/= ']') rest2
        depNames = map (\[_,x] -> x) $ splitBefore ',' $ rest3
    in  [(Activity {aName = aName, aLength = aLength, depNames = depNames},rest)]

main = getLine >>= putStrLn . \input ->
  let activities = map read $ splitBefore '[' $ input :: [Activity]
      activityByName a = fromJust . find ((a ==) . aName) $ activities
      dependencies = map activityByName . depNames
      dependents a = filter ((a `elem`) . dependencies) $ activities
      estart   a = case dependencies a of
                     [] -> 0
                     ds -> maximum $ map efinish ds
      efinish  a = estart a + aLength a
      critLength = maximum $ map efinish $ activities
      lfinish  a = case dependents a of
                     [] -> critLength
                     ds -> minimum $ map lstart ds
      lstart   a = lfinish a - aLength a
      critical a = estart a == lstart a
      format   a = printf " %4c | %6d | %7d | %6d | %7d | %8c "
                     (aName a) (estart a) (efinish a) (lstart a) (lfinish a)
                     (if critical a then 'Y' else 'N')

  in  unlines $ " name | estart | efinish | lstart | lfinish | critical "
              : "------+--------+---------+--------+---------+----------"
              : map format activities


text:
The Final Stand - Defeat the Zombie Horde
Introduction
You are alone on an island. The remainder of humanity is dead (probably due to the bug in user12345's code). The Zombie Pirate Horde has reached your island, and they are endless. It's time to kick ass or chew bubble gum, and you're all outta bubble gum.
Problem
Our doomsday scenario is described by 2 integers on a single line, m and n. On your island are outposts uniquely numbered from 1 to m. The following n lines each contain three integers, x, y, and z, separated by a space. x and y are the unique IDs of two outposts, and z is the number of zombies that will be encountered on the path between them.
When you travel a path, you lose z ammunition and you kill z zombies. If you travel the same path again, you will encounter the same number of zombies, unfortunately. All outposts generate +1 ammunition each time you travel a path. You begin with 100 ammunition at outpost 1. All outposts begin with 0 ammunition. You die immediately if no path exists for which your ammunition is greater than the number of zombies on that path, and the remainder of your ammunition is converted to kills. Such is your final stand.
Write a program that outputs the maximum number of zombies you can kill for a given scenario. If you can kill an infinite number of zombies, simply output x.
Example Input
5 6
1 2 4
2 3 4
3 1 4
2 4 10
2 5 10
1 1 50

Example Output
x

Assumptions

A path will be between two valid outposts. That is to say 1 <= x/y <= m
If a path between x and y is not listed, it cannot be traveled
A path is bidirectional
1 < m <= 100
1 < n <= 500
Input must be provided through stdin, read from a file, or accepted as a sole argument to the program, and it must exactly follow the format of the example
The runtime of your program may be arbitrarily large but must be determinably finite

The code with the fewest characters wins!

Does each outpost other than 1 start with 0 ammo? Is the graph undirectional?

It would probably also be useful to pre-empt a certain class of bugs by having a test case in which there is a cycle which doesn't run down your ammo but which can't be reached in time. (I should add that I'm not convinced that the current test case is correct: it seems to me that the cycle 1->1 costs 49 ammo, and the cycle 1->2->3->1 costs 3 ammo in the long run.

@PeterTaylor I had to retract both of my comments because it appears that I made the example bidirectional. So allow me to start over - all paths are bidirectional and all outposts start with 0. The example should now work.

@Rusher: Nice example! Took me 45 steps to show myself that it is indeed infinitely sustainable. Can we assume that all outposts will be reachable or do you want us to handle the case where there are outposts disconnected from the main graph?

@Claudiu You aren't the only one - http://imgur.com/3VfSNiG . Don't assume all outposts will be reachable. When our team solved this one in Java, we didn't need a special case for unreachable nodes. We simply never visited them.

@m.buettner Two nodes can have more than one path. In fact, the requirements hold that n > 1. They could loop like 1 to 1, or you could simply have two paths between 1 to 2. One could even be shorter than the other.

@PeterTaylor: The cycle 1->2->3->1 costs 6 ammo not 3, how did you get this result ? EDIT : the first cycle costs 6 but next cycles cost 3... Ok, sorry !!!

I don't understand the refuelling: "All outposts generate +1 ammunition each time you travel a path." In your example, starting with 100 ammo and going from 1 to 2, does this mean that I use 4 ammo and get 5 back?

@Tobia If 1 -> 2 is your very first move, you'll lose 4 ammo and then gain 1 ammo. How would you get 5 ammo back if only 1 ammo is generated per turn? If you visit an outpost on turn 5 that you have never visited before, then you can get 5 ammo from it.

24 steps to a cost neutral path = 1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,2,4,2,5,2,3 (it is cost neutral from the second iteration onwards).

Ahhh... So for each step from A to B, every outpost "generates" an ammo and keeps it there until you visit it.

Java ( less grotesque: 8415 5291 3301)
Ok. Basically, I'm embarrassed no-one has submitted a solution. So a few days ago I began trying to solve this problem, b/c it's great.. Follow that link to watch my progress on it via GitHub.
Edit
New solver version, much more "golfed", with corrected cycle checker as identified by MT0. It also supports fast-forwarding routes, tuneable by changing how much memory is available to the VM. Latest BIG edit: realized that I had a few other small index errors and premature optimizations, that resulted in a failure to consider quite a large number of types of wins. So that's fixed, carefully. The new version is both smaller and below.
For our reference route, java -Xmx2GB ZombieHordeMin does the trick quite nicely (be warned, it will take a while).
Cool factoid
In a fascinating twist, there are MANY solutions at length 24, and my solver finds one different from MT0's, but identical in principle, except that it starts by visiting the the other outposts connected to 1. Fascinating! Totally counter human intuition, but perfectly valid.
Solution Highlights
So here's mine. It's (partially) golfed, b/c it's an exponential, almost-brute-force solver. I use an IDDFS (iterative deepening depth first search) algorithm, so it's a great general solver that doesn't skip, so it solves both parts of the OP's question, namely:

If a winning route is found (infinite zombies), output 'x'.
If all routes end in death (finite zombies), output the largest number of zombies killed.

Give it enough power, memory, and time, and it will do just that, even slow-death maps. I spent some more time improving this solver, and while more can be done, it's a bit better now. I also integrated MT0's advice on the best infinite-zombies solution, and removed several premature optimizations from my win-checker that prevented the previous version from finding it, and now I do in fact find a very similar solution to the one MT0 described.
A few other highlights:

As mentioned, uses an IDDFS to find the shortest possible winning route.
Since it is at core a DFS, it will also discover if every route ends in the death of our hero, and keeps track of the "best" route in terms of most zombies killed. Die a hero!
I've instrumented the algorithm to make it more interesting to watch Removed for golfing purposes. Follow one of the links to github to see the ungolfed version.
There are a number of comments throughout as well, so feel free to re-implement for your own solution building on my approach, or show me how it should be done!
Memory-adaptive route fast-forwarding

Up to available system memory, will keep track of "end routes" that did not result in death.
Using a fancy route compression and decompression routine, progress from a prior iteration of IDDFS is restored to prevent rediscovery all prior visited routes.
As an intentional side-bonus, acts as a dead-end route cull. Dead end routes aren't stored, and will never be visited again in future depths of IDDFS.

History of the solver

I tried a bunch of one-step look-ahead algorithms, and while for very simple scenarios they would work, ultimately they fall flat.
Then I tried a two-step look-ahead algorithm, which was.. unsatisfying.
I then began building an n-step lookahead, when I recognized that this approach is reducible to DFS, yet DFS is far ... more elegant.
While building the DFS, it occurred to me that IDDFS would ensure (a) find best HERO (death) route or (b) first winning cycle.
Turns out building a win-cycle checker is easy, but I had to go through several very very wrong iterations before I got to a provably successful checker.
Factored in MT0's win-path to remove three lines of premature optimization that made my algorithm blind to it.
Added an adaptive route-caching algorithm that will use all the memory you give it to prevent unnecessary redoing of work between IDDFS calls, and also culls dead-end routes up to the limits of memory.

The (golfed) code
On to the code (get the ungolfed version here or here):
import java.util.*;public class ZombieHordeMin{int a=100,b,m,n,i,j,z,y,D=0,R,Z,N;int p[][][];Scanner in;Runtime rt;int[][]r;int pp;int dd;int[][]bdr;int ww;int[][]bwr;int[][]faf;int ff;boolean ffOn;public static void main(String[]a){(new ZombieHordeMin()).pR();}ZombieHordeMin(){in=new Scanner(System.in);rt=Runtime.getRuntime();m=in.nextInt();N=in.nextInt();p=new int[m+1][m+1][N+1];int[]o=new int[m+1];for(b=0;b<N;b++){i=in.nextInt();j=in.nextInt();z=in.nextInt();o[i]++;o[j]++;D=(o[i]>D?o[i]:D);p[i][j][++p[i][j][0]]=z;if(i!=j)p[j][i][++p[j][i][0]]=z;D=(o[j]>D?o[j]:D);}m++;}void pR(){r=new int[5000][m+3];r[0][0]=a;Arrays.fill(r[0],1,m,1);r[0][m]=1;r[0][m+1]=0;r[0][m+2]=0;ww=-1;pp=dd=0;pR(5000);}void pR(int aMD){faf=new int[D][];ff=0;ffOn=true;for(int mD=1;mD<=aMD;mD++){System.out.printf("Checking len %d\n",mD);int k=ffR(0,mD);if(ww>-1){System.out.printf("%d x\n",ww+1);for(int win=0;win<=ww;win++)System.out.printf(" %d:%d,%d-%d",win,bwr[win][0],bwr[win][1],bwr[win][2]);System.out.println();break;}if(k>0){System.out.printf("dead max %d kills, %d steps\n",pp,dd+1);for(int die=0;die<=dd;die++)System.out.printf(" %d:%d,%d-%d",die,bdr[die][0],bdr[die][1],bdr[die][2]);System.out.println();break;}}}int ffR(int dP,int mD){if(ff==0)return pR(dP,mD);int kk=0;int fm=ff;if(ffOn&&D*fm>rt.maxMemory()/(faf[0][0]*8+12))ffOn=false;int[][]fmv=faf;if(ffOn){faf=new int[D*fm][];ff=0;}for(int df=0;df<fm;df++){dS(fmv[df]);kk+=pR(fmv[df][0],mD);}fmv=null;rt.gc();return kk==fm?1:0;}int pR(int dP,int mD){if(dP==mD)return 0;int rT=0;int dC=0;int src=r[dP][m];int sa=r[dP][0];for(int dt=1;dt<m;dt++){for(int rut=1;rut<=p[src][dt][0];rut++){rT++;r[dP+1][0]=sa-p[src][dt][rut]+r[dP][dt];for(int cp=1;cp<m;cp++)r[dP+1][cp]=(dt==cp?1:r[dP][cp]+1);r[dP+1][m]=dt;r[dP+1][m+1]=rut;r[dP+1][m+2]=r[dP][m+2]+p[src][dt][rut];if(sa-p[src][dt][rut]<1){dC++;if(pp<r[dP][m+2]+sa){pp=r[dP][m+2]+sa;dd=dP+1;bdr=new int[dP+2][3];for(int cp=0;cp<=dP+1;cp++){bdr[cp][0]=r[cp][m];bdr[cp][1]=r[cp][m+1];bdr[cp][2]=r[cp][0];}}}else{for(int chk=0;chk<=dP;chk++){if(r[chk][m]==dt){int fR=chk+1;for(int cM=0;cM<m+3;cM++)r[dP+2][cM]=r[dP+1][cM];for(;fR<=dP+1;fR++){r[dP+2][0]=r[dP+2][0]-p[r[dP+2][m]][r[fR][m]][r[fR][m+1]]+r[dP+2][r[fR][m]];for(int cp=1;cp<m;cp++)r[dP+2][cp]=(r[fR][m]==cp?1:r[dP+2][cp]+1);r[dP+2][m+2]=r[dP+2][m+2]+p[r[dP+2][m]][r[fR][m]][r[fR][m+1]];r[dP+2][m]=r[fR][m];r[dP+2][m+1]=r[fR][m+1];}if(fR==dP+2&&r[dP+2][0]>=r[dP+1][0]){ww=dP+1;bwr=new int[dP+2][3];for(int cp=0;cp<dP+2;cp++){bwr[cp][0]=r[cp][m];bwr[cp][1]=r[cp][m+1];bwr[cp][2]=r[cp][0];}return 0;}}}dC+=pR(dP+1,mD);if(ww>-1)return 0;}for(int cp=0;cp<m+3;cp++)r[dP+1][cp]=0;}}if(rT==dC)return 1;else{if(ffOn&&dP==mD-1)faf[ff++]=cP(dP);return 0;}}int[]cP(int dP){int[]cmp=new int[dP*2+3];cmp[0]=dP;cmp[dP*2+1]=r[dP][0];cmp[dP*2+2]=r[dP][m+2];for(int zip=1;zip<=dP;zip++){cmp[zip]=r[zip][m];cmp[dP+zip]=r[zip][m+1];}return cmp;}void dS(int[]cmp){int[]lv=new int[m];int dP=cmp[0];r[dP][0]=cmp[dP*2+1];r[dP][m+2]=cmp[dP*2+2];r[0][0]=100;r[0][m]=1;for(int dp=1;dp<=dP;dp++){r[dp][m]=cmp[dp];r[dp][m+1]=cmp[dP+dp];r[dp-1][cmp[dp]]=dp-lv[cmp[dp]];r[dp][m+2]=r[dp-1][m+2]+p[r[dp-1][m]][cmp[dp]][cmp[dP+dp]];r[dp][0]=r[dp-1][0]+r[dp-1][cmp[dp]]-p[r[dp-1][m]][cmp[dp]][cmp[dP+dp]];lv[cmp[dp]]=dp;}for(int am=1;am<m;am++)r[dP][am]=(am==cmp[dP]?1:dP-lv[am]+1);}}

Get the code from github here, to track any changes I make. Here are some other maps I used.
Output example
Example output for reference solution:
    $ java -d64 -Xmx3G ZombieHordeMin > reference_route_corrected_min.out
    5 6 1 2 4 2 3 4 3 1 4 2 4 10 2 5 10 1 1 50
    Checking len 1
    Checking len 2
    Checking len 3
    Checking len 4
    Checking len 5
    Checking len 6
    Checking len 7
    Checking len 8
    Checking len 9
    Checking len 10
    Checking len 11
    Checking len 12
    Checking len 13
    Checking len 14
    Checking len 15
    Checking len 16
    Checking len 17
    Checking len 18
    Checking len 19
    Checking len 20
    Checking len 21
    Checking len 22
    Checking len 23
    Checking len 24
    25 x
     0:1,0-100 1:3,1-97 2:1,1-95 3:2,1-94 4:5,1-88 5:2,1-80 6:4,1-76 7:2,1-68 8:1,1-70 9:2,1-68 10:1,1-66 11:2,1-64 12:1,1-62 13:2,1-60 14:1,1-58 15:2,1-56 16:1,1-54 17:2,1-52 18:1,1-50 19:2,1-48 20:1,1-46 21:2,1-44 22:1,1-42 23:2,1-40 24:1,1-38

Read the route output like this: step:source,route-to-get-here-ammo. So in the above solution, you would read it as:

At step 0, at outpost 1 with ammo 100.
At step 1, use route 1 to get to outpost 3 with ending ammo 97
At step 2, use route 1 to get to outpost 1 with ending ammo 95
...

Closing notes
So, I hope I've made my solution harder to beat, but PLEASE TRY! Use it against me, add in some parallel processing, better graph theory, etc. A couple of things I figure could improve this approach:

aggressively "reduce" loops to cut out needless retread as the algorithm progresses.

An example: in the example problem, consider the loops 1-2-3 and other permutations as "one step", so that we can make our way to end-cycle more quickly.
E.g. if you are at node 1, you can either (a) go to 2, (b) go to 1, (c) go through 1-2-3 as one step and so on. This would allow a solved to fold depth into breadth, increasing the number of routes at a particular depth but greatly speeding time-to-solution for long cycles.

cull dead routes. My current solution doesn't "remember" that a particular route is dead-ended, and has to rediscover it every time. It would be better to keep track of the earliest moment in a route that death is certain, and never progress beyond it. did this...
if careful, you could apply the dead route culling as a sub-route cull. By example, if 1-2-3-4 always results in death, and the solver is about to test the route 1-3-1-2-3-4, it should immediately stop descending that path as it is guaranteed to end in disappointment. It would still be possible to calculate # of kills, with some careful math.
Any other solution that trades memory for time, or allows aggressive avoidance of following dead-end routes. did this too!

Nice answer! Who needs to golf their code when they are the only ones who can solve the problem? I am motivated now to write my own solution, so I'll be working on that.

Excellent, that was what I hoped this would do. Feel free to borrow/steal anything from my answer that you find useful! Although of course I hope other folks than just myself and OP will try to solve :P

I got sidetracked and started minifying your code. If you thought your answer was grotesque before, check this out: http://tny.cz/17ef0b3a . Still a work in progress.

Haha, you really did get sidetracked. Looking good (appropriately horrific for code-golf? You know what I mean) so far!

@Rusher Any luck so far? I've got a few ideas for improvements I've been brewing, including a route-representation compression technique and a way to fast-forward through already processed routes (up to a point).

I haven't had too much time to work on it yet. Besides that, I have been doing more reading about graphs than coding. It will be a while.

Fair enough, graphs are pretty cool. Anyway, my first draft of the route compression is a bust, it will work, except it breaks my win-check routine, so it's a no-go. I left the app version posted running for over 24 hours now, and it's nearly done checking all routes of length 30 in the reference problem. Probably another month to go at this rate!

There is a route of length 24 which is cost neutral - the thing is that it is cost neutral from the second iteration through the route (rather than being cost neutral from the start).

Hey @MT0, awesome. I'll check my solution checker, it should find static paths, so there must be a bug in it somewhere! I bet it has to do with a win optimization I put in, that likely ignores static solutions (mistake on my part!)

@MT0 So I checked through my code. I see the issue -- I will find this solution, after about 60 moves. The reason is I find static solutions only when they are a "true loop", meaning the ammo levels at every step along the route are identical. I'm going to use your solution to find a better win checker! Thanks so much.

@MTO in fact, the issue is my early-win-path termination check. In it, I test that the ammo in the "retread" is not below the ammo level of the original traversal. Clearly, this test, while well-intentioned, is wrong. So the simplest thing to do is to remove it. That means that each individual win-test will take longer, but I will find the 30 step solution you outline now.

@Rusher So, I got my compression to work. However, it eats up memory like no-one's business :). Going to take some tweaking to get it to work for sure. Feel free to check it out on the github I link to.

Some abstract notes on a solution
If I get time I'll convert this into an algorithm...
For a given graph G then there exists a connected sub-graph G' which contains town 1. If there is an infinite solution then there will exist a connected sub-graph G'' of G' which contains V towns and P paths.
The paths P of G'' can be partitioned such that {p} contains a path which has then minimal cost of all the paths in P and P/{p} is all the other paths (forming a spanning tree or possibly a cycle). If we assume that p is not a looping edge (connecting both ends to the same town) then it will connect two towns (v1 and v2) and has cost c ammunition then you (the survivor) can then traverse from v1 to v2 and back at a total cost of 2c ammunition and this will increase the ammunition in all the towns by 2 (for a total increase of 2|V| within G'' - some of which will have been collected from v1 and v2).
If you travel from v1 to v2 and back to v1 multiple (m) times and then take a trip from v1 along the edges P/{p} to visit all the towns other than v1 and v2 before returning to v1 and this takes n paths to achieve (where |P/{p}| ≤ n ≤ 2|P/{p}| since you should never need to traverse a path more than twice) with a cost of k and the towns will gain 2m|V| ammunition (again some of which will have been collected during traversal).
Given all this then you can tell if an infinite solution is potentially possible if then cost k + 2mc is equal or lower than the total reward 2(m+n)|V|.
There is a additional complexity to the problem in that:

you may need to travel from the starting town 1 to {p} on the first iteration and need to factor in this cost; and
you also need to ensure that the m and n are low enough that you don't run out of ammunition before you can make it through the first iteration since the first iteration will have a higher cost than the subsequent iterations).

This leads to a 24 path cost neutral solution to the example in the question (the numbers are the towns visited):
1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,2,4,2,5,2,3, ... and repeat ...

One small thing to add - you may have to consider looping edges with a cost of 1, because those edges alone form a win condition if you can reach them in time.


text:
Create a random 3D asteroid
Imagine you are working on a 3D adaptation of the classical video game Asteroids. Your task is to write an algorithm that can create a random 3D asteroid.
This is a popularity contest, not code golf. Write nice code and create interesting results. Add other cool features if you want.
Rules:

Your algorithm must actually create the model, not just load it from an external source or similar.
The results must be (pseudo-)random. Running the algorithm several times must create different results.
Real-time capability is desirable, but not necessary.
Low or high polygon count? Realistic or stylized? You decide...
The output must be a mesh, either in memory or as a file such as Wavefront OBJ. In either case you need to render it in some way.
Explain your algorithm, so that everybody can learn from it.
Show some images of your results.

Blender + Python
Blender's built-in Python scripting is perfect for this sort of thing.

Open a Python console and paste in the following:
import bpy
import random

def asteroid():
    bpy.ops.mesh.primitive_ico_sphere_add()
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.faces_shade_smooth()
    bpy.ops.mesh.select_mode(type='VERT')
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(1.1,1.4),random.uniform(1.1,1.4),random.uniform(1.1,1.4)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(1.05,1.15),random.uniform(1.05,1.15),random.uniform(1.05,1.15)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    bpy.ops.mesh.select_random()
    bpy.ops.transform.resize(value=(random.uniform(0.92,1.05),random.uniform(0.92,1.05),random.uniform(0.92,1.05)))
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.subdivide(smoothness=1)
    stretch = random.uniform(0.9,1.5)
    bpy.ops.transform.resize(value=(stretch,1,1))
    bpy.ops.transform.rotate(value=(random.uniform(-1.57,1.57)), axis=(random.uniform(-1.57,1.57),random.uniform(-1.57,1.57),random.uniform(-1.57,1.57)))
    bpy.ops.object.mode_set(mode='OBJECT')

asteroid()

An asteroid will then be created at the position of your 3D cursor:

Want another asteroid? Move the 3D cursor somewhere else and then type asteroid() into the Python console again (or just ↑Enter to repeat the last line entered).
To make it look more like a piece of space rock and less like a blob of plastic, you need to apply a suitable material. The following procedural material works quite well. I used a diffuse colour of #635C5B, and #8D887F in the marble texture.

How it works:

Start by creating a simple icosahedron (bpy.ops.mesh.primitive_ico_sphere_add()).
Enter edit mode (bpy.ops.object.mode_set(mode='EDIT')) and apply smooth shading so that the individual facets blend into one another (bpy.ops.mesh.faces_shade_smooth()).
Select a random subset of the object's vertices (bpy.ops.mesh.select_random()).
Scale them randomly in the X, Y and Z directions (bpy.ops.transform.resize()).
Select the whole object (bpy.ops.mesh.select_all(action='SELECT')) and apply smooth subdivision to add new vertices by interpolating smoothly across the deformed object (bpy.ops.mesh.subdivide(smoothness=1)).
(Repeat steps 3–5 a couple more times.)
Stretch the object in the X direction to make it a bit less spherical (bpy.ops.transform.resize(value=(stretch,1,1)))
Apply a random rotation transform (bpy.ops.transform.rotate())
Finally, exit edit mode and leave the object selected (bpy.ops.object.mode_set(mode='OBJECT')).

More examples:

Holy Bajeezus! .

Wow that is great!


text:
Point-free look and say sequence
You are too make a program that take an integer as the input and outputs the first what ever that number was of the look and say sequence.
For example:
$ ./LAS
8
[1,11,21,1211,111221,312211,13112221,1113213211]

The exact way you output the list is unimportant, as long as users can distinctly see the different numbers of the sequence. Here is the catch though. You can't use any sort of user-defined variable.
For example:

No variables, including scoped variables.
When you have functions, they can not have a name. (Exception, if your language requires a main function or similar to work, you may have that function.)
When you have functions, they can not have named arguments.

Also, you may not use a library with specific capabilities relating to the look and say sequence, and you can not access the network, or provide your program with any files (although it can generate and use its own.) This is code golf, so shortest code in characters wins!

What is "EXTREME POINT FREENESS"?

@Quincunx I had to look it up: http://stackoverflow.com/questions/944446/what-is-point-free-style-in-functional-programming

Can you explain this rule: When you have functions, they can not have named arguments.?

Same sequence, different code constraint

@ n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳  In several languages (like the J language or stack/based languages like forth or postscript), functions don't have argument; they apply to some external context (a stack or arguments coming from an external scope).

VTC as unclear.  What is a "user defined variable"?  For example, Perl has many variables which may be used, but are defined (initially) by the interpreter itself.  It also has a default variable which is referenced by many functions implicitly.

@Xcali neither of those are user defined. If the user redefines them, they become user defined.

I am not going to unilaterally close this but it is my opinion that user defined variable or even variable on its own are not clear from the challenge, and probably very hard to make clear, except within specific contexts.

I decided not to VTC as unclear, but rather to just close this as a duplicate. I don't think the added restrictions make the challenge different enough from the existing one. It's an old question, so Idk. Things were a bit different 6 years ago.

@mbomb007 this one predates the other one by a few years. Voted to reopen.

It's not uncommon to close an older challenge as a duplicate of a newer one. https://codegolf.meta.stackexchange.com/a/8286/34718. The same happened to this one, which also had weird and arbitrary restrictions.

GolfScript (31 chars)
~[]\{[1\{.2$={;\)}1if\}*].n@}*;

Adapted from my answer to a previous look-and-say question. This one has a less onerous restriction for functional languages, which allows saving 5 chars, but because most answers to the previous question can't be adapted (it's a crazily onerous restriction for non-functional languages) I don't think it makes sense to close it as a dupe.

Haskell 206 Chars
import Data.List
import Control.Applicative
import Data.Function
main= readLn >>= print .(flip take (map read $ fix (("1":). map (concat .(map ((++)<$>(show . length)<*>((:[]). head))). group))::[Integer]))

It works by using the group function to group them into groups of equal things. Then it uses applicatives with functions to build a function that simultaneously reads the length, and appends it to with one the elements. It uses a fix and a map to create a recursive definition (point-free.) And there ya go.

J (42 chars)
Point-free (also called tacit) programming is natural in J.
,@:((#,{.);.1~(1,}.~:}:))&.>^:(<`((<1)"_))

That's a function, to use it you write the code, a space, and the input number. For example,
   ,@:((#,{.);.1~(1,}.~:}:))&.>^:(<`((<1)"_)) 8
┌─┬───┬───┬───────┬───────────┬───────────┬───────────────┬───────────────────┐
│1│1 1│2 1│1 2 1 1│1 1 1 2 2 1│3 1 2 2 1 1│1 3 1 1 2 2 2 1│1 1 1 3 2 1 3 2 1 1│
└─┴───┴───┴───────┴───────────┴───────────┴───────────────┴───────────────────┘

Notice the pretty boxes in the output.
Addendum: Here are a couple of "cheats" I was too bashful to use at first, but now that I've seen other use them first...

Here's a 36 char version with a different "calling convention": replace 8 with the number of terms you want.
,@:((#,{.);.1~(1,}.~:}:))&.>^:(<8)<1

And if having extra zeroes in the output is OK, here's a 32 char version:
,@:((#,{.);.1~(1,}.~:}:))^:(<8)1

Bash and coreutils, 111 73 chars
eval echo 1\|`yes 'tee -a o|fold -1|uniq -c|(tr -dc 0-9;echo)|'|sed $1q`:

uniq -c is doing the heavy lifting to produce the next number in the sequence.  yes, sed and eval create the necessary number of repeats of the processing pipeline.  The rest is just formatting.
Output is placed in a file called o.:

$ ./looksay.sh 8
ubuntu@ubuntu:~$ cat o
1
11
21
1211
111221
312211
13112221
1113213211
$

GolfScript, 36 chars
~([1]\{.[0\{.2$=!{0\.}*;\)\}/](;}*]`

Variables are pretty rarely used in GolfScript, and this task certainly doesn't need them.  Input is on stdin, output to stdout.  For example, the input 8 gives the output:
[[1] [1 1] [2 1] [1 2 1 1] [1 1 1 2 2 1] [3 1 2 2 1 1] [1 3 1 1 2 2 2 1] [1 1 1 3 2 1 3 2 1 1]]

I may write a detailed explanation of this code later, but at least you can easily tell that it uses no variables by the fact that it doesn't include the variable assignment operator : anywhere.

Haskell, 118 chars (80 without imports)
import Data.List
import Control.Monad
main=readLn>>=print.flip take(iterate(ap((++).show.length)(take 1)<=<group)"1")

Mathematica, 65 chars
FromDigits/@NestList[Flatten@Reverse[Tally/@Split@#,3]&,{1},#-1]&

Example:
FromDigits/@NestList[Flatten@Reverse[Tally/@Split@#,3]&,{1},#-1]&[8]

{1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211}

J, 37 characters
1([:,((1,2&(~:/\))(#,{.);.1]))@[&0~i.

Based on my answer to the Pea Pattern question. There may be some potential for shortening here. Usage is as for the other J answer:
   1([:,((1,2&(~:/\))(#,{.);.1]))@[&0~i. 7
1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
2 1 0 0 0 0 0 0
1 2 1 1 0 0 0 0
1 1 1 2 2 1 0 0
3 1 2 2 1 1 0 0
1 3 1 1 2 2 2 1

It also has the extra zeroes problem my pea pattern answer had.

Ah, there's more than one previous question, and more answers from that one can be copied to this one without any tweaks at all than from the question I found. I'm almost convinced to vote to close as dupe.

@PeterTaylor The Pea pattern one is slightly different in that you have to sort the numbers in the previous line before creating the next.

Perl 6: 63 53 characters
say (1,*.subst(/(\d)$0*/,{.chars~.[0]},:g)...*)[^get]

Create a lazy list of the Look and Say sequence (1,*.subst(/(\d)$0*/,{.chars~.[0]},:g)...*), and then get as many elements as specified by the user ([^get], which is an array subscript and means [0..(get-1)]), and say them all.
The lazy list works by first taking 1, then to generate each successive number, it takes the last one it found and substitutes all the sequences of the same digit, as matched by /(\d)$0*/, and replaces them with {how many}+{what digit}, or .chars~.[0].
The only variables in this code are $0, the first capture of the match, and the implicit, topical $_ variable that bare .methods call, and neither of these are user-defined.

Dyalog APL, 35 characters
(⊢,⊂∘∊∘((≢,⊃)¨⊃⊂⍨2≢/0,⊃)∘⌽)⍣(⎕-1)⊢1
⎕ is evaluated input.  In the link I've replaced it with 8, as tryapl.org does not allow user input.
No named variables (a←1), no named functions (f←{}), no arguments (⍺, ⍵).
Only composition of functions:

monadic operators—each:f¨, reduce:f/, commute:f⍨
dyadic operators—power:f⍣n, compose:f∘g
forks—(f g h)B ←→ (f B)g(h B); A(f g h)B ←→ (A f B)g(A h B)
atops—(f g)B ←→ f(g B); A(f g)B ←→ f(A g B)
4-trains (fork-atops)—(f g h k) ←→ (f (g h k))

Primitive functions used:

right:A⊢B ←→ B
reverse:⌽B
first:⊃B
concatenate:A,B
not match:A≢B, count:≢B
enclose:⊂B, partition:A⊂B
flatten:∊B

In tryapl.org, if you remove the trailing ⊢1, which is the argument to this massive composed thing, you can see a diagram of how it's parsed:
     ⍣
   ┌─┴─┐
 ┌─┼─┐ 7
 ⊢ , ∘
    ┌┴┐
    ∘ ⌽
 ┌──┴───┐
 ∘    ┌─┴─┐
┌┴┐   ¨ ┌─┼───┐
⊂ ∊ ┌─┘ ⊃ ⍨ ┌─┼───┐
  ┌─┼─┐ ┌─┘ 2 / ┌─┼─┐
  ≢ , ⊃ ⊂   ┌─┘ 0 , ⊃
            ≢

GolfScript, 57 43 chars
My own approach. Ended up longer than the existing one sadly =(.
~[1 9]{.);p[{...1<^0=?.@(\@(>.,(}do 0=]}@*;

Sample output for stdin of 8:
[1]
[1 1]
[2 1]
[1 2 1 1]
[1 1 1 2 2 1]
[3 1 2 2 1 1]
[1 3 1 1 2 2 2 1]
[1 1 1 3 2 1 3 2 1 1]

Alternate version w/out the 9 sentinel, yet it's longer at 47 characters. I suspect it has more potential:
~[1]{.p[{...1<^.{0=?.@(\@(>1}{;,\0=0}if}do]}@*;

Scala 178
(0 to Console.in.readLine.toInt).map(i=>Function.chain(List.fill[String=>String](i)(y=>(('0',0,"")/:(y+" ")){case((a,b,c),d)=>if(d==a)(a,b+1,c)else(d,1,c+b+a)}._3.drop(2)))("1"))

I'm pretty sure that the i in i=> is a variable.

Husk, 11 bytes
↑¡oṁ§eL←g;1

Try it online!
1-indexed.

J 66 (with I/O)
".@(_5}&',@((#,&:":{.);.1~1&(0})&(~:_1|.]))^:(<X)":1')@{.&.stdin''

without IO, scores 43:
NB. change the 8 for the number of numbers you'd want
,@((#,&:":{.);.1~1&(0})&(~:_1|.]))^:(<8)'1'

Funny question to pose yourself, when is the first 9 to show up?

Never look at the integer sequence page.

Ok, I see. Then ... why so?

http://voices.yahoo.com/look-say-sequences-mathematical-proofs-841045.html?cat=70

Nice trick in the IO version of replacing the X by the input in a string and then calling eval!

As for the funny question: isn't it pretty clear you only ever have 1, 2 & 3? I mean to get a 4 or higher, in the previous step you'd need four consecutive equal digits, xaaaay, but that can't happen since you'd be saying a further step earlier you saw "x a's, a a's" or "a a's, a a's".

Jelly, 11 10 bytes
1ŒrUFƊ’}¡)

Try it online!
Jelly doesn't have variables.
Explanation
1ŒrUFƊ’}¡)
         )   For each i in 1..n:
1              Begin with 1
      ’}¡      i - 1 times
     Ɗ         (
 Œr              Run-length encode
   U             Reverse each
    F            Flatten
     Ɗ         )

authors: n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

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