From bc46bac92724c8b6055eb5b7274d36a5bca65a2a Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 1 Dec 2023 11:03:36 -0500 Subject: Solve day 1 part 2 --- 2023/day01.awk | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to '2023') diff --git a/2023/day01.awk b/2023/day01.awk index 3127556..519b414 100644 --- a/2023/day01.awk +++ b/2023/day01.awk @@ -1,7 +1,39 @@ { - gsub("[^[:digit:]]", ""); + first = 0; + for (i = 0; i <= length; i++) { + digit = 0; + s = substr($0, i); + if (s ~ /^one/) { + digit = 1; + } else if (s ~ /^two/) { + digit = 2; + } else if (s ~ /^three/) { + digit = 3; + } else if (s ~ /^four/) { + digit = 4; + } else if (s ~ /^five/) { + digit = 5; + } else if (s ~ /^six/) { + digit = 6; + } else if (s ~ /^seven/) { + digit = 7; + } else if (s ~ /^eight/) { + digit = 8; + } else if (s ~ /^nine/) { + digit = 9; + } else if (s ~ /^[[:digit:]]/) { + digit = substr(s, 1, 1); + } + if (digit) { + if (!first) first = digit; + last = digit; + } + } + gsub(/[^[:digit:]]/, ""); part1 += substr($0, 1, 1) substr($0, length, 1); + part2 += first last; } END { print part1; + print part2; } -- cgit 1.4.1 ref='/catgirl/refs/?h=2.2a&id=1daf23d8a5261d42bf64e75b44cb943086cedcf8'>refs log tree commit diff
path: root/Makefile (unfollow)
Commit message (Collapse)Author
2018-08-03Ignore NOTICEs not sent to the channelJune McEnroe
2018-08-03Handle KICK and NICKJune McEnroe
2018-08-03Continue on EINTR from pollJune McEnroe
Resizing the terminal causes it.
2018-08-03Handle ACTIONsJune McEnroe
2018-08-03Use more octal char literalsJune McEnroe
I might be coming around to octal.
2018-08-03Send a WHO in response to NAMES to get usernamesJune McEnroe
Other than this slight hack, I think coloring by username rather than nick is a much better idea.
2018-08-03Colorize nicks and channelsJune McEnroe
2018-08-03Add support for mIRC colorsJune McEnroe
2018-08-03Handle bold, italic, underlineJune McEnroe
2018-08-03Add prift function for "prefix shift"June McEnroe
Forgive me.
2018-08-03Link with -lcurseswJune McEnroe
2018-08-02Use libtls "compat" ciphersJune McEnroe
irc.mozilla.org, using GnuTLS, doesn't support *any* of the "secure" ciphers!
2018-08-02Add UI and handle some kinds of server messagesJune McEnroe
Seems like handling input is going to be the worst thing ever.
2018-08-02Add chroot.tar targetJune McEnroe