Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactorings for v0.1.79 #29

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
"prerequisites": [],
"difficulty": 1
},
{
"slug": "resistor-color-duo",
"name": "Resistor Color Duo",
"uuid": "8a49347f-461f-415c-b203-bb491ac98fac",
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "reverse-string",
"name": "Reverse String",
Expand Down
7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ exercises:
prerequisites: []
difficulty: 1

- slug: resistor-color-duo
name: Resistor Color Duo
uuid: 8a49347f-461f-415c-b203-bb491ac98fac
practices: []
prerequisites: []
difficulty: 1

- slug: reverse-string
name: Reverse String
uuid: 89681570-5734-4f20-b68f-de8b176accdc
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
21 changes: 0 additions & 21 deletions exercises/practice/allergies/allergies.ys
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
!yamlscript/v0

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

defn allergic-to(item score):
# Implement the 'allergic-to' function.

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:
ingydotnet marked this conversation as resolved.
Show resolved Hide resolved
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
Loading