aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--advent-of-code/2022/01/1.rkt2
-rw-r--r--advent-of-code/2022/01/2.rkt2
-rw-r--r--advent-of-code/2022/02/1.rkt28
-rw-r--r--advent-of-code/2022/02/2.rkt45
-rw-r--r--advent-of-code/2023/01/1.rkt2
-rw-r--r--advent-of-code/2023/01/2.rkt2
-rw-r--r--advent-of-code/2023/02/1.rkt2
-rw-r--r--advent-of-code/2023/02/2.rkt2
-rw-r--r--advent-of-code/2023/03/1.rkt2
-rw-r--r--advent-of-code/2023/04/1.rkt2
-rw-r--r--advent-of-code/2023/04/2.rkt2
-rwxr-xr-xadvent-of-code/2023/05/1.rkt2
-rwxr-xr-xadvent-of-code/2023/05/2.rkt2
-rw-r--r--advent-of-code/2023/06/1.rkt2
-rw-r--r--advent-of-code/2023/06/2.rkt2
-rw-r--r--advent-of-code/2023/07/1.rkt2
-rw-r--r--advent-of-code/2023/07/2.rkt2
-rw-r--r--advent-of-code/lib/obj.rkt2
-rw-r--r--advent-of-code/lib/utils.rkt2
-rw-r--r--codewars/6-kyu/pyramid-array/solution.rkt2
-rw-r--r--codewars/7-kyu/a-rule-of-divisibility-by-7/solution.rkt2
21 files changed, 92 insertions, 19 deletions
diff --git a/advent-of-code/2022/01/1.rkt b/advent-of-code/2022/01/1.rkt
index 340a531..e7c335e 100644
--- a/advent-of-code/2022/01/1.rkt
+++ b/advent-of-code/2022/01/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2022/01/2.rkt b/advent-of-code/2022/01/2.rkt
index 40b4f23..1644885 100644
--- a/advent-of-code/2022/01/2.rkt
+++ b/advent-of-code/2022/01/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2022/02/1.rkt b/advent-of-code/2022/02/1.rkt
new file mode 100644
index 0000000..35c5a5c
--- /dev/null
+++ b/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)) \ No newline at end of file
diff --git a/advent-of-code/2022/02/2.rkt b/advent-of-code/2022/02/2.rkt
new file mode 100644
index 0000000..4b0dd02
--- /dev/null
+++ b/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)) \ No newline at end of file
diff --git a/advent-of-code/2023/01/1.rkt b/advent-of-code/2023/01/1.rkt
index 0e57c95..57d366d 100644
--- a/advent-of-code/2023/01/1.rkt
+++ b/advent-of-code/2023/01/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2023/01/2.rkt b/advent-of-code/2023/01/2.rkt
index a5bbee2..7b252db 100644
--- a/advent-of-code/2023/01/2.rkt
+++ b/advent-of-code/2023/01/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2023/02/1.rkt b/advent-of-code/2023/02/1.rkt
index 818eb36..e0a7bf9 100644
--- a/advent-of-code/2023/02/1.rkt
+++ b/advent-of-code/2023/02/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2023/02/2.rkt b/advent-of-code/2023/02/2.rkt
index 40e8a09..87599d7 100644
--- a/advent-of-code/2023/02/2.rkt
+++ b/advent-of-code/2023/02/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
diff --git a/advent-of-code/2023/03/1.rkt b/advent-of-code/2023/03/1.rkt
index 09bc7d0..2b9a1d2 100644
--- a/advent-of-code/2023/03/1.rkt
+++ b/advent-of-code/2023/03/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
(require "../../lib/obj.rkt")
diff --git a/advent-of-code/2023/04/1.rkt b/advent-of-code/2023/04/1.rkt
index 8dc0ee6..8198403 100644
--- a/advent-of-code/2023/04/1.rkt
+++ b/advent-of-code/2023/04/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
(require "../../lib/obj.rkt")
diff --git a/advent-of-code/2023/04/2.rkt b/advent-of-code/2023/04/2.rkt
index f6febf3..fa1dd86 100644
--- a/advent-of-code/2023/04/2.rkt
+++ b/advent-of-code/2023/04/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(require "../../lib/utils.rkt")
(require "../../lib/obj.rkt")
diff --git a/advent-of-code/2023/05/1.rkt b/advent-of-code/2023/05/1.rkt
index 411a36b..f0ad5ed 100755
--- a/advent-of-code/2023/05/1.rkt
+++ b/advent-of-code/2023/05/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define port (open-input-file "input"))
diff --git a/advent-of-code/2023/05/2.rkt b/advent-of-code/2023/05/2.rkt
index 9a0233f..5024c1e 100755
--- a/advent-of-code/2023/05/2.rkt
+++ b/advent-of-code/2023/05/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define port (open-input-file "input"))
diff --git a/advent-of-code/2023/06/1.rkt b/advent-of-code/2023/06/1.rkt
index 92d0bf6..ea0d013 100644
--- a/advent-of-code/2023/06/1.rkt
+++ b/advent-of-code/2023/06/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define in (open-input-file "input"))
diff --git a/advent-of-code/2023/06/2.rkt b/advent-of-code/2023/06/2.rkt
index cc381cf..5d124e0 100644
--- a/advent-of-code/2023/06/2.rkt
+++ b/advent-of-code/2023/06/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define in (open-input-file "input"))
diff --git a/advent-of-code/2023/07/1.rkt b/advent-of-code/2023/07/1.rkt
index 635d6be..a22571d 100644
--- a/advent-of-code/2023/07/1.rkt
+++ b/advent-of-code/2023/07/1.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define input
(with-input-from-file "input"
diff --git a/advent-of-code/2023/07/2.rkt b/advent-of-code/2023/07/2.rkt
index e88f949..50d9526 100644
--- a/advent-of-code/2023/07/2.rkt
+++ b/advent-of-code/2023/07/2.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(define input
(with-input-from-file "input"
diff --git a/advent-of-code/lib/obj.rkt b/advent-of-code/lib/obj.rkt
index 578ea36..9217976 100644
--- a/advent-of-code/lib/obj.rkt
+++ b/advent-of-code/lib/obj.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(provide obj-maker
obj-set
diff --git a/advent-of-code/lib/utils.rkt b/advent-of-code/lib/utils.rkt
index 1e777c8..42b36af 100644
--- a/advent-of-code/lib/utils.rkt
+++ b/advent-of-code/lib/utils.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
(provide get-lines
enumerate
diff --git a/codewars/6-kyu/pyramid-array/solution.rkt b/codewars/6-kyu/pyramid-array/solution.rkt
index 4973db9..0d6a00b 100644
--- a/codewars/6-kyu/pyramid-array/solution.rkt
+++ b/codewars/6-kyu/pyramid-array/solution.rkt
@@ -1,4 +1,4 @@
-#lang racket/base
+#lang racket
;; https://www.codewars.com/kata/515f51d438015969f7000013
diff --git a/codewars/7-kyu/a-rule-of-divisibility-by-7/solution.rkt b/codewars/7-kyu/a-rule-of-divisibility-by-7/solution.rkt
index a8172a1..6859107 100644
--- a/codewars/7-kyu/a-rule-of-divisibility-by-7/solution.rkt
+++ b/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