Browse Source

aoc 2022 02

Mistivia 1 year ago
parent
commit
3a4e5447a7

+ 1 - 1
advent-of-code/2022/01/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 1 - 1
advent-of-code/2022/01/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 28 - 0
advent-of-code/2022/02/1.rkt

@@ -0,0 +1,28 @@
+#lang racket
+
+(require "../../lib/utils.rkt")
+
+(define lines
+    (call-with-input-file "input"
+        (lambda (fp) (get-lines fp))))
+
+(define games (map string-split lines))
+
+(define (score game)
+    (define (base-score mine)
+        (cond ((string=? "X" mine) 1)
+              ((string=? "Y" mine) 2)
+              ((string=? "Z" mine) 3)))
+    (define (win-score mine oppo)
+        (cond ((string=? "X" mine) (cond ((string=? "A" oppo) 3)
+                                         ((string=? "B" oppo) 0)
+                                         ((string=? "C" oppo) 6)))
+              ((string=? "Y" mine) (cond ((string=? "A" oppo) 6)
+                                         ((string=? "B" oppo) 3)
+                                         ((string=? "C" oppo) 0)))
+              ((string=? "Z" mine) (cond ((string=? "A" oppo) 0)
+                                         ((string=? "B" oppo) 6)
+                                         ((string=? "C" oppo) 3)))))
+    (+ (base-score (cadr game)) (win-score (cadr game) (car game))))
+
+(apply + (map score games))

+ 45 - 0
advent-of-code/2022/02/2.rkt

@@ -0,0 +1,45 @@
+#lang racket
+
+(require "../../lib/utils.rkt")
+
+(define lines
+    (call-with-input-file "input"
+        (lambda (fp) (get-lines fp))))
+
+(define games (map string-split lines))
+
+(define (transform-cheat mine oppo)
+    (cond ((string=? "X" mine) (cond ((string=? "A" oppo) "Z")
+                                     ((string=? "B" oppo) "X")
+                                     ((string=? "C" oppo) "Y")))
+          ((string=? "Y" mine) (cond ((string=? "A" oppo) "X")
+                                     ((string=? "B" oppo) "Y")
+                                     ((string=? "C" oppo) "Z")))
+          ((string=? "Z" mine) (cond ((string=? "A" oppo) "Y")
+                                     ((string=? "B" oppo) "Z")
+                                     ((string=? "C" oppo) "X")))))
+
+(set! games
+    (map
+        (lambda (x)
+            (list (car x) (transform-cheat (cadr x) (car x))))
+        games))
+
+(define (score game)
+    (define (base-score mine)
+        (cond ((string=? "X" mine) 1)
+              ((string=? "Y" mine) 2)
+              ((string=? "Z" mine) 3)))
+    (define (win-score mine oppo)
+        (cond ((string=? "X" mine) (cond ((string=? "A" oppo) 3)
+                                         ((string=? "B" oppo) 0)
+                                         ((string=? "C" oppo) 6)))
+              ((string=? "Y" mine) (cond ((string=? "A" oppo) 6)
+                                         ((string=? "B" oppo) 3)
+                                         ((string=? "C" oppo) 0)))
+              ((string=? "Z" mine) (cond ((string=? "A" oppo) 0)
+                                         ((string=? "B" oppo) 6)
+                                         ((string=? "C" oppo) 3)))))
+    (+ (base-score (cadr game)) (win-score (cadr game) (car game))))
+
+(apply + (map score games))

+ 1 - 1
advent-of-code/2023/01/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 1 - 1
advent-of-code/2023/01/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 1 - 1
advent-of-code/2023/02/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 1 - 1
advent-of-code/2023/02/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 

+ 1 - 1
advent-of-code/2023/03/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 (require "../../lib/obj.rkt")

+ 1 - 1
advent-of-code/2023/04/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 (require "../../lib/obj.rkt")

+ 1 - 1
advent-of-code/2023/04/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (require "../../lib/utils.rkt")
 (require "../../lib/obj.rkt")

+ 1 - 1
advent-of-code/2023/05/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define port (open-input-file "input"))
 

+ 1 - 1
advent-of-code/2023/05/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define port (open-input-file "input"))
 

+ 1 - 1
advent-of-code/2023/06/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define in (open-input-file "input"))
 

+ 1 - 1
advent-of-code/2023/06/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define in (open-input-file "input"))
 

+ 1 - 1
advent-of-code/2023/07/1.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define input 
   (with-input-from-file "input"

+ 1 - 1
advent-of-code/2023/07/2.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (define input 
   (with-input-from-file "input"

+ 1 - 1
advent-of-code/lib/obj.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (provide obj-maker
          obj-set

+ 1 - 1
advent-of-code/lib/utils.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 (provide get-lines
          enumerate

+ 1 - 1
codewars/6-kyu/pyramid-array/solution.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 ;; https://www.codewars.com/kata/515f51d438015969f7000013
 

+ 1 - 1
codewars/7-kyu/a-rule-of-divisibility-by-7/solution.rkt

@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
 
 ;; https://www.codewars.com/kata/55e6f5e58f7817808e00002e