50 lines
1.1 KiB
V
50 lines
1.1 KiB
V
import os
|
|
|
|
const input = os.read_file('./input.txt')!
|
|
|
|
//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')
|
|
mut sum := 0
|
|
|
|
for line in lines {
|
|
if line.is_blank() {
|
|
continue
|
|
}
|
|
|
|
//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()
|
|
}
|
|
|
|
println("Result is ${sum}")
|
|
}
|