Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Programming Diversions
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams
this week in the
Agile and Other Processes
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Devaka Cooray
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Jeanne Boyarsky
Tim Cooke
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Mikalai Zaikin
Carey Brown
Bartenders:
Forum:
Programming Diversions
[SPOILER ALERT] Advent of Code 2022: Day 4 solutions
Junilu Lacar
Sheriff
Posts: 17630
300
I like...
posted 1 year ago
Number of slices to send:
Optional 'thank-you' note:
Send
SPOILER ALERT
This
thread
contains solution code for
Day 4
of
Advent of Code 2022
.
-- This space intentionally left blank --
SPOILER ALERT
This thread contains solution code for
Day 4
of
Advent of Code 2022
.
Liutauras Vilda
Marshal
Posts: 8829
631
I like...
posted 1 year ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
After I got Day 4 solved, I refactored it to some good extent. My solution wouldn't be optimal if ranges were big (very).
(define input (map (λ (e) (list (inclusive-range (first (car e)) (second (car e))) (inclusive-range (first (cadr e)) (second (cadr e))))) (map (λ (e) (list (map (λ (f) (string->number f)) (car e)) (map (λ (f) (string->number f)) (cadr e)))) (map (λ (e) (list (string-split (car e) "-") (string-split (cadr e) "-"))) (map (λ (e) (string-split e ",")) (file->lines "input/day04.txt")))))) (define (play input sum f) (cond [(empty? input) sum] [else (play (cdr input) (if (f (car input)) (add1 sum) sum) f)])) (play input 0 (λ (e) (or (= (length (set-intersect (car e) (cadr e))) (length (car e))) (= (length (set-intersect (car e) (cadr e))) (length (cadr e)))))) (play input 0 (λ (e) (not (empty? (set-intersect (car e) (cadr e))))))
please buy this thing and then I get a fat cut of the action:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
[SPOILER ALERT] Advent of Code 2022: Day 1 Solutions
[SPOILER ALERT] Advent of Code 2022: Day 2 solutions
[SPOILER ALERT] Advent of Code 2022: Day 3 solutions
Advent of Code 2022
Advent of Code 2021
More...