Skip to content

Commit

Permalink
Update solutions for 0.1.81 cast changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Oct 13, 2024
1 parent 6c1b978 commit 98ec7ed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions exercises/practice/bank-account/.meta/bank-account.ys
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!yamlscript/v0

account =: atom(nil)
account =: nil:A

defn reset-test-state():
reset! account: nil
Expand All @@ -14,28 +14,28 @@ defn bank-account(operations):
.call(operation)

defn- do-open(op):
when deref(account):
when account:D:
die: 'account already open'
reset! account: 0

defn- do-close(op):
when-not deref(account):
when-not account:D:
die: 'account not open'
reset! account: nil

defn- do-balance(op):
balance =: deref(account)
balance =: account:D
if-not balance:
die: 'account not open'
else: balance

defn- do-deposit(op):
when-not deref(account):
when-not account:D:
die: 'account not open'
swap! account +: op:get-amount

defn- do-withdraw(op):
balance =: deref(account)
balance =: account:D
when-not balance:
die: 'account not open'
amount =: op:get-amount
Expand Down
15 changes: 8 additions & 7 deletions exercises/practice/circular-buffer/.meta/circular-buffer.ys
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!yamlscript/v0

defn run(capacity operations):
buffer =: M(:B V(capacity * [nil]), :P 0)
buffer =: -{:B V(capacity * [nil]), :P 0}
reduce _ buffer operations:
fn(buffer op):
op item pass want =:
Expand All @@ -10,14 +10,14 @@ defn run(capacity operations):
args =:
condp eq op:
-'clear' : -[buffer]
-'read' : L(buffer pass want)
-'write' : L(buffer pass item)
-'overwrite' : L(buffer pass item)
-'read' : -[buffer pass want]
-'write' : -[buffer pass item]
-'overwrite' : -[buffer pass item]
value("op-$op"): args*
=>: true

defn op-clear(buffer):
M: :B V(buffer.B.# * [nil]) :P 0
hash-map: :B V(buffer.B.# * [nil]) :P 0

defn op-read(buffer pass want):
cell =: buffer.B.nth(buffer.P)
Expand All @@ -26,8 +26,9 @@ defn op-read(buffer pass want):
die: S("Can't read:\ " buffer)
when cell != want:
die: "Bad read:\ $cell != $want ($buffer)"
M: :B update-in(buffer.B [buffer.P] constantly(nil))
:P (buffer.P.++ % buffer.B.#)
hash-map:
:B update-in(buffer.B [buffer.P] constantly(nil))
:P (buffer.P.++ % buffer.B.#)

defn op-write(buffer pass item):
B P =: buffer.slice(q(B P))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/etl/.meta/etl.ys
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
defn transform(legacy):
into {}:
for [score letters] legacy, letter letters:
V: lc(letter) score:N
vector: lc(letter) score:N
4 changes: 2 additions & 2 deletions exercises/practice/pascals-triangle/.meta/pascals-triangle.ys
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ defn rows(count):
or _ [1]:
when row > 1:
mapv _ (-1 .. row.sub(2)):
\(last(tri).get(_):N.or(0) +
last(tri).get(_.++):N.or(0))
\(last(tri).get(_ 0):N +
last(tri).get(_.++).or(0):N)
2 changes: 1 addition & 1 deletion exercises/practice/raindrops/.meta/raindrops.ys
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!yamlscript/v0

defn convert(number):
ps =: M(3 'Pling' 5 'Plang' 7 'Plong')
ps =: -{3 'Pling' 5 'Plang' 7 'Plong'}
words =:
mapcat _ [3 5 7]:
fn(n):
Expand Down

0 comments on commit 98ec7ed

Please sign in to comment.