Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List
  2.  
  3. --shift String left
  4. rl::[String]->[String]
  5. rl (x:xs) = xs++[x]
  6.  
  7. --shift string right
  8. rr::[String]->[String]
  9. rr (x:xs) = (take 1 (reverse xs))++x:init xs
  10.  
  11. --extract char string from a column
  12. ms::Int->Int->[[String]]->[Char]
  13. ms z y (x:xs) = map (!!y) (map (!!z) (x:xs))
  14.  
  15. --print cube
  16. pc::[[String]]->String
  17. pc (x:xs) = t++"\n"++m++"\n"++b
  18.     where t = (unwords x)
  19.           m = (unwords (xs!!0))
  20.           b = (unwords (xs!!1))
  21.    
  22.  
  23. --top down representation of top and bottom sides of cube
  24. td=        [["www"],  
  25.             ["www"],
  26.             ["www"]]
  27.      
  28. --side to side representation of cube    
  29. ss = [["bbb","def","ghi","jjj"],
  30.       ["bbb","def","ghi","jjj"],
  31.       ["bbb","def","ghi","jjj"]]
  32.      
  33. bt =       [["yyy"],  
  34.             ["yyy"],
  35.             ["yyy"]]
  36.      
  37. --extract row as string    
  38. er::Int->([[String]],[[String]])->String
  39. er z (x,y) = unwords (snd((x,y))!!z)
  40.  
  41. --insert row as string     )
  42. ir::Int->[String]->([[String]],[[String]])->[[String]]
  43. ir 0 nr (x,y) = nr:s
  44.     where s = snd (x,y)
  45. ir 1 nr (x,y) = [head s]++[nr]++tail s
  46.     where s = snd (x,y)
  47. ir 2 nr (x,y) = (tail s)++[nr]
  48.     where s = snd (x,y)
  49.  
  50.  
  51.  
  52. cube = (td,ss)
  53.    
  54. main = putStr(pc(ir 2 ["yes","hh"] cube))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement