diff --git a/01/part1.v b/01/part1.v index 6d53283..aa5f4eb 100644 --- a/01/part1.v +++ b/01/part1.v @@ -1,6 +1,10 @@ import os const input = os.read_file('./input.txt')! +//const input = "1abc2 +//pqr3stu8vwx +//a1b2c3d4e5f +//treb7uchet" fn main() { lines := input.split('\n') diff --git a/01/part2.v b/01/part2.v index 0aa1b39..f5fc1ed 100644 --- a/01/part2.v +++ b/01/part2.v @@ -1,14 +1,31 @@ import os -//const input = os.read_file('./input.txt')! +const input = os.read_file('./input.txt')! -const input = "two1nine -eightwothree -abcone2threexyz -xtwone3four -4nineeightseven2 -zoneight234 -7pqrstsixteen" +//const input = "two1nine +//eightwothree +//abcone2threexyz +//xtwone3four +//4nineeightseven2 +//zoneight234 +//7pqrstsixteen" + + +fn replace_letter_numbers(txt string) string { + mut tmp := txt + + tmp = tmp.replace('one', 'o1e') + tmp = tmp.replace('two', 't2o') + tmp = tmp.replace('three', 't3e') + tmp = tmp.replace('four', 'f4r') + tmp = tmp.replace('five', 'f5e') + tmp = tmp.replace('six', 's6x') + tmp = tmp.replace('seven', 's7n') + tmp = tmp.replace('eight', 'e8t') + tmp = tmp.replace('nine', 'n9e') + + return tmp +} fn main() { lines := input.split('\n') @@ -19,8 +36,13 @@ fn main() { continue } - trimmed := line.trim('abcdefghijklmnopqrstuvwxyz') + //println('-> line: ${line}') + replaced := replace_letter_numbers(line) + //println('-> replaced: ${replaced}') + trimmed := replaced.trim('abcdefghijklmnopqrstuvwxyz') + //println('-> trimmed: ${trimmed}') n := trimmed[0].ascii_str() + trimmed[trimmed.len-1].ascii_str() + //println('=> n: ${n}') sum += n.int() }