Align lists like coreutils' `ls` Make program that takes the list from the files from STDIN, and aligns it nicely, just like ls command from coreutils. For example, assuming the following list (taken from The ASCII Collab, which takes place in the chatroom on this site).

alligator
ant
bear
bee
bird
camel
cat
cheetah
chicken
chimpanzee
cow
crocodile
deer
dog
dolphin
duck
eagle
elephant
fish
fly
fox
frog
giraffe
goat
goldfish
hamster
hippopotamus
horse
kangaroo
kitten
leopard
lion
lizard
llama
lobster
monkey
octopus
ostrich
otter
owl
oyster
panda
parrot
pelican
pig
pigeon
porcupine
puppy
rabbit
rat
reindeer
rhinoceros
rooster
scorpion
seal
shark
sheep
shrimp
snail
snake
sparrow
spider
squid
squirrel
swallow
swan
tiger
toad
tortoise
turtle
vulture
walrus
weasel
whale
wolf
zebra


Align the results, like the in the example below (the example shows columns set to 80). The terminal width is received as the first argument. If any argument is bigger than this argument, you can do anything. Try to use as many columns as possible with two space separators, as long nothing overflows.

alligator   crocodile  giraffe       llama    pig         shark     tiger
ant         deer       goat          lobster  pigeon      sheep     toad
bear        dog        goldfish      monkey   porcupine   shrimp    tortoise
bee         dolphin    hamster       octopus  puppy       snail     turtle
bird        duck       hippopotamus  ostrich  rabbit      snake     vulture
camel       eagle      horse         otter    rat         sparrow   walrus
cat         elephant   kangaroo      owl      reindeer    spider    weasel
cheetah     fish       kitten        oyster   rhinoceros  squid     whale
chicken     fly        leopard       panda    rooster     squirrel  wolf
chimpanzee  fox        lion          parrot   scorpion    swallow   zebra
cow         frog       lizard        pelican  seal        swan
Bash, 48 46 bytes

cd `mktemp -d`
xargs -d\\n tee
stty cols $1
ls


Guaranteed to work like ls.