@@ -29,16 +29,29 @@ const getLastDigit = (line: string) => {
29
29
}
30
30
31
31
const getSumofFirstAndLastDigits = ( line : string ) => {
32
- console . log ( line )
33
-
34
- const firstDigit = getFirstDigit ( line )
35
- const lastDigit = getLastDigit ( line )
36
-
37
- console . log ( 'first ' , firstDigit , 'and last ' , lastDigit )
38
-
39
- return parseInt ( firstDigit + lastDigit )
32
+ return Number ( getFirstDigit ( line ) + getLastDigit ( line ) )
40
33
}
41
34
42
- const total = input . trimEnd ( ) . split ( '\n' ) . reduce ( ( prev , curr ) => prev + getSumofFirstAndLastDigits ( curr ) , 0 )
43
-
44
- console . log ( `Result is : ${ total } ` )
35
+ const total = testInput . trimEnd ( ) . split ( '\n' ) . reduce ( ( prev , curr ) => prev + getSumofFirstAndLastDigits ( curr ) , 0 )
36
+ console . log ( `Result for part 1 is : ${ total } ` )
37
+
38
+ const testInput2 = `two1nine
39
+ eightwothree
40
+ abcone2threexyz
41
+ xtwone3four
42
+ 4nineeightseven2
43
+ zoneight234
44
+ 7pqrstsixteen`
45
+
46
+ const easyInput = input . replaceAll ( 'one' , 'o1e' )
47
+ . replaceAll ( 'two' , 't2o' )
48
+ . replaceAll ( 'three' , 't3e' )
49
+ . replaceAll ( 'four' , 'f4r' )
50
+ . replaceAll ( 'five' , 'f5e' )
51
+ . replaceAll ( 'six' , 's6x' )
52
+ . replaceAll ( 'seven' , 's7n' )
53
+ . replaceAll ( 'eight' , 'e8t' )
54
+ . replaceAll ( 'nine' , 'n9e' )
55
+
56
+ const total2 = easyInput . trimEnd ( ) . split ( '\n' ) . reduce ( ( prev , curr ) => prev + getSumofFirstAndLastDigits ( curr ) , 0 )
57
+ console . log ( `Result for part 2 is : ${ total2 } ` )
0 commit comments