We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4850431 commit ea52f1bCopy full SHA for ea52f1b
src/AddBinary.hs
@@ -14,3 +14,17 @@ intToBinary n
14
digit
15
| rest == 0 = '0'
16
| otherwise = '1'
17
+
18
+-- #againwhatlearned
19
20
+-- 1. use `showBin` of `Numeric` module
21
+-- addBinary a b = showBin (a+b) ""
22
23
+-- 2. use `showIntAtBase` of `Numeric` module
24
+-- addBinary a b = showIntAtBase 2 intToDigit (a+b) ""
25
26
+-- 3. Simple `toBinary` function
27
+-- toBinary :: Int -> String
28
+-- toBinary 0 = "0"
29
+-- toBinary 1 = "1"
30
+-- toBinary n = toBinary (n `div` 2) <> toBinary (n `mod` 2)
0 commit comments