rename deflocal localVar

This commit is contained in:
2021-07-24 12:53:27 -06:00
parent 12884b4a2d
commit 9c185839ca
10 changed files with 33 additions and 32 deletions

View File

@@ -5,7 +5,7 @@
(unless (<= 0 (line.indexOf "contain no other bags"))
(let [[containerStr contents] (line.split "contain ")
contentStrs (contents.split ", ")]
(deflocal :Map<String,Int> innerMap (new Map))
(localVar :Map<String,Int> innerMap (new Map))
(doFor str contentStrs
(let [parts (str.split " ")
quantity (Std.parseInt (parts.shift))
@@ -24,7 +24,7 @@
(defun totalChildBags [bag :ParentMap parentMap]
(if (parentMap.exists bag)
(begin
(deflocal &mut sum 0)
(localVar &mut sum 0)
(doFor =>childColor quantity (dictGet parentMap bag)
(set sum (+ sum quantity (* quantity (totalChildBags childColor parentMap)))))
sum)

View File

@@ -17,7 +17,7 @@
(true fullSeat)))
(defun neighbors [x y :Array<Array<FerrySquare>> grid]
(deflocal &mut n [])
(localVar &mut n [])
(doFor xx (range (- x 1) (+ x 2))
(doFor yy (range (- y 1) (+ y 2))
(unless (and (= x xx) (= y yy))
@@ -28,7 +28,7 @@
(defprop &mut :Array<Array<FerrySquare>> state [])
(defmethod simulate []
(deflocal changed (object changed false))
(localVar changed (object changed false))
(set state
(for rowIdx (range state.length)
(let [:Array<FerrySquare> row (nth state rowIdx)]

View File

@@ -24,7 +24,7 @@
(assert (= 673 (count (map (Util.readLines "src/year2020/inputs/day2-1.txt") (.bind Passwords.validateInputLine _ Passwords.parsePasswordCheck2)) (lambda [v] v)))))
(day 3
(deflocal exampleHillTile [
(localVar exampleHillTile [
"..##......."
"#...#...#.."
".#....#..#."
@@ -55,8 +55,8 @@
(let [:kiss.List<Int> seatIds (map (Util.readLines "src/year2020/inputs/day5-1.txt") Seating.seatId)]
(seatIds.sort (lambda [a b] (- a b)))
(assert (= 947 (nth seatIds -1)))
(deflocal &mut lastId -1)
(deflocal &mut myId -1)
(localVar &mut lastId -1)
(localVar &mut myId -1)
(doFor id seatIds
(when (and (<= 0 lastId) !(= lastId (- id 1)))
(set myId (- id 1))
@@ -71,11 +71,11 @@
(assert (= 3122 (apply + (map (Util.readParagraphLines "src/year2020/inputs/day6-1.txt") Customs.countAllYes)))))
(day 7
(deflocal parentMap (new ParentMap))
(deflocal childMap (new ChildMap))
(localVar parentMap (new ParentMap))
(localVar childMap (new ChildMap))
(doFor line (Util.readLines "src/year2020/inputs/day7.txt")
(Bags.parseRule line parentMap childMap))
(deflocal :Map<String,Bool> shinyGoldParents (new Map))
(localVar :Map<String,Bool> shinyGoldParents (new Map))
(Bags.findIndirectContainers "shiny gold" childMap shinyGoldParents)
(assert (= 172 (count shinyGoldParents)))
(assert (= 39645 (Bags.totalChildBags "shiny gold" parentMap))))

View File

@@ -1,6 +1,6 @@
(defun :kiss.List<Int> pairWithSum [sum :kiss.List<Int> numbers]
// Put the numbers in a map for random access. This gives an O(n) solution
(deflocal :Map<Int,Int> numbersMap (new Map))
(localVar :Map<Int,Int> numbersMap (new Map))
(doFor number numbers
(dictSet numbersMap number (- sum number))
(let [requiredForPair (dictGet numbersMap number)]
@@ -18,7 +18,7 @@
(defun contiguousSumTuple [sum :kiss.List<Int> numbers]
(doFor i (range numbers.length)
(deflocal &mut testSum (nth numbers i))
(localVar &mut testSum (nth numbers i))
(doFor j (range (+ i 1) numbers.length)
(set testSum (+ testSum (nth numbers j)))
(cond