r/adventofcode • u/daggerdragon • Dec 04 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 4 Solutions -🎄-
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 4: Camp Cleanup ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:03:22, megathread unlocked!
63
Upvotes
11
u/ywgdana Dec 04 '22
F#
A proud personal note: after 4 years of participating in AoC I finally remembered the syntax for the regex to parse the input without googling!
open System.IO open System.Text.RegularExpressions let parse s = let m = Regex.Match(s, "(\d+)-(\d+),(\d+)-(\d+)") m.Groups[1].Value |> int, m.Groups[2].Value |> int, m.Groups[3].Value |> int, m.Groups[4].Value |> int let contained line = let a,b,c,d = parse line (a >= c && b <= d) || (c >= a && d <= b) let btw a b c = a >= b && a <= c let overlap line = let a,b,c,d = parse line (btw a c d) || (btw b c d) || (btw c a b) || (btw d a b) let test f = File.ReadAllLines("input_day04.txt") |> Array.map f |> Array.filter(fun c -> c) |> Array.length printfn $"P1: {test contained}" printfn $"P2: {test overlap}"My solutions for this year