day 1 solution
parent
829c87d96d
commit
1646399f9f
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,4 @@
|
|||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
|
@ -0,0 +1,7 @@
|
|||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
|
@ -0,0 +1,2 @@
|
|||
{ gsub("[^0-9]", " "); gsub("[0-9]", "& "); n = $1 $NF; T += n; print n }
|
||||
END { print T }
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
d1 = "";
|
||||
d2 = "";
|
||||
if (match($0, "one|two|three|four|five|six|seven|eight|nine|[0-9]")) { d1 = substr($0,RSTART,RLENGTH) }
|
||||
for (i = length($0); i > 0; i--) {
|
||||
s = substr($0, i);
|
||||
if (match(s, "one|two|three|four|five|six|seven|eight|nine|[0-9]")) { d2 = substr(s,RSTART,RLENGTH); break; }
|
||||
}
|
||||
n = d1 d2;
|
||||
print n;
|
||||
gsub("one","1",n); gsub("two","2",n); gsub("three","3",n);
|
||||
gsub("four","4",n); gsub("five","5",n); gsub("six","6",n);
|
||||
gsub("seven","7",n); gsub("eight","8",n); gsub("nine","9",n);
|
||||
T += n;
|
||||
print $0, n;
|
||||
}
|
||||
#{ print $0 }
|
||||
END { print T }
|
Loading…
Reference in New Issue