Skip to main content
incorporate Anders Kaseorg's suggestion
Source Link
Kevin Reid
  • 1.7k
  • 10
  • 14

Haskell, 144133

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
l x|x>'@'&&x<'['=iterate succ x!!32|0<1=x
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

iterate succ x!!32 is 2 characters shorter than the non-silly way Explaining toEnum$fromEnum x+32l, and 1 character shorter than importing and using Data.Char.toLower with a condition to restrict itthe function to ASCII.lowercase one character:

  • sum[32|condition] is a shorter form of if condition then 32 else 0.
  • [x..]!!count is iterate succ x !! count is toEnum $ fromEnum x + count and shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.
  • '@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.

'@' and '[' are Thanks to Anders Kaseorg for contributing the characters immediately preceding Asum[...|...] and following Z, so that I can use < instead of <=[x..]!! tricks.

Haskell, 144

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
l x|x>'@'&&x<'['=iterate succ x!!32|0<1=x
f[]=[getContents]
f n=map readFile n

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

iterate succ x!!32 is 2 characters shorter than the non-silly way toEnum$fromEnum x+32, and 1 character shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.

'@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.

Haskell, 133

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
f[]=[getContents]
f n=map readFile n
l x=[x..]!!sum[32|x>'@',x<'[']

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

Explaining l, the function to lowercase one character:

  • sum[32|condition] is a shorter form of if condition then 32 else 0.
  • [x..]!!count is iterate succ x !! count is toEnum $ fromEnum x + count and shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.
  • '@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.

Thanks to Anders Kaseorg for contributing the sum[...|...] and [x..]!! tricks.

Source Link
Kevin Reid
  • 1.7k
  • 10
  • 14

Haskell, 144

import System.Environment
main=getArgs>>=mapM_(>>=putStr.map l).f
l x|x>'@'&&x<'['=iterate succ x!!32|0<1=x
f[]=[getContents]
f n=map readFile n

The cat-style args processing is derived from this tutorial, then rearranged to shave characters.

iterate succ x!!32 is 2 characters shorter than the non-silly way toEnum$fromEnum x+32, and 1 character shorter than importing and using Data.Char.toLower with a condition to restrict it to ASCII.

'@' and '[' are the characters immediately preceding A and following Z, so that I can use < instead of <=.