fork download
  1. main = do mapM_ ph [(29,15),(29,5),(5,24),(99,99),(1,2),(10,0),(0,10),(50,60),(10,10)]
  2. mapM_ mh [(29,15),(29,5),(5,24),(99,99),(1,2),(10,0),(0,10),(50,60),(10,10)]
  3. where ph (x,y) = (putStrLn.plsformat) $ plshissan x y
  4. mh (x,y) = (putStrLn.mulformat) $ mulhissan x y
  5.  
  6. plshissan n m = (n, m, x, y, x + y * 10)
  7. where
  8. x = n `mod` 10 + m `mod` 10
  9. y = n `div` 10 + m `div` 10
  10.  
  11. plsformat (n,m,x,y,z) = (zero2null.concat) [" ",numw n,
  12. "\n+ ",numw m,
  13. bar ++ " ",
  14. numw x,
  15. "\n ",numw y,
  16. chkxz x z zsp numw,"\n"]
  17.  
  18. mulhissan n m = (n, m, x, y, xx, yy, x + y * 10 + xx * 10 + yy * 100)
  19. where
  20. x = (n `mod` 10) * (m `mod` 10)
  21. y = (n `div` 10) * (m `mod` 10)
  22. xx = (n `mod` 10) * (m `div` 10)
  23. yy = (n `div` 10) * (m `div` 10)
  24.  
  25. mulformat (n,m,x,y,xx,yy,z) = (zero2null.concat) [" ",numw n,
  26. "\n* ",numw m,
  27. bar ++ " ",
  28. numw x,
  29. "\n ",numw y,
  30. "\n ",numw xx,
  31. "\n",numw yy,
  32. chkxz x z zsp numw,"\n"]
  33.  
  34. numw x | length (show x) == 1 = " " ++ show x
  35. numw x = show x
  36.  
  37. zsp x | length (show x) == 3 = bar ++ " "
  38. zsp x | length (show x) == 4 = bar
  39. zsp x = bar ++ " "
  40.  
  41.  
  42. bar = "\n-----\n"
  43.  
  44. zero2null [] = []
  45. zero2null xs | take n xs == s = zero2null (drop n xs)
  46. where
  47. s = "\n 0"
  48. n = length s
  49. zero2null xs | take n xs == s = zero2null (drop n xs)
  50. where
  51. s = "\n 0"
  52. n = length s
  53. zero2null xs | take n xs == s = zero2null (drop n xs)
  54. where
  55. s = "\n 0"
  56. n = length s
  57. zero2null xs | take n xs == s = s ++ zero2null (drop n xs)
  58. where
  59. s = bar ++ " 0"
  60. n = length s
  61. zero2null (x:xs) = x:zero2null xs
  62.  
  63. chkxz x z s1 s2 | x == z = ""
  64. chkxz x z f1 f2 = f1 z ++ f2 z
  65.  
Success #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
  29
+ 15
-----
  14
  3
-----
  44

  29
+  5
-----
  14
  2
-----
  34

   5
+ 24
-----
   9
  2
-----
  29

  99
+ 99
-----
  18
 18
-----
 198

   1
+  2
-----
   3

  10
+  0
-----
   0
  1
-----
  10

   0
+ 10
-----
   0
  1
-----
  10

  50
+ 60
-----
   0
 11
-----
 110

  10
+ 10
-----
   0
  2
-----
  20

  29
* 15
-----
  45
 10
  9
 2
-----
 435

  29
*  5
-----
  45
 10
-----
 145

   5
* 24
-----
  20
 10
-----
 120

  99
* 99
-----
  81
 81
 81
81
-----
9801

   1
*  2
-----
   2

  10
*  0
-----
   0

   0
* 10
-----
   0

  50
* 60
-----
   0
30
-----
3000

  10
* 10
-----
   0
 1
-----
 100