[Spoilers] Advent of Code 2023 Day 1 #2192
Replies: 4 comments
-
Mine is way less compact. I followed a different strategy for part two, duplicating the string, and the first part parsing just until the first "written number" and the second starting in reverse. Then I concat them because what only matters is the first and last one, it doesn't matter that we duplicate the string if we keep the first and last to be the same: https://github.com/aarroyoc/advent-of-code-2023/blob/main/day1/main.pl |
Beta Was this translation helpful? Give feedback.
-
Hi! I had this strategy: keep_first_digit(N), [N] --> first_digit(N).
keep_first_digit(N) --> digit(N).
first_digit(N) --> digit(N), ... .
first_digit(N) --> letter, first_digit(N).
last_digit(N) --> ..., digit(N).
last_digit(N) --> last_digit(N),letter.
concat_first_and_last_digit(N) --> keep_first_digit(N1), last_digit(N2), {number_chars(N, [N1,N2])}. Note that my |
Beta Was this translation helpful? Give feedback.
-
Oh hell yeah, thanks for this. I've been on the aoc subreddit solution megathreads looking for prolog solutions but it's inconsistent. Ideally we'd have some motivated folks here to provide them so those of us learning can have a reference. |
Beta Was this translation helpful? Give feedback.
-
I'm posting my AoC 2023 solutions here: https://github.com/infogulch/aoc It's got solutions for day 1,2,4, and day5 part1. I'm having trouble with day3... |
Beta Was this translation helpful? Give feedback.
-
A friend wanted a solution to refer to, so i wrote this solution that covers the problem.
Usage:
pt(p1,String,Result)
orpt(p2,String,Result)
.I think I can improve how I handle lines in this one, but i'm not sure how. I'd like to use a dcg containing
p1
orp2
usingphrase_to_file
, but when i tried earlier it made the interpreter unresponsive.Beta Was this translation helpful? Give feedback.
All reactions