text:
My daughter's alphabet
The other day we were writing sentences with my daughter with a fridge magnet letter. While we were able to make some(I love cat), we didn't have enough letters to make the others (I love you too) due to an insufficient amount of letters o (4)
I then found out that while one set included 3 e letters it had only 2 o letters. Probably inspired by http://en.wikipedia.org/wiki/Letter_frequency this would still not reflect the actual situation "on the fridge".
Problem
Given the text file where each line contains a "sample sentence" one would want to write on the fridge, propose an alphabet set with minimum amount of letters but still sufficient to write each sentence individually.
Note: ignore cases, all magnet letters are capitals anyway.
Input
The file contain newline separated sentences:
hello
i love cat
i love dog
i love mommy
mommy loves daddy

Output
Provide back sorted list of letters, where each letter appears only as many times to be sufficient to write any sentence:
acdddeghillmmmoostvyy

(thanks, isaacg!)
Winner
Shortest implementation (code)
UPDATED: Testing
I have created an extra test and tried with various answers here:
https://gist.github.com/romaninsh/11159751

There should be a letter v in the output ;)

I believe the correct output is: acdddeghillmmmoostvyy

Damnit, I accidentally bought one pack with lowercase letters too...

Are we allowed / required to substitute an upside-down M for a W, or a sideways N for a Z? ;-)

Basically you can construct any letter using Is.

More seriously, when you say "ignore cases", do you mean that we can assume that the input is already all in the same case, or that we must convert it all into the same case? Also, is it OK for the output to include some leading spaces?

@swish Try making a G out of Is :P Or an S

@Doorknob: _\¯

@IlmariKaronen looks more like a backwards Z

@swish or you can use m's as pixels, as they're the closest thing to a filled in square

Lordy you guys want to bring back 1337 5p33|<  ?

May we assume all uppercase input? Does the output have to be sorted?

GolfScript, 28 / 34 chars
n/:a{|}*{a{.[2$]--}%*$-1=}%$

The 28-character program above assumes that all the input letters are in the same case.  If this is not necessarily so, we can force them into upper case by prepending {95&}% to the code, for a total of 34 chars:
{95&}%n/:a{|}*{a{.[2$]--}%*$-1=}%$

Notes:

For correct operation, the input must include at least one newline.  This will be true for normal text files with newlines at the end of each line, but might not be true if the input consists of just one line with no trailing newline.  This could be fixed at the cost of two extra chars, by prepending n+ to the code.
The uppercasing used in the 34-character version is really crude — it maps lowercase ASCII letters to their uppercase equivalents (and spaces to NULs), but makes a complete mess of numbers and most punctuation.  I'm assuming that the input will not include any such characters.
The 28-character version treats all input characters (except newlines and NULs) equally.  In particular, if the input contains any spaces, some will also appear in the output; conveniently, they will sort before any other printable ASCII characters.  The 34-character version, however, does ignore spaces (because it turns out I can do that without it costing me any extra chars).

Explanation:

The optional {95&}% prefix uppercases the input by zeroing out the sixth bit of the ASCII code of each input byte (95 = 64 + 31 = 10111112).  This maps lowercase ASCII letters to uppercase, spaces to null bytes, and leaves newlines unchanged.
n/ splits the input at newlines, and :a assigns the resulting array into the variable a.  Then {|}* computes the set union of the strings in the array, which (assuming that the array has at least two elements) yields a string containing all the unique (non-newline) characters in the input.
The following { }% loop then iterates over each of these unique characters.  Inside the loop body, the inner loop a{.[2$]--}% iterates over the strings in the array a, removing from each string all characters not equal to the one the outer loop is iterating over.
The inner loop leaves the ASCII code of the current character on the stack, below the filtered array.  We make use of this by repeating the filtered array as many times as indicated by the ASCII code (*) before sorting it ($) and taking the last element (-1=).  In effect, this yields the longest string in the filtered array (as they all consist of repeats of the same character, lexicographic sorting just sorts them by length), except if the character has ASCII code zero, in which case it yields nothing.
Finally, the $ at the end just sorts the output alphabetically.

Amazing. TODO: Learn GolfScript!

You may even reduce it to 26: n/:a{|}*{{{=}+,}+a%$-1=}%$.

J - 37 char
Reads from stdin, outputs to console.
dlb#&a.>./+/"2=/&a.tolower;._2[1!:1]3

1!:1]3 is the call to stdin. tolower;._2 performs double duty by splitting up the lines and making them lowercase simultaneously. Then we count how many times a character occurs in each row with +/"2=/&a., and take the pointwise maximum over all lines with >./.
Finally, we pull that many of each character out of the alphabet with #&a.. This includes spaces—all found at the front due to their low ASCII value—so we just delete leading blanks with dlb.

JavaScript (ECMAScript 6) - 148 139 135 Characters
Version 2:
Updated to use array comprehension:
[a[i][0]for(i in a=[].concat(...s.split('\n').map(x=>x.split(/ */).sort().map((x,i,a)=>x+(a[i-1]==x?++j:j=0)))).sort())if(a[i-1]<a[i])]

Version 1:
[].concat(...s.split('\n').map(x=>x.split(/ */).sort().map((x,i,a)=>x+(a[i-1]==x?++j:j=0)))).sort().filter((x,i,a)=>a[i-1]!=x).map(x=>x[0])

Assumes that:

The input string is in the variable s;
We can ignore the case of the input (as specified by the question - i.e. it is all in either upper or lower case);
The output is an array of characters (which is about as close as JavaScript can get to the OP's requirement of a list of characters); and
The output is to be displayed on the console.

With comments:
var l = s.split('\n')             // split the input up into sentences
         .map(x=>x.split(/ */)   // split each sentence up into letters ignoring any
                                  // whitespace
                  .sort()         // sort the letters in each sentence alphabetically
                  .map((x,i,a)=>x+(a[i-1]==x?++j:j=0)))
                                  // append the frequency of previously occurring identical
                                  // letters in the same sentence to each letter.
                                  // I.e. "HELLO WORLD" =>
                                  // ["D0","E0","H0","L0","L1","L2","O0","O1","R0","W0"]
[].concat(...l)                   // Flatten the array of arrays of letters+frequencies
                                  // into a single array.
  .sort()                         // Sort all the letters and appended frequencies
                                  // alphabetically.
  .filter((x,i,a)=>a[i-1]!=x)     // Remove duplicates and return the sorted
  .map(x=>x[0])                   // Get the first letter of each entry (removing the
                                  // frequencies) and return the array.

If you want to:

Return it as a string then add .join('') on the end;
Take input from a user then replace the s variable with prompt(); or
Write it as a function f then add f=s=> to the beginning.

Running:
s="HELLO\nI LOVE CAT\nI LOVE DOG\nI LOVE MOMMY\nMOMMY LOVE DADDY";
[].concat(...s.split('\n').map(x=>x.split(/ */).sort().map((x,i,a)=>x+(a[i-1]==x?++j:j=0)))).sort().filter((x,i,a)=>a[i-1]!=x).map(x=>x[0])

Gives the output:
["A","C","D","D","D","E","G","H","I","L","L","M","M","M","O","O","T","V","Y","Y"]

Nice! You can save 3 bytes by reducing /\s*/ to / */ and removing the parens around j=0

couldn't you use ... instead of apply ?

Thanks to you both - that saves 9 characters - The spread (...) operator is one I've not come across before.

[].concat(...s.split`N`.map(x=>x.split(/ */).map((x,i,a)=>x+(a[x]=a[x]?++j:j=1)))).sort().map((x,i,a)=>a[i-1]<x?x[0]:'').join``;

Perl - 46 bytes
#!perl -p
$s=~s/$_//ifor/./g;$s.=uc}for(sort$s=~/\w/g){

Counting the shebang as 1. This is a loose translation of the Ruby solution below.

Ruby 1.8 - 72 bytes
s='';s+=$_.upcase.scan(/./){s.sub!$&,''}while gets;$><<s.scan(/\w/).sort

Input is taken from stdin.
Sample usage:
$ more in.dat
Hello
I love cat
I love dog
I love mommy
Mommy loves daddy

$ ruby fridge-letters.rb < in.dat
ACDDDEGHILLMMMOOSTVYY

Output needs to be sorted.

@Matt now fixed.

Nice. If your Perl is vaguely recent though, you'll want a space between /i and for.

Python - 206 204 199 177 145 129 117 94 88 chars
print(''.join(c*max(l.lower().count(c)for l in open(f))for c in map(chr,range(97,123))))

I wasn't sure how I was supposed to obtain the file name, so at the moment the code assumes that it is contained in a variable named f. Please let me know if I need to change that.

in the spirit of unix - you could read from stdin.

always make the file name one character long...

@professorfish is that the customary thing to do here? I'm still fairly new to this site

@Tal I'm also new, but if it saves characters, why not?

@professorfish I felt that the "right" thing to do is replace that with proper input (argv, stdin, whatever), but that felt like a waste of characters, so I decided to just leave it

By assuming f for the input filename and using uppercase (all magnet letters are uppercase anyway), you can get it down to 91: print(''.join([chr(i)*max(l.upper().count(chr(i))for l in open(f))for i in range(65,91)]))

you can reduce by a few characters by using for i in string.uppercase rather than for i in range(65,91), as you wouldn't need the chr(i) (should be 6 characters less). Don't know if the import string shouldn't be counted too, though

(do we need the print, btw?)

@njzk2 well, if we run this in the console, in theory it would just print the result by itself...

92 in Python 2: print ''.join([c*max(l.lower().count(c)for l in open('i'))for c in map(chr,range(97,123))])

My solution almost exactly. :) You can save two characters by eliminating the [] around the list comprehension: a comprehension, being iterable, can be passed directly to the join() function.

I wonder if the output's format is totally necessary, I could just print the list and drop the ''.join

Save 1 by switching to uppercase: print(''.join(c*max(l.upper().count(c)for l in open(f))for c in map(chr,range(65,91))))

Ruby 1.9+, 51 (or 58 or 60)
a=*$<
?a.upto(?z){|c|$><<c*a.map{|l|l.count c}.max}

Assumes everything's in lowercase. Case insensitivity costs 7 characters via .upcase, while case insensitivity and lowercase output costs 9 characters via .downcase.

Perl 6: 56 53 characters; 58 55 bytes
say |sort
([∪] lines.map:{bag comb /\S/,.lc}).pick(*)

For each line, this combs through it for the non-space characters of the lower-cased string (comb /\S/,.lc), and makes a Bag, or a collection of each character and how many times it occurs. [∪] takes the union of the Bags over all the lines, which gets the max number of times the character occurred. .pick(*) is hack-y here, but it's the shortest way to get all the characters from the Bag replicated by the number of times it occurred.
EDIT: To see if it would be shorter, I tried translating histocrat's Ruby answer. It is 63 characters, but I still very much like the approach:
$!=lines».lc;->$c{print $c x max $!.map:{+m:g/$c/}} for"a".."z"

R (156, incl. file read)
With table I construct the letter frequency table for each sentence. Then I end up with taking for each letter the maximum value.
a=c();for(w in tolower(read.csv(fn,h=F)$V1))a=c(a,table(strsplit(w,"")[[1]]));a=tapply(seq(a),names(a),function(i)max(a[i]))[-1];cat(rep(names(a),a),sep="")

Ungolfed:
a=c()
words = read.csv(fn,h=F)$V1
for(w in tolower(words))
  a=c(a, table(strsplit(w, "")[[1]]))
a = tapply(seq(a), names(a), function(i) max(a[i]))[-1] ## The -1 excludes the space count.
cat(rep(names(a), a), sep="")

Solution:
acdddeghillmmmoooooostuvyy

@lambruscoAcido you could vectorize the three first lines (of the ungolfed code) which would give you a=unlist(lapply(readLines(fn),function(x)table(strsplit(tolower(x),""))));a=tapply(seq(a),names(a),function(i)max(a[i]))[-1];cat(rep(names(a),a),sep=""), but it is only 3 characters shorter

Another approach with only 112 characters would be cat(unlist(sapply(letters,function(i)rep(i,max(sapply(gregexpr(i,readLines(f)),function(x)sum(x>0)))))),sep="") assuming f is the filename

Haskell, 109 108
import Data.List
import Data.Char
main=interact$sort.filter(/=' ').foldl1(\x y->x++(y\\x)).lines.map toLower

The program reads from stdin and writes to sdtout.
It is quite straightforward: it breaks the string into a list of lines, and rebuilds it by iterating on the list and adding the new letters contained in each line.

Oh wow why have I never heard of (\) before?

@Flonk http://www.haskell.org/ghc/docs/7.6-latest/html/libraries/base-4.6.0.1/Data-List.html#v:-92--92-

C, 99 chars
t[256];main(c){for(--*t;++t[1+tolower(getchar())];);for(c=97;c<123;c++)while(t[c]--)putchar(c-1);}

It crashes if less than one newline is provided. I think it could be fixed quite easily.

I tried, but it didn't produce correct results. https://gist.github.com/romaninsh/11159751

kdb (q/k): 59 characters:
d:.Q.a! 26#0
.z.pi:{d|:.Q.a##:'=_y}.z.exit:{-1@,/.:[d]#'!:d}

generate pre-sorted seed dictionary from alphabet .Q.a
process each line of input, convert to lowercase, group into dictionary, count each element, take alphabetic characters from result (I.e. prune spaces, newlines, etc at this stage) and use max-assign to global d to keep a running total.
define exit handler, which gets passed in to .z.pi to save a delimiter but otherwise unused there. Take from each key-value to generate list of characters, flatten and finally print to stdout.

-1 adds a newline, using 1 would save a character but does not generate the output specified. Wish I could get rid of the .z.pi / .z.exit boilerplate, which would remove 14 characters.
Edit: avoid use of inter/asc by using seed dictionary.

Haskell, 183 162 159
Assuming the file is in file.txt!
import Data.Char
import Data.List
main=readFile"file.txt">>=putStr.concat.tail.map(tail.maximum).transpose.map(group.sort.(++' ':['a'..'z'])).lines.map toLower

If file.txt contains, for example
abcde
abcdef
aaf

The script will output
aabcdef

Basically I'm appending the whole alphabet to each line, so that when grouping and sorting, I'm sure I'll end up with a list that contains 27 elements. Next, I transpose the "frequency table", so that each row in this array consists of the frequencies of a single letter in each line, e.g. ["a","","aaa","aa","aaaa"]. I then choose the maximum of each array (which works just like I want because of how the Ord-instance of Strings work), and drop the letter that I appended at the start, get rid of the spaces, and output the result.

Instead of drop 1, just use tail

@Bergi Haha derp, thanks! I changed it in the post.

Javascript, 261 chars
eval('s=prompt().toUpperCase().split("\\n");Z=[########0,0];H=Z.slice();s@r){h=Z.slice();r.split("")@c){if(c.match(/\\w/))h[c.charCodeAt(0)-65]++});H=H@V,i){return V>h[i]?V:h[i]})});s="";H@n,i){s+=Array(n+1).join(String.fromCharCode(i+97))});s'.replace(/@/g,".map(function(").replace(/#/g,"0,0,0,"))

Remove the eval(...) and execute to get the real code; this is (somewhat) compressed.
s multi-functions as the array of lines and as the outputted string, h contains the histogram of the letters per line and H contains the histogram with the maximum values up until now. It's case-insensitive, and just ignores anything but a-z and A-Z (I think... JS arrays are sometimes weird).
Now correct :)

This just totals the characters, not quite what the question asked. The letters should be totalled to be the bare minimum set to form any single sentence in the input, not all of them. I quite like your approach to prevent the need to sort the output though.

@Matt oh that's right... I'll fix it later. Haven't really got time right now.

Wondered what was going on with the @ until I got to the end. I like it :)

Bash, 171 159 158, 138 with junk output
Requires lowercase-only input. Assumes that the file is called _ (underscore). Maximum of 26 lines in the input file due to the annoying filenames which split creates (xaa, xab... xaz, ???).
In bash, {a..z} outputs a b c d e f ....
touch {a..z}
split _ -1
for l in {a..z}
do for s in {a..z}
do grep -so $l xa$s>b$l
if [ `wc -l<b$l` -ge `wc -l<$l` ]
then mv b$l $l
fi
done
tr -d '\n'<$l
done

Sample output
acdddeghillmmmoostvyy

Explanation
touch {a..z}

Create files that we will be reading from later on so that bash doesn't complain that they don't exist. If you remove this line you will save 13 chars but get a lot of junk output.
split _ -1

Split the input file into sections, each storing 1 line. The files this command creates are named xaa, xab, xac and so on, I have no idea why.
for l in {a..z}
do for s in {a..z}

For each letter $l read through all lines stored in files xa$s.
do grep -so $l xa$s>b$l

Remove the -s switch to save 1 char and get a lot of junk output. It prevents grep from complaining about nonexistent files (will occur unless you have 26 lines of input).
This processes the file xa$s, removing anything but occurences of $l, and sending output to the file b$l. So "i love mommy" becomes "mmm" with new lines after each letter when $l is m.
if [ `wc -l<b$l` -ge `wc -l<$l` ]

If the number of lines in the file we just created is greater than or equal to  (i.e. more letters since there is one letter per line) the number of lines in our highest result so far (stored in $l)...
then mv b$l $l

...store our new record in the file $l. At the end of this loop, when we have gone through all the lines, the file $l will store x lines each containing the letter $l, where x is the highest number of occurences of that letter in a single line.
fi
done
tr -d '\n'<$l

Output the contents of our file for that particular letter, removing new lines. If you don't want to remove the new lines, change the line with tr to echo $l, saving 6 chars.
done

Tried with GNU bash, version 3.2.51 (apple), but file '-l1aa' in a current folder containing input data..

@romaninsh It might be that you have a different version of split (from coreutils). I am currently running GNU bash 4.3.8 and GNU coreutils 8.21 on Ubuntu 14.04 and it works fine (it also worked on Ubuntu 13.10 before I upgraded). However, I did have to place the program and the input file in a separate directory for it to work properly - I suspect this was only because of the millions of junk files in my home folder.

@romaninsh in fact, if you look at the exact command in the script: split _ -l1 and you notice that your input is being saved to -l1aa, I think that your version of split isn't recognising -l1 as an option and instead taking it to be a prefix for output. Try putting a space between -l and 1, or  putting --lines=1, or just -1 (this appears to be an obsolete and more golfy syntax which I will now update the post with).

Perl, 46
for$:(a..z){$a[ord$:]|=$:x s/$://gi}}{print@a

Here's another Perl solution, reads from STDIN, requires -n switch (+1 to count), ties with primo's score but runs without complaints :-). It exploits the fact that bitwise or's result has longer string argument's length.

tried with my test and it worked great.

C#, 172 bytes
var x="";foreach(var i in File.ReadAllText(t).ToLower().Split('\r','\n'))foreach(var j in i)if(x.Count(c=>c==j)<i.Count(c=>c==j))x+=j;string.Concat(x.OrderBy(o=>o)).Trim();

Clever ...clever ... I thought about playing with linq, but doubt it'll be as short as these contorted foreachs :)

I'm adding my own solution:
Bash - 72
Assumes that input is in file "i"
for x in {A..Z};do echo -n `cat i|sed "s/[^$x]//g"|sort -r|head -1`;done

Explanation
For each possible letter, filters it out only from input file resulting in something like this:
AAA
A
A

AAAA

A
AAAAAAAAAAAAAAAA

Then result is sorted and the longest line is selected. echo -n is there to remove newlines.

05AB1E, 12 10 8 bytes
Aεδ¢ày×?

-2 bytes thanks to @ovs, which also allowed -2 more bytes.
Input taken as a list of lowercase strings. (Would require 1 additional byte if taking the input newline-delimited is mandatory.)
Try it online.
Explanation:
A        # Push the lowercase alphabet
 ε       # For-each over the letters:
  δ¢     #  Count how many times this letter occurs in each string of the (implicit)
         #  input-list
    à    #  Pop and leave the maximum of these counts
     y×  #  Repeat the current letter that many times
       ? #  And print it (without newline)

ASδ¢ saves a byte, and Aεδ¢ày×}J (or Avyδ¢àFy?) comes in at 10 bytes.

@ovs Thanks! And it can actually be just Aεδ¢ày×? for an additional -2 (you will need the --no-lazy flag, though) :)

Python 2, 154 bytes
import collections
c = collections.Counter()
for line in open("input.txt"):
    c |= collections.Counter(line.upper())
print "".join(sorted(c.elements()))

Welcome to PCG! This site supports Markdown syntax, which you can use to format your code, so that it appears nice: just indent each line of code 4 spaces.

You'll need to add the characters necessary to import collections.

does not answer the question, as you need the minimum amount of letters to write each sentence individually. In your code, you output the number of letters needed to write all sentences at the same time.

You're missing an s at the end of the import statement and the with block lacks indentation. And since this is code golf, it would benefit you greatly to remove unnecessary whitespace where possible.

since this is code golf, remove the with statement (just loop over a call to open) and I don't think the elements need sorting.

good remarks guys, thank you. Sorting output is a requirement.

(1) You can indent by just one space to save three bytes. (2) Use one-letter variable names, e.g. l instead of line. (3) Since you reference collections.Counter twice, you should cache it (C = collections.Counter) and use c = C() and c |= C(line.upper()). (4) You should indicate the length of your code in characters in the answer.

Good effort. It does pre-pend a proper output with all the spaces, but seems to work OK.

PowerShell - 141
Reads text from a file named 'a'.
$x=@{}
gc a|%{[char[]]$_|group|%{$c=$_.name.tolower().trim()
$n=$_.count;$x[$c]=($n,$x[$c])[$n-lt$x[$c]]}}
($x.Keys|sort|%{$_*$x[$_]})-join""

Python 2 - 129
Idea from @Tal
a,r=[0]*26,range(26)
for l in open('f'):a=[max(a[i],l.lower().count(chr(i+97)))for i in r]
print''.join(chr(i+97)*a[i]for i in r)

A couple more ways to do the same thing in the same number of characters:
a=[0]*26
b='(chr(i+97)))for i in range(26)'
exec'for l in open("f"):a=[max(a[i],l.lower().count'+b+']\nprint"".join(a[i]*('+b+')'

a=[0]*26
b='(chr(i+97)))for i in range(26))'
exec'for l in open("f"):a=list(max(a[i],l.lower().count'+b+'\nprint"".join(a[i]*('+b

This assumes the file is saved as f in an accessible directory. This program is directly runable, with no extra input necessary.

Why the down vote? Sorry if I did something wrong.

Mathematica v10 - 110
It's not out yet, but reading new documentation very carefully, I think this should work:
StringJoin@MapIndexed[#2~Table~{#1}&,Rest@Merge[Counts/@Characters@StringSplit[ToLowerCase@Input[],"\n"],Max]]

Scala, 125 characters
val i=""::io.Source.stdin.getLines.toList.map(_.toLowerCase);println('a'to'z'map(c=>(""+c)*i.map(_.count(_==c)).max)mkString)

First I read the input, converting it into lower case and adding one empty line.
Then for each letter from a to z I repeat that letter maximum number of times it appears in any of the lines (that's why I need the empty line: max cannot be called on an enpty input). Then I just join the results and print to the output.
To read from a file, replace stdin with fromFile("FILENAME"), increasing the size of the code to 132 characters + file name length.

JavaScript (ES5) 141 bytes
Assuming variable s is the input string with no case-checking requirements and array output:
for(a in s=s[o=_='',y='split']('\n'))for(i=0;x=s[a][i++];)o+=x!=0&&(l=s[a][y](x).length-~-o[y](x).length)>0?Array(l).join(x):_;o[y](_).sort()

I tested your solution and was looking inside "o" for an output, but it does not seem to be sorted properly. (see https://gist.github.com/romaninsh/11159751)

@romaninsh the output I see in your gist looks properly sorted

Yes, that's a reference / correct output. When I tried your code, I have got this: https://gist.github.com/romaninsh/11161018

Apologies if I executed your example incorrectly.

@romaninsh ah, I had intended for it to just be run in the browser's console. Here's a version reformatted that works on node: https://gist.github.com/nderscore/96aa888c77d275c26c15

Ah I see. The gist you provided still didn't output result correctly, however I tried your original sample in console. It produced a sorted result, but too many letters: ["A", "A", "A", "A", "A", "A", "A", "A", "A",.

Working here

Groovy, 113/127 102/116 characters
Assuming the file is all in one case (102 chars):
t=new File('f').text;t.findAll('[A-Z]').unique().sort().each{c->print c*t.readLines()*.count(c).max()}

Assuming the file is in mixed case (116 chars):
t=new File('f').text.toUpperCase();t.findAll('[A-Z]').unique().sort().each{c->print c*t.readLines()*.count(c).max()}

Basically:

t=new File('f').text To get the text of the file.
t.findAll('[A-Z]').unique().sort().each{c-> To get the unique characters, sort them, and iterate.
print c*t.readLines()*.count(c).max() Get the max occurances in a single line and print the character that many times.

Bash (mostly awk) - 172 163 157
awk -v FS="" '{delete l;for(i=1;i<=NF;i++)l[toupper($i)]++;for(i in l)o[i]=(o[i]>l[i]?o[i]:l[i])}END{for(i in o)for(j=0;j<o[i];j++)print i}'|sort|tr -d ' \n'

Text needs to be piped in to awk (or specified as a file).
Example Input
Hello
I love cat
I love dog
I love mommy
Mommy loves daddy

Example Output
ACDDDEGHILLMMMOOSTVYY

PHP (probably could be better) - 174 210
$o=array();foreach(explode("\n",$s) as $a){$l=array();$i=0;while($i<strlen($a)){$k=ucfirst($a[$i++]);if($k==' ')continue;$o[$k]=max($o[$k],++$l[$k]);}}ksort($o);foreach($o as $k=>$v)for($i=0;$i<$v;$i++)echo $k;

Assumes that the string is contained in the variable $s
Example Input
Hello
I love cat
I love dog
I love mommy
Mommy loves daddy

Example Output
ACDDDEGHILLMMMOOSTVYY

I realize this probably isn't the most efficient answer, but I wanted to try and solve the problem anyways.  Here's my ObjC variation:
- (NSArray *) lettersNeededForString:(NSString *)sourceString {
    sourceString = [sourceString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    sourceString = [sourceString stringByReplacingOccurrencesOfString:@" " withString:@""];
    const char * sourceChars = sourceString.UTF8String;
    NSMutableArray * arr = [NSMutableArray new];
    for (int i = 0; i < sourceString.length; i++) {
        [arr addObject:[NSString stringWithFormat:@"%c", sourceChars[i]]];
    }
    return [arr sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}

Then you can call it for whatever string:
NSArray * letters = [self lettersNeededForString:@"Hello\nI love cat\nI love dog\nI love mommy\nMommy loves daddy"];
NSLog(@"%@",letters);

I was thinking about applications with larger amounts of text and I'd rather not have to count my array.  For this, I added to the method to get this:
- (NSDictionary *) numberOfLettersNeededFromString:(NSString *)sourceString {

    sourceString = [sourceString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    sourceString = [sourceString stringByReplacingOccurrencesOfString:@" " withString:@""];
    const char * sourceChars = sourceString.UTF8String;
    NSMutableArray * arr = [NSMutableArray new];
    for (int i = 0; i < sourceString.length; i++) {
        [arr addObject:[NSString stringWithFormat:@"%c", sourceChars[i]]];
    }

    static NSString * alphabet = @"abcdefghijklmnopqrstuvwxyz";
    NSMutableDictionary * masterDictionary = [NSMutableDictionary new];
    for (int i = 0; i < alphabet.length; i++) {
        NSString * alphabetLetter = [alphabet substringWithRange:NSMakeRange(i, 1)];
        NSIndexSet * indexes = [arr indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
            if ([[(NSString *)obj lowercaseString] isEqualToString:alphabetLetter]) {
                return YES;
            }
            else {
                return NO;
            }
        }];

        masterDictionary[alphabetLetter] = @(indexes.count);
    }

    return masterDictionary;
}

Run like:
NSDictionary * lettersNeeded = [self numberOfLettersNeededFromString:@"Hello\nI love cat\nI love dog\nI love mommy\nMommy loves daddy"];
NSLog(@"%@", lettersNeeded);

Will give you:

{
      a = 2;
      b = 0;
      c = 1;
      d = 4;
      e = 5;
      f = 0;
      g = 1;
      h = 1;
      i = 3;
      j = 0;
      k = 0;
      l = 6;
      m = 6;
      n = 0;
      o = 8;
      p = 0;
      q = 0;
      r = 0;
      s = 1;
      t = 1;
      u = 0;
      v = 4;
      w = 0;
      x = 0;
      y = 3;
      z = 0;
  }

Which I think is better if I had a very large amount of text and I just needed to know how many of each letter I would need.

C, 298 bytes
char c;
int j,n;
char C[26];
char D[26];
int main()
{
char a='a';
while((c=getchar())>=0)
{
c=tolower(c);
if(c>=a&&c<='z'){j=c-a;D[j]++;}
if(c=='\n'){
for(j=0;j<26;j++){
if(D[j]>C[j])
{C[j]=D[j];}
D[j]=0;
}
}
}
for(j=0;j<26;j++)
{
n=C[j];
while(n--)
{
putchar(a+j);
}
}
}

Array D holds tally of letters for each line, then the maximum count is copied to C.
Note: I put my answer yesterday but is now not listed, maybe I pressed delete instead of edit by mistake?

It's only 271 bytes. You also have a lot of extraneous newlines. Also, you can you can omit the int from int main() and int j,n;.

Also, your previous answer is still there.

PHP, 143 bytes
Assuming that input is passed in variable $s:
$i=explode("\n",$s);foreach(range('a','z')as$c){$x=array_map(function($l)use($c){return substr_count($l,$c);},$i);echo str_repeat($c,max($x));}

Explanation
For each possible letter I'm mapping array containing list of strings through a user-defined function which replaces each line with number of characters used. For letter 'd' the line "Mommy loves daddy" will be mapped into 3.
Afterwards I find maximum value inside array and output letter just this many times. Here is multi-line version:
$i=explode("\n",$s);
foreach(range('A','Z')as $c){
    $x=array_map(function($l)use($c){
        return substr_count($l,$c);
    },$i);
    echo str_repeat($c,max($x));
}

K, 34
{`$a@<a:,/(.:a)#'!:a:|/#:''=:'0:x}

Haskell, 41 bytes
f s=do c<-['a'..];maximum$filter(==c)<$>s

Try it online! f takes a list of lines as input.
Add main=interact$f.lines to get a full program for a total of 63 bytes.
Explanation
f s=                -- input s is the list of lines
 do c<-['a'..];     -- for each char c starting at c='a', concatenate the following strings
    filter(==c)<$>s -- for each line in s remove all characters except for the current c
   maximum$         -- take the longest of those strings

Jelly, 7, 6, 5 or 4 bytes
ỴŒuœ|/Ṣ

Try it online!
Function submission. Depending on how you interpret the I/O rules, it may be possible to drop the leading Ỵ (which would then require input to be the data structure "list of strings", as opposed to a single string that was divided using newlines); and it may be possible to drop the Œu (which would then require the input to use a consistent case for the output to be correct).
Explanation
ỴŒuœ|/Ṣ
Ỵ        Split on newlines
 Œu      Uppercase each resulting string
     /   Combine the resulting strings using…
   œ|      …multiset union
      Ṣ  Sort

Many answers interpret ignore cases, all magnet letters are capitals anyway as that we don't have to handle input with different cases. The fact that the test case uses lowercase letters supports this interpretation.

I interpreted the question as requiring you to standardise case (although it didn't matter whether you used uppercase or lowercase). Without that, you can obviously drop the Œu for a 5 or 4 byte solution.

Julia
78 bytes
it is my 1st approach
!I=join((A='A':'Z').^[max([count(c->c==a,i)
for i=split(I,'\n')]...) for a=A])
Attempt This Online!
or
69 66 bytes

-3 bytes: @MarcMush, thank You
it is inspired by @Laikoni's Haskell answer

!I=prod(maximum(filter(==(a),i) for i=split(I,'
')) for a='A':'Z')
Attempt This Online!

You can use a literal line break instead of \n and ==(a) instead of c->c==a

C++, 264 characters.
Reads lowercase text from standard input.
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;main(){string s;map<int,long> m;while(getline(cin,s)){int c='`';while(c++<'z')m[c]=max(m[c],count_if(begin(s),end(s),[c](int d){return d==c;}));}for(auto i:m)cout<<string(i.second,i.first);}

C++ function, 205 characters.
string a(istream&i){string s;map<int,long> m;while(getline(i,s)){int c='`';while(c++<'z')m[c]=max(m[c],count_if(begin(s),end(s),[c](int d){return d==c;}));}for(auto i:m)s.append(i.second,i.first);return s;}

JavaScript, 199 characters
function(n){for(s in p=n.toUpperCase(t=[]).split("\n"))for(i in p[k={},s])t[l=p[s][i]]=Math.max(t[l]||0,k[l]=k[l]+1||1);for(l in t)t.push(new Array(t[l]+1).join(l));return t.sort().join('').trim()}

In Chrome 33, doing for(..in..) on a string results in function properties being accessed. It breaks this solution. The example input from OP gives this result: "ACDDDEGHILLMMMOOSTVYYfunction (){var e=this.toString();if(!arguments.length)return e;var t=typeof arguments[0],n="string"==t||"number"==t?Array.prototype.slice.call(arguments):arguments[0];for(var i in n)e=e.replace(new RegExp("\\{"+i+"\\}","gi"),n[i]);return e}function (e){return this.indexOf(e)>-1}function (e){var t=this.lastIndexOf(e);return 0>t?[this]:[this.substr(0,t),this.substr(t)]}function (e,t){var n=this.toString();re...

Lua - 206 Chars
g=string
f,t,b,e=io.lines(({...})[1]),{},g.byte,g.char
for s in f do for c=b"a",b"a" do _,d=s:lower():gsub(e(c),"");t[c]=t[c]and(t[c]>d and t[c])or d end end for c=b"a",b"z" do io.write(g.rep(e(c),t[c]))end

Reads from the file passed via command line, then creates a table with the maximum number of occurences per letter. Finally outputs the occuring letters.

Julia, 159
My objective is help understand/improve the expressiveness of Julia. Here's a first attempt.
a='a'-1;print(foldl((c,n)->(global a+=1;"$c"*"$a"^n),"",int(mapreduce(s->hist(int({s...}),0:255)[2],(S,T)->max(S,T),zeros(255),readlines(STDIN))[97:122]))"\n")

Here's my crazy idea.
Using mapreduce, foldl, and hist (builtin histogram) were advantageous, but having to deal assembling an array from a string and then back to a string from an array and globals expanded the length.
Program reads from STDIN.  Required foldl which is new in Julia 0.30.
Sample Input
alskdja
flkjaslakjd
asa
as
g
alkdjaslkajsd

Output
aaaddfgjjkkllss

Python (209, with the sample included, 136 without.):
from collections import*;c=Counter()
for i in ["Hello","I love cat", "I love Dog", "I love mommy", "Mommy loves daddy"]:
 for j in i.lower(): c[j]=max(c[j],list(i).count(j))
print "".join(sorted(c.elements()))

I'll post a PYG sample this afternoon.

I had no idea Python strings had a count method... I don't suppose it's considered legit to change my answer to the question to use this new found knowledge? :p

@tal They don't. It's a method of a list, if you look closer

Oh, I see... but in an unexpected twist it turns out strings apparently have this method as well (in 3.x anyway)

JavaScript - 244
Accepts a parameter of string with newlines.
function s(z){n=m="",y=[];z.toLowerCase().split("\n").map(function(g){a=[];g.replace(/ /g,n).split(n).map(function(e,i){if((+y[e]|0)<(a[e]=(+a[e]|0)+1))y[e]=a[e];});});for(var b in y){m+=Array(y[b]+1).join(b);}return m.split(n).sort().join(n);}

Not happy with the sorting and preparation of the output.
Edit: case-insensitive regex unnecessary! Thanks @Bergi

Upper- and lowercase spaces in that regex?

Java, 335
Here is the executable code in java in a more readable form. Once all the unnecessary white spaces are removed, you will see 335 characters in all. The output is:

ACDDDEGHILLMMMOOSTVYY

It gets a filename as input and reads each character from the file, converts it to uppercase and stores the count of it's occurrence in an array. For every new line, the maximum
occurrence of each character is updated. At last it is printed.
Pre-requiste: The file should end with a newline.
class F {
    public static void main(String[] a) throws Exception {
        java.io.FileInputStream f = new java.io.FileInputStream(a[0]);
        int j, r, l = 256;
        int[] i = new int[l], t = new int[l];
        while ((r = f.read()) > 0) {
            r = r > 96 ? r - 32 : r;
            if (r == 10)
                for (j = 0; j < l; j++) {
                    i[j] = i[j] < t[j] ? t[j] : i[j];
                    t[j] = 0;
                }
            else
                t[r]++;
        }
        for (j = 65; j < 91; j++)
            while (i[j]-- > 0)
                System.out.print((char) j);
    }
}

After removing the white spaces the code will look like the following:
class F{public static void main(String[] a)throws Exception{java.io.FileInputStream f=new java.io.FileInputStream(a[0]);int j,r,l=256;int[] i=new int[l],t=new int[l];while((r=f.read())>0){r=r>96?r-32:r;if(r==10)for(j=0;j<l;j++){i[j]=i[j]<t[j]?t[j]:i[j];t[j]=0;}else t[r]++;}for(j=65;j<91;j++)while(i[j]-->0)System.out.print((char)j);}}

C#, 265 characters
Assuming input is in variable s, here's a C# Expression, using mainly LINQ (Enumerable.cs):
string.Join("",s.ToLower().Split('\n').Select(e=>e.Where(l=>l!=' '&&l!='\r')
.GroupBy(l=>l).ToDictionary(k=>k.Key,v=>v.Count())).SelectMany(u=>u).GroupBy(l=>l.Key)
.Select(g=>new String(Enumerable.Range(1,g.Max(v=>v.Value)).Select(i=>g.Key).ToArray()))
.OrderBy(l=>l))

Japt v1.4.5, 11 bytes
;CËpUmèD rw

Try it online!
Unpacked & How it works
;CmDEF{DpUmèD rw

;                 Use an alternative set of predefined variables
 C                "abc...z"
  mDEF{           Map over each char and form a string...
         UmèD       Map over input array into char count
              rw    Reduce with max
       Dp           Repeat the char this number of times

Powershell, 118 116 87 bytes
-join($args|%{$_|% t*y|group|%{-join$_.Group}}|sort|group{$_[0]}|%{$_.Group[-1]})|% t*m

Less golfed test script:
$f = {

$x=$args|%{$_|% t*y|group|%{-join$_.Group}} # unsorted groups of the same letters for each sentence: (h,e,ll,o), (...), (...), (i, ,l,oo,v,e,d,g),...
$y=$x|sort|group{$_[0]}                     # sort all groups and group it again by the first letter (( , , , ), (a,a), (c), (d,ddd), ... (y,yy))
$z=$y|%{$_.Group[-1]}                       # get a last item (maximum item) from each group
-join($z)|% t*m                             # join it and trim spaces

}

@(
    ,("acdddeghillmmmoostvyy",
      "hello",
      "i love cat",
      "i love dog",
      "i love mommy",
      "mommy loves daddy")

    ,("AAAAAAAAAAAAAAAABBBCCCCDDDDDEEEEEEEEEFFGGGGHHHHHHIIIIIIIIIIJJKKLLLLMMMMMMMNNNNNNNNNNNNNOOOOOOOOOPPPPPPPQRRRRRRSSSSSSSTTTTTTUUUUUVWWXYYY",
      "I SAW THE MAN WITH THE BINOCULARS",
      "THEY ARE HUNTING DOGS",
      "FREE WHALES",
      "POLICE HELP DOG BITE VICTIM",
      "HE SAW THAT GAS CAN EXPLODE",
      "TURN RIGHT HERE",
      "WE SAW HER DUCK",
      "IN ANIMAL CRACKERS GROUCHO MARX AS CAPTAIN RUFUS T SPAULDING QUIPPED ONE MORNING I SHOT AN ELEPHANT IN MY PAJAMAS HOW HE GOT IN MY PAJAMAS I DONT KNOW",
      "SHIP SAILS TOMORROW",
      "BOOK STAYS IN LONDON",
      "WANTED A NURSE FOR A BABY ABOUT TWENTY YEARS OLD",
      "THE GIRL IN THE CAR THAT NEEDED WATER IS WAITING",
      "DID YOU EVER HEAR THE STORY ABOUT THE BLIND CARPENTER WHO PICKED UP HIS HAMMER AND SAW",
      "THOSE PROSECUTORS HAVE BEEN TRYING TO LOCK HIM UP FOR TEN YEARS",
      "FLYING PLANES CAN BE DANGEROUS",
      "I ONCE SAW A DEER RIDING MY BICYCLE",
      "TOILET OUT OF ORDER PLEASE USE FLOOR BELOW",
      "LOOK AT THE DOG WITH ONE EYE")
) | %{
    $expected,$s = $_
    $result = &$f @s
    "$($result-eq$expected): $result"
}

Output:
True: acdddeghillmmmoostvyy
True: AAAAAAAAAAAAAAAABBBCCCCDDDDDEEEEEEEEEFFGGGGHHHHHHIIIIIIIIIIJJKKLLLLMMMMMMMNNNNNNNNNNNNNOOOOOOOOOPPPPPPPQRRRRRRSSSSSSSTTTTTTUUUUUVWWXYYY

Vyxal as, 12 bytes
ȧ∑U:ƛ?vOG;*s

Try it Online!
  U          # Unique characters of...
ȧ∑           # The input, with whitespace removed
          *  # Repeated by...
   :ƛ    ;   # Themselves mapped to...
        G    # The highest...
      vO     # Amount of...
             # (implicit) That character
     ?       # In the input
           s # Sorted.

Japt -Px, 9 8 bytes
I knew there had to be a way to to it in 8!
cü üÎËÍÌ

Try it
cü üÎËÍÌ     :Implicit input of array
c            :Flat map
 ü           :  Group & sort by value
   ü         :Group & sort by
    Î        :  First character
     Ë       :Map
      Í      :  Sort
       Ì     :  Last element
             :Implicitly join, trim and output

Original (w/o flags), 9 bytes
Takes input as an array of lowercase strings.
;C£ËoXÃÍo

Try it
;C£ËoXÃÍo     :Implicit input of array U
;C            :Lowercase alphabet
  £           :Map each X
   Ë          :  Map U
    oX        :    Remove all characters but X
      Ã       :  End inner map
       Í      :  Sort
        o     :  Pop last element

JavaScript (Node.js), 95 bytes
a=>(g=i=>i?g(i-1,i=i.toString(36))+i.repeat(Math.max(...a.map(y=>y.split(i).length))-1):'')(35)

Try it online!

C, 298 bytes
(242 bytes by not counting newlines)
Array D keeps tally of letters in each line, then the maximum count of each letter is copied into array C.
char c;
int j,n;
char C[26];
char D[26];
int main()
{
char a='a';
while((c=getchar())>=0)
{
c=tolower(c);
if(c>=a&&c<='z'){j=c-a;D[j]++;}
if(c=='\n'){
for(j=0;j<26;j++){
if(D[j]>C[j])
{C[j]=D[j];}
D[j]=0;
}
}
}
for(j=0;j<26;j++)
{
n=C[j];
while(n--)
{
putchar(a+j);
}
}
}

Note: I just discovered Notepad++ which gives my character count, counts newlines as 2 chars. Should these be subtracted?

That's because you use CRLF (Windows) line terminators. You should tell Notepad++ to use LF (Unix), then they will only count as one character.

C# / LINQPad, 181 bytes
In C# Expression mode; assumes input file is named a (and probably in the LINQPad Program Files folder)
string.Join("",File.ReadAllLines("a").SelectMany(s=>s.ToUpper().Where(c=>c>64&&c<91).GroupBy(c=>c)).GroupBy(g=>g.Key).Select(g=>new string(g.Key,g.Max(x=>x.Count()))).OrderBy(s=>s))

Ungolfed
string.Join("",                                                     // concat all substrings, with no separator
    File.ReadAllLines("a")                                          // read all lines from text file called 'a'
        .SelectMany(                                                // apply function to each subset and union into a single set
            s => s.ToUpper()                                        // convert strings to uppercase
                  .Where(c => c > 64 && c < 91)                     // shorter than char.IsLetter(c) for all uppercase
                  .GroupBy(c => c)                                  // group on each character in the string
         )
        .GroupBy(g => g.Key)                                        // group again on each character (I'd love to get rid of this...)
        .Select(g => new string(g.Key, g.Max(x => x.Count())))      // string(char, count) constructor build repeating-char string
        .OrderBy(s => s)                                            // sorted set required
)

Input (text file called a)
Hello
I love cat
I love dog
I love mommy
Mommy loves daddy

Output
ACDDDEGHILLMMMOOSTVYY

C# - 146 Bytes
var x="";foreach(var l in File.ReadAllLines(t))foreach(var p in l)if(x.Count(c=>c==p)<l.Count(c=>c==p))x+=p;string.Concat(x.OrderBy(o=>o)).Trim();

Well, I think this is as short as C# can get.
This code expects a path to the text file in the variable t.

Kotlin, 189 bytes
lines().map{it.filter{it.isLetter()}.groupingBy{it}.eachCount()}.fold(mutableMapOf<Char,Int>()){r,i->i.map{(t,u)->r[t]=maxOf(r[t] ?:0,u)}
r}.flatMap{(k,v)->(0..v-1).map{k}}.joinToString("")

Beautified
lines()
    .map { it.filter { it.isLetter() }.groupingBy { it }.eachCount() }
    .fold(mutableMapOf<Char, Int>()) { r, i ->
        i.map { (t, u) -> r[t] = maxOf(r[t] ?: 0, u)}
        r
    }
    .flatMap { (k, v) -> (0..v-1).map { k } }
    .joinToString("")

Test
fun String.f() =

lines().map{it.filter{it.isLetter()}.groupingBy{it}.eachCount()}.fold(mutableMapOf<Char,Int>()){r,i->i.map{(t,u)->r[t]=maxOf(r[t] ?:0,u)}
r}.flatMap{(k,v)->(0..v-1).map{k}}.joinToString("")

fun main(args: Array<String>) {
    val i = """hello
i love cat
i love dog
i love mommy
mommy loves daddy"""
    println(i.f().map { it }.sorted().joinToString(""))
    println("acdddeghillmmmoostvyy")
}

TIO
TryItOnline

Stax, 8 bytes
ü2lLÜ▀⌂æ

Run and debug it

Reduce the array of inputs using a multiset union operation.
Sort the resulting characters.
Remove spaces.

PHP, 116 bytes
foreach(file(T)as$y=>$s)for($i=0;~$c=ucfirst($s[$i++]);)$$c[$y]++;for($c=A;!$c[1];$c++)echo str_repeat($c,max($$c));

assumes filename T. Run with -nr.
breakdown
foreach(file(T)as$y=>$s)            # loop through lines of file
    for($i=0;~$c=ucfirst($s[$i++]);)    # loop through line characters
        $$c[$y]++;       # increment counter ($A..$Z)
 for($c=A;!$c[1];$c++)    # loop $c through uppercase letters
  echo str_repeat($c,max($$c));      # get max from $A, $B etc, use as multiplier for str_repeat

JavaScript, 105 104 bytes
Takes input as an array of character arrays and returns a string.
a=>[...new Set(a+``)].sort().map(c=>c.repeat(a.map(r=w=>r=w.map(l=>o+=c>{}&c==l,o=0)|o<r?r:o)|r)).join``

Try it online

Pyth, 14 10 bytes
smeS@Ld.zG

Accepts input as lowercase strings. Try it online here.
smeS@Ld.zG   Implicit: .z=input as list of strings, G=lowercase alphabet
 m       G   Map each letter in G, as d, using:
     L .z      In each string in .z ...
    @ d        ... keep only those characters which match d
   S           Sort by length
  e            Take the last element (i.e. longest)
s            Concatenate into string, implicit print

Edit: golfed 3 bytes. Previous version: sm*deSml@dk.zG

Vyxal s, 5 bytes
ɾƒÞ∪s

Try it Online!

jq, 94 bytes
[.,inputs]|map(explode-[32]|group_by(.)[])|group_by(.[0])|map(max_by(length)|implode)|join("")

Try it online!

[., inputs]                          # from raw input to array of strings
                                     # e.g. ["hello", "i love cat", …]

| map(explode-[32] | group_by(.)[])  # splits each string into groups of
                                     # similar codepoints (excluding spaces)
                                     # e.g. "hello" -> [[101],[104],[108,108],[111]]

| group_by(.[0])                     # groups all groups of similar codepoints

| map(max_by(length)|implode)        # then only keep the largest group of
                                     # each sub groups and transform the
                                     # group into a string

| join("")                           # finally join all the strings

Thunno 2 J, 7 bytes
ẠıȷcGn×

Attempt This Online!
Port of Kevin Cruijssen's 05AB1E answer.
Explanation
ẠıȷcGn×  # Implicit input
Ạı       # Map over lowercase alphabet:
  ȷc     #  Count in each input string
    G    #  Pop and leave the maximum
     n×  #  Repeat the character that many times
         # Implicit output, joined


text:
Length of String Using Set Theory
From Wikipedia Set-theoretic definition of natural numbers

The set N of natural numbers is defined as the smallest set containing
  0 and closed under the successor function S defined by S(n) = n ∪ {n}.
The first few numbers defined this way are 0 = {}, 1 = {0} = {{}}, 2 = {0,1} = {{},{{}}}, 3 = {0,1,2} = {{},{{}},{{},{{}}}}.

Using this definition of natural numbers count the length of a string.
Input  a string of characters from a-zA-Z of any length
Output the length of the string in set notation without separators
Examples
Input  Empty string
Output {}
Input  a
Output {{}}
Input  aaaa
Output {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}
For readability output for 'aaaa' with separators is
{
    {}
    {{}}
    {{} {{}} }
    {{}   {{}}   {{} {{} } }   }
}

Conditions

No digits 0 to 9 to appear in the code;
No use of character code conversion to generate numbers;
No use of +-*/ for arithmetic calculations including increment and decrement;
No mathematical operations other than Boolean Logic;
Input string does not count in determining byte length;

Winner Shortest code length in bytes.
As this is my first question I hope I have made it clear and rigorous enough. Friendly advice accepted.

Hm, can you implement a recursive definition without calling f(n-1)?

I have a solution (non-optimal in terms of byte length) that does not use recursion. If A is an array then A.pop();f(A) is recursive.

That's a good point.

@jing3142 Kudos for implementing a solution yourself to make sure it's possible. +1 for great question.

What does the restriction to a-zA-Z mean? Should we detect whitespace/rubish? or should we just expect this and report the length of the string, regardles on the content?

@V-X the input string only consists of these characters, content is immaterial.

GolfScript (18 17 bytes)
'{'\{;.'}'++}/'}'

Takes input on the stack (so if run as a program, via stdin). Leaves the output as two strings on the stack (so if run as a program, the correct output is sent to stdout).
To leave a single string on the stack, either append + to concat, or use the alternative
'{}'\{;.);\'}'++}/

Dissection
# Stack: input-str
'{'\
# Stack: <0< input-str  where <0< means the string representing 0 without its final }
# Loop over each character of the input string
{
    # Stack: <n< char
    # Discard the input character
    ;
    # Concatenate two copies of <n< and a }
    .'}'++
}/
# Push the final } to the stack
'}'

Alternative:
# Stack: input-str
'{}'\
# Stack: <0> input-str  (where <0> means the string representing 0)
# Loop over each character of the input string
{
    # Stack: <n> char
    # Discard the input character
    ;
    # Duplicate <n> and remove the final '}'
    .);
    # Stack manipulations
    \'}'
    # Stack: <n>-less-final-'}' <n> '}'
    # Concatenate the three strings to get <n+1>
    ++
}/

Impact of the restrictions
If decrement were allowed, it would permit the 15-byte solution
'{}'\{;..,(/*}/

Haskell function, 35 34 characters
f[]="{}";f(_:x)='{':f x++tail(f x)

Haskell program with hardcoded input, 48 or 49 47 or 48 characters
 f[]="{}";f(_:x)='{':f x++tail(f x);main=print$f"aaaa"

(47 characters if you don't mind extra quotes around the output; if you do, use putStr instead of print for a total of 48 characters)
Haskell program, 51 50 characters
f[]="{}";f(_:x)='{':f x++tail(f x);main=interact f

If you're OK with reversing the order, since it's a set, you can use: f[]="{}";f(_:x)='{':f x++(tail.f)x to save a character.

@isaacg Nice one. OP should tell us if he minds, though.

As its a set order does not matter so @isaacg 's suggestion is good

Python 3 - 64
o=['{}']
for a in input():o+=['{'+''.join(o)+'}']
print(o.pop())

If inlining the input is allowed:
Python 2 - 54
o=['{}']
for a in'whatever':o+=['{'+''.join(o)+'}']
print o.pop()

Isn't raw-input() the method of inputing not the input string itself. Not being familiar with the range of languages possible I was disallowing the string length if something like w='aaaaaaaaaaaa' was necessary within the code. Sorry if not clear. Any help in re-wording question accepted.

I see. I'll rewrite my code accordingly. In general, however, I think you should just leave that line out. Essentially every language has an I/O system.

You can save a symbol by using o[-1] instead of o.pop()

"No digits 0 to 9 to appear in the code;"

A strange character-save for the first one: Initialize o=[], which becomes o=['{}'] after one step, and lengthen the input by one by replacing it with '_'+input(), cutting the space after in.

J - 22 20 char
'{','}' '{'&(,,~)~#

How this can be derived:
   #'123'                      NB. string length
3
   'Left' (,,~) 'Right'        NB. dyad to concat L,R,R
LeftRightRight
   '{' (,,~) '}'               NB. using braces
{}}
   '{'&(,,~) '}'               NB. bind left argument, now it's a monad
{}}
   '{'&(,,~) '{'&(,,~) '}'     NB. twice
{{}}{}}
   '{'&(,,~)^:2 '}'            NB. ^: is monad functional power
{{}}{}}
   '{'&(,,~)^:3 '}'            NB. any integer
{{{}}{}}{{}}{}}
   3 '{'&(,,~) '}'             NB. convenient feature of dyadic &
{{{}}{}}{{}}{}}
   '}' '{'&(,,~)~ 3            NB. swap argument order
{{{}}{}}{{}}{}}
   '}' '{'&(,,~)~ #'123'       NB. using string length
{{{}}{}}{{}}{}}
   '{', '}' '{'&(,,~)~ #'123'  NB. add final brace
{{{{}}{}}{{}}{}}
   ('{','}' '{'&(,,~)~#) '123' NB. works as a verb
{{{{}}{}}{{}}{}}

Alternatively, this can be written '{','{'&(,,~)&'}'@#, meaning the same thing.
Usage:
   '{','}' '{'&(,,~)~# 'aaaa'
{{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}
   f =: '{','}' '{'&(,,~)~#  NB. can be assigned to a function
   f 'VeryBig'
{{{{{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}{{{{}}{}}{{}}{}}{{{}}{}}{{}}{}}

Javascript 70 (chars)
s='';c=prompt().split('');while(c.pop()){s+='{'+s+'}'}alert('{'+s+'}')

This was my effort before setting the question. I would assume someone with more knowledge of Javascript than me can probably beat it.
Thank you Jan Dvorak and Peter Taylor for further reductions
now 62
s='{';c=prompt().split('');while(c.pop())s+=s+'}';alert(s+'}')

and now 61
s='{';for(c=prompt().split('');c.pop();)s+=s+'}';alert(s+'}')

Explanation of Original Code
set s to be empty
input string into c and split into an array
while it is possible to pop() a character from c do so and reset s=s{s} as successor
output current s but need to surround with set brackets.

You don't need braces after while (saves one character).

There's a 7-char saving without any more knowledge of JS required: initialise s='{' and ditch the two '{'+. (This then behaves like my GS solution). There's a further 1-char saving by using for instead of while and pulling in one of the two initialisations to the for-loop initialisation.

@peter-taylor not sure how you mean to apply for-loop. I have only ever used it for counting.

for(a;b;c){d} is directly equivalent to a;while(b){d;c} in most languages which have both. So while for(;b;) is identical to while(b) in effect and character count, for(a;b;) saves one char over a;while(b) and is identical in effect.

@peter-taylor +1 for very clear and concise explanation within a comment

@PeterTaylor Except c will still be called even if a continue statement is used in the body of the loop

Haskell - 35 charactes
g[]="{}";g(_:x)=(init.g)x++g x++"}"

Solution is influenced by Jan Dvorak's one, but without reversing the order.

Scala, 64 characters
def f(s:String):String=s"{${s.tails.toSeq.tail.map(f)mkString}}"

Note the dual roles that both the braces and s play in this code.
EDIT: removed a digit

There is a digit in the code

@jing3142 Oops. Not any more.

Python 3 (44)
s='{'
for _ in input():s+=s+'}'
print(s+'}')

At each step, s is the string representing the set with the final } removed. We create the set representing n+1 from the set representing n via the relationship f(n+1) = f(n) ∪ {f(n)}. To implement the union with strings, we append the string for {f(n)}, which is exactly s but with the final } returned, and neglect to include the final } in the result. Finally, we add back a final '}' before printing.
If I may hardcode the string, the character count cuts down to 35 character, switching to Python 2 to save parantheses on the print.
s='{'
for _ in'string':s+=s+'}'
print s+'}'

There might be a way to save the space after the print by doing something like print'{'+s with a reversed s, but this messes up with the += appending on the right.

gs2, 12 bytes
7b 7d 05 27 a0 42 30 30 e4 43 2e 32

mnemonics:
"{}"
right-uncons @0 swap + + b5
rot length times

Mathematica, 115 characters
StringReplace[ToString@Function[s,NestWhile[#~Append~#&,{},(s~Read~Character//StringQ)&]]@StringToStream@"test",", "->""]

The complete code as shown has 121 characters, but 6 of them are used for the input string ("test") which, according to the rules, doesn't count.
Without the requirement that there are no delimiters, the code length could be reduced further by 24 characters; without explicit conversion to string then another 9 characters could be removed.

I thought that removing the need for deliminators, which are usually are required in set notation, I was helping to reduce code size. So if using them reduces your code size go ahead and use them.

Ruby, 27, kind of cheating
a=*a
gets.chars{a=*a,a}
p a

Questionable things:

Output looks like [[], [[]], [[], [[]]], [[], [[]], [[], [[]]]]]
Most methods of input to ruby will include a trailing newline, which inflates the count by 1.

It should be perfectly legit if you inspect the array manually and tr the result.

Pure Bash, 54
f()([ $@ ]&&(a=`f ${@%?}`
echo $a{$a}))
echo {`f $@`}

Output:

$ ./strlenset.sh
{}
$ ./strlenset.sh a
{{}}
$ ./strlenset.sh aa
{{}{{}}}
$ ./strlenset.sh aaa
{{}{{}}{{}{{}}}}
$ ./strlenset.sh aaaa
{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}
$

Mathematica, 45 57 48 bytes
"{"~~Fold[#~~"{"~~#~~"}"&,"",Characters@#]~~"}"&

A 36 bytes solution:
Fold[{##{##}}&@@#&,{},Characters@#]&

However, it uses some arithmetic calculations.

Julia 43
f(z)="{"foldl((x,y)->"$x{$x}","",{z...})"}"

The construct {z...} expands the string z into an array.  Fold loops over all elements of the array ignoring the contents and instead building up from the empty string.  The function foldl is available in Julia 0.30.
Sample Output
julia> f("")
"{}"
julia> f("aa")
"{{}{{}}}"
julia> f("aaaa")
"{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}"
julia> f("aaaaaa")
"{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}}}"

Haskell, 31 bytes
foldl(\s _->init s++s++"}")"{}"

Perl 6: 37 characters
say ({"\{@_.join()\}"}...*)["(input string)".chars]

or from STDIN:
say ({"\{@_.join()\}"}...*)[get.chars]

{"\{@_.join()\}"}...* makes a lazy list of the set forms of the natural numbers, and we just grab the one we need with get.chars.
The lazy list might be more readably written:
-> *@prev { '{'~ @prev.join ~'}' } ... *

Which reads pretty similarly to the definition.

Delphi XE3 (264)
Ok I dont even come close to the other but it was fun to do :)
Probably overthinking it. Going to see if there is a better way to do this.
Golfed
uses System.SysUtils;var s,f:string;a:TArray<char>;b:TArray<string>;i,x:integer;begin readln(s);a:=s.ToCharArray;f:='{';setlength(b,Length(a));for I:=Low(a)to High(a) do begin s:='{';for x:=Low(b)to High(b)do s:=s+b[x];b[i]:=s+'}';f:=f+b[i];end;writeln(f+'}');end.

Ungolfed
uses
  System.SysUtils;
var
  s,f:string;
  a:TArray<char>;
  b:TArray<string>;
  i,x:integer;
begin
    readln(s);
    a:=s.ToCharArray;
    f:='{';
    setlength(b,Length(a));
    for I:=Low(a)to High(a) do
    begin
      s:='{';
      for x:=Low(b)to High(b)do
        s:=s+b[x];
      b[i]:=s+'}';
      f:=f+b[i];
    end;
    writeln(f+'}');
end.

Testing results
Tested strings with length 0..10
{}
{{} }
{{} {{}} }
{{} {{}} {{}{{}}} }
{{} {{}} {{}{{}}} {{}{{}}{{}{{}}}} }
{{} {{}} {{}{{}}} {{}{{}}{{}{{}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}} }
{{} {{}} {{}{{}}} {{}{{}}{{}{{}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}} }
{{} {{}} {{}{{}}} {{}{{}}{{}{{}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}}} }
{{} {{}} {{}{{}}} {{}{{}}{{}{{}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}} {{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}{{}{{}}{{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}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}{{}{{}}{{}{{}}}{{}{{}}{{}{{}}}}}}}}}} }

Thanks for trying. In my mind I was considering length as a mathematical operation as it returns a number and as is the use of a 'for' loop which involves counting.

Perl 5: 33 characters
It's not quite clear which characters I should count as part of the solution. Probably not the echo ... | part because that's just used to feed a line in to stdin. Probably not the name of the perl binary, because you could rename that whatever you wanted.
So I've counted the command-line switches passed to perl, the quote marks wrapped around the Perl code, and the Perl code itself.
#                                1         2         3
#                     12  3456789012345678901234567890123
$ echo "aaaa" | perl -ple'$s.="{$s}"while s/.//;$_="{$s}"'

Also, related.

You should count pl as astandard, but you get -e and the quotes around the code for free. Ref

Dart: 85 characters
a(p,i)=>(--i).isNegative?p:a("$p{$p}",i);
main(s){print("{${a("",s.first.length)}}");}

(with extra newline for readability).
The requirement of not using "0" really bites, otherwise .first would be [0] and (..).isNegative would be ..<0.

Javascript, 171 149 147 142 bytes
(Will likely be golfed further later)

n=prompt().split("");for(a=[];n.pop();)a.push(a.slice());alert(JSON.stringify({a:a})[R="replace"](/[^\[\]]/g,"")[R](/\[/g,"{")[R](/\]/g,"}"));

Pyth, 13 bytes
+u++GG\}z\{\}

This is the golfed Pyth equivalent of @xnor's Python answer. Note that Pyth is newer than this question, so this answer is not eligible to win this challenge.
Demonstration.

u+G]GlQY

source: Stack Exchange

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

sort: votes