minor improvements

main
Inga 🏳‍🌈 12 months ago
parent 80af1ea047
commit 2bd8d0f87d
  1. 34
      day05-hard/main.scm

@ -378,10 +378,12 @@
(define symbol-current (quote current))
(define symbol-previous (quote previous))
(define (mark-state-value-previous state-entry) (cons symbol-previous (cdr state-entry)))
(define (is-state-value-current state-entry) (equal? symbol-current (car state-entry)))
(define get-state-value cdr)
(define create-state-value cons)
(define (create-state-value state-symbol) (lambda (range) (cons state-symbol range)))
(define create-state-value-current (create-state-value symbol-current))
(define create-state-value-previous (create-state-value symbol-previous))
(define (mark-state-value-previous state-entry) (create-state-value-previous (cdr state-entry)))
(define swap-state (compose (list
#!(tee-with-comment "state after swap")!#
(map mark-state-value-previous)
@ -395,17 +397,6 @@
(define get-range-start car)
(define get-range-end (compose (list car cdr)))
(define parse-initial
(compose (list
(map (lambda (raw-range) (create-state-value symbol-current (create-range-from-input raw-range))))
(chunks 2)
(map (compose (list
string->number
list->string)))
cdr
(split (is #\space))
string->list)))
(define (create-map numbers) (list
;; convert it from destination_start, source_start, length
;; to source_start, source_end, destination_start
@ -422,11 +413,11 @@
(map (lambda (intersection)
(if
(equal? symbol-in-both-ranges (car intersection))
(create-state-value symbol-current
(create-state-value-current
(create-range
(+ map-destination-start (- (get-range-start (cdr intersection)) map-source-start))
(+ map-destination-start (- (get-range-end (cdr intersection)) map-source-start))))
(create-state-value symbol-previous (create-range (get-range-start (cdr intersection)) (get-range-end (cdr intersection)))))))
(create-state-value-previous (create-range (get-range-start (cdr intersection)) (get-range-end (cdr intersection)))))))
(filter (lambda (intersection)
(or
(equal? symbol-in-second-range (car intersection))
@ -478,6 +469,19 @@
raw-seed-maps)
swap-state)))
(define parse-initial
(compose (list
(map (compose (list
create-state-value-current
create-range-from-input)))
(chunks 2)
(map (compose (list
string->number
list->string)))
cdr
(split (is #\space))
string->list)))
(define (final-state lines)
(((compose (list
compose

Loading…
Cancel
Save