Skip to content

Commit 72a341f

Browse files
author
gfixler
committed
Add functions to pull heights of each * column
1 parent c4fb863 commit 72a341f

File tree

1 file changed

+21
-0
lines changed
  • 233_easy_theHouseThatASCIIBuilt

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module Main where
2+
3+
import Data.List (transpose)
4+
5+
sumHeights :: Num a => [a] -> [a] -> [a]
6+
sumHeights xs [] = xs
7+
sumHeights [] ys = ys
8+
sumHeights (x:xs) (y:ys) = x + y : sumHeights xs ys
9+
10+
height :: Char -> Int
11+
height '*' = 1
12+
height _ = 0
13+
14+
heights :: String -> [Int]
15+
heights = foldr1 sumHeights . map (map height) . lines
16+
17+
input1 = " *\n ***\n******"
18+
input2 = " *\n***\n***\n***\n***\n***\n***"
19+
challenge1 = " **\n*** **\n******"
20+
challenge2 = "*** ***\n*** ** *** ** ***\n*** *************** ***\n*** *************** ***\n*** *************** ***\n**************************\n**************************"
21+

0 commit comments

Comments
 (0)