
Hi, all Below is my solution to SPOJ->Polybius squarehttp://www.spoj.com/problems/POLYBIUS Please try to shorten it: *import Data.Maybe* *d=[1..5]* *f s=unwords$map(\c->fromJust$lookup c((' ',""):('J',"24"):zip(['A'..'I']++['K'..'Z'])[show(x+10*y)|y<-d,x<-d]))s* *main=getLine>>(interact$unlines.map f.lines)* Thanks, Nadav

Hi, the target of this program is to encode string of [A..Z] characters by
method of Polybius http://en.wikipedia.org/wiki/Polybius_square.
Additionally, most short code will receive more points.
Nadav
On Wed, Jul 24, 2013 at 3:36 AM, Kim-Ee Yeoh
On Tue, Jul 23, 2013 at 5:41 PM, Nadav Chernin
wrote: Please try to shorten it:
What would you achieve by doing so?
-- Kim-Ee
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Tue, 23 Jul 2013 12:41:32 +0200, Nadav Chernin
Hi, all Below is my solution to SPOJ->Polybius squarehttp://www.spoj.com/problems/POLYBIUS
Please try to shorten it:
*import Data.Maybe* *d=[1..5]* *f s=unwords$map(\c->fromJust$lookup c((' ',""):('J',"24"):zip(['A'..'I']++['K'..'Z'])[show(x+10*y)|y<-d,x<-d]))s* *main=getLine>>(interact$unlines.map f.lines)*
If you remove the unnecessary spaces from the following code, it is shorter than yours: d="12345" f s = unwords $ map (\c -> let (Just x) = lookup c ((' ',"") : ('J',"24") : zip (['A'..'I'] ++ ['K'..'Z']) [y : [x] | y <- d, x <- d]) in x) s main = getLine >> (interact $ unlines . map f . lines) Note, that this is not a real solution to the problem, as you don't do anything with the first input. Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On Wed, Jul 24, 2013 at 4:18 PM, Henk-Jan van Tuyl
On Tue, 23 Jul 2013 12:41:32 +0200, Nadav Chernin
wrote: Hi, all Below is my solution to SPOJ->Polybius squarehttp://www.spoj.com/problems/POLYBIUS
Please try to shorten it:
*import Data.Maybe* *d=[1..5]* *f s=unwords$map(\c->fromJust$lookup c((' ',""):('J',"24"):zip(['A'..'I']++['K'..'Z'])[show(x+10*y)|y<-d,x<-d]))s* *main=getLine>>(interact$unlines.map f.lines)* d="12345" f s = unwords $ map (\c -> let (Just x) = lookup c ((' ',"") : ('J',"24") : zip (['A'..'I'] ++ ['K'..'Z']) [y : [x] | y <- d, x <- d]) in x) s main = getLine >> (interact $ unlines . map f . lines)
Note that you can point-freeify that solution a little and sacrifice totality, yielding an even shorter solution. (I didn't remove the lambda expression, as it ends up being shorter than flipping lookup) Inline the definitions and remove redundant spaces and newlines in the code below: d = "12345" f = unwords . map $ \c -> fromJust $ lookup c ((' ',"") : ('J',"24") : zip (['A'..'Z']\\"J") [[y,x] | y <- d, x <- d]) main = interact $ unlines . map f . drop 1 . lines Just my two cents. Gesh

On Thu, 01 Aug 2013 17:09:11 +0200, Gesh hseG
On Wed, Jul 24, 2013 at 4:18 PM, Henk-Jan van Tuyl
wrote: d="12345" f s = unwords $ map (\c -> let (Just x) = lookup c ((' ',"") : ('J',"24") : zip (['A'..'I'] ++ ['K'..'Z']) [y : [x] | y <- d, x <- d]) in x) s main = getLine >> (interact $ unlines . map f . lines)
Note that you can point-freeify that solution a little and sacrifice totality, yielding an even shorter solution. (I didn't remove the lambda expression, as it ends up being shorter than flipping lookup) Inline the definitions and remove redundant spaces and newlines in the code below: d = "12345" f = unwords . map $ \c -> fromJust $ lookup c ((' ',"") : ('J',"24") : zip (['A'..'Z']\\"J") [[y,x] | y <- d, x <- d]) main = interact $ unlines . map f . drop 1 . lines
There are imports necessary for fromJust and \\, this makes it longer again. Regards, Henk-Jan van Tuyl -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --
participants (4)
-
Gesh hseG
-
Henk-Jan van Tuyl
-
Kim-Ee Yeoh
-
Nadav Chernin