Skip to content

Commit

Permalink
Refactorings for v0.1.79
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Oct 1, 2024
1 parent f731bf2 commit 625d0fc
Show file tree
Hide file tree
Showing 161 changed files with 337 additions and 305 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defaults:
jobs:
test:
runs-on: ubuntu-latest
container: ingy/exercism-yamlscript-test-runner:0.1.76
container: ingy/exercism-yamlscript-test-runner:0.1.79

steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ROOT := $(shell pwd)

BIN := bin

YS_VERSION := 0.1.76
YS_VERSION := 0.1.79

YS_LOCAL := .local
YS_LOCAL_PREFIX := $(YS_LOCAL)/v$(YS_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion common/gnumakefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion common/meta-makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
4 changes: 3 additions & 1 deletion exercises/practice/acronym/.meta/acronym.ys
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
!yamlscript/v0

defn abbreviate(phrase):
uc(phrase).re-seq(/[A-Z']+/).map(first).str(*)
uc(phrase):
.re-seq(/[A-Z']+/)
.map(first):join
2 changes: 1 addition & 1 deletion exercises/practice/acronym/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
14 changes: 7 additions & 7 deletions exercises/practice/all-your-base/.meta/all-your-base.ys
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
!yamlscript/v0

defn rebase(input-base digits output-base):
:: Converts a sequence of digits given in input-base into a sequence of
digits in the desired output-base.
:: Converts a sequence of digits given in input-base
into a sequence of digits in the desired output-base.

cond:
input-base < 2: die('input base must be >= 2')
input-base < 2: die('input base must be >= 2')
output-base < 2: die('output base must be >= 2')
digits.some(neg?) || digits.some(\(_ >= input-base)):
digits.some(neg?) || digits.some(ge(input-base)):
die: 'all digits must satisfy 0 <= d < input base'

digits.every?(zero?) || digits.! :: [0]
digits.every?(zero?) || count(digits).eq(0) :: [0]

else: digits
.digits-to-decimal(input-base)
.decimal-to-digits(output-base)

defn digits-to-decimal(digits input-base):
reduce \((%1 * input-base) + %2): 0 digits
reduce \(%2 + (%1 * input-base)): digits

defn decimal-to-digits(number output-base):
loop digits nil, num number:
if num > 0:
recur:
conj: digits (num % output-base)
conj digits: num % output-base
quot: num output-base
else: digits
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/anagram/.meta/anagram.ys
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
defn find-anagrams(subject candidates):
filter _ candidates:
partial _ subject:
fn(*):
-[word1 word2] =: _.map(lc)
word1 != word2 &&: sort(word1) == sort(word2)
fn(*words):
word1 word2 =: words.map(lc)
word1 != word2 &&:
sort(word1) == sort(word2)
2 changes: 1 addition & 1 deletion exercises/practice/anagram/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
!yamlscript/v0

defn is-armstrong-number(number):
number ==: map(\(_ ** str(number).#) digits(number)).sum()
ds =: digits(number)
number ==: ds.map(\(_ ** ds.#)):sum
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/atbash-cipher/.meta/atbash-cipher.ys
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ dict =:
zipmap (\\a .. \\z): \\z .. \\a

defn encode(phrase):
lc(phrase).replace(/[^a-z0-9]/ '').str/escape(dict)
.partition(5 5 '').map(join).join(' ')
lc(phrase):
.replace(/[^a-z0-9]/).escape(dict)
.partition(5 5 '').map(join):joins

defn decode(phrase):
phrase.replace(' ' '').str/escape(dict)
phrase.replace(' ').escape(dict)
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/bank-account/.meta/bank-account.ys
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ defn- do-balance(op):
defn- do-deposit(op):
when-not deref(account):
die: 'account not open'
swap! account +: op.get-amount()
swap! account +: op:get-amount

defn- do-withdraw(op):
balance =: deref(account)
when-not balance:
die: 'account not open'
amount =: op.get-amount()
amount =: op:get-amount
when amount > balance:
die: 'amount must be less than balance'
swap! account -: amount

defn- get-amount(op):
amount =: op.amount
if amount <= 0:
if amount < 0:
die: 'amount must be greater than 0'
else: amount
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/binary-search/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
5 changes: 3 additions & 2 deletions exercises/practice/binary-search/.meta/binary-search.ys
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
!yamlscript/v0

defn find(array value):
loop low 0, high array.#--:
loop low 0, high array.--:
when low > high:
die: 'value not in array'
mid =: quot((high + low) 2)
mid =: (high + low).quot(2)
item =: array.$mid

cond:
value == item : mid
value < item : recur(low mid.--)
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/binary-search/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/.meta/bob.ys
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
!yamlscript/v0

defn response(hey-bob):
condp re-matches hey-bob.trim():
condp re-matches hey-bob:trim:
/\s*/ : 'Fine. Be that way!'
/[^a-zA-Z]+\?/ : 'Sure.'
/[^a-z]+\?/ : "Calm down, I know what I'm doing!"
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bottle-song/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
12 changes: 6 additions & 6 deletions exercises/practice/bottle-song/.meta/bottle-song.ys
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
!yamlscript/v0

defn recite(start-bottles take-down):
lines:
join "\n":
map verse: start-bottles .. (start-bottles - take-down).++
nums =: start-bottles ..
(start-bottles - take-down).++
nums: .map(verse).join("\n"):lines

defn- verse(num): |
$uc1(bottles(num)) hanging on the wall,
$uc1(bottles(num)) hanging on the wall,
And if one green bottle should accidentally fall,
There'll be $bottles(num - 1) hanging on the wall.
There'll be $bottles(num.--) hanging on the wall.

dict =:
nums =:
zipmap (2 .. 10):
qw(two three four five six seven eight nine ten)

defn- bottles(num):
case num:
0 : 'no green bottles'
1 : 'one green bottle'
else : "$(dict.$num) green bottles"
else : "$(nums.$num) green bottles"
2 changes: 1 addition & 1 deletion exercises/practice/bottle-song/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION)
ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok))
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/collatz-conjecture/.meta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.76
export YS_VERSION := 0.1.79

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
!yamlscript/v0

defn steps(number):
when-not pos?(number):
die('Only positive integers are allowed')
number > 0 ||:
die: 'Only positive integers are allowed'

loop num number, steps 0:
cond:
num == 1: steps
even?(num): recur((num / 2), steps.++)
else: recur((num * 3).++, steps.++)
num.eq(1) : steps
num:even? : recur(num.div(2), steps.++)
else : recur(num.mul(3).++, steps.++)
Loading

0 comments on commit 625d0fc

Please sign in to comment.