Skip to content

Commit ea52f1b

Browse files
committed
Extend 'Binary Addition' kata
1 parent 4850431 commit ea52f1b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/AddBinary.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ intToBinary n
1414
digit
1515
| rest == 0 = '0'
1616
| 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

Comments
 (0)