text:
The world ends in ed
Taken straight from the ACM Winter Programming Contest 2013. You are a person who likes to take things literally. Therefore, for you, the end of The World is ed; the last letters of "The" and "World" concatenated.
Make a program which takes a sentence, and output the last letter of each word in that sentence in as little space as possible (fewest bytes). Words are separated with anything but letters from the alphabet (65 - 90, 97 - 122 on the ASCII table.) That means underscores, tildes, graves, curly braces, etc. are separators. There can be more than one seperator between each word.
asdf jkl;__zxcv~< vbnm,.qwer| |uiop -> flvmrp
pigs, eat dogs; eat Bob: eat pigs -> ststbts
looc si siht ,gnitirw esreveR -> citwR
99_bottles_of_beer_on_the_wall -> sfrnel

Could you add a test case including digits and underscores?

The world ends in ed? I knew vim and Emacs couldn't measure up!

Well, the “real men use ed” essay has been part of the Emacs distribution for as long as I can remember.

Will the inputs be ASCII only?

Perl 5, 18 bytes
s/\pL*(\pL)|./$1/g

Requires a -p command line switch. The named property L matches only letter characters A-Za-z. There are several hundred such named properties, but when dealing with ASCII text, very few of them are interesting. Besides \pL, the only other one of any real note is \pP, which matches punctuation.
Try it online!

Perl 5, 17 bytes
A one byte improvement by Dom Hastings
print/\pL*(\pL)/g

Requires -n (and -l to support multiple inputs).
Try it online!

Sample usage
$ more in.dat
asdf jkl;__zxcv~< vbnm,.qwer| |uiop
pigs, eat dogs; eat Bob: eat pigs
looc si siht ,gnitirw esreveR
99_bottles_of_beer_on_the_wall

$ perl -p ends-in-ed.pl < in.dat
flvmrp
ststbts
citwR
sfrnel

I think \w also matches digits and underscores.

Hmm, indeed. That will need to be updated.

Brilliant. Regex was an obvious solution, but |. was not obvious (to me, at least).

Just noticed a -1 in print/\pL*(\pL)/g, seems to output the same for your test cases!

s/(\pL)*|./$1/g and print/(\pL)*/g for 15 and 14 bytes since the capturing group captures here one char at a time so it store the last char of the word

ed, 35 characters
s/[a-zA-Z]*\([a-zA-Z]\)\|./\1/g
p
Q

So, the world ends in ed. As I like to be too literal, I decided to write to write the solution with ed - and apparently it is actually a programming language. It's surprisingly short, even considering many shorter solutions already exist in this thread. It would be nicer if I could use something other than [a-zA-Z], but considering ed isn't a programming language, it's actually good enough.
First, I would like to say this only parses the last line in file. It would be possible to parse more, just type , at beginning of two first lines (this specified "everything" range, as opposed to standard last line range), but that would increase code size to 37 characters.
Now for explanations. The first line does exactly what Perl solution does (except without support for Unicode characters). I haven't copied the Perl solution, I just invented something similar by coincidence.
The second line prints last line, so you could see the output. The third line forces quit - I have to do it, otherwise ed would print ? to remind you that you haven't saved the file.
Now for how to execute it. Well, it's very simple. Just run ed with the file containing test case, while piping my program, like that.
ed -s testcase < program

-s is silent. This prevents ed from outputing ugly file size at beginning. After all, I use it as a script, not editor, so I don't need metadata. If I wouldn't do that, ed would show file size that I couldn't prevent otherwise.

I installed ed just to try this.

32 bytes... Try it Online!

Javascript, 49
alert(prompt().replace(/.(?=[a-z])|[^a-z]/gi,''))

It uses a regular expression to remove all characters that come before a letter, as well as all non-letter characters. Then we're left with the last letter of each word.
Thanks to tomsmeding for a nice improvement.

You can probably improve this by making the regex case-insensitive, like in: alert(prompt().replace(/.(?=[a-z])|[^a-z]/gi,''))

C, 78
Golfed:
main(int c,char**s){for(;c=*s[1]++;)isalpha(c)&&!isalpha(*s[1])?putchar(c):0;}

With whitespace:
main(int c,char**s)
{
  for(;c=*s[1]++;)
    isalpha(c)&&!isalpha(*s[1])?putchar(c):0;
}

Output:

You can save 4 bytes by using K&R declaration and defaulting c: main(c,s)char**s;{for

GNU Sed, 40 38 37
s/[a-z]\b/&\n/g; s/[^\n]*\(.\)\n/\1/g

Testing
cat << EOF > data.txt
asdf jkl;__zxcv~< vbnm,.qwer| |uiop
pigs, eat dogs; eat Bob: eat pigs
looc si siht ,gnitirw esreveR
EOF

Run sed:
sed 's/[A-Za-z]\b/&\n/gi; s/[^\n]*\(.\)\n/\1/g' data.txt

Output:
flvmrp
ststbts
citwR

Explanation
The first substitution replaces all word boundaries, that are preceded by the desired match group, with a new-line. This makes it easy to remove all extraneous characters in the second substitution.
Edit

Use case-insensitive flag (-2), thanks manatwork.
Don't count whitespace (-1).

sed's s command has i flag for cases insensitive matching: s/[a-z]\b/&\n/gi.

@manatwork: good point, this would make it GNU sed only, but it seems it already is, thanks.

\b considers _s to be letters, so if any words in the test END with _, that word's last letter is not included in the output

Mathematica, 39
""<>StringCases[#,(__~~x_)?LetterQ:>x]&

Test:
""<>StringCases[#,(__~~x_)?LetterQ:>x]& /@
 {"asdf jkl;__zxcv~< vbnm,.qwer| |uiop",
  "pigs, eat dogs; eat Bob: eat pigs",
  "looc si siht ,gnitirw esreveR",
  "99_bottles_of_beer_on_the_wall"}

{"flvmrp", "ststbts", "citwR", "sfrnel"}

Good one. LetterQ should be called LettersQ :) I haven't thought of it for testing whole strings.

@belisarius Actually, with this construct it is applied character-wise, so it could be a literal "LetterQ" and still work.

Grep and Paste, 36 34 28
> echo 'asdf jkl;__zxcv~< vbnm,.qwer| |uiop' | grep -io '[a-z]\b' | tr -d \\n
flvmrp

> echo 'pigs, eat dogs; eat Bob: eat pigs'   | grep -io '[a-z]\b' | tr -d \\n
ststbts

echo 'looc si siht ,gnitirw esreveR'         | grep -io '[a-z]\b' | tr -d \\n
citwR

If a final new-line is needed, replace tr -d \\n with paste -sd ''.
Edit

Use case-insensitive grep (-2), thanks manatwork.
Use tr instead of paste (-4), thanks manatwork.
Don't count whitespace around pipe (-2).

Quite creative with that paste -sd '', but tr -d \\n is shorter. Regarding grep, it has -i switch meaning “ignore case”, which can make it shorter: grep -io '[a-z]\b'.

@manatwork, tr also delete the final newline. Case insensitive mode is of course shorter, thanks.

there is no rule requiring final newline.

@manatwork: I can agree with that, updated answer.

sed, 37 chars
Equal length to Thor's answer, but, I think, simpler.
s/[a-z]*\([a-z]\)/\1/ig;s/[^a-z]*//ig

The logic is quite trivial - replace letter sequences with their last letter, then delete all non-letters.

Zsh (builtins only), 40
for j (${=@//[^a-zA-Z]/ });printf $j[-1]

Try it Online...

Nibbles, 4.5 bytes (9 nibbles)
.%~$\$a/\

.%~$\$a/\       # 9 nibble program
.%~$\$a/\$$     # with implicit variables added:
 $~             # split
   $            # the input
    \           # by whether the character class
     $          # of each element
      a         # is alphabetic;
.               # now, map over this
        \       # reversing
         $      # each group
       /        # and folding across these
          $     # returning the first (left-hand) argument
                # (in other words, return the first character of each group)

Mathematica 62 57 52
Row@StringTake[StringCases[#,LetterCharacter..],-1]&

Testing
l = {"asdf jkl;__zxcv~<vbnm,.qwer| |uiop",
     "pigs,eat dogs;eat Bob:eat pigs",
     "looc si siht,gnitirw esreveR"}

Row@StringTake[StringCases[#,LetterCharacter..],-1]&/@ l
(*{flvmrp,ststbts,citwR}*)

I mistakenly edited yours, but then rolled it back. Ooops.

K, 49
{last'f@&"b"$#:'f:"|"\:@[x;&~x in,/.Q`a`A;:;"|"]}

.
k){last'f@&"b"$#:'f:"|"\:@[x;&~x in,/.Q`a`A;:;"|"]}"asdf jkl;__zxcv~< vbnm,.qwer| |uiop"
"flvmrp"
k){last'f@&"b"$#:'f:"|"\:@[x;&~x in,/.Q`a`A;:;"|"]}"pigs, eat dogs; eat Bob: eat pigs"
"ststbts"
k){last'f@&"b"$#:'f:"|"\:@[x;&~x in,/.Q`a`A;:;"|"]}"looc si siht ,gnitirw esreveR"
"citwR"

Scala, 59 (or 43)
Assuming the string in already in s:
s.split("[^a-zA-Z]+").map(_.last).mkString

If you need to read from a prompt and print rather than using the REPL output, convert s to readLine and wrap in println() for 59.

x86: 54 bytes
Assume a cdecl routine with the signature void world_end(char *input, char *output):
60 8b 74 24 24 8b 7c 24 28 33 d2 8a 0e 8a c1 24
df 3c 41 72 08 3c 5a 77 04 8a d1 eb 09 84 d2 74
05 88 17 47 33 d2 46 84 c9 75 e0 84 d2 74 03 88
17 47 88 0f 61 c3

By the way, I realize the question asks for a program and not a routine, but I wanted to do something different.  Contrary to the problem statement, I guess I'm not a "person who likes to take things literally" after all. :P

Xi, 32
println$ @{=>.-1}<>input re"\W+"

Xi is a language still in its beta phase, but it seems to work well with code golf so I figured I might as well show yet another short and functional solution (and advertise the language a little :-)).

Python, 76 chars
import re;print "".join(re.findall("([a-zA-Z])(?=$|[^a-zA-Z])",raw_input()))

You can remove the space after print.

Shorten by porting to Python 3: import re;print(*re.findall("([a-zA-Z])(?=$|[^a-zA-Z])",input()),sep='')

Python3, 59 chars
import re;print(re.sub('.(?=[a-z])|[^a-z]','',input(),0,2))

Correctly deals with capital letters and underscores.  The 2 is to pass re.sub the re.IGNORECASE flag without having to use re.I.

Japt v2.0a0 -P, 16 9 6 bytes
q\L mÌ

Try it or run all test cases
q\L mÌ     :Implicit input of string U
q          :Split on
 \L        :  Regex /[^a-z]/gi
    m      :Map
     Ì     :  Last character
           :Implicitly join & output

I think you can just do f"%l(?!%l)" q (doesn't work in v2 because the parser doesn't like the (?)

Haskell, 62 60 bytes
f s=last<$>words[last$' ':[c|'@'<c,c<'{','`'<c||c<'[']|c<-s]

Try it online! Thanks to Wheat Wizard for a version without the import, saving two bytes!

Haskell, 62 bytes
import Data.Char
f s=last<$>words[last$' ':[c|isAlpha c]|c<-s]

Try it online!
Given an input string s, [last$' ':[c|isAlpha c]|c<-s] converts all non-alphabetic characters to spaces. words splits the resulting string on white space and last<$> takes the last character of each of the resulting strings.

60 bytes.

Pyth, 27 19 bytes
seMc:z"[^A-Za-z]+"d

Test suite
Explanation:
seMc:z"[^A-Za-z]+"d | Full code
--------------------+---------------------------------------------
    :z"[^A-Za-z]+"d | In the input, replace non-letters with space
   c                | Split on spaces
 eM                 | Replace each word with its last letter
s                   | Concatenate each letter

R, 126
My R solution
function(x){cat(paste(unlist(sapply(strsplit(unlist(strsplit(gsub("
[^[:alpha:]]"," ",x)," ")),""),tail,1)),collapse=""),"\n")}

Nice approach, golfed down a bit to 111 bytes...

Pip, 8 bytes
DQ*a@+XA

Verify all test cases: Try it online!
Explanation
      XA  Built-in regex variable: `[A-Za-z]`
     +    Apply regex + quantifier: `[A-Za-z]+`
   a@     Find all matches in the input
DQ*       Dequeue the last character from each match
          Concatenate together and autoprint (implicit)

VBA, 147 161
Sub a(s)
For n=0 To 255:m=Chr(n):s=Replace(s,IIf(m Like"[A-Za-z]","",m)," "):Next
For Each r In Split(s," "):t=t & Right(r,1):Next
MsgBox t
End Sub

Smalltalk, Squeak/Pharo flavour
122 char with traditional formatting for this method added to String:
endOfWords
    ^(self subStrings: (CharacterSet allCharacters select: #isLetter) complement) collect: #last as: String

62 chars in Pharo 1.4, with regex and weird formatting
endOfWords^''join:(self regex:'[a-zA-Z]+'matchesCollect:#last)

J: 60 characters (or 38 characters for a less correct version)
(#~e.&(,26&{.&(}.&a.)"0(97 65))){:&>;:]`(' '"_)@.(e.&'_:')"0

If we're willing let the program break whenever there are words ending in a colon or an underscore, then we can simplify this to 38 characters.
(#~e.&(,26&{.&(}.&a.)"0(97 65))){:&>;:

Sample run:
    (#~e.&(,26&{.&(}.&a.)"0(97 65))){:&>;:]`(' '"_)@.(e.&'_:')"0'asdf jkl;__zxcv~< vbnm,.qwer| |uiop'
flvmrp
    (#~e.&(,26&{.&(}.&a.)"0(97 65))){:&>;:]`(' '"_)@.(e.&'_:')"0'pigs, eat dogs; eat Bob: eat pigs'
ststbts
    (#~e.&(,26&{.&(}.&a.)"0(97 65))){:&>;:]`(' '"_)@.(e.&'_:')"0'99_bottles_of_beer_on_the_wall'
sfrnel

38 Bytes (for a correct version): (#~[:2&|64 90 96 122&I.@(u:inv)){:&>;:, or 43 bytes for a non-explicit version: (#~[:2&|64 90 96 122&I.@(u:inv))@:({:@>)@;:. This uses the interval index verb, I., which interprets 64 90 96 122 as the set of intervals (__, 64] (64, 90], (90, 96], (96, 122], (122, _), and returns the index of the iterval to which its argument, the ascii code of the char, belongs. If this index is odd, it's not alphabetical.

@BolceBussiere doesn’t work with underscores for some reason (last test case).

@FrownyFrog ah, I see why, ;: interprets abc_ as one word since variable names can contain underscores. +10 bytes to add (#~~:&'_'), probably an inefficient fix

@BolceBussiere that’s just '_'-.~ or something similar.

C#
Method, 105 bytes: (assumes usings for System, System.Text.RegularExpressions and System.Linq)
string R(string i){return string.Concat(Regex.Split(i,"[^a-zA-Z]").Where(x=>x!="").Select(n=>n.Last()));}

Program, 211 bytes:
using System;using System.Text.RegularExpressions;using System.Linq;class A{static void Main(){Console.WriteLine(string.Concat(Regex.Split(Console.ReadLine(),"[^a-zA-Z]").Where(x=>x!="").Select(n=>n.Last())));}}

Mathematica 71 47 45 61
Back to the drawing board, after @belisarius found an error in the code.
StringCases[#, RegularExpression["[A-Za-z](?![A-Za-z])"]] <> "" &

Testing
l = {"asdf jkl;__zxcv~<vbnm,.qwer| |uiop", "asdf jkl__zxcv~<vbnm,.qwer| |uiop",
"pigs,eat dogs;eat Bob:eat pigs", "looc si siht,gnitirw esreveR"};

StringCases[#, RegularExpression["[A-Za-z](?![A-Za-z])"]] <> "" & /@ l

{"flvmrp", "flvmrp", "ststbts", "citwR"}

\\w matches _, so it doesn't work for (for example) "asdf jkl__zxcv~<vbnm,.qwer| |uiop"

Wait Row@StringTake[     StringCases[#,       LetterCharacter ..], -1] &@"asdf jkl__zxcv~<vbnm,.qwer| |uiop" gives me flvmrp, but #~StringCases~RegularExpression@"\\w\\b" <>     "" &@"asdf jkl__zxcv~<vbnm,.qwer| |uiop" returns fvmrp here. Are we getting the same results??

@belisarius You were right about the error in my earlier version.  I was testing it with the wrong string!

Hehe , +1 again

@belisarius guys, please see the answer I posted.  If it is correct it's shorter.

Python 2, 88 80 75 69 68
s=p=''
for c in raw_input()+' ':a=c.isalpha();s+=p[a:];p=c*a
print s

Input: 435_ASDC__uio;|d re;fG o55677jkl..f
Output: CodeGolf

This solution can be shortened to 67 characters if you allow the output to include backspace characters (ASCII code 8) at the beginning. The output will be visually identical.
s=p='<BS>'
for c in raw_input()+p:a=c.isalpha();s+=p[a:];p=c*a
print s

Same input, (visually) same output. <BS> is meant to be the backspace character.

Python 3.x, 64 bytes
import re;print(''.join(a[-1] for a in re.split('\W+',input())))

The last example is not working. Also, an error occurs if the line begins or ends with a separator

You can remove the space before for.

Lua, 42
print(((...):gsub('.-(.)%f[%A]%A*','%1')))

Usage example: lua script.lua "asdf jkl;__zxcv~< vbnm,.qwer| |uiop"

It's in PHP. 197 bytes :(
I'm beginner
$l=$_GET['line'];
$l=preg_replace('/(\W|_)+/',' ',$l);
$s=explode(' ',$l);
foreach($s as $d){
$a=substr($d,-1,1);
$o=ORD($a);
if(($o>=97 && $o<=122) || ($o>=65 && $o<=90)){
echo $a;
  }
}

EDITED
Now it's 171 bytes
<?$l=$_GET['l'];$l=preg_replace('/(\W|_)+/',' ',$l);$s=explode(' ',$l);foreach($s as $d){$a=substr($d,-1,1);$o=ORD($a);if(($o>=97&&$o<=122)||($o>=65&&$o<=90)){echo$a;}}

For golf, you should as much as possible reduce your variable names to single characters at the very least.

edited it.Thanks for telling me.I'm new here.

Sure. You may also want to look here for some additional PHP-specific help.

foreach((' ',preg_replace('/(\W|_)+/',' ',$_GET['line'])) as $d){$a=substr($d,-1,1);$o=ORD();if(($o>=97 && $o<=122) || ($o>=65 && $o<=90)){echo $a;}} is 149, if it works.

\W|_ excludes digits; so you should add \d to your regex or use /[^a-z]+/i

K 30
q)k)f:{x@&-1=-':(1_x," ")in,/.Q`a`A}
q)f "asdf jkl;__zxcv~< vbnm,.qwer| |uiop"
"flvmrp"
q)f "pigs, eat dogs; eat Bob: eat pigs"
"ststbts"
q)f "looc si siht ,gnitirw esreveR"
"citwR"
q)f "99_bottles_of_beer_on_the_wall"
"sfrnel"

Ruby 2.0, 25 (+1) chars
gsub(/(\w+)\W*/){$1[-1]}

Must be run with the -p switch:
 $ ruby -p ed.rb <<< "asdf jkl;__zxcv~< vbnm,.qwer| |uiop"
flvmrp

Please specify the ruby version. 1.9.2 outputs “#Enumerator:0x9f65e10#Enumerator:0x9f65d98#Enumerator:0x9f65d34#Enumerator:0x9f65cd0”.

You're right. I had completely forgotten that I installed it, but my current Ruby version is 2.0 (ruby 2.0.0p0 (2013-02-24 revision 39474). When running the program with version 1.8.7 it outputs an ASCII value! Didn't know there were so many differences between the versions.

Thanks, will definitely have to update my Ruby. (Both the interpreter and the knowledge.) The second capturing group is not necessary: gsub(/(\w+)\W*/){$1[-1]}.

Oh, of course it's not. Thanks, updated :)

JavaScript, 37 bytes
t=>t.match(/[a-z](?![a-z])/ig).join``

I don't think so. The question explicitly stated the letters should be output in as few bytes as possible (without separators)

adding .join\`` (7 bytes) will fix the output

SNOBOL4 (CSNOBOL4), 117 bytes
	L =&UCASE &LCASE
	N =INPUT
B	N SPAN(L) . X BREAK(L) REM . N	:F(O)
	X RPOS(1) LEN(1) . X
	O =O X	:(B)
O	OUTPUT =O
END

Try it online!
	L =&UCASE &LCASE			;*upper and lowercase letters
	N =INPUT				;*read input
B	N SPAN(L) . X BREAK(L) REM . N	:F(O)	;*while match success, set X to first run of L characters, split on non-L characters, and set N to remainder
	X RPOS(1) LEN(1) . X			;*set X to the last character of X
	O =O X	:(B)				;*append X to O, goto B
O	OUTPUT =O				;*output O
END

I feel like there's a way to directly set X to the end of the SPAN(L) but I haven't figured it out yet.

05AB1E, 17 bytes
Sžosåγ€g£ʒDáQ}€θJ

Try it online!

Retina, 20 bytes
i`.(?=[a-z])|[^a-z]

Try it online
This program is compatible with version 0.8.2

Haskell, 76 bytes
import Data.Char
u=isAlpha
f(a:i@(b:_))|u b=f i|u a=a:f i|1>0=f i
f(a:b)=[a]

Try it online!

Vim, 26 bytes:
:s/\v\S*(\a)\A*( |$)/\1/g<CR>

Try it online!

Retina, 16 bytes
Li, -1|""`[a-z]+

Try it online!
Explanation
Li, -1|""`[a-z]+
L         [a-z]+        List all the sequences of letters in the input
 i                      case insensitive
  ,                     Keep all the results
    -1                  but only the last character for each of them
      |""               Use the empty string as separator

Java 8, 43 bytes
s->s.replaceAll("(?i).(?=[a-z])|[^a-z]","")

Port of @mbomb007's Retina answer.
Explanation:
Try it online.
s->  // Method with String as both parameter and return-type
  s.replaceAll("(?i).(?=[a-z])|[^a-z]","")
     //  Remove every match of this regex, and return as result

Additional explanation for the regex:
"(?i).(?=[a-z])|[^a-z]"  // Main regex to match
 (?i)                    //  Case insensitive
     .                   //   Any character
      (?=[a-z])          //   Followed by a letter (as positive look-ahead)
               |[^a-z]   //   or a non-letter

""                       // Replace it with: nothing

That's actually (?i) for the flag.

PHP, 52 bytes
The narrow word characeter definition quite of narrows the number of approaches.
I wonder if anything else can compete with regex here.
Try them online.

<?=preg_filter("/.*?([a-z])[^a-z]+/i","$1",$argn._);

This requires PHP 7.1 for the negative string index. Run as pipe with -nF.

Another solution, 53 bytes (requires PHP 7.1)
foreach(preg_split("/[^a-z]/i",$argn)as$s)echo$s[-1];

Run as pipe with -nR.

The shortest non-regex solution I could find so far takes 60 bytes:
while(~$c=$argn[$i++])$b=ctype_alpha($c)?$c:!print$b;echo$b;

Run as pipe with -nR.

Gema, 12 characters
<L1>\X=$0
?=

Sample run:
bash-4.4$ gema '<L1>\X=$0;?=' <<< 'asdf jkl;__zxcv~< vbnm,.qwer| |uiop'
flvmrp

Is there a reason you said 12 characters instead of 12 bytes? Just curious

Nothing special. I started golfing before the deluge of languages using multibyte characters, so all solutions mentioned characters. As I enjoyed those times more, I kept the habit of mentioning characters. In case of my solutions makes no difference anyway.

Add++, 81 bytes
D,u,@@,o
D,l,@,V91 65r123 97r+bU€CJGe
D,T,@~,
L~,€lB]ABcB*"."dV€uJG$tbU€TBZVcGbUJ

Try it online!

GAWK, 49 46 bytes
BEGIN{RS="[^A-z]"}{printf substr($0,length$0)}

Try it online!

Julia 0.6, 46 bytes
f(s)=string(matchall(r"[a-z](?![a-z])"i,s)...)

Try it online!
Simple Julia with Standard regex. The r"" constructor creates a Regex class. Notice how the i letter after the last " makes the expression case insensitive.

Jelly, 12 bytes
e€ØẠ¬œpµLƇṪ€

Try it online!
e€ØẠ¬œpµLƇṪ€ - Main link. Takes a string S on the left
  ØẠ         - Yield "ABC...XYZabc...xyz"
 €           - For each character in S:
e            -   Is it in the alphabet?
    ¬        - Logical NOT
               This yields a list, L, with 1s at non-alphabet characters
     œp      - Partition S at truthy indices of L, without keeping the borders
       µ     - Begin a new chain with the partitioned list, P, as the argument
         Ƈ   - Keep those with a truthy:
        L    -   Length
           € - Over each:
          Ṫ  -   Yield the last character

Husk, 10 bytes
m→fo√←ġo¬√

Try it online!
since there's no conditional spliting function, group-by is used. Golflangs with regex are really strong here.
Explanation
m→fo√←ġo¬√
      ġo¬√ group on nonalphabets
  fo√←     filter out nonalphabets
m→         map to last character

Well done!!!  Nonalphabets is the secret!  I was trying to do this last night, and ended up with this, which is completely embarassing and so I was ashamed to post it!

One of my first husk answers had this same problem and √ was very helpful.

sed (-E), 29 bytes
s/[a-zA-Z]*([a-zA-Z])|./\1/gp

Try it Online!
Beats other sed answers by 8 bytes. Port of the excellent ed solution.

Python 3,  51  50 bytes
lambda s:re.sub("([a-zA-Z])*|.","\\1",s)
import re

Try it online!
How it works:

([a-zA-Z])* will match a whole word capturing every single char in group 1 (one at a time).
if no words are found, . match the char to discard it
re.sub(<pattern>,"\\1",s) substitute every occurence of our pattern by the content of capturing group 1 (the last char of the word since it only captures one char at a time)

JavaScript, 36 37 bytes
s=>s.match(/[A-z](?![a-z])/ig).join``

[A-z] matches characters outside the alphabet, so this is invalid.

wut? what characters? @Razetime

oh, []^_` didnt know nor expact that, thanks

Vyxal s, 6 bytes
Thanks to lyxal for reminding me not to be a sussy baka
øWǍƛ[t

Try it Online!
Explanation:
øW      # Group words together
  Ǎ     # Remove non-alphabet characters
   ƛ    # For each remaining string:
    [   #   If it is not empty:
     t  #     Tail

Try it Online! for a flagless 6

05AB1E, 7 bytes
áмS¡€θJ

Try it online or verify all test cases.
Explanation:
á       # Only keep all letters of the (implicit) input-string
 м      # Remove all those letters from the (implicit) input-string
  S     # Convert it to a list of characters
   ¡    # Split the (implicit) input-string by those characters,
        # so only empty strings and strings consisting of letters are left in the list
    €θ  # Only keep the last character of each string
      J # Join it together to a single string
        # (which is output implicitly as result)

Go, 134 bytes
import."regexp"
func f(s string)(o string){for _,e:=range MustCompile(`[A-Za-z]+`).FindAllString(s,-1){o+=string(e[len(e)-1])}
return}

Attempt This Online!

PowerShell Core, 36 bytes
-join($args-split'[^a-z]'|%{$_[-1]})

Try it online!

Case insensitive split on non alphabetical characters
Get the last character of each word
Join them in a string

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


text:
recursive power algorithm
Have a look at my (javascript) version of a O(log(n)) xn algorithm:
function pow(x,n)
{
     return n==0?1:n==1?x:n==2?x*x:pow(pow(x,(n-n%2)/2),2)*(n%2==0?1:x);
}

Can you get it shorter?

other languages, which does it shorter are also welcome!

Python, 4 chars: x**n

this dosn't count, cause it's not a algo itself. It use an underlying algorithm.

I think I win this one

If you don't mind using a global variable:
return n?(t=pow(x,n>>1))*t*(n%2?x:1):1

Through some ingenious trickery, Howard devised a clean alternative:
return n?(n%2?x:1)*(x=pow(x,n>>1))*x:1

And Peter Taylor managed to shave one character:
return(n%2?x:1)*(x=n?pow(x,n>>1):1)*x

Even shorter based on ratchet freak's idea:
return(n%2?x:1)*(n?pow(x*x,n>>1):1)

nice, but it's not a real recursion cause of the glob. var..  but never mind its not bad!

@ChrisTobba Well, it is recursive, the variable doesn't have to be global as the value is only used in the same invocation. It's just shorter to make it (implicitly) global. You could add "var t" before the return to make it local.

Or if you don't want to use a global variable: return n?(n%2?x:1)*(x=pow(x,n>>1))*x:1

nice... good programmers out there!

may I ask how old you are(to code so beautiful)? I'm 28

I'm 0b100010 :)

Or for one character less and a different perspective on the structure, return(n%2?x:1)*(x=n?pow(x,n>>1):1)*x

@peter nice! i love recursive algo`s.. so much logic in such a short form..

@PeterTaylor don't you think you should post that as an answer?

I'm not sure from memory whether it's been discussed on meta, but the general etiquette seems to be that for very small improvements by refactoring someone else's code we post a comment rather than an answer.

Ok I don't know much about etiquette, I credited you in my answer

What am I missing here, why can you not just use the far more simple, literal return n?pow(x,n-1)*x:1. Is that pow function doing something more that I don't understand?

hmmm... starting to notice difference when not using positive integers... what is that pow function doing exactly?

@BillyMoon n is assumed to be a non-negative integer, and your implementation runs in O(n) instead of O(log n) - compare pow(1, 1000000000). If you don't understand how it works, the basic idea is: x^(2k)=(x^k)^2 and x^(2k+1)=x*(x^k)^2 (^ = power in this context)

BrainFuck (482 characters)
Solution is modulo 256. Reads n in digit by digit.  Each time it sees a new digit d, it raises the current value to the tenth power and then multiplies that by x^d
Input must be x followed by single space, followed by n, followed by newline
>,--------------------------------[--------------->,--------------------------------]<[<]>>[<-[->++++++++++<]>>]<->+>>>>>,----------[--------------------------------------<++++++++++<+>[-<[-<<<[->+>+<<]>[-<+>]>>]<[->+<]>>]<[-<+>]>>[-<<+>>]<<<<<[-]>>>[-<[-<<<[->+>+<<]>[-<+>]>>]<[->+<]>>]<[-<<+>>]>>>,----------]>>+<<+<<+<<+<<[-]>[->[>+----------[>-<[-<+>]]<-[->+<]+>++++++++++>]+<<[<----------<]>++++++++++]>[>++++++++++++++++++++++++++++++++++++++++++++++++>]<<<<[>.<<<]++++++++++.

function pow(x,n)
{
     return n==0?1:n==1?x:pow(x*x,n>>1)*pow(x,n&1);
}

removed the n==2 case,
replaced the (n-n%2)/2 with n>>1 (you can also use n&-2)
used x*x instead of pow(pow(...),2)
replaced *(n%2==0?1:x) with *pow(x,n&1)

GolfScript (29 chars as function, 24 chars as block)
{1@@2base-1%{{.@*\}*.*}/;}:P;

without the function wrapper that's
1@@2base-1%{{.@*\}*.*}/;

It's not recursive, but it is O(lg n) time, using the binary decomposition of n. Essentially it takes the fact that the recursive pow can be made tail-recursive with an accumulator and pushes that to its conclusion:
# Stack: a n
1@@
# Stack: 1 a n
2base
# Stack: 1 a [bits of n]
# Reverse the bits so that we loop over them starting at the least significant
-1%
# foreach
{
    # Stack: accum x bit
    # where accum = a^(n%(2^i)) and x = a^(2^i)

    # If the bit is set, multiply the accumulator by x
    {.@*\}*

    # Square x
    .*
}/
# Pop the unwanted a^(2^(2+lg n)) and we're left with a^n
;

(There is also the built-in ? for one char, but I don't think that's in the spirit of this codegolf).

Love the :P at the end of the first one!

GolfScript - 33
This feels awfully clumsy but here it goes:
{.2/.{2$\P}{;1}if.*@@1&{*.}*;}:P;

Usage: 2 11P -> 2048
(Thanks Peter Taylor)

Simple ifs can often be replaced by bool{...}*. In the case of \1&{*}{\;}if (12 ch) observe that the * doesn't care about the order of its arguments, so could be \1&{\*}{\;}if (13 ch); now reorder things so that the common \  is unnecessary: a bit of work shows that @@1&{*}{;}if (12 ch) is equivalent. But now the else clause does virtually nothing; refactor via @@1&{*.}{}if; (13 ch) to @@1&{*.}*; (10 ch). I haven't checked whether a similar elimination can be performed on the first if.

its unreadable for me.. but also nice! On golfscript.com i doesn't found an interpreter for that.. Is it only a pseudo code language?

@ChrisTobba, the interpreter is at http://www.golfscript.com/golfscript/golfscript.rb (and requires Ruby). See also http://meta.codegolf.stackexchange.com/a/521/194

C++, 44 characters
int p(int x,int n){return !n?1:x*p(x,n-1);}

This runs in O(n) time.

Java
int pow(int x, int n){
    int t=1;
    return n==0?1:(n%2==0?1:x)*(t=pow(x,n/2))*t;
}

And if t is an initialized class variable, you can remove the first line.

k4 (38)
fairly straightforward port of the java solution
{$[y;*/((y-2*r)#x),2#x .z.s/r:_y%2;1]}

Haskell, 49 characters
x^0=1;x^2=x*x;x^n|odd n=x*x^(n-1)|1>0=x^div n 2^2

readable version:
x^0 = 1
x^2 = x * x
x^n | odd  x = x * x^(n-1)
    | even x = x ^ (d`div`2) ^ 2

The idea to special-case x^2 shamelessly stolen from the asker.
Another 49-character version, requires common subexpression elimination (which GHCi doesn't do in this case) to be efficient:
x^0=1;x^n|odd n=x*x^(n-1)|1>0=x^div n 2*x^div n 2

PHP
function p($x,$n){return($n>1)?p($x*$x,$n-1):$x}

This doesn't compute powers (it instead computes x^(2^(n-1)) ) and isn't logarithmic time in n

In python we have 2 methods for doing this :

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

Output corresponding to it is:

4
100000

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

You have not written an algorithm as the question asks, you're using Python's builtin algorithms. In JS it can be done with Math.pow(), so this is in no way interesting...

source: Stack Exchange

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

sort: votes


text:
Matlab/Octave Eratosieve using minimal big-O iterations
I'm trying to come up with ways to write Sieve of Eratosthenes in Octave that vectorize as much as possible (ie minimizing the number of times iterating over the for-loop/while-loop/recursive call)
I found one that requires only O(log(log(n))) iterations inside the for-loop, but the big-O running time (and also space) is O(n^(5/4)/log(n)) so it's arguably not the Sieve of Eratosthenes
Now I think I have one with the usual running time O(nlog(log(n))) and only O(log(n)) iterations, but I want to see if someone else comes up with a better solution.

You're asking us to come up with an improvement to an algorithm that dates back to ancient Greece?
You might have better luck posting your code and asking for suggestions for improvement.

I'm not asking for a big-O running-time improvement.  I'm just saying can you write a SOE that's better vectorized for Octave?

Is this really in a form appropriate for CodeGolf.SE? Perhaps it would be better on CodeReview?

Here's my solution
The loop clearly runs O(logn) times and it's easy to see that the number of operations is bounded above by the normal number of operations for SOE(2n) so it's within O(nlog(logn)) big-O running time
function [primes] = eratosieve(n)
    isprime = ones(n, 1);
    isprime(1) = false;
    m = 1;
    while(m ^ 2 < n)
        nprimes = find(isprime(m + 1 : m * 2)) + m;
        mult = (m + 1) : (n/(m + 1));
        a = nprimes * mult;
        isprime(a(a<=n)) = false;
        m *= 2;
    end
    primes = find(isprime);
endfunction

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


text:
Convert JSON string to Key / Value Arrays
Convert JSON (key/value pairs) to two native arrays, one array of keys and another of values, in your language.
var X = '{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}';

The value array could be an array of strings or integers.
So we need two functions keys & vals, returning native arrays on input of JSON string.
In above example the output would be:
keys : ["a", "b", "c", "d", "e", "f", "g", "h"]
vals : ["a", "b", "c", "d", "e", "f9", "g2", "h1"]

Here is my attempt at this using javascript:
keys : (53 Chars)
function keys(X){return X.match(/[a-z0-9]+(?=":)/gi)}

vals : (56 Chars)
function vals(X){return X.match(/[a-z0-9]+(?="[,}])/gi)}

Can other languages challenge this??

What assumptions are you making about the input? You seem to be assuming that it's a single JSON object all of whose member values are strings, and none of whose names or values require escaping. Those assumptions seem to be rather unmotivated / arbitrary.

I know. But you could say it's a JSON with some constraints. It need not be arbitrary since we could find such cases a lot, in a practical data set. Besides, answers handling the general set would be more than welcome... (as in one of the answers)

function keys(x){return Object.keys(JSON.parse(x))}...

I'd VTRO (edit: it's not closed, so I'd not-vote-to-close) this, but there's still a few things that are unclear: Can we have a single function that returns both arrays? What can we assume the keys or values look like? What is a "native array"?

Python, 27/30
To actually comply with the rules:
keys=lambda x:list(eval(x))
vals=lambda x:eval(x).values()

Python, 30
Just using one function:
lambda x:zip(*eval(x).items())

This will separate the keys from the values and return them in a list.
Python, 7
If returning a dictionary is allowed, then this is all you need:
eval(x)

APL 32
Index origin 1. If you will accept the keys and values being returned as a two row array then a simple one liner will do the job in APL. This takes screen input via ←⍞
⍉((.5×⍴j),2)⍴j←(~j∊'{":;,}')⊂j←⍞

Taking the given example as input:
{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"};

a b c d e f  g  h
a b c d e f9 g2 h1

Perl 28 bytes
Instead of 2 separate functions to return keys and values, I'm returning both in the form of a hash.
sub j2h{eval pop=~y/:"/,/dr}

Sample usage:
$_='{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}';
%h=j2h($_);
print $h{f}; # prints f9
print $h{g}; # prints g2

It even works for arbitrarily deeply nested variables:
$_='{"a":{"b":{"c":"c3","d":"d4"},"c":"c5"},"b":"b6"}';
%h=j2h($_);
print $h{a}{b}{d}; # prints d4
print $h{a}{c};    # prints c5

Tcl 69,69
first attempt 132 keys+vals
proc j {x n} {
regsub -all {(".*?"):(".*?")} $x "\[lappend o \\$n\]" x
subst $x
set o $o
}
proc keys x {j $x 1}
proc vals x {j $x 2}

second try 69 keys, 69 values
proc keys x {regsub -all {(".*?"):(".*?").} $x {\1 } x
lindex $x\} 0}

proc vals x {regsub -all {(".*?"):(".*?").} $x {\2 } x
lindex $x\} 0}

Compared to the answers, this one is very, very long. Is there a way you can compact this down, to (say) less than 50 characters?

69 per proc is the best I could get. It looks like Johannes Kuhn has a good one for Tcl 8.6.

You can shorten a bit because you are regex' tagging expressions you don't need, so you can remove some (): http://rextester.com/EFMSXX16344

May be I am wrong, but I think you also don't need  0 at the end.

K, 22
{+`$":"\:'","\:1_-1_x}

The double quotes in the input string have to be escaped
k){+`$":"\:'","\:1_-1_x} "{\"a\":\"a\",\"b\":\"b\",\"c\":\"c\",\"d\":\"d\",\"e\":\"e\",\"f\":\"f9\",\"g\":\"g2\",\"h\":\"h1\"}"
"a" "b" "c" "d" "e" "f"  "g"  "h"
"a" "b" "c" "d" "e" "f9" "g2" "h1"

For the same bytecount you could just read from stdin
+`$":"\:'","\:1_-1_0:0

.
k)+`$":"\:'","\:1_-1_0:0
{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}
"a" "b" "c" "d" "e" "f"  "g"  "h"
"a" "b" "c" "d" "e" "f9" "g2" "h1"

PHP, 56/58
Pssh, PHP has functions for this stuff (although it won't win the shortest answer award).
function keys($j){return array_keys(json_decode($j,1));}
function vals($j){return array_values(json_decode($j,1));}

APL (Dyalog Unicode), 18 bytesSBCS
Anonymous tacit prefix function. Prints list of keys, then returns list of values.
'⍎¨⎕←⎕NL¯2'⍎⍨⎕JSON

Try it online!
⎕JSON convert JSON string to APL namespace object
'…'⍎⍨ in that namespace, execute the following code:
 ⎕NL¯2 name list for all all variables
 ⎕← print that list
 ⍎¨ execute each name

PowerShell, 34/36 28/28  bytes
-14 bytes total thanks to @mazzy!
To fetch the keys:
&(gcm *F*son)"$args" -a|% k*

Try it online!
To fetch the values:
&(gcm *F*son)"$args" -a|% v*

Try it online!
Kinda cheap, as it uses the built-in method ConvertFrom-Json -AsHashtable to convert the data from JSON.

keys and values

ECMAScript
I'm surprised no one has proposed a better ECMAScript solution, so here's my simple attempt:
keys: (29 chars)

X=>Object.keys(JSON.parse(X))

values: (31 chars)

X=>Object.values(JSON.parse(X))

28 bytes, 30 bytes: X=>Object.keys(eval("1,"+X)), X=>Object.values(eval("1,"+X))

@EnderShadow8 Much better than my solution

C (gcc), 103 bytes
char*b[99],**o,*l;f(s,n)char*s;{for(o=b;*s++;l=*s-34?l:++n%4?s+1:(*o++=strndup(l,s-l)));*o=0;return b;}

Try it online!
Usage:
f(input, 2) returns an array with the keys
f(input, 0) returns an array with the values
C (clang), 67 bytes
*l;f(*s,n){for(;*s++;l=*s-34?l:++n%4?s+1:printf("%.*ls\n",s-l,l));}

Writes the output to stdout instead of returning arrays.
Try it online!

jq, 11–∞ bytes
Try it online!
This answer will take some refining, as I'm not yet clear on the rules. It states that two functions are required, but jq doesn't have functions and I don't know how much of our current meta consensus applies to such old posts
The essence is in two snippets:

keys: keys
values: [.[]]

These are both valid jq programs that each give their respective piece. Counted like this we have 11 bytes. We can also do:
# Return an array of arrays as [keys, values]
[keys, [.[]]]

# Return another nice JSON as {"keys": keys, "values": values}
{keys:keys, values:[.[]]}

I'll add a bit more explanation when the final entry is clearer.

CoffeeScript:
vals = []
keys = []
vals.push(v) and keys.push(k) for own k, v of JSON.parse(X)

Ruby, 19
eval X.gsub':','=>'
Similar, unsurprisingly, to the Perl solution. The Ruby 1.9 literal for a Hash would be identical to the input form if it weren't for the quoted keys; as it is we just need to convert the colons to =>.

Lua
function keys(x)return loadstring("return"..x:gsub(':".-"',''))()end
function vals(x)return loadstring("return"..x:gsub('"[^"]*":',''))()end

68 and 71 chars

Tcl 8.6, 82
 package r json;lmap keys [dict k [set d [json::json2dict $X]]] vals [dict v $d] {}

The Tcl core is (unlike php) very small.
This requires the tcllib, which is available as package for most linux distributions.
I use this library because too much languages have a json_parse build in.

PHP 7.4+, 39/41 bytes
(demo)
The keys via closure with PHP7.4 arrow function syntax: 39 bytes
(fn()=>array_keys(json_decode($X,1)))()

The values via closure with PHP7.4 arrow function syntax: 41 bytes
(fn()=>array_values(json_decode($X,1)))()

Python 3 (Total 35 characters)
Input JSON String
X = '{"a":"a","b":"b","c":"c","d":"d","e":"e","f":"f9","g":"g2","h":"h1"}'

Get Keys(16 characters)
k=eval(X).keys()

Get Values(18 characters)
v=eval(X).values()

Try online

Burlesque, 12 bytes
'";;:an2cou[

Try it online!
'";; # Split by "s
:an  # Filter by alphanumeric
2co  # Group in pairs
u[   # Unzip giving array of vals and array of keys


text:
The making of "Spot It!": Finding almost unique sets
Puzzle: Find a deck of c cards, each containing p pictures, such that no two pictures match on a given card, and exactly 1 picture on each card matches exactly 1 picture on each of the other cards, where the number of unique pictures in the deck is minimized.
Criteria: Fastest code for c = 31 and p = 6.
Inspiration: This puzzle was inspired by wondering how the makers of the card game Spot It! came up with a deck of cards that differ from each other by only one picture. If it helps, the game's instructions say it contains 31 cards with at least 30 unique pictures.
Brute-force reference implementation: (Entirely impractical for use at the scale of the contest judging criteria, but perhaps useful for thinking about the problem.)
class Program
{
    const int CardCount = 31, PicturesPerCard = 6;

    static void Main()
    {
        for (int pictureLimit = PicturesPerCard; ; ++pictureLimit)
            new Solver(pictureLimit).FindValidCards(0, 0);
    }

    class Solver
    {
        readonly byte[,] cards = new byte[CardCount, PicturesPerCard];
        readonly int pictureLimit;

        public Solver(int pictureLimit)
        {
            this.pictureLimit = pictureLimit;
        }

        public void FindValidCards(int c, int p)
        {
            for (; c < CardCount; ++c) {
                for (; p < PicturesPerCard; ++p) {
                    for (int picture = p == 0 ? 0 : cards[c, p - 1] + 1; picture < pictureLimit; ++picture) { // Only consider pictures in numerically increasing sequence, since sequence order is irrelevant.
                        cards[c, p] = (byte)picture;
                        if (p < PicturesPerCard - 1) {
                            FindValidCards(c, p + 1);
                        } else if (c < CardCount - 1) {
                            FindValidCards(c + 1, 0);
                        } else if (AreCardsValid()) {
                            WriteCards();
                            System.Environment.Exit(0);
                        }
                    }
                }
            }
        }

        bool AreCardsValid()
        {
            for (int c = 0; c < CardCount; ++c)
                for (int otherC = c + 1; otherC < CardCount; ++otherC) {
                    int matchCount = 0;
                    for (int p = 0; p < PicturesPerCard; ++p)
                        for (int otherP = 0; otherP < PicturesPerCard; ++otherP)
                            if (cards[c, p] == cards[otherC, otherP])
                                ++matchCount;
                    if (matchCount != 1)
                        return false;
                }
            return true;
        }

        /// <summary>
        /// Writes to the console all the cards with each unique picture placed in its own column for easier comparison between cards.
        /// </summary>
        void WriteCards()
        {
            for (int c = 0; c < CardCount; ++c) {
                string cardString = string.Empty;
                for (int picture = 0; picture < pictureLimit; ++picture)
                    for (int p = 0; ; ++p) {
                        if (p == PicturesPerCard) {
                            cardString += ' ';
                            break;
                        }
                        if (cards[c, p] == picture) {
                            cardString += (char)(picture < 26 ? 'A' + picture : 'a' + (picture - 26));
                            break;
                        }
                    }
                System.Console.WriteLine(cardString);
            }
        }
    }
}

Edits: Reworded puzzle to correctly articulate the intent that the goal is to find a deck that matches the constraints. Added the missing constraint that no two pictures on a card may match. Changed contest type from code golf to speed.

Algorithmically this isn't a very interesting question - brute force is probably the shortest, although it won't have good asymptotic performance because we're in Ramsey theory territory. I suspect that this is a problem which has been studied in maximal graph theory, so you might get a link to a good analysis if you instead ask on math.stackexchange.com.

Although it doesn't appear in OEIS, so it may not have been studied previously.

Is the idea to reduce the given deck to a more compact deck?

Thanks for the feedback! I updated the question accordingly. See edit summary at end.

@Peter: As you suggested, I asked on Mathematics.

Related: http://stackoverflow.com/questions/6240113/what-are-the-mathematical-computational-principles-behind-this-game

This should be a comment rather than an answer, but it's not going to fit in a comment.
One way of looking at this problem is to flip it around:

Given that you have N distinct pictures, what's the largest deck of cards you can build each of which has n distinct pictures such that the intersection of any two cards is precisely one picture?

Another way of phrasing this flipped-round problem is:

What is the maximal size of binary code of length N, constant weight n and exact pairwise Hamming distance 2(n-1)?

This is bounded by the maximal size of binary codes of length N, constant weight n, and minimal Hamming distance 2(n-1). The best resource for such bounds appears to be http://www.win.tue.nl/~aeb/codes/Andw.html although some values here are extracted from OEIS (specifically A001839).
 N \ n  0   1   2   3   4   5   6   7   8   9
 0      1   -   -   -   -   -   -   -   -   -
 1      1   1   -   -   -   -   -   -   -   -
 2      1   1   1   -   -   -   -   -   -   -
 3      1   1   3   1   -   -   -   -   -   -
 4      1   1   3   1   1   -   -   -   -   -
 5      1   1   4   2   1   1   -   -   -   -
 6      1   1   5   4   1   1   1   -   -   -
 7      1   1   6   7   2   1   1   1   -   -
 8      1   1   7   8   2   1   1   1   1   -
 9      1   1   8   12  3   2   1   1   1   1
 10     1   1   9   13  5   2   1   1   1   1
 11     1   1   10  17  6   2   2   1   1   1
 12     1   1   11  20  9   3   2   1   1   1
 13     1   1   12  26  13  3   2   2   1   1
 14     1   1   13  28  14  4   2   2   1   1
 15     1   1   14  35  15  6   3   2   2   1
 16     1   1   15  37  20  6   3   2   2   1
 17     1   1   16  44  20  7   3   2   2   2
 18     1   1   17  48  22  9   4   3   2   2
 19     1   1   18  57  25  12  4   3   2   2
 20     1   1   19  60  30  16  5   3   2   2
 21     1   1   20  70  31  21  7   3   3   2
 22     1   1   21  73  37  21  7   4   3   2
 23     1   1   22  83  40  23  8   4   3   2
 24     1   1   23  88  42  24  9   4   3   3
 25     1   1   24  100 50  30  10  5   3   3
 26     1   1   25  104 52  30  13  5   4   3
 27     1   1   26  117 54  31  14  6   4   3
 28     1   1   27  121 63  33  16  8   4   3
 29     1   1   28  134 65  ?   20  8   4   3
 30     1   1   29  140 ?   ?   25  9   5   4
 31     1   1   30  155 ?   ?   31  9   5   4
 32     1   1   31  160 ?   ?   31  10  5   4

There are some easy to prove properties, but from what I've read so far it seems that in general there's no better method known than brute force.
Note that for n > 2 these bounds appear to be loose for N > n^2 - n + 1 (certainly they are for the values of n in the table above), and tight for N <= n^2 - n + 1.
One useful result which handles the case that most interests you is as follows. (I could also write some code to wrap this up by using special cases and falling back to brute force, but I don't see the point).

If N = n^2 - n + 1 then there is a nicely structured deck of N cards satisfying the required property.

The construction is quite simple:
(-1,-1) (x,0) (x,1) ... (x,n-2)                for x in 0..n-1
(0,y) (1,y+z % n-1) ... (n-1, y+(n-1)z % n-1)  for y in 0..n-2, z in 0..n-2

Each element appears in precisely n cards, which makes it optimal for decks in which more than one picture repeats.
Call the most frequent picture (selecting arbitrarily in case of a tie) f.
Lemma 1

If f appears in more than n cards then it must appear in every card, and no other element repeats.

Proof: because each pairwise intersection contains precisely one element, all of the other elements in the cards containing f must be distinct. But then a card which doesn't contain f must have a non-trivial intersection with more than n disjoint sets despite having only n elements, which is impossible.
Corollary

The largest possible deck in which f appears in more than n cards has size floor((N-1) / (n-1))

Excluding f from the N available pictures we get N-1 from which to draw disjoint sets of size n-1 to complete each card.
Lemma 2

Any deck in which f appears in no more than n cards has at most n^2 - n + 1 cards.

Consider an arbitrary card containing f. By definition of f, none of the n elements of that card appears in more than n cards, and since each appears in that card the number of other cards is no more than n(n-1). Hence the deck cannot be larger than n(n-1) + 1.
Theorem

The largest possible deck has an upper bound of max(n^2 - n + 1, floor((N-1) / (n-1))).

By combining the corollary and lemma 2.

I had noticed that these look an awful lot like projective planes... well researched!

Note that the setting in the question (c=31, p=6) is in form of N=n^2-n+1 with c=N and p=n

@justhalf, "One useful result which handles the case that most interests you"...

@PeterTaylor: Yeah, that's so subtly put in your answer which is started by the statement "This should be a comment rather than an answer, but it's not going to fit in a comment.". My point is that you already give an answer to the question, albeit in English =) You just need to add the running time, if that's well-defined, haha

Because I view this question as primarily a challenge question, I'll describe how an approach can be developed.  I'll present the code in ungolfed format in the hopes that it might shed light on how  the solution was constructed.  Perhaps I'll add a golfed version later.
Throughout I'll illustrate using the example of the deck of 7 cards, each having 3 pictures on it.
Complete Graph
Whatever the size of the deck, the problem calls for a complete graph. If each vertex or node in the graph represents a distinct card from the deck, there should be a single link or edge between each vertex. This corresponds to the constraint that any pair of cards shares a single  picture.

Adjacency Matrix
Another way to express this it through an adjacency matrix. Rows and Columns correspond to cards.  A cell (i,j) with a 1 in it indicates that card i has one picture in common with card j.  No cells can contain an integer greater than 1 (that would mean that cards i and j share more than one picture). The diagonal consists of zeros; there are no links from a card to itself.

Which pictures are in each card?
Below we include additional information that was not in the above diagrams.  And in fact this is not the only possible solution.  Even if you accept that this constitutes one viable deck of 7 cards and 7 pictures, we might have stumbled upon it by chance.  We need an approach that will work for any number of pictures and cards.

Filling in the Complete Graph
We may as well use the preceding picture to fill in information in the complete graph.
Remember, we haven't solved anything. We're merely explore different ways of thinking about a specific solution, once found.

Matrix of Cards by Pictures
Let's represent the above illustration in a another matrix. This time, the rows represent cards; the columns represent pictures.

Reading the first row, we see that card 1 contains picture 1, picture 2, and picture 3.
Card 2 contains picture 1 (the picture in common between cards 1 and 2), as well as pictures 4 and 5.  And so on.
By studying the distribution of pictures to cards (where the 1's appear in the matrix) we can identify a procedure that will guarantee a full deck.  (Be sure to see Peter Taylor's analysis of why a pictures per card can produce a maximum deck of a(a-1)+1 cards using a total of a(a-1)+1 pictures.)  In the example, 3 pictures per card suffice to make a deck of 7 cards.
Steps for making a deck of Spot It! cards.

Choose how many pictures per card, a. Your deck will have c=a(a-1)+1 cards.
Make a c by c null matrix (all zeros). The rows will represent cards. The columns will represent pictures.
We will arbitrarily proceed row by row, left to right.  We need to distribute three 1's to each row (three distinct pictures per card) such that: (a) there is at most one picture from the present card's row that matches a picture from any other card's row and (b) at most a copies of picture will be used in the deck.  Because of how a and c were set, It automatically turns out that the proper number of pictures per card will result. (If you desire a slightly smaller deck, simply remove the extra cards. Any one is as good as the other.)

Code in Mathematica (ungolfed)
deck[picsPerCard_]:=

Module[{pics=picsPerCard (picsPerCard-1)+1,cards,matrix,linked,elegible},
(*pics not really needed, but it helps distinguish columns from rows *)
cards=pics;

(*the null matrix *)
matrix=ConstantArray[0,{cards,pics}];

(* cards considered already linked; hence the cell under consideration will not be
 elegible for receiving a 1.*)
linked[m_,row1_,row2_]:=row1==row2\[Or]Tr[m[[row1]] m[[row2]]]>0;

(*Checks whether cell (r,c) is elegible for receiving card c *)
elegible[m_,{r_,c_},ppc_]:=Tr[m[[r]]]<ppc\[And](m[[r,c]]==0)\[And]
(Length[(f=Flatten[Position[matrix\[Transpose][[c]],1]])]<ppc)\[And]\[Not]
(Or@@(linked[matrix,r,#]&/@f));

(* Fill in with 1's all elegible cells.  Proceed row by row, i.e. card by card *)
Do[If[elegible[matrix,{i,j},picsPerCard], matrix=ReplacePart[matrix,{i,j}->1]],
{i,cards},{j,pics}];

(*return the solution matrix *)
matrix]

Examples:
deck[3] // MatrixForm

Note: There remains a glitch in the code that affects decks with an even numbers of pictures per card. I will repair this within a day or two.

I encountered difficulty with the premise (lemma?) that the matrix is square. See my answer for the code that failed for want of more pictures than cards. Of course, there could just be a bug that I missed.

I think you are correct about the square matrix assumption being unnecessary. In fact, this suggests a straightforward fix: keep introducing additional unique pictures as the case requires.  I.e. Extend the columns as required.

I have a feeling that my above seat-of-the-pants approach is naive.  There are subtleties, hinted at in P. Taylor's contribution, that I have not yet fathomed.

I implemented the "fix" of introducing unique pictures as needed. I don't know whether the result uses the minimum number of unique pictures, however.

So did I (but I didn't post it yet). Here are the numbers, organized by {picsPerCard, Total pics, cards}:
{3, 7, 7} {4, 17, 13} {5, 21, 21} {6, 47, 31} {7, 63, 43} {8, 88, 57} {9, 121, 73} {10, 147, 91}. As you say, they may not be optimal.

This is a (correct?) C# implementation of David Carraher's algorithm. I am posting it in case it provides insight into the glitch he discovered. When run with 3 pictures per card, it provides identical output as David's solution. However, for 4 or more pictures per card, it fails for want of more unique pictures across the deck than there are cards in the deck.
Edit: Updated to allow creation of additional pictures as needed (so it no longer fails). Also added sample runs.
/// <summary>Finds a deck that solves the puzzle.</summary>
/// <returns>An array of cards, where each card is a bit vector and each bit is true only if the corresponding picture is present.</returns>
static long[] FindDeck(int picturesPerCard, out int uniquePicturesCount)
{
    // Start with an initially zeroed matrix of rows of cards and columns of picture bits (bit is on if the card contains that picture).
    int cardCount = picturesPerCard * (picturesPerCard - 1) + 1;
    var deck = new long[cardCount];
    var pictureCountsForDeck = new List<int>();

    // Go through each card row, and find a valid card for that row:
    for (int c = 0; c < cardCount; ++c) { // Single-letter variables are indexes.
        var card = deck[c];
        int pictureCountForCurrentCard = 0;

        // Go through each possible picture, and turn on that picture bit if it is valid:
        for (int p = 0; ; ++p) {
            var proposedCard = card;
            proposedCard |= 1L << p; // Sets the bit for the proposed picture to true.

            // Each picture can only be used so often across the entire deck. The cap is the same as the number of pictures per card.
            if (pictureCountsForDeck.Count <= p)
                pictureCountsForDeck.Add(0);
            if (pictureCountsForDeck[p] == picturesPerCard)
                continue;

            // Check whether the picture bit is valid against the previous picture cards.
            for (int checkC = 0; ; ++checkC) {

                // If this card has been successfully checked against all previous cards:
                if (checkC == c) {
                    deck[c] = card = proposedCard;
                    ++pictureCountsForDeck[p];
                    if (++pictureCountForCurrentCard == picturesPerCard)
                        goto NextCard; // All pictures found for this card. Move to the next card.
                    break; // Find another picture for this card.
                }

                // To determine that a picture proposal is invalid, show that there was a previous match or that the new set of matched pictures differs from the previous set. This indicates more than one picture matches.
                var checkCard = deck[checkC];
                long existingMatch = card & checkCard;
                if (existingMatch != 0 && existingMatch != (proposedCard & checkCard))
                    break; // This picture proposal is invalid. Move on to the next picture.
            }
        }
    NextCard: ;
    }
    uniquePicturesCount = pictureCountsForDeck.Count;
    return deck;
}

The results for 4 pictures per card looks good for the square part of the matrix. However, the matrix gets sparse as columns are added:
1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0
0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0
0 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0
0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0
0 0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 0
0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0
0 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 1 0
0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0 1

Or is it just an anomaly at that size? The matrix is square and well filled for 5 pictures per card:
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1
0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 1 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0
0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0
0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
0 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0
0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0
0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0
0 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0
0 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 1
0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0
0 0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1
0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0
0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 0 0 1 0 0

On the other hand, at 6 pictures per card (also even), it's back to sparse again at the tail. Have we really minimized the number of unique pictures?
01000000100001000010000100001000000000000000000
01000000010000100001000010000100000000000000000
01000000001000010000100001000010000000000000000
00100010000010000010000010000010000000000000000
00100001000100000001000100000001000000000000000
00100000100000101000001000000000100000000000000
00100000010001000100010000000000010000000000000
00100000001000000000000000100000001110000000000
00010010000001000001001000000000001000000000000
00010001000000100010010000000000000100000000000
00010000100100000100000010000000000010000000000
00010000010010001000000100000000000001000000000
00010000001000000000000000010001110000000000000
00001010000000100100000100000000000000100000000
00001001000001001000000010000000000000010000000
00001000100010000001010000000000000000001000000
00001000010100000010001000000000000000000100000
00001000001000000000000000001000000001000011000
00000110000000010000000000010000000101000000000
00000101000000000000100000100000100000100000000
00000100100000000000000001000101001000000000000
00000100010000000000000000001000000010011000000
00000100001100000000000000000000000000000000111


text:
Create a Twitter Parser
Introduction
You use Twitter (let's pretend, if not), where you are limited to 140 characters per individual tweet you care to share with the world. If you wanted to tweet to your followers Abraham Lincoln's Gettysburg Address, then you would need to break up the text into multiple 140-character chunks in order to get the whole message out. However, those chunks should not always be exactly 140 characters long. Say for example, we broke the speech into 17-character chunks, we'd end up with these tweets:

FOUR SCORE AND SE
VEN YEARS AGO OUR
FATHERS BROUGHT
FORTH ON THIS CON
TINENT A NEW NATI
ON CONCEIVED IN L
(and so on)

That's no good! When individual words are broken up, then it can get difficult to understand what you are trying to say. Also, in the twitterverse, one of your followers may come across a specific tweet and not realize that there's more to the message, so you'll want to number your tweets so they have some context to work with (still using 17-character chunks):

(1/7) FOUR SCORE AND
(2/7) SEVEN YEARS AGO
(3/7) OUR FATHERS
(4/7) BROUGHT FORTH ON
(5/7) THIS CONTINENT A
(6/7)  NEW NATION
(7/7) CONCEIVED IN...

You could manually figure out the best configuration for your tweets by hand, but that's what we have computers for!
Challenge
In the shortest code possible, parse the Gettysburg Address (or any text, but we'll stick with this one as an example) into a set of tweets consisting of no more than 140 characters (assume ASCII, since our example text should not have any uncommon/unusual bits in it).
Details

Your function/program/etc should take in a single string argument and output one line of text for each tweet.

Assume this input will never result in more than 99 total tweets when parsed, regardless of how you choose to parse (so long as that choice still fits the other points of the challenge).

Tweets need to include a tweet number of total tweets indicator in the format "(x/y)" preceding the body of the tweet.

This count will take up part of your 140-character space!

Tweet chunks may only be split on newlines or spaces.

No hyphens, periods, commas or other punctuation is allowed, unless immediately preceded or followed by a space or newline.

Tweets should consist of as many complete words as possible.

This constraint is a little flexible, e.g. when your final tweet only has one word

This is code golf, so the shortest code wins.

Full Text of Gettysburg Address
(Your code should still be able to handle any ASCII string passed to it.)

FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE PROPOSITION THAT ALL MEN ARE CREATED EQUAL.
  NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF THAT FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND PROPER THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND. THE BRAVE MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL LITTLE NOTE NOR LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE DEDICATED HERE TO THE UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE DEDICATED TO THE GREAT TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH THEY GAVE THE LAST FULL MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS NATION UNDER GOD SHALL HAVE A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH FROM THE EARTH.

In your example tweets, you've broken words -- but in the rules, you say not to.  Please make this consistent -- either change the rules or the examples.

@boothby Well, the example is to explicitly show what's not allowed... I'll see if I can't re-word that.

Please clarify the question to make it clear whether or not answers must deal with possibility of having to recompute word -> tweet packings due to the (X/Y) part. This makes the problem significantly harder and  introduces a cap on the largest message one may communicate without encoding data in the (X/Y) part.

@rmckenzie Sorry, not sure if I get you? You mean to account for the fact that you could have 100+ tweets in a set?

@Gaffi - Yes, is there a maximum number of parts into which our messages will be divided (in which cases assumptions may be made and grc's sol is valid) or do we have to support the general case such as serializing a multi-thousand word to a tweet which your problem statement as is suggests.

@rmckenzie I'll update the spec, but to respond directly: assume no input large enough to result in more than 99 total tweets.

This is one of the main reasons I absolutely HATE twitter :p

Do I get bonus points if my code posts them to twitter, too?

Perl, 51 Characters
s#\G(.{1,132})(\s+|$)#(${\++$a}/~) $1\n#g;s#~#$a#g

Requires -p command line prompt, 1 char included.
Explanation: insert the count portion before and newline after word groups of up to 132 characters.  Insert a placeholder (~) for the total, which is then replaced by a second substitution. This breaks if the message contains ~, but one could easily use an unprintable character instead.
It cheats slightly: it always allows seven characters for the count portion, (nn/nn). Really, if it is (n/n) it should allow two extra characters. However, an arbitrary solution to this would greatly increase the complexity of the problem.

\G is useless here, isn't it?

Python, 140
^ 140 chars was actually a coincidence.
def f(s):
 s=s.split();i=0;l=[]
 while s:
  i+=1;t='(%d/%%d)'%i
  while s and len(t+s[0])<140:t+=' '+s.pop(0)
  l+=[t]
 for t in l:print t%i

While there are words left, the solution will create new tweets from the supply of words and append them to a list. For each tweet, it will keep trying to add words until the tweet's length reaches over 140 characters. Two characters are reserved for the total tweets, which are filled in later as each tweet in the list is printed.
Example output:
(1/11) FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE
(2/11) PROPOSITION THAT ALL MEN ARE CREATED EQUAL. NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO
(3/11) CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF THAT
(4/11) FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND PROPER
(5/11) THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND. THE BRAVE
(6/11) MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL LITTLE NOTE NOR
(7/11) LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE DEDICATED HERE TO THE
(8/11) UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE DEDICATED TO THE GREAT
(9/11) TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH THEY GAVE THE LAST FULL
(10/11) MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS NATION UNDER GOD SHALL HAVE
(11/11) A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH FROM THE EARTH.

It was exactly what I needed. This solution is cool. Thanks @grc

Ruby, 77 characters
f=->t{i=0;$><<t.gsub(/(.{1,132})([ \n]|$)/m){"(#{i+=1}/%{i}) #{$1}\n"}%{i:i}}

Packed the logic into a single regular expression. Output of f[text]:
(1/11) FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE
(2/11) PROPOSITION THAT ALL MEN ARE CREATED EQUAL. NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO
(3/11) CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF
(4/11) THAT FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND
(5/11) PROPER THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND. THE
(6/11) BRAVE MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL LITTLE
(7/11) NOTE NOR LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE DEDICATED
(8/11) HERE TO THE UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE DEDICATED TO
(9/11) THE GREAT TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH THEY GAVE THE
(10/11) LAST FULL MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS NATION UNDER GOD
(11/11) SHALL HAVE A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH FROM THE EARTH.

Ruby, 75
Can't beat Perl, but at least it marginally beats the other Ruby solution. Note that it prints the tweets in reverse order (the problem does not specify one).
f=->t,i=1{t=~/\S.{,130}\S(?!\S)/?puts("(#{i}/%d) #$&"%n=f[$',i+1])||n :i-1}

Hm... I suppose I did not specify the order. Good job hijacking the rules. ;-)

VBA, 251
Tried another method... Not quite as good as my original, but I'm still working on it...
Sub a(s)
Dim n(99)
m=1
r=Split(StrConv(s,64),Chr(0))
For i=0 To Len(s)
If i-g>132 Then n(m)=Mid(s,g+1,u-g):i=u:g=i:m=m+1
If r(i)=" " Or r(i)=vbCr Then i=i+1:u=i
Next
n(m)=Mid(s,g+1)
For o=1 To m
Debug.Print "(" & o & "/" & m & ") " & n(o)
Next
End Sub

Outputs:
(1/11) FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE
(2/11) PROPOSITION THAT ALL MEN ARE CREATED EQUAL. NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO
(3/11) CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF
(4/11) THAT FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND
(5/11) PROPER THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND. THE
(6/11) BRAVE MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL LITTLE
(7/11) NOTE NOR LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE DEDICATED
(8/11) HERE TO THE UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE DEDICATED TO
(9/11) THE GREAT TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH THEY GAVE THE
(10/11) LAST FULL MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS NATION UNDER GOD
(11/11) SHALL HAVE A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH FROM THE EARTH.

BASH (88 Chars)
fold -132 -s |tac|cat -n |tac|awk '{if(NR==1)a=$1;$1="";printf "(%d/%d) %s\n",NR,a,$0 }'

Fold the line at 132 characters (to allow for our tweet count), on spaces (-s), Read text backwards (tac), number the text (cat -n), re-reverse (tac). Inside Awk: First line (NR==1), assign the letter 'a' the value in the first . Blank the number column. Print (NR/'a') then the line.
Output:
(1/12)  FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE
(2/12)  PROPOSITION THAT ALL MEN ARE CREATED EQUAL. NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO
(3/12)  CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF
(4/12)  THAT FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND
(5/12)  PROPER THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND.
(6/12)  THE BRAVE MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL
(7/12)  LITTLE NOTE NOR LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE
(8/12)  DEDICATED HERE TO THE UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE
(9/12)  DEDICATED TO THE GREAT TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH
(10/12)  THEY GAVE THE LAST FULL MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS
(11/12)  NATION UNDER GOD SHALL HAVE A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH
(12/12)  FROM THE EARTH.

I'm confident there is a shorter bash command, one that abused wc -l

Javascript (FF only), 92 chars
r=(s)=>{s.match(/.{1,132}(\s|$)/gm).map((v,i,a)=>console.log(v,'('+(i+1)+'/'+a.length+')'))}

Formatted, that's a rip-off of the Perl script:
r=(s)=>{
    s.match(/.{1,132}(\s|$)/gm).map((v,i,a) => console.log(v,'('+(i+1)+'/'+a.length+')'))
}

VBA, 227
Sub a(s)
Dim n(99)
m=1
x=133
While Len(s)>x
t=Left(s,x):p=InStrRev(t," "):q=InStrRev(t,vbCr):i=IIf(p>q,p,q):t=Left(s,i):s=Mid(s,i+1):n(m)=t:m=m+1
Wend
n(m)=s
For o=1 To m
Debug.Print "(" & o & "/" & m & ") " & n(o)
Next
End Sub

Outputs:
(1/11) FOUR SCORE AND SEVEN YEARS AGO OUR FATHERS BROUGHT FORTH ON THIS CONTINENT A NEW NATION CONCEIVED IN LIBERTY AND DEDICATED TO THE
(2/11) PROPOSITION THAT ALL MEN ARE CREATED EQUAL. NOW WE ARE ENGAGED IN A GREAT CIVIL WAR TESTING WHETHER THAT NATION OR ANY NATION SO
(3/11) CONCEIVED AND SO DEDICATED CAN LONG ENDURE. WE ARE MET ON A GREAT BATTLEFIELD OF THAT WAR. WE HAVE COME TO DEDICATE A PORTION OF
(4/11) THAT FIELD AS A FINAL RESTING PLACE FOR THOSE WHO HERE GAVE THEIR LIVES THAT THAT NATION MIGHT LIVE. IT IS ALTOGETHER FITTING AND
(5/11) PROPER THAT WE SHOULD DO THIS. BUT IN A LARGER SENSE WE CAN NOT DEDICATE, WE CAN NOT CONSECRATE, WE CAN NOT HALLOW, THIS GROUND. THE
(6/11) BRAVE MEN LIVING AND DEAD WHO STRUGGLED HERE HAVE CONSECRATED IT FAR ABOVE OUR POOR POWER TO ADD OR DETRACT. THE WORLD WILL LITTLE
(7/11) NOTE NOR LONG REMEMBER WHAT WE SAY HERE BUT IT CAN NEVER FORGET WHAT THEY DID HERE. IT IS FOR US THE LIVING RATHER TO BE DEDICATED
(8/11) HERE TO THE UNFINISHED WORK WHICH THEY WHO FOUGHT HERE HAVE THUS FAR SO NOBLY ADVANCED. IT IS RATHER FOR US TO BE HERE DEDICATED TO
(9/11) THE GREAT TASK REMAINING BEFORE US, THAT FROM THESE HONORED DEAD WE TAKE INCREASED DEVOTION TO THAT CAUSE FOR WHICH THEY GAVE THE
(10/11) LAST FULL MEASURE OF DEVOTION, THAT WE HERE HIGHLY RESOLVE THAT THESE DEAD SHALL NOT HAVE DIED IN VAIN, THAT THIS NATION UNDER GOD
(11/11) SHALL HAVE A NEW BIRTH OF FREEDOM, AND THAT GOVERNMENT OF THE PEOPLE BY THE PEOPLE FOR THE PEOPLE SHALL NOT PERISH FROM THE EARTH.

Javascript (FF only), 135 chars
n=(s)=>{for(g=[],i=1,a=s.split(/(\s)/),r='';c=a.shift();g[i]=r+=c)if((c+r)[132]&&i++)r='';g.map((v,k)=>console.log(v,'('+k+'/'+i+')'))}

Formatted, that's:
n=(s)=>{
    for (g=[],i=1,a=s.split(/(\s)/),r=''; c=a.shift(); g[i]=r+=c) {
        if((c+r)[132]&&i++) {
            r='';
        }
    }
    g.map((v,k)=>console.log(v,'('+k+'/'+i+')'))
}

I think this is more clever than my shorter answer

PHP, 233
Am I correct in assuming that this is the first answer that does not cheat on the count portion?
(It also works with more than 99 tweets; I could shave off two more bytes if I would allow an infinite loop in that case.)
function t($s,$e=1){$a=explode(' ',$s);while($a){$t=++$n;while($a&&strlen($t.$a[0])<137-$e)$t.=' '.array_shift($a);$r[]=$t;}if($n>=10**$e)t($s,$e+1);else foreach($r as$i=>$s)echo preg_replace('%(^\d+)%',"(\$1/$n)",$s),'
';}

ungolfed:
function t($s,$e=1)
{
    $a=explode(' ',$s);
    while($a)
    {
        $t=++$n;
        while($a&&strlen($t.$a[0])<137-$e)$t.=' '.array_shift($a);
        $r[]=$t;
    }
    if($n>=10**$e)                  // if tweet count has more than $e digits
        t($s,ceil(log10($n+1)));    // use correct length (golfed: try with length+1)
    else
        foreach($r as$i=>$s)
            echo preg_replace('%(^\d+)%',"(\$1/$n)",$s),"\n";
}


text:
IPv4 "in subnet" function
Implement the following JavaScript method as short as possible:
function same_subnet(ip_a,ip_b,sn_mask)
{

}

It should get 2 IP addresses and a subnet mask. It should return true if ip_a and ip_b are in the same subnet.
Example calls:

same_subnet("192.168.0.1","192.168.0.15","255.255.255.0") → true
same_subnet("192.168.0.1","192.168.1.15","255.255.0.0") → true
same_subnet("192.168.0.1","192.168.1.15","255.255.255.0") → false

Could it be any language or just javascript? If just javascript, please add javascript tag!

In other words, implement the isInNet function as used in Proxy Auto-Config (PAC) files, but under a different name, and only accepting an IPv4 address as the "host".

126
Fits into a tweet and doesn't even leak globals.
function same_subnet(a,b,c){function x(n){return n=n.split("."),n[0]<<24|n[1]<<16|n[2]<<8|n[3]}return(x(a)&x(c))==(x(b)&x(c))}

Looks to me like it leaks the global x.

@PeterTaylor Try again ;-)

Maybe I've misunderstood or misremembered Crockford's book.


text:
Write an ASP/Prolog/SAT flow solver
Flow Free is an addictive android game where you have to connect pairs of elements together via non-overlapping snakes and fill the entire grid.  For a description, see here:
https://play.google.com/store/apps/details?id=com.bigduckgames.flow&hl=en
I have an ASP (answer set programming) solution which is only a couple rules and I don't think it's possible to phrase the same solution nearly as concisely as a SAT instance, but I'd be interested in being proven wrong.
Any language is fine, but I doubt it can be done concisely without running some sort of solver which is why I labeled it ASP/Prolog/SAT
Winner is fewest characters.
You may assume the problem is defined using the predicates:
v(V). % A vertex

a(V,W). % V and W are adjacent

c(C). % A color

s(V,C). % V is an endpoint of color C

Furthermore, the input satisfies
a(W,V) :- a(V,W) % Adjacencies are bidirectional

2{s(V,C) : v(V)}2 :- c(C). % Every color has exactly two endpoints

The solution predicate will be of the form
e(V,W,C).

Saying there's an edge between V and W of color C.
Edges must be bidirectional (of the same color).  Each vertex must have edges to and from it of exactly one color. Endpoints have exactly one edge, all other vertices have exactly two edges.  There are no loops, every snake must be traceable back to two endpoints.
Here's a sample input to test it on (5x5 Level 2 in the Regular Pack):
v(v11; v12; v13; v14; v15).
v(v21; v22; v23; v24; v25).
v(v31; v32; v33; v34; v35).
v(v41; v42; v43; v44; v45).
v(v51; v52; v53; v54; v55).

a(v11, v12).
a(v12, v13).
a(v13, v14).
a(v14, v15).
a(v12, v11).
a(v13, v12).
a(v14, v13).
a(v15, v14).
a(v11, v21).
a(v12, v22).
a(v13, v23).
a(v14, v24).
a(v15, v25).

a(v21, v22).
a(v22, v23).
a(v23, v24).
a(v24, v25).
a(v22, v21).
a(v23, v22).
a(v24, v23).
a(v25, v24).
a(v21, v31).
a(v22, v32).
a(v23, v33).
a(v24, v34).
a(v25, v35).
a(v21, v11).
a(v22, v12).
a(v23, v13).
a(v24, v14).
a(v25, v15).

a(v31, v32).
a(v32, v33).
a(v33, v34).
a(v34, v35).
a(v32, v31).
a(v33, v32).
a(v34, v33).
a(v35, v34).
a(v31, v41).
a(v32, v42).
a(v33, v43).
a(v34, v44).
a(v35, v45).
a(v31, v21).
a(v32, v22).
a(v33, v23).
a(v34, v24).
a(v35, v25).

a(v41, v42).
a(v42, v43).
a(v43, v44).
a(v44, v45).
a(v42, v41).
a(v43, v42).
a(v44, v43).
a(v45, v44).
a(v41, v51).
a(v42, v52).
a(v43, v53).
a(v44, v54).
a(v45, v55).
a(v41, v31).
a(v42, v32).
a(v43, v33).
a(v44, v34).
a(v45, v35).

a(v51, v52).
a(v52, v53).
a(v53, v54).
a(v54, v55).
a(v52, v51).
a(v53, v52).
a(v54, v53).
a(v55, v54).
a(v51, v41).
a(v52, v42).
a(v53, v43).
a(v54, v44).
a(v55, v45).

s(v11, yellow).
s(v45, yellow).
s(v41, blue).
s(v55, blue).
s(v51, red).
s(v43, red).
s(v42, green).
s(v33, green).

c(red; green; blue; yellow).

And to test the output
shouldbe(v33,v32,green).
shouldbe(v42,v32,green).
shouldbe(v43,v53,red).
shouldbe(v51,v52,red).
shouldbe(v55,v54,blue).
shouldbe(v41,v31,blue).
shouldbe(v45,v35,yellow).
shouldbe(v11,v12,yellow).
shouldbe(v12,v11,yellow).
shouldbe(v35,v45,yellow).
shouldbe(v31,v41,blue).
shouldbe(v54,v55,blue).
shouldbe(v52,v51,red).
shouldbe(v53,v43,red).
shouldbe(v32,v42,green).
shouldbe(v32,v33,green).
shouldbe(v53,v52,red).
shouldbe(v52,v53,red).
shouldbe(v54,v44,blue).
shouldbe(v31,v21,blue).
shouldbe(v35,v25,yellow).
shouldbe(v12,v13,yellow).
shouldbe(v13,v12,yellow).
shouldbe(v25,v35,yellow).
shouldbe(v21,v31,blue).
shouldbe(v44,v54,blue).
shouldbe(v44,v34,blue).
shouldbe(v21,v22,blue).
shouldbe(v25,v15,yellow).
shouldbe(v13,v14,yellow).
shouldbe(v14,v13,yellow).
shouldbe(v15,v25,yellow).
shouldbe(v22,v21,blue).
shouldbe(v34,v44,blue).
shouldbe(v34,v24,blue).
shouldbe(v22,v23,blue).
shouldbe(v15,v14,yellow).
shouldbe(v14,v15,yellow).
shouldbe(v23,v22,blue).
shouldbe(v24,v34,blue).
shouldbe(v24,v23,blue).
shouldbe(v23,v24,blue).

:-not e(V,W,C),shouldbe(V,W,C).
:-e(V,W,C),not shouldbe(V,W,C).

Also Level 21 5x5 should be the first puzzle with more than 1 solution (specifically, there are 9 solutions, not 40)
To set up level 21, set the last few lines of the input to
s(v55, yellow).
s(v44, yellow).
s(v15, blue).
s(v45, blue).
s(v51, red).
s(v53, red).
s(v22, green).
s(v14, green).
s(v23, orange).
s(v43, orange).

c(red; green; blue; yellow; orange).

See also https://codegolf.stackexchange.com/questions/38366/can-you-connect-the-dots

ASP (clingo), 180 bytes
{e(V,W,C):a(V,W),c(C)}.r(V):-s(V,_).r(V):-r(W),e(W,V,_).o(V):-r(V),{e(V,W,_):v(W);s(V,_)}=2.:-e(V,_,C),e(V,_,D),C!=D.:-e(V,W,C),not e(W,V,C).:-v(V),not o(V).:-s(V,C),e(V,_,D),C!=D.

I am new to ASP, so I was excited to find this task, even if it is somewhat old. It was nice to see there were places for variations and an opportunity for golfing which was leading to the limits of my understanding (I hope it is still correct, it seems to be).
Here is a commented version:
% Select some edges e(V,W,C) s.t. V and W are adjacent and C is a color.
{e(V,W,C):a(V,W),c(C)}.

% Auxilary predicates:

% A vertex is reachable from an endpoint if
% it is an endpoint ...
r(V):-s(V,_).
% ... or it has an edge to it from a reachable vertex.
r(V):-r(W),e(W,V,_).

% A vertex is okay if it is reachable and either
% is an endpoint with one edge or is not an endpoint and has two edges.
% This is golfed to: the set of edges from V and endpoints V has
% cardinality 2.
o(V):-r(V),{e(V,W,_):v(W);s(V,_)}=2.

% Constraints:  We do not want ...

% edges from the same vertex with different colors:
:-e(V,_,C),e(V,_,D),C!=D.

% edges without their inverses:
:-e(V,W,C),not e(W,V,C).

% vertices that are not okay:
:-v(V),not o(V).

% edges from endpoints with the wrong color
:-s(V,C),e(V,_,D),C!=D.

% We're only interested in the e predicate:
#show e/3.

I don't know about different ASP solvers, but I used clingo, which in debian is contained in the gringo package.
If you have a problem in a file prob and my code in a file solve, call clingo 0 prob solve. For each solution, you will get the list of colored edges it uses (and all the other predicates if you use the golfed version which lacks the #show line). If you only want the number of solutions, add the option -q. If you only want to know if there is at least one solution, call without 0.


text:
Variable board size 3D Connect Four
Write a 3D version (the game logic being 3D, not the visual representation) of the popular Connect Four game ( http://en.wikipedia.org/wiki/Connect_Four ) where the user can play against the computer. The user may freely chose the dimensions of the game board (width, height, depth) up to a limit of 10 x 10 x 10.
The computer must play an intelligent (probably even optimal) game, apart from its first move which should be random. Ideally a solution will be optimal and never lose. Like tic-tac-toe, perfect play should always result in a draw.
The first player to place four pieces in a row (vertically, horizontally, diagonally, .. (23 combinations in 3D)) wins.
Winner is shortest code.

For what it's worth, 4x4x4 is probably the most interesting variant, and has already been manufactured under the name Score Four. It may also make it easier to develop an optimal AI.

There was already a question about standard connect 4, which deserves more attention and answers: http://codegolf.stackexchange.com/q/5496/7486

so why would this other question "deserve more attention and answers"? my question has nothing to do with standard plain vanilla 2D Connect Four.

There are only on the order of 9! = 362880 possible tic-tac-toe games, which is a trivial number to search for a computer.  On the other hand, for an n x n x n board, there are on the order of pow(n, 2 n) possible 3D Connect Four games.  Granted, those are loose upper bounds, but it gives one idea of the size of the search space.  Is optimally solving a 10 x 10 x 10 3D Connect Four game feasible on today's hardware?

@lightxx, this question has everything to do with standard Connect 4.  It is the exact same problem put in a larger, more generalized space.  I think the 2D version is a better fit for golfing because it is not quite so complex.

@dan1111 I still think you are wrong. The 2D version of this game has been solved mathematically by Victor Allis (see his master's thesis here http://www.connectfour.net/Files/connect4.pdf ) and James Allen (http://homepages.cwi.nl/~tromp/c4.html ). So creating a shorter or more compact version is just a matter of code refactoring. However, none of their approaches scales well - or at all in case of Allis' approach) to 3D. So it is NOT the exact same problem.

people are talking about the search space but no one seems to have mentioned an even more fundamental issue. Shortest code and "intelligent probably optimal" do not go together. There is almost certainly no known way to demonstrate the play is optimal, which means that scoring by shortest code cannot be fair. This challenge could perhaps lend itself to a king-of-the-hill scoring (possibly with a restriction of code to say around 600 bytes.)

Wow this question is old, what was it doing in the review queue? I think it has potential, its a shame that the scoring is problematic


text:
shortest possible python pascal triangle code
the contest is already finished, so I don't think it's cheating to ask:
I am trying to optimize this small contest: pascal triangle
I started with 4.72 and worked myself up to 7.48.
The best made a 9.05 but in perl, python2 best score is 8.25.
Unfortunately they don't let you look at what others did.
My current solution is the following:
l=[1]
print 1
while(len(l)<31):
 print' '.join(map(str,l+[1]))
 l=[1]+map(lambda x,y:x+y,l,l[1:]+[1])

Now I tried to get rid of the loop in using list comprehension, but I am too new to python to get this done. Can anyone give me a hint for nested list comprehension shortening this code further down?
Thank you for your audience.

In the list of answers to Generate Pascal's triangle you may find additional ideas.

The shortest solution I know of is 68 bytes, which would have scored a 8.3. But apparently a 63 byte solution exists.

There's a 63-byte Python solution in the duplicate thread, but that's taking input from stdin, so hard-coding 31 would save 5 for a score of 8.55.

@PeterTaylor The only problem with that solution, is that you'd need to replace print x with print' '.join(map(str,x)) for a loss of 18 bytes.

@primo, ok. Still, using that with the even better Python answer there (oh, I see it's yours) equals the 8.25 best score in python2.

Interesting. I must have posted that before I registered. That could have been made a byte shorter, actually: a=[];exec"a=map(sum,zip(a,[0]+a))+[1];print a;"*input()

Having seem this thread on the mother meta I know this is not going to be what you want to hear, but ... with the very limited exception of the "Tip" series of questions (python version) we don't actually answer "Help me to golf this particular code" questions here. We pose open challenges and compete on the answers. And, yeah, that's a little different from most Stack Exchange sites, But in any case, welcome. Please stay around.

This is a bit shorter, but still no good:
l=[1]
while(len(l)<32):
 print' '.join(map(str,l))
 l=[1]+map(int.__add__,l,l[1:]+[0])

And this one comes in at a score of 8.28 (credit to @primo):
l=[1];exec"print' '.join(map(str,l));l=map(sum,zip([0]+l,l+[0]));"*31

Thank you, I learned a lot. Replacing the loop with a exec"..;"*count will server for future challenges.
Also I like your int.add in replacement of lambda x,y:x+y

I like to say sorry not looking at the duplicate thread. I posted this one at stackoverflow and they recomended this site. So I posted it again, but forgot to do a thorough search.
Thank you for your answers.