From d241df3765ed309ea24d05baae40eb3c2765aa19 Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: May 20 2019 16:31:30 +0000
Subject: [PATCH 1/3] [wip] Add fbo answers for homework 1


---

diff --git a/assignments/fbo/hm1/ex1.hs b/assignments/fbo/hm1/ex1.hs
new file mode 100644
index 0000000..1ec11aa
--- /dev/null
+++ b/assignments/fbo/hm1/ex1.hs
@@ -0,0 +1,11 @@
+toDigits :: Integer -> [Integer]
+toDigits r
+  | r <= 0 = []
+  | otherwise = toDigits (div r 10) ++ [mod r 10]
+
+toDigitsRev :: Integer -> [Integer]
+toDigitsRev r
+  | r <= 0 = []
+  | otherwise = (mod r 10) : toDigitsRev (div r 10)
+
+main = print (toDigits (-17))
diff --git a/assignments/fbo/hm1/ex2.hs b/assignments/fbo/hm1/ex2.hs
new file mode 100644
index 0000000..b9b837b
--- /dev/null
+++ b/assignments/fbo/hm1/ex2.hs
@@ -0,0 +1,9 @@
+doubleEveryOtherLR :: [Integer] -> [Integer]
+doubleEveryOtherLR [] = []
+doubleEveryOtherLR (x:[]) = [x]
+doubleEveryOtherLR (x:y:zs) = x : y*2 : doubleEveryOtherLR zs
+
+doubleEveryOther :: [Integer] -> [Integer]
+doubleEveryOther zs = reverse (doubleEveryOtherLR (reverse zs))
+
+main = print (doubleEveryOther [10, 9, 8, 7])

From 558ee323881b87bbe1ccf6a550ea4411b5fae3d7 Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: May 22 2019 12:28:14 +0000
Subject: [PATCH 2/3] Add ex3


---

diff --git a/assignments/fbo/hm1/ex3.hs b/assignments/fbo/hm1/ex3.hs
new file mode 100644
index 0000000..463de6c
--- /dev/null
+++ b/assignments/fbo/hm1/ex3.hs
@@ -0,0 +1,17 @@
+intToList :: Integer -> [Integer]
+intToList 0 = []
+intToList x = (mod x 10) : (intToList (div x 10))
+
+-- Same as above
+-- sumDigits :: [Integer] -> Integer
+-- sumDigits (l:[]) =
+--     if l >= 0 && l <= 10
+--         then l
+--         else (sumDigits (intToList l))
+-- sumDigits (x:y:xs) = x + y + (sumDigits xs)
+
+sumDigits :: [Integer] -> Integer
+sumDigits (l:[]) = if l >= 0 && l <= 10 then l else (sumDigits (intToList l))
+sumDigits (x:y:xs) = x + y + (sumDigits xs)
+
+main = print (sumDigits [22215])

From 716fdf2388321ef7655164e7f23c380a06fcb6ef Mon Sep 17 00:00:00 2001
From: Fabien Boucher <fboucher@redhat.com>
Date: May 24 2019 10:14:00 +0000
Subject: [PATCH 3/3] Provided ex4 and started ex5


---

diff --git a/assignments/fbo/hm1/ex3.hs b/assignments/fbo/hm1/ex3.hs
index 463de6c..6fd692b 100644
--- a/assignments/fbo/hm1/ex3.hs
+++ b/assignments/fbo/hm1/ex3.hs
@@ -2,16 +2,8 @@ intToList :: Integer -> [Integer]
 intToList 0 = []
 intToList x = (mod x 10) : (intToList (div x 10))
 
--- Same as above
--- sumDigits :: [Integer] -> Integer
--- sumDigits (l:[]) =
---     if l >= 0 && l <= 10
---         then l
---         else (sumDigits (intToList l))
--- sumDigits (x:y:xs) = x + y + (sumDigits xs)
-
 sumDigits :: [Integer] -> Integer
-sumDigits (l:[]) = if l >= 0 && l <= 10 then l else (sumDigits (intToList l))
-sumDigits (x:y:xs) = x + y + (sumDigits xs)
+sumDigits [] = 0
+sumDigits (x:xs) = sum(intToList x) + sumDigits xs
 
-main = print (sumDigits [22215])
+main = print (sumDigits [12, 4])
diff --git a/assignments/fbo/hm1/ex4.hs b/assignments/fbo/hm1/ex4.hs
new file mode 100644
index 0000000..ef0bb34
--- /dev/null
+++ b/assignments/fbo/hm1/ex4.hs
@@ -0,0 +1,31 @@
+toDigits :: Integer -> [Integer]
+toDigits r
+  | r <= 0 = []
+  | otherwise = toDigits (div r 10) ++ [mod r 10]
+
+doubleEveryOtherLR :: [Integer] -> [Integer]
+doubleEveryOtherLR [] = []
+doubleEveryOtherLR (x:[]) = [x]
+doubleEveryOtherLR (x:y:zs) = x : y*2 : doubleEveryOtherLR zs
+
+doubleEveryOther :: [Integer] -> [Integer]
+doubleEveryOther zs = reverse (doubleEveryOtherLR (reverse zs))
+
+intToList :: Integer -> [Integer]
+intToList 0 = []
+intToList x = (mod x 10) : (intToList (div x 10))
+
+sumDigits :: [Integer] -> Integer
+sumDigits [] = 0
+sumDigits (x:xs) = sum(intToList x) + sumDigits xs
+
+validate :: Integer -> Bool
+validate x = 
+  if mod (
+    sumDigits (
+      doubleEveryOther (toDigits x))) 10 == 0
+  then True
+  else False
+
+main = print (validate 4012888888881881)
+main = print (validate 4012888888881882)
diff --git a/assignments/fbo/hm1/ex5.hs b/assignments/fbo/hm1/ex5.hs
new file mode 100644
index 0000000..95629d2
--- /dev/null
+++ b/assignments/fbo/hm1/ex5.hs
@@ -0,0 +1,12 @@
+type Peg = String
+type Move = (Peg, Peg)
+hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
+hanoi n a b c
+  | n == 1 = [(a, c) :: Move]
+
+a = "A" :: Peg
+b = "B" :: Peg
+c = "C" :: Peg
+
+main = print (hanoi 1 a b c)
+-- TBC

