From 3a67e0ac3823f144f3c8d60aee7a127a592e9054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Sun, 22 Sep 2024 11:45:47 -0700 Subject: [PATCH 1/4] Refactorings for v0.1.79 --- .github/workflows/test.yml | 2 +- Makefile | 2 +- common/gnumakefile.mk | 2 +- common/meta-makefile.mk | 2 +- exercises/practice/acronym/.meta/Makefile | 2 +- exercises/practice/acronym/.meta/acronym.ys | 4 +++- exercises/practice/acronym/GNUmakefile | 2 +- .../practice/all-your-base/.meta/Makefile | 2 +- .../all-your-base/.meta/all-your-base.ys | 14 +++++------ exercises/practice/all-your-base/GNUmakefile | 2 +- exercises/practice/allergies/.meta/Makefile | 2 +- exercises/practice/allergies/GNUmakefile | 2 +- exercises/practice/anagram/.meta/Makefile | 2 +- exercises/practice/anagram/.meta/anagram.ys | 7 +++--- exercises/practice/anagram/GNUmakefile | 2 +- .../practice/armstrong-numbers/.meta/Makefile | 2 +- .../.meta/armstrong-numbers.ys | 3 ++- .../practice/armstrong-numbers/GNUmakefile | 2 +- .../practice/atbash-cipher/.meta/Makefile | 2 +- .../atbash-cipher/.meta/atbash-cipher.ys | 7 +++--- exercises/practice/atbash-cipher/GNUmakefile | 2 +- .../practice/bank-account/.meta/Makefile | 2 +- .../bank-account/.meta/bank-account.ys | 6 ++--- exercises/practice/bank-account/GNUmakefile | 2 +- .../practice/binary-search/.meta/Makefile | 2 +- .../binary-search/.meta/binary-search.ys | 5 ++-- exercises/practice/binary-search/GNUmakefile | 2 +- exercises/practice/bob/.meta/Makefile | 2 +- exercises/practice/bob/.meta/bob.ys | 2 +- exercises/practice/bob/GNUmakefile | 2 +- exercises/practice/bottle-song/.meta/Makefile | 2 +- .../practice/bottle-song/.meta/bottle-song.ys | 12 +++++----- exercises/practice/bottle-song/GNUmakefile | 2 +- .../collatz-conjecture/.meta/Makefile | 2 +- .../.meta/collatz-conjecture.ys | 10 ++++---- .../practice/collatz-conjecture/GNUmakefile | 2 +- exercises/practice/darts/.meta/Makefile | 2 +- exercises/practice/darts/GNUmakefile | 2 +- exercises/practice/diamond/.meta/Makefile | 2 +- exercises/practice/diamond/.meta/diamond.ys | 14 +++++++---- exercises/practice/diamond/GNUmakefile | 2 +- .../difference-of-squares/.meta/Makefile | 2 +- .../.meta/difference-of-squares.ys | 5 ++-- .../difference-of-squares/GNUmakefile | 2 +- exercises/practice/eliuds-eggs/.meta/Makefile | 2 +- .../practice/eliuds-eggs/.meta/eliuds-eggs.ys | 6 ++--- exercises/practice/eliuds-eggs/GNUmakefile | 2 +- exercises/practice/etl/.meta/Makefile | 2 +- exercises/practice/etl/.meta/etl.ys | 2 +- exercises/practice/etl/GNUmakefile | 2 +- exercises/practice/grains/.meta/Makefile | 2 +- exercises/practice/grains/.meta/grains.ys | 4 ++-- exercises/practice/grains/GNUmakefile | 2 +- exercises/practice/hamming/.meta/Makefile | 2 +- exercises/practice/hamming/.meta/hamming.ys | 4 ++-- exercises/practice/hamming/GNUmakefile | 2 +- exercises/practice/hello-world/.meta/Makefile | 2 +- exercises/practice/hello-world/GNUmakefile | 2 +- exercises/practice/isogram/.meta/Makefile | 2 +- exercises/practice/isogram/.meta/isogram.ys | 7 +++--- exercises/practice/isogram/GNUmakefile | 2 +- .../largest-series-product/.meta/Makefile | 2 +- .../.meta/largest-series-product.ys | 15 +++++++----- .../largest-series-product/GNUmakefile | 2 +- exercises/practice/leap/.meta/Makefile | 2 +- exercises/practice/leap/.meta/leap.ys | 4 +++- exercises/practice/leap/GNUmakefile | 2 +- exercises/practice/list-ops/.meta/Makefile | 2 +- exercises/practice/list-ops/.meta/list-ops.ys | 12 +++++----- exercises/practice/list-ops/GNUmakefile | 2 +- exercises/practice/luhn/.meta/Makefile | 2 +- exercises/practice/luhn/.meta/luhn.ys | 14 ++++++----- exercises/practice/luhn/GNUmakefile | 2 +- .../practice/matching-brackets/.meta/Makefile | 2 +- .../.meta/matching-brackets.ys | 8 +++---- .../practice/matching-brackets/GNUmakefile | 2 +- exercises/practice/minesweeper/.meta/Makefile | 2 +- .../practice/minesweeper/.meta/minesweeper.ys | 10 ++++---- exercises/practice/minesweeper/GNUmakefile | 2 +- exercises/practice/nth-prime/.meta/Makefile | 2 +- .../practice/nth-prime/.meta/nth-prime.ys | 3 ++- exercises/practice/nth-prime/GNUmakefile | 2 +- .../practice/nucleotide-count/.meta/Makefile | 2 +- .../practice/nucleotide-count/GNUmakefile | 2 +- exercises/practice/pangram/.meta/Makefile | 2 +- exercises/practice/pangram/.meta/pangram.ys | 6 +++-- exercises/practice/pangram/GNUmakefile | 2 +- .../practice/pascals-triangle/.meta/Makefile | 2 +- .../.meta/pascals-triangle.ys | 5 ++-- .../practice/pascals-triangle/GNUmakefile | 2 +- .../practice/perfect-numbers/.meta/Makefile | 2 +- .../perfect-numbers/.meta/perfect-numbers.ys | 2 +- .../practice/perfect-numbers/GNUmakefile | 2 +- .../practice/phone-number/.meta/Makefile | 2 +- .../phone-number/.meta/phone-number.ys | 24 +++++++++---------- exercises/practice/phone-number/GNUmakefile | 2 +- exercises/practice/pig-latin/.meta/Makefile | 2 +- .../practice/pig-latin/.meta/pig-latin.ys | 24 +++++++++++-------- exercises/practice/pig-latin/GNUmakefile | 2 +- .../protein-translation/.meta/Makefile | 2 +- .../.meta/protein-translation.ys | 2 +- .../practice/protein-translation/GNUmakefile | 2 +- .../practice/queen-attack/.meta/Makefile | 2 +- .../queen-attack/.meta/queen-attack.ys | 8 ++++--- exercises/practice/queen-attack/GNUmakefile | 2 +- exercises/practice/raindrops/.meta/Makefile | 2 +- .../practice/raindrops/.meta/raindrops.ys | 14 +++++++---- exercises/practice/raindrops/GNUmakefile | 2 +- .../practice/resistor-color/.meta/Makefile | 2 +- .../resistor-color/.meta/resistor-color.ys | 17 +++---------- exercises/practice/resistor-color/GNUmakefile | 2 +- .../practice/reverse-string/.meta/Makefile | 2 +- .../reverse-string/.meta/reverse-string.ys | 5 +++- exercises/practice/reverse-string/GNUmakefile | 2 +- .../practice/rna-transcription/.meta/Makefile | 2 +- .../.meta/rna-transcription.ys | 6 +++-- .../practice/rna-transcription/GNUmakefile | 2 +- .../practice/robot-simulator/.meta/Makefile | 2 +- .../robot-simulator/.meta/robot-simulator.ys | 11 ++++----- .../practice/robot-simulator/GNUmakefile | 2 +- .../practice/roman-numerals/.meta/Makefile | 2 +- .../roman-numerals/.meta/roman-numerals.ys | 10 ++++---- exercises/practice/roman-numerals/GNUmakefile | 2 +- .../practice/rotational-cipher/.meta/Makefile | 2 +- .../.meta/rotational-cipher.ys | 14 +++++++---- .../practice/rotational-cipher/GNUmakefile | 2 +- .../run-length-encoding/.meta/Makefile | 2 +- .../.meta/run-length-encoding.ys | 11 ++++----- .../practice/run-length-encoding/GNUmakefile | 2 +- .../practice/scrabble-score/.meta/Makefile | 2 +- .../scrabble-score/.meta/scrabble-score.ys | 7 +++--- exercises/practice/scrabble-score/GNUmakefile | 2 +- .../practice/secret-handshake/.meta/Makefile | 2 +- .../.meta/secret-handshake.ys | 18 +++++++------- .../practice/secret-handshake/GNUmakefile | 2 +- exercises/practice/sieve/.meta/Makefile | 2 +- exercises/practice/sieve/.meta/sieve.ys | 7 +++--- exercises/practice/sieve/GNUmakefile | 2 +- exercises/practice/space-age/.meta/Makefile | 2 +- .../practice/space-age/.meta/space-age.ys | 2 +- exercises/practice/space-age/GNUmakefile | 2 +- exercises/practice/square-root/.meta/Makefile | 2 +- .../practice/square-root/.meta/square-root.ys | 4 ++-- exercises/practice/square-root/GNUmakefile | 2 +- .../practice/sum-of-multiples/.meta/Makefile | 2 +- .../.meta/sum-of-multiples.ys | 3 ++- .../practice/sum-of-multiples/GNUmakefile | 2 +- exercises/practice/triangle/.meta/Makefile | 2 +- exercises/practice/triangle/.meta/triangle.ys | 6 ++--- exercises/practice/triangle/GNUmakefile | 2 +- exercises/practice/two-bucket/.meta/Makefile | 2 +- .../practice/two-bucket/.meta/two-bucket.ys | 16 ++++++------- exercises/practice/two-bucket/GNUmakefile | 2 +- exercises/practice/two-fer/.meta/Makefile | 2 +- exercises/practice/two-fer/GNUmakefile | 2 +- exercises/practice/word-count/.meta/Makefile | 2 +- .../practice/word-count/.meta/word-count.ys | 8 ++++--- exercises/practice/word-count/GNUmakefile | 2 +- exercises/practice/yacht/.meta/Makefile | 2 +- exercises/practice/yacht/.meta/yacht.ys | 12 +++++----- exercises/practice/yacht/GNUmakefile | 2 +- 161 files changed, 340 insertions(+), 304 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86cf552..5105027 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/Makefile b/Makefile index 5d34e5b..396c730 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/common/gnumakefile.mk b/common/gnumakefile.mk index 381cd29..e8fb5be 100644 --- a/common/gnumakefile.mk +++ b/common/gnumakefile.mk @@ -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)) diff --git a/common/meta-makefile.mk b/common/meta-makefile.mk index ba39335..08aff24 100644 --- a/common/meta-makefile.mk +++ b/common/meta-makefile.mk @@ -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) diff --git a/exercises/practice/acronym/.meta/Makefile b/exercises/practice/acronym/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/acronym/.meta/Makefile +++ b/exercises/practice/acronym/.meta/Makefile @@ -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) diff --git a/exercises/practice/acronym/.meta/acronym.ys b/exercises/practice/acronym/.meta/acronym.ys index bdbf53b..4cfcb63 100644 --- a/exercises/practice/acronym/.meta/acronym.ys +++ b/exercises/practice/acronym/.meta/acronym.ys @@ -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 diff --git a/exercises/practice/acronym/GNUmakefile b/exercises/practice/acronym/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/acronym/GNUmakefile +++ b/exercises/practice/acronym/GNUmakefile @@ -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)) diff --git a/exercises/practice/all-your-base/.meta/Makefile b/exercises/practice/all-your-base/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/all-your-base/.meta/Makefile +++ b/exercises/practice/all-your-base/.meta/Makefile @@ -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) diff --git a/exercises/practice/all-your-base/.meta/all-your-base.ys b/exercises/practice/all-your-base/.meta/all-your-base.ys index 0d82d97..91b4ad5 100644 --- a/exercises/practice/all-your-base/.meta/all-your-base.ys +++ b/exercises/practice/all-your-base/.meta/all-your-base.ys @@ -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 diff --git a/exercises/practice/all-your-base/GNUmakefile b/exercises/practice/all-your-base/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/all-your-base/GNUmakefile +++ b/exercises/practice/all-your-base/GNUmakefile @@ -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)) diff --git a/exercises/practice/allergies/.meta/Makefile b/exercises/practice/allergies/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/allergies/.meta/Makefile +++ b/exercises/practice/allergies/.meta/Makefile @@ -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) diff --git a/exercises/practice/allergies/GNUmakefile b/exercises/practice/allergies/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/allergies/GNUmakefile +++ b/exercises/practice/allergies/GNUmakefile @@ -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)) diff --git a/exercises/practice/anagram/.meta/Makefile b/exercises/practice/anagram/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/anagram/.meta/Makefile +++ b/exercises/practice/anagram/.meta/Makefile @@ -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) diff --git a/exercises/practice/anagram/.meta/anagram.ys b/exercises/practice/anagram/.meta/anagram.ys index 7c0668a..5b3c4ec 100644 --- a/exercises/practice/anagram/.meta/anagram.ys +++ b/exercises/practice/anagram/.meta/anagram.ys @@ -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) diff --git a/exercises/practice/anagram/GNUmakefile b/exercises/practice/anagram/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/anagram/GNUmakefile +++ b/exercises/practice/anagram/GNUmakefile @@ -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)) diff --git a/exercises/practice/armstrong-numbers/.meta/Makefile b/exercises/practice/armstrong-numbers/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/armstrong-numbers/.meta/Makefile +++ b/exercises/practice/armstrong-numbers/.meta/Makefile @@ -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) diff --git a/exercises/practice/armstrong-numbers/.meta/armstrong-numbers.ys b/exercises/practice/armstrong-numbers/.meta/armstrong-numbers.ys index 031d33f..b7f26d5 100644 --- a/exercises/practice/armstrong-numbers/.meta/armstrong-numbers.ys +++ b/exercises/practice/armstrong-numbers/.meta/armstrong-numbers.ys @@ -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 diff --git a/exercises/practice/armstrong-numbers/GNUmakefile b/exercises/practice/armstrong-numbers/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/armstrong-numbers/GNUmakefile +++ b/exercises/practice/armstrong-numbers/GNUmakefile @@ -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)) diff --git a/exercises/practice/atbash-cipher/.meta/Makefile b/exercises/practice/atbash-cipher/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/atbash-cipher/.meta/Makefile +++ b/exercises/practice/atbash-cipher/.meta/Makefile @@ -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) diff --git a/exercises/practice/atbash-cipher/.meta/atbash-cipher.ys b/exercises/practice/atbash-cipher/.meta/atbash-cipher.ys index 64e9c0e..a3df94f 100644 --- a/exercises/practice/atbash-cipher/.meta/atbash-cipher.ys +++ b/exercises/practice/atbash-cipher/.meta/atbash-cipher.ys @@ -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) diff --git a/exercises/practice/atbash-cipher/GNUmakefile b/exercises/practice/atbash-cipher/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/atbash-cipher/GNUmakefile +++ b/exercises/practice/atbash-cipher/GNUmakefile @@ -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)) diff --git a/exercises/practice/bank-account/.meta/Makefile b/exercises/practice/bank-account/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/bank-account/.meta/Makefile +++ b/exercises/practice/bank-account/.meta/Makefile @@ -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) diff --git a/exercises/practice/bank-account/.meta/bank-account.ys b/exercises/practice/bank-account/.meta/bank-account.ys index 69a00cf..d7b446a 100644 --- a/exercises/practice/bank-account/.meta/bank-account.ys +++ b/exercises/practice/bank-account/.meta/bank-account.ys @@ -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 diff --git a/exercises/practice/bank-account/GNUmakefile b/exercises/practice/bank-account/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/bank-account/GNUmakefile +++ b/exercises/practice/bank-account/GNUmakefile @@ -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)) diff --git a/exercises/practice/binary-search/.meta/Makefile b/exercises/practice/binary-search/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/binary-search/.meta/Makefile +++ b/exercises/practice/binary-search/.meta/Makefile @@ -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) diff --git a/exercises/practice/binary-search/.meta/binary-search.ys b/exercises/practice/binary-search/.meta/binary-search.ys index 32b5bed..cb3baf9 100644 --- a/exercises/practice/binary-search/.meta/binary-search.ys +++ b/exercises/practice/binary-search/.meta/binary-search.ys @@ -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.--) diff --git a/exercises/practice/binary-search/GNUmakefile b/exercises/practice/binary-search/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/binary-search/GNUmakefile +++ b/exercises/practice/binary-search/GNUmakefile @@ -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)) diff --git a/exercises/practice/bob/.meta/Makefile b/exercises/practice/bob/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/bob/.meta/Makefile +++ b/exercises/practice/bob/.meta/Makefile @@ -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) diff --git a/exercises/practice/bob/.meta/bob.ys b/exercises/practice/bob/.meta/bob.ys index 9f2b692..91c497b 100644 --- a/exercises/practice/bob/.meta/bob.ys +++ b/exercises/practice/bob/.meta/bob.ys @@ -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!" diff --git a/exercises/practice/bob/GNUmakefile b/exercises/practice/bob/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/bob/GNUmakefile +++ b/exercises/practice/bob/GNUmakefile @@ -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)) diff --git a/exercises/practice/bottle-song/.meta/Makefile b/exercises/practice/bottle-song/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/bottle-song/.meta/Makefile +++ b/exercises/practice/bottle-song/.meta/Makefile @@ -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) diff --git a/exercises/practice/bottle-song/.meta/bottle-song.ys b/exercises/practice/bottle-song/.meta/bottle-song.ys index b013399..a044804 100644 --- a/exercises/practice/bottle-song/.meta/bottle-song.ys +++ b/exercises/practice/bottle-song/.meta/bottle-song.ys @@ -1,17 +1,17 @@ !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) @@ -19,4 +19,4 @@ defn- bottles(num): case num: 0 : 'no green bottles' 1 : 'one green bottle' - else : "$(dict.$num) green bottles" + else : "$(nums.$num) green bottles" diff --git a/exercises/practice/bottle-song/GNUmakefile b/exercises/practice/bottle-song/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/bottle-song/GNUmakefile +++ b/exercises/practice/bottle-song/GNUmakefile @@ -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)) diff --git a/exercises/practice/collatz-conjecture/.meta/Makefile b/exercises/practice/collatz-conjecture/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/collatz-conjecture/.meta/Makefile +++ b/exercises/practice/collatz-conjecture/.meta/Makefile @@ -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) diff --git a/exercises/practice/collatz-conjecture/.meta/collatz-conjecture.ys b/exercises/practice/collatz-conjecture/.meta/collatz-conjecture.ys index 5fa4d8a..056b428 100644 --- a/exercises/practice/collatz-conjecture/.meta/collatz-conjecture.ys +++ b/exercises/practice/collatz-conjecture/.meta/collatz-conjecture.ys @@ -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.++) diff --git a/exercises/practice/collatz-conjecture/GNUmakefile b/exercises/practice/collatz-conjecture/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/collatz-conjecture/GNUmakefile +++ b/exercises/practice/collatz-conjecture/GNUmakefile @@ -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)) diff --git a/exercises/practice/darts/.meta/Makefile b/exercises/practice/darts/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/darts/.meta/Makefile +++ b/exercises/practice/darts/.meta/Makefile @@ -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) diff --git a/exercises/practice/darts/GNUmakefile b/exercises/practice/darts/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/darts/GNUmakefile +++ b/exercises/practice/darts/GNUmakefile @@ -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)) diff --git a/exercises/practice/diamond/.meta/Makefile b/exercises/practice/diamond/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/diamond/.meta/Makefile +++ b/exercises/practice/diamond/.meta/Makefile @@ -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) diff --git a/exercises/practice/diamond/.meta/diamond.ys b/exercises/practice/diamond/.meta/diamond.ys index 7a8ad8f..df5995a 100644 --- a/exercises/practice/diamond/.meta/diamond.ys +++ b/exercises/practice/diamond/.meta/diamond.ys @@ -1,7 +1,13 @@ !yamlscript/v0 defn rows(letter): - loop C letter.0, I (' ' * (((-64 + C) * 2) - 3)), O '', dmnd '': - line =: if(I.? "$O$C$I$C$O\n" "$O$C$O\n") - dmnd =: if(dmnd.? "$line$dmnd$line" line) - if I.?: recur(C.--, I.drop(2).join(), "$O ", dmnd), dmnd + ipad =: + letter.0:N.sub(64).mul(2).sub(3) * ' ' + + loop C letter.0, I ipad, O '', dmnd '': + line =: I.?.if("$O$C$I$C$O\n" "$O$C$O\n") + dmnd =: dmnd.?.if("$line$dmnd$line" line) + + if I.?: + recur: C.--, I.chop(2), "$O ", dmnd + else: dmnd diff --git a/exercises/practice/diamond/GNUmakefile b/exercises/practice/diamond/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/diamond/GNUmakefile +++ b/exercises/practice/diamond/GNUmakefile @@ -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)) diff --git a/exercises/practice/difference-of-squares/.meta/Makefile b/exercises/practice/difference-of-squares/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/difference-of-squares/.meta/Makefile +++ b/exercises/practice/difference-of-squares/.meta/Makefile @@ -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) diff --git a/exercises/practice/difference-of-squares/.meta/difference-of-squares.ys b/exercises/practice/difference-of-squares/.meta/difference-of-squares.ys index e4cccb6..f7c86b2 100644 --- a/exercises/practice/difference-of-squares/.meta/difference-of-squares.ys +++ b/exercises/practice/difference-of-squares/.meta/difference-of-squares.ys @@ -4,7 +4,8 @@ defn square-of-sum(number): sqr: sum(1 .. number) defn sum-of-squares(number): - 1 .. number: .map(sqr).sum() + sum: (1 .. number).map(sqr) defn difference-of-squares(number): - square-of-sum(number) -: sum-of-squares(number) + square-of-sum(number) - + sum-of-squares(number) diff --git a/exercises/practice/difference-of-squares/GNUmakefile b/exercises/practice/difference-of-squares/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/difference-of-squares/GNUmakefile +++ b/exercises/practice/difference-of-squares/GNUmakefile @@ -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)) diff --git a/exercises/practice/eliuds-eggs/.meta/Makefile b/exercises/practice/eliuds-eggs/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/eliuds-eggs/.meta/Makefile +++ b/exercises/practice/eliuds-eggs/.meta/Makefile @@ -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) diff --git a/exercises/practice/eliuds-eggs/.meta/eliuds-eggs.ys b/exercises/practice/eliuds-eggs/.meta/eliuds-eggs.ys index bd76ac9..e2e7993 100644 --- a/exercises/practice/eliuds-eggs/.meta/eliuds-eggs.ys +++ b/exercises/practice/eliuds-eggs/.meta/eliuds-eggs.ys @@ -2,6 +2,6 @@ defn egg-count(number): loop num number, eggs 0: - if num.?: - recur: quot(num 2), (eggs + (num % 2)) - else: eggs + num + if num > 0: + recur: quot(num 2), eggs.add(num % 2) + else: eggs diff --git a/exercises/practice/eliuds-eggs/GNUmakefile b/exercises/practice/eliuds-eggs/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/eliuds-eggs/GNUmakefile +++ b/exercises/practice/eliuds-eggs/GNUmakefile @@ -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)) diff --git a/exercises/practice/etl/.meta/Makefile b/exercises/practice/etl/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/etl/.meta/Makefile +++ b/exercises/practice/etl/.meta/Makefile @@ -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) diff --git a/exercises/practice/etl/.meta/etl.ys b/exercises/practice/etl/.meta/etl.ys index f7e436c..47d15cd 100644 --- a/exercises/practice/etl/.meta/etl.ys +++ b/exercises/practice/etl/.meta/etl.ys @@ -3,4 +3,4 @@ defn transform(legacy): into {}: for [score letters] legacy, letter letters: - vector: lc(letter) score.to-num() + V: lc(letter) score:N diff --git a/exercises/practice/etl/GNUmakefile b/exercises/practice/etl/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/etl/GNUmakefile +++ b/exercises/practice/etl/GNUmakefile @@ -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)) diff --git a/exercises/practice/grains/.meta/Makefile b/exercises/practice/grains/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/grains/.meta/Makefile +++ b/exercises/practice/grains/.meta/Makefile @@ -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) diff --git a/exercises/practice/grains/.meta/grains.ys b/exercises/practice/grains/.meta/grains.ys index 0acddb9..d5760ba 100644 --- a/exercises/practice/grains/.meta/grains.ys +++ b/exercises/practice/grains/.meta/grains.ys @@ -1,7 +1,7 @@ !yamlscript/v0 defn square(square): - when-not 1 <= square <= 64: + (1 <= square <= 64) |||: die: 'square must be between 1 and 64' - 2 **: square.-- + pow 2: square - 1 diff --git a/exercises/practice/grains/GNUmakefile b/exercises/practice/grains/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/grains/GNUmakefile +++ b/exercises/practice/grains/GNUmakefile @@ -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)) diff --git a/exercises/practice/hamming/.meta/Makefile b/exercises/practice/hamming/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/hamming/.meta/Makefile +++ b/exercises/practice/hamming/.meta/Makefile @@ -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) diff --git a/exercises/practice/hamming/.meta/hamming.ys b/exercises/practice/hamming/.meta/hamming.ys index 8048f51..6ba3c67 100644 --- a/exercises/practice/hamming/.meta/hamming.ys +++ b/exercises/practice/hamming/.meta/hamming.ys @@ -1,7 +1,7 @@ !yamlscript/v0 defn distance(strand1 strand2): - when strand1.# != strand2.#: + strand1.# == strand2.# ||: die: 'strands must be of equal length' - strand1: .map(ne _ strand2).filter(true?).# + len: map(ne strand1 strand2).filter(a) diff --git a/exercises/practice/hamming/GNUmakefile b/exercises/practice/hamming/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/hamming/GNUmakefile +++ b/exercises/practice/hamming/GNUmakefile @@ -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)) diff --git a/exercises/practice/hello-world/.meta/Makefile b/exercises/practice/hello-world/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/hello-world/.meta/Makefile +++ b/exercises/practice/hello-world/.meta/Makefile @@ -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) diff --git a/exercises/practice/hello-world/GNUmakefile b/exercises/practice/hello-world/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/hello-world/GNUmakefile +++ b/exercises/practice/hello-world/GNUmakefile @@ -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)) diff --git a/exercises/practice/isogram/.meta/Makefile b/exercises/practice/isogram/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/isogram/.meta/Makefile +++ b/exercises/practice/isogram/.meta/Makefile @@ -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) diff --git a/exercises/practice/isogram/.meta/isogram.ys b/exercises/practice/isogram/.meta/isogram.ys index e4ae8e8..a352636 100644 --- a/exercises/practice/isogram/.meta/isogram.ys +++ b/exercises/practice/isogram/.meta/isogram.ys @@ -1,8 +1,7 @@ !yamlscript/v0 defn isogram(string): - string.! ||: - lc(string) \"Want to be case insensitive" - .split() \"Split string into chars" - .filter(\(/^\w$/)) \"Keep letters only" + empty?(string) ||: + lc(string):split \"Want to be case insensitive" + .filter(/^[a-z]$/) \"Keep letters only" .distinct?(*) \"Check if distinct letters" diff --git a/exercises/practice/isogram/GNUmakefile b/exercises/practice/isogram/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/isogram/GNUmakefile +++ b/exercises/practice/isogram/GNUmakefile @@ -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)) diff --git a/exercises/practice/largest-series-product/.meta/Makefile b/exercises/practice/largest-series-product/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/largest-series-product/.meta/Makefile +++ b/exercises/practice/largest-series-product/.meta/Makefile @@ -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) diff --git a/exercises/practice/largest-series-product/.meta/largest-series-product.ys b/exercises/practice/largest-series-product/.meta/largest-series-product.ys index 35e1491..8a6b3e1 100644 --- a/exercises/practice/largest-series-product/.meta/largest-series-product.ys +++ b/exercises/practice/largest-series-product/.meta/largest-series-product.ys @@ -2,9 +2,12 @@ defn largest-product(digits span): cond: - span < 0: die('span must not be negative') - span > digits.#: die('span must be smaller than string length') - digits =~ /[^0-9]/: die('digits input must only contain digits') - else: digits.split('').map(to-num) - .partition(span 1) - .map(\(_.mul(*))).max(*) + span < 0 : die('span must not be negative') + span > digits.# : die('span must be smaller than string length') + digits =~ /[^\d]/ : die('digits input must only contain digits') + + digits.split(''): + .map(to-num) + .partition(span 1) + .map(\(_.mul(*))) + .max(*) diff --git a/exercises/practice/largest-series-product/GNUmakefile b/exercises/practice/largest-series-product/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/largest-series-product/GNUmakefile +++ b/exercises/practice/largest-series-product/GNUmakefile @@ -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)) diff --git a/exercises/practice/leap/.meta/Makefile b/exercises/practice/leap/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/leap/.meta/Makefile +++ b/exercises/practice/leap/.meta/Makefile @@ -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) diff --git a/exercises/practice/leap/.meta/leap.ys b/exercises/practice/leap/.meta/leap.ys index ba82f68..838d5e7 100644 --- a/exercises/practice/leap/.meta/leap.ys +++ b/exercises/practice/leap/.meta/leap.ys @@ -1,4 +1,6 @@ !yamlscript/v0 defn is-leap-year(year): - (year % 4).! &&: (year % 100).? || (year % 400).! + (year % 4):zero? &&: + (year % 100):pos? ||: + (year % 400):zero? diff --git a/exercises/practice/leap/GNUmakefile b/exercises/practice/leap/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/leap/GNUmakefile +++ b/exercises/practice/leap/GNUmakefile @@ -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)) diff --git a/exercises/practice/list-ops/.meta/Makefile b/exercises/practice/list-ops/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/list-ops/.meta/Makefile +++ b/exercises/practice/list-ops/.meta/Makefile @@ -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) diff --git a/exercises/practice/list-ops/.meta/list-ops.ys b/exercises/practice/list-ops/.meta/list-ops.ys index 60ba76f..0c07974 100644 --- a/exercises/practice/list-ops/.meta/list-ops.ys +++ b/exercises/practice/list-ops/.meta/list-ops.ys @@ -4,25 +4,25 @@ defn append(list1 list2): list1 + list2 defn concat(lists): - lists.conj([]).clojure::core/concat(*) + lists.mapcat(a) defn filter(list function): list.filter(function) defn length(list): - list.# + list:count defn map(list function): list.map(function) defn foldl(list initial function): - reduce function: initial list + list.reduce(function initial) defn foldr(list initial function): - if list.?: - function _ list.0: + if len(list) > 0: + function _ list:first: foldr: rest(list) initial function else: initial defn reverse(list): - clojure::core/reverse(list) + core/reverse: list diff --git a/exercises/practice/list-ops/GNUmakefile b/exercises/practice/list-ops/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/list-ops/GNUmakefile +++ b/exercises/practice/list-ops/GNUmakefile @@ -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)) diff --git a/exercises/practice/luhn/.meta/Makefile b/exercises/practice/luhn/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/luhn/.meta/Makefile +++ b/exercises/practice/luhn/.meta/Makefile @@ -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) diff --git a/exercises/practice/luhn/.meta/luhn.ys b/exercises/practice/luhn/.meta/luhn.ys index 0a9d7f3..c3b9698 100644 --- a/exercises/practice/luhn/.meta/luhn.ys +++ b/exercises/practice/luhn/.meta/luhn.ys @@ -1,16 +1,18 @@ !yamlscript/v0 defn valid(value): - digits =: value.replace(' ' '') + digits =: value.replace(' ') and: digits.# >=: 2 - digits !~: /[^0-9]/ - digits: .split().remove(empty?).map(to-num) - .reverse().vec().conj(0).partition(2) - .map(munge).flatten().sum().rem(10).! + digits !~: /[^\d]/ + digits:split: + .map(to-num):reverse:V + .conj(0).partition(2) + .map(munge):flat:sum + .mod(10).eq(0) defn munge([a b]): - b =: 2 * b + b *=: 2 vector a: if b > 9: (b - 9) b diff --git a/exercises/practice/luhn/GNUmakefile b/exercises/practice/luhn/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/luhn/GNUmakefile +++ b/exercises/practice/luhn/GNUmakefile @@ -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)) diff --git a/exercises/practice/matching-brackets/.meta/Makefile b/exercises/practice/matching-brackets/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/matching-brackets/.meta/Makefile +++ b/exercises/practice/matching-brackets/.meta/Makefile @@ -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) diff --git a/exercises/practice/matching-brackets/.meta/matching-brackets.ys b/exercises/practice/matching-brackets/.meta/matching-brackets.ys index e05e938..64cb419 100644 --- a/exercises/practice/matching-brackets/.meta/matching-brackets.ys +++ b/exercises/practice/matching-brackets/.meta/matching-brackets.ys @@ -1,13 +1,13 @@ !yamlscript/v0 -pairs =: seq('()[]{}').reverse().to-map() -opening =: set(vals(pairs)) -closing =: set(keys(pairs)) +pairs =: reverse('()[]{}'):M +opening =: vals(pairs):set +closing =: keys(pairs):set defn is-paired(value): loop stack [], [char *chars] value: cond: - char.!: stack.! + char:nil?: stack:count:zero? opening(char): recur: conj(stack char) chars closing(char): diff --git a/exercises/practice/matching-brackets/GNUmakefile b/exercises/practice/matching-brackets/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/matching-brackets/GNUmakefile +++ b/exercises/practice/matching-brackets/GNUmakefile @@ -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)) diff --git a/exercises/practice/minesweeper/.meta/Makefile b/exercises/practice/minesweeper/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/minesweeper/.meta/Makefile +++ b/exercises/practice/minesweeper/.meta/Makefile @@ -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) diff --git a/exercises/practice/minesweeper/.meta/minesweeper.ys b/exercises/practice/minesweeper/.meta/minesweeper.ys index c0bdea0..d5a083f 100644 --- a/exercises/practice/minesweeper/.meta/minesweeper.ys +++ b/exercises/practice/minesweeper/.meta/minesweeper.ys @@ -1,22 +1,22 @@ !yamlscript/v0 defn annotate(minefield): - grid =: minefield.map(split).vec() + grid =: minefield.map(split):V reduce-kv _ [] grid: fn(acc x row): - height =: grid.#-- - width =: grid.0.#-- + height =: grid.-- + width =: grid.0.-- conj acc: reduce-kv _ '' row: fn(acc y cell): str acc: or? _ cell: - when cell == ' ': + when cell:blank?: sum: ? for i (-1 .. 1) j (-1 .. 1) :let [row (x + i), col (y + j)] : to-num: - ((i != 0) || (j != 0)) && + (i.ne(0) || j.ne(0)) && (0 <= row <= height) && (0 <= col <= width) && (grid.$row.$col == '*') diff --git a/exercises/practice/minesweeper/GNUmakefile b/exercises/practice/minesweeper/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/minesweeper/GNUmakefile +++ b/exercises/practice/minesweeper/GNUmakefile @@ -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)) diff --git a/exercises/practice/nth-prime/.meta/Makefile b/exercises/practice/nth-prime/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/nth-prime/.meta/Makefile +++ b/exercises/practice/nth-prime/.meta/Makefile @@ -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) diff --git a/exercises/practice/nth-prime/.meta/nth-prime.ys b/exercises/practice/nth-prime/.meta/nth-prime.ys index 4f3cef1..aad608f 100644 --- a/exercises/practice/nth-prime/.meta/nth-prime.ys +++ b/exercises/practice/nth-prime/.meta/nth-prime.ys @@ -8,7 +8,8 @@ defn- lazy-primes(d=2 table={}): recur d.++: reduce _ table.dissoc(d) factors: \(update-in(%1 [(%2 + d)] conj %2)) + lazy-seq: cons d: lazy-primes d.++: - table.assoc(sqr(d) [d]) + assoc table: sqr(d) [d] diff --git a/exercises/practice/nth-prime/GNUmakefile b/exercises/practice/nth-prime/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/nth-prime/GNUmakefile +++ b/exercises/practice/nth-prime/GNUmakefile @@ -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)) diff --git a/exercises/practice/nucleotide-count/.meta/Makefile b/exercises/practice/nucleotide-count/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/nucleotide-count/.meta/Makefile +++ b/exercises/practice/nucleotide-count/.meta/Makefile @@ -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) diff --git a/exercises/practice/nucleotide-count/GNUmakefile b/exercises/practice/nucleotide-count/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/nucleotide-count/GNUmakefile +++ b/exercises/practice/nucleotide-count/GNUmakefile @@ -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)) diff --git a/exercises/practice/pangram/.meta/Makefile b/exercises/practice/pangram/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/pangram/.meta/Makefile +++ b/exercises/practice/pangram/.meta/Makefile @@ -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) diff --git a/exercises/practice/pangram/.meta/pangram.ys b/exercises/practice/pangram/.meta/pangram.ys index 8c3a8e2..dc80805 100644 --- a/exercises/practice/pangram/.meta/pangram.ys +++ b/exercises/practice/pangram/.meta/pangram.ys @@ -1,5 +1,7 @@ !yamlscript/v0 defn is-pangram(sentence): - sentence.lc().replace(/[^a-z]/ '') - .sort().distinct().len().eq(26) + 26 ==: + len: lc(sentence) + .replace(/[^a-z]/) + .distinct() diff --git a/exercises/practice/pangram/GNUmakefile b/exercises/practice/pangram/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/pangram/GNUmakefile +++ b/exercises/practice/pangram/GNUmakefile @@ -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)) diff --git a/exercises/practice/pascals-triangle/.meta/Makefile b/exercises/practice/pascals-triangle/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/pascals-triangle/.meta/Makefile +++ b/exercises/practice/pascals-triangle/.meta/Makefile @@ -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) diff --git a/exercises/practice/pascals-triangle/.meta/pascals-triangle.ys b/exercises/practice/pascals-triangle/.meta/pascals-triangle.ys index 43365e0..830e110 100644 --- a/exercises/practice/pascals-triangle/.meta/pascals-triangle.ys +++ b/exercises/practice/pascals-triangle/.meta/pascals-triangle.ys @@ -6,5 +6,6 @@ defn rows(count): conj tri: or _ [1]: when row > 1: - mapv _ (-1 .. (row - 2)): - \(to-num(get(last(tri) _)) + to-num(get(last(tri) _.++))) + mapv _ (-1 .. row.sub(2)): + \(last(tri).get(_):N.or(0) + + last(tri).get(_.++):N.or(0)) diff --git a/exercises/practice/pascals-triangle/GNUmakefile b/exercises/practice/pascals-triangle/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/pascals-triangle/GNUmakefile +++ b/exercises/practice/pascals-triangle/GNUmakefile @@ -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)) diff --git a/exercises/practice/perfect-numbers/.meta/Makefile b/exercises/practice/perfect-numbers/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/perfect-numbers/.meta/Makefile +++ b/exercises/practice/perfect-numbers/.meta/Makefile @@ -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) diff --git a/exercises/practice/perfect-numbers/.meta/perfect-numbers.ys b/exercises/practice/perfect-numbers/.meta/perfect-numbers.ys index f822599..6e8e043 100644 --- a/exercises/practice/perfect-numbers/.meta/perfect-numbers.ys +++ b/exercises/practice/perfect-numbers/.meta/perfect-numbers.ys @@ -12,5 +12,5 @@ defn classify(number): defn sum-of-divisors(number): sum: ? for n range(1 quot(number 2).++) - :when (number % n).! + :when (number % n).eq(0) : n diff --git a/exercises/practice/perfect-numbers/GNUmakefile b/exercises/practice/perfect-numbers/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/perfect-numbers/GNUmakefile +++ b/exercises/practice/perfect-numbers/GNUmakefile @@ -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)) diff --git a/exercises/practice/phone-number/.meta/Makefile b/exercises/practice/phone-number/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/phone-number/.meta/Makefile +++ b/exercises/practice/phone-number/.meta/Makefile @@ -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) diff --git a/exercises/practice/phone-number/.meta/phone-number.ys b/exercises/practice/phone-number/.meta/phone-number.ys index 45fefa6..25404f7 100644 --- a/exercises/practice/phone-number/.meta/phone-number.ys +++ b/exercises/practice/phone-number/.meta/phone-number.ys @@ -1,22 +1,22 @@ !yamlscript/v0 defn clean(phrase): - numstr =: phrase.replace(/[^\d]/ '') + numstr =: phrase.replace(/[^\d]/) + + phrase =~ /[a-z]/ &&: die('letters not permitted') + phrase.has?('@') &&: die('punctuations not permitted') - when phrase.lc() =~ /[a-z]/: die('letters not permitted') - when phrase =~ /@/: die('punctuations not permitted') case numstr.#: - 9: die('must not be fewer than 10 digits') - range(8): die('incorrect number of digits') - 11: - when numstr.0 != \\1: die('11 digits must start with 1') - else: nil - when numstr.# > 11: die('must not be greater than 11 digits') + 0 .. 9: die('must not be fewer than 10 digits') + 10: nil + 11: (numstr.0 == \\1) || die('11 digits must start with 1') + else: die('must not be greater than 11 digits') + + numstr .=: take-last(10):join - numstr .=: take-last(10).join() cond: - numstr =~ /^0/: die('area code cannot start with zero') - numstr =~ /^1/: die('area code cannot start with one') + numstr.0 == \\0: die('area code cannot start with zero') + numstr.0 == \\1: die('area code cannot start with one') numstr.3 == \\0: die('exchange code cannot start with zero') numstr.3 == \\1: die('exchange code cannot start with one') else: numstr diff --git a/exercises/practice/phone-number/GNUmakefile b/exercises/practice/phone-number/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/phone-number/GNUmakefile +++ b/exercises/practice/phone-number/GNUmakefile @@ -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)) diff --git a/exercises/practice/pig-latin/.meta/Makefile b/exercises/practice/pig-latin/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/pig-latin/.meta/Makefile +++ b/exercises/practice/pig-latin/.meta/Makefile @@ -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) diff --git a/exercises/practice/pig-latin/.meta/pig-latin.ys b/exercises/practice/pig-latin/.meta/pig-latin.ys index 4724f78..e999835 100644 --- a/exercises/practice/pig-latin/.meta/pig-latin.ys +++ b/exercises/practice/pig-latin/.meta/pig-latin.ys @@ -1,13 +1,17 @@ !yamlscript/v0 -trans =: - -{ /^([aeiou]|yt|xr).*/ \(_.0 + 'ay') - /^(s?qu|thr|sch|[crst]h|[^aeiou])(.*)/ \("$(_.2)$(_.1)ay") } +rules =:: + ^(?:[aeiou]|yt|xr).*:: + \(_ + 'ay') + ^(s?qu|thr|sch|[crst]h|[^aeiou])(.*):: + \("$(_.2)$(_.1)ay") -defn translate(phrase): words(phrase).map(pig-latin).join(' ') - -defn pig-latin(word): - reduce-kv _ nil trans: - fn(trans regex function): - match =: word =~ regex - trans ||: match && function(match) +defn translate(phrase): + join ' ': + map _ words(phrase): + fn(word): + reduce-kv _ nil rules: + fn(translated regex function): + match =: word =~ qr(regex) + translated ||: + match && function(match) diff --git a/exercises/practice/pig-latin/GNUmakefile b/exercises/practice/pig-latin/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/pig-latin/GNUmakefile +++ b/exercises/practice/pig-latin/GNUmakefile @@ -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)) diff --git a/exercises/practice/protein-translation/.meta/Makefile b/exercises/practice/protein-translation/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/protein-translation/.meta/Makefile +++ b/exercises/practice/protein-translation/.meta/Makefile @@ -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) diff --git a/exercises/practice/protein-translation/.meta/protein-translation.ys b/exercises/practice/protein-translation/.meta/protein-translation.ys index 769dbde..e5064c3 100644 --- a/exercises/practice/protein-translation/.meta/protein-translation.ys +++ b/exercises/practice/protein-translation/.meta/protein-translation.ys @@ -4,7 +4,7 @@ defn proteins(strand): proteins =: strand.str('XX').partition(3) .map(join).map(translate-codon) - .take-while(\(_ != 'STOP')) + .take-while(/^(?!STOP)/) if proteins.has?('INVALID'): die: 'Invalid codon' diff --git a/exercises/practice/protein-translation/GNUmakefile b/exercises/practice/protein-translation/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/protein-translation/GNUmakefile +++ b/exercises/practice/protein-translation/GNUmakefile @@ -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)) diff --git a/exercises/practice/queen-attack/.meta/Makefile b/exercises/practice/queen-attack/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/queen-attack/.meta/Makefile +++ b/exercises/practice/queen-attack/.meta/Makefile @@ -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) diff --git a/exercises/practice/queen-attack/.meta/queen-attack.ys b/exercises/practice/queen-attack/.meta/queen-attack.ys index 1e92aeb..59c3562 100644 --- a/exercises/practice/queen-attack/.meta/queen-attack.ys +++ b/exercises/practice/queen-attack/.meta/queen-attack.ys @@ -1,6 +1,8 @@ !yamlscript/v0 -defn create({{r 'row' c 'column'} 'position'}): +defn create(queen): + r c =: queen.position.map(qw(row column)) + cond: r < 0 : die('row not positive') r > 7 : die('row not on board') @@ -9,8 +11,8 @@ defn create({{r 'row' c 'column'} 'position'}): else : 0 defn can-attack(white-queen black-queen): - -{w-r "row" w-c "column"} =: white-queen.position - -{b-r "row" b-c "column"} =: black-queen.position + w-r w-c =: white-queen.position.slice(q(row column)) + b-r b-c =: black-queen.position.slice(q(row column)) or: w-r ==: b-r diff --git a/exercises/practice/queen-attack/GNUmakefile b/exercises/practice/queen-attack/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/queen-attack/GNUmakefile +++ b/exercises/practice/queen-attack/GNUmakefile @@ -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)) diff --git a/exercises/practice/raindrops/.meta/Makefile b/exercises/practice/raindrops/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/raindrops/.meta/Makefile +++ b/exercises/practice/raindrops/.meta/Makefile @@ -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) diff --git a/exercises/practice/raindrops/.meta/raindrops.ys b/exercises/practice/raindrops/.meta/raindrops.ys index 7749c57..7c0ef9e 100644 --- a/exercises/practice/raindrops/.meta/raindrops.ys +++ b/exercises/practice/raindrops/.meta/raindrops.ys @@ -1,7 +1,13 @@ !yamlscript/v0 -dict =:: { 3: Pling, 5: Plang, 7: Plong } - defn convert(number): - words =: mapcat(\((number % _).! &&& dict.get(_)) [3 5 7]) - if words.?: str(words*) str(number) + ps =: M(3 'Pling' 5 'Plang' 7 'Plong') + words =: + mapcat _ [3 5 7]: + fn(n): + (number % n) == 0 &&&: + get ps: n + + if words.?: + str(words*) + str(number) diff --git a/exercises/practice/raindrops/GNUmakefile b/exercises/practice/raindrops/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/raindrops/GNUmakefile +++ b/exercises/practice/raindrops/GNUmakefile @@ -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)) diff --git a/exercises/practice/resistor-color/.meta/Makefile b/exercises/practice/resistor-color/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/resistor-color/.meta/Makefile +++ b/exercises/practice/resistor-color/.meta/Makefile @@ -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) diff --git a/exercises/practice/resistor-color/.meta/resistor-color.ys b/exercises/practice/resistor-color/.meta/resistor-color.ys index 937b992..88c1ac9 100644 --- a/exercises/practice/resistor-color/.meta/resistor-color.ys +++ b/exercises/practice/resistor-color/.meta/resistor-color.ys @@ -1,19 +1,8 @@ !yamlscript/v0 -codes =:: - black: 0 - brown: 1 - red: 2 - orange: 3 - yellow: 4 - green: 5 - blue: 6 - violet: 7 - grey: 8 - white: 9 - defn color-code(color): - codes.$color + zipmap(colors() range()).$color defn colors(): - codes.keys() + qw(black brown red orange yellow + green blue violet grey white) diff --git a/exercises/practice/resistor-color/GNUmakefile b/exercises/practice/resistor-color/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/resistor-color/GNUmakefile +++ b/exercises/practice/resistor-color/GNUmakefile @@ -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)) diff --git a/exercises/practice/reverse-string/.meta/Makefile b/exercises/practice/reverse-string/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/reverse-string/.meta/Makefile +++ b/exercises/practice/reverse-string/.meta/Makefile @@ -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) diff --git a/exercises/practice/reverse-string/.meta/reverse-string.ys b/exercises/practice/reverse-string/.meta/reverse-string.ys index 3d57eb9..e948ea0 100644 --- a/exercises/practice/reverse-string/.meta/reverse-string.ys +++ b/exercises/practice/reverse-string/.meta/reverse-string.ys @@ -1,4 +1,7 @@ !yamlscript/v0 defn reverse(s): - str/reverse: s + loop s s, r '': + if s.?: + recur: rest(s) "$first(s)$r" + else: r diff --git a/exercises/practice/reverse-string/GNUmakefile b/exercises/practice/reverse-string/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/reverse-string/GNUmakefile +++ b/exercises/practice/reverse-string/GNUmakefile @@ -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)) diff --git a/exercises/practice/rna-transcription/.meta/Makefile b/exercises/practice/rna-transcription/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/rna-transcription/.meta/Makefile +++ b/exercises/practice/rna-transcription/.meta/Makefile @@ -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) diff --git a/exercises/practice/rna-transcription/.meta/rna-transcription.ys b/exercises/practice/rna-transcription/.meta/rna-transcription.ys index c3ec778..7fa7a7e 100644 --- a/exercises/practice/rna-transcription/.meta/rna-transcription.ys +++ b/exercises/practice/rna-transcription/.meta/rna-transcription.ys @@ -1,5 +1,7 @@ !yamlscript/v0 -dna-to-rna =: list('GCAT' 'CGUA').map(split).zipmap(*) +dna-to-rna =: + map(split ['GCAT' 'CGUA']).zipmap(*) -defn to-rna(dna): dna.split().map(dna-to-rna).join() +defn to-rna(dna): + split(dna).map(dna-to-rna):join diff --git a/exercises/practice/rna-transcription/GNUmakefile b/exercises/practice/rna-transcription/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/rna-transcription/GNUmakefile +++ b/exercises/practice/rna-transcription/GNUmakefile @@ -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)) diff --git a/exercises/practice/robot-simulator/.meta/Makefile b/exercises/practice/robot-simulator/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/robot-simulator/.meta/Makefile +++ b/exercises/practice/robot-simulator/.meta/Makefile @@ -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) diff --git a/exercises/practice/robot-simulator/.meta/robot-simulator.ys b/exercises/practice/robot-simulator/.meta/robot-simulator.ys index 58be5cc..52aff21 100644 --- a/exercises/practice/robot-simulator/.meta/robot-simulator.ys +++ b/exercises/practice/robot-simulator/.meta/robot-simulator.ys @@ -13,14 +13,13 @@ defn move(position direction instructions): : if instruction: recur instructions: case instruction: - \\A: robot.advance() - \\R: robot.turn-right() - \\L: robot.turn-left() + \\A: robot:advance + \\R: robot:turn-right + \\L: robot:turn-left else: robot defn advance(robot): - x =: robot.position.x - y =: robot.position.y + x y =: robot.position.slice(q(x y)) d =: robot.direction create _ d: condp eq d: @@ -39,4 +38,4 @@ defn turn-left(robot): defn turn(direction directions): directions.mul+(2): - .drop-while(\(_ != direction)).second() + .drop-while(ne(direction)).1 diff --git a/exercises/practice/robot-simulator/GNUmakefile b/exercises/practice/robot-simulator/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/robot-simulator/GNUmakefile +++ b/exercises/practice/robot-simulator/GNUmakefile @@ -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)) diff --git a/exercises/practice/roman-numerals/.meta/Makefile b/exercises/practice/roman-numerals/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/roman-numerals/.meta/Makefile +++ b/exercises/practice/roman-numerals/.meta/Makefile @@ -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) diff --git a/exercises/practice/roman-numerals/.meta/roman-numerals.ys b/exercises/practice/roman-numerals/.meta/roman-numerals.ys index 80fee94..2255920 100644 --- a/exercises/practice/roman-numerals/.meta/roman-numerals.ys +++ b/exercises/practice/roman-numerals/.meta/roman-numerals.ys @@ -1,6 +1,6 @@ !yamlscript/v0 -numeral-mapping =:: +rules =:: 1000: M 900: CM 500: D @@ -16,7 +16,9 @@ numeral-mapping =:: 1: I defn roman(number): - when pos?(number): - -[part letter] =: - numeral-mapping.filter(\(_.0 <= number)).0 + when number > 0: + part letter =: + first: + filter _ rules: + le(number).comp(first) str letter: roman(number - part) diff --git a/exercises/practice/roman-numerals/GNUmakefile b/exercises/practice/roman-numerals/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/roman-numerals/GNUmakefile +++ b/exercises/practice/roman-numerals/GNUmakefile @@ -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)) diff --git a/exercises/practice/rotational-cipher/.meta/Makefile b/exercises/practice/rotational-cipher/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/rotational-cipher/.meta/Makefile +++ b/exercises/practice/rotational-cipher/.meta/Makefile @@ -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) diff --git a/exercises/practice/rotational-cipher/.meta/rotational-cipher.ys b/exercises/practice/rotational-cipher/.meta/rotational-cipher.ys index 36a87d1..8590461 100644 --- a/exercises/practice/rotational-cipher/.meta/rotational-cipher.ys +++ b/exercises/practice/rotational-cipher/.meta/rotational-cipher.ys @@ -1,8 +1,12 @@ !yamlscript/v0 -upper =: \\A .. \\Z -lower =: \\a .. \\z +UC =: \\A .. \\Z +LC =: \\a .. \\z -defn rotate(text shift-key): text - .str/escape(lower.zipmap(cycle(lower).drop(shift-key))) - .str/escape(upper.zipmap(cycle(upper).drop(shift-key))) +defn rotate(text shift-key): + char-map =: + \(zipmap(_ drop(shift-key cycle(_)))) + + text: + .escape(char-map(UC)) + .escape(char-map(LC)) diff --git a/exercises/practice/rotational-cipher/GNUmakefile b/exercises/practice/rotational-cipher/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/rotational-cipher/GNUmakefile +++ b/exercises/practice/rotational-cipher/GNUmakefile @@ -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)) diff --git a/exercises/practice/run-length-encoding/.meta/Makefile b/exercises/practice/run-length-encoding/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/run-length-encoding/.meta/Makefile +++ b/exercises/practice/run-length-encoding/.meta/Makefile @@ -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) diff --git a/exercises/practice/run-length-encoding/.meta/run-length-encoding.ys b/exercises/practice/run-length-encoding/.meta/run-length-encoding.ys index c9bb86c..56357c0 100644 --- a/exercises/practice/run-length-encoding/.meta/run-length-encoding.ys +++ b/exercises/practice/run-length-encoding/.meta/run-length-encoding.ys @@ -3,20 +3,17 @@ defn encode(string): apply str: for part partition-by(a string): - str: - ((part.# > 1) &&& part.#) - part.0 + str: part.--.gt(0).and?(part.#) part.0 defn decode(string): ? loop - [p1 p2 *parts] - re-seq(/\d+|[^\d]/ string) + [p1 p2 *parts] re-seq(/\d+|[^\d]/ string) val '' : if p1: if p1 =~ /\d/: - recur parts: "$val$(to-int(p1) * p2)" + recur parts: "$val$(I(p1) * p2)" recur cons(p2 parts): "$val$p1" else: val defn consistency(string): - string.encode().decode() + string:encode:decode diff --git a/exercises/practice/run-length-encoding/GNUmakefile b/exercises/practice/run-length-encoding/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/run-length-encoding/GNUmakefile +++ b/exercises/practice/run-length-encoding/GNUmakefile @@ -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)) diff --git a/exercises/practice/scrabble-score/.meta/Makefile b/exercises/practice/scrabble-score/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/scrabble-score/.meta/Makefile +++ b/exercises/practice/scrabble-score/.meta/Makefile @@ -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) diff --git a/exercises/practice/scrabble-score/.meta/scrabble-score.ys b/exercises/practice/scrabble-score/.meta/scrabble-score.ys index 51bb6d9..7453de7 100644 --- a/exercises/practice/scrabble-score/.meta/scrabble-score.ys +++ b/exercises/practice/scrabble-score/.meta/scrabble-score.ys @@ -1,9 +1,10 @@ !yamlscript/v0 defn score(word): - uc(word).split().map( + uc(word):split.map( S(1 'AEIOULNRST') + S(2 'DG') + S(3 'BCMP') + S(4 'FHVWY') + S(5 'K') + S(8 'JX') + S(10 'QZ') - ).sum() + ):sum -defn S(score chars): zipmap(split(chars) repeat(score)) +defn S(score chars): + zipmap: chars:split repeat(score) diff --git a/exercises/practice/scrabble-score/GNUmakefile b/exercises/practice/scrabble-score/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/scrabble-score/GNUmakefile +++ b/exercises/practice/scrabble-score/GNUmakefile @@ -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)) diff --git a/exercises/practice/secret-handshake/.meta/Makefile b/exercises/practice/secret-handshake/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/secret-handshake/.meta/Makefile +++ b/exercises/practice/secret-handshake/.meta/Makefile @@ -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) diff --git a/exercises/practice/secret-handshake/.meta/secret-handshake.ys b/exercises/practice/secret-handshake/.meta/secret-handshake.ys index e7aa52b..0b94ee5 100644 --- a/exercises/practice/secret-handshake/.meta/secret-handshake.ys +++ b/exercises/practice/secret-handshake/.meta/secret-handshake.ys @@ -1,13 +1,13 @@ !yamlscript/v0 +cmds =:: [wink, double blink, close your eyes, jump] + defn commands(number): - cmds =:: [wink, double blink, close your eyes, jump] + commands =: + range(cmds.#) + .map(\(number.bit-test(_) && cmds.get(_))) + .filter(a) - ->> range(cmds.#): - map fn([n] (number.bit-test(n) && cmds.$n)): - filter identity: - call: - fn(commands): - if number.bit-test(cmds.#): - reverse(commands) - commands + if number.bit-test(cmds.#): + commands:reverse + commands diff --git a/exercises/practice/secret-handshake/GNUmakefile b/exercises/practice/secret-handshake/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/secret-handshake/GNUmakefile +++ b/exercises/practice/secret-handshake/GNUmakefile @@ -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)) diff --git a/exercises/practice/sieve/.meta/Makefile b/exercises/practice/sieve/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/sieve/.meta/Makefile +++ b/exercises/practice/sieve/.meta/Makefile @@ -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) diff --git a/exercises/practice/sieve/.meta/sieve.ys b/exercises/practice/sieve/.meta/sieve.ys index e9666f8..09ab5e4 100644 --- a/exercises/practice/sieve/.meta/sieve.ys +++ b/exercises/practice/sieve/.meta/sieve.ys @@ -1,11 +1,12 @@ !yamlscript/v0 defn primes(limit): - loop idx 2, primes ([nil nil] + range(2 limit.++)): + loop idx 2, primes ([nil nil] + (2 ... limit.++)): if idx < sqrt(limit): recur idx.++: if primes.$idx: map-indexed _ primes: - \(if ((_ >= sqr(idx)) && (_ % idx).!) nil %2) + fn(a b): + when (a < sqr(idx)) || (a % idx).?: b else: primes - primes: .remove(nil?) + filter a: primes diff --git a/exercises/practice/sieve/GNUmakefile b/exercises/practice/sieve/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/sieve/GNUmakefile +++ b/exercises/practice/sieve/GNUmakefile @@ -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)) diff --git a/exercises/practice/space-age/.meta/Makefile b/exercises/practice/space-age/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/space-age/.meta/Makefile +++ b/exercises/practice/space-age/.meta/Makefile @@ -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) diff --git a/exercises/practice/space-age/.meta/space-age.ys b/exercises/practice/space-age/.meta/space-age.ys index 13a3cb1..645bacb 100644 --- a/exercises/practice/space-age/.meta/space-age.ys +++ b/exercises/practice/space-age/.meta/space-age.ys @@ -17,4 +17,4 @@ defn age(planet seconds): die('not a planet') seconds / seconds-in-year / factor: - .mul(100).math/round().div(100) + .format('%.2f'):F diff --git a/exercises/practice/space-age/GNUmakefile b/exercises/practice/space-age/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/space-age/GNUmakefile +++ b/exercises/practice/space-age/GNUmakefile @@ -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)) diff --git a/exercises/practice/square-root/.meta/Makefile b/exercises/practice/square-root/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/square-root/.meta/Makefile +++ b/exercises/practice/square-root/.meta/Makefile @@ -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) diff --git a/exercises/practice/square-root/.meta/square-root.ys b/exercises/practice/square-root/.meta/square-root.ys index 9f1cb69..830a0a3 100644 --- a/exercises/practice/square-root/.meta/square-root.ys +++ b/exercises/practice/square-root/.meta/square-root.ys @@ -2,6 +2,6 @@ defn square-root(radicand): loop n 0: - if (n * n) != radicand: - recur: n + 1 + if sqr(n) != radicand: + recur: n.++ else: n diff --git a/exercises/practice/square-root/GNUmakefile b/exercises/practice/square-root/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/square-root/GNUmakefile +++ b/exercises/practice/square-root/GNUmakefile @@ -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)) diff --git a/exercises/practice/sum-of-multiples/.meta/Makefile b/exercises/practice/sum-of-multiples/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/sum-of-multiples/.meta/Makefile +++ b/exercises/practice/sum-of-multiples/.meta/Makefile @@ -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) diff --git a/exercises/practice/sum-of-multiples/.meta/sum-of-multiples.ys b/exercises/practice/sum-of-multiples/.meta/sum-of-multiples.ys index 42c18e4..6c80329 100644 --- a/exercises/practice/sum-of-multiples/.meta/sum-of-multiples.ys +++ b/exercises/practice/sum-of-multiples/.meta/sum-of-multiples.ys @@ -1,4 +1,5 @@ !yamlscript/v0 defn sum(factors limit): - factors.mapcat(\(when(_.? range(_ limit _))) _).distinct().std/sum() + f =: \(_ &&& range(_ limit _)) + factors: .mapcat(f):distinct:std/sum diff --git a/exercises/practice/sum-of-multiples/GNUmakefile b/exercises/practice/sum-of-multiples/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/sum-of-multiples/GNUmakefile +++ b/exercises/practice/sum-of-multiples/GNUmakefile @@ -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)) diff --git a/exercises/practice/triangle/.meta/Makefile b/exercises/practice/triangle/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/triangle/.meta/Makefile +++ b/exercises/practice/triangle/.meta/Makefile @@ -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) diff --git a/exercises/practice/triangle/.meta/triangle.ys b/exercises/practice/triangle/.meta/triangle.ys index ef11241..7d0fb32 100644 --- a/exercises/practice/triangle/.meta/triangle.ys +++ b/exercises/practice/triangle/.meta/triangle.ys @@ -4,12 +4,12 @@ defn equilateral(sides): eq(sides*) &&: sides.0 > 0 defn isosceles(sides): - -[a b c] =: sort(sides) + a b c =: sort(sides) (a + b) > c &&: - sides.frequencies().# <= 2 + len(sides:frequencies) <= 2 defn scalene(sides): boolean: when-not isosceles(sides): - -[a b c] =: sort(sides) + a b c =: sort(sides) a + b >: c diff --git a/exercises/practice/triangle/GNUmakefile b/exercises/practice/triangle/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/triangle/GNUmakefile +++ b/exercises/practice/triangle/GNUmakefile @@ -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)) diff --git a/exercises/practice/two-bucket/.meta/Makefile b/exercises/practice/two-bucket/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/two-bucket/.meta/Makefile +++ b/exercises/practice/two-bucket/.meta/Makefile @@ -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) diff --git a/exercises/practice/two-bucket/.meta/two-bucket.ys b/exercises/practice/two-bucket/.meta/two-bucket.ys index e447a2e..a87cbb4 100644 --- a/exercises/practice/two-bucket/.meta/two-bucket.ys +++ b/exercises/practice/two-bucket/.meta/two-bucket.ys @@ -6,25 +6,25 @@ defn measure(bucket1 bucket2 goal start): goal == [0 bucket2 bucket1].$start: ret: 2 (start % 2).++ [0 bucket1 bucket2].$start else: - -[b1 b2] =: + b1 b2 =: if start == 1: - -[bucket1 bucket2] [bucket2 bucket1] + -[bucket1 bucket2] + [bucket2 bucket1] n =: keep-indexed \(when (== %2 goal) %1): if b1 < b2: - map \(_ % b2): range(b1 lcm(b1 b2).++ b1) - reverse: - map \(_ % b1): range(b2 lcm(b1 b2) b2) + range(b1 lcm(b1 b2).++ b1).map(\(_ % b2)) + range(b2 lcm(b1 b2) b2).map(\(_ % b1)):reverse n |||: die('impossible') n =: n.0.++ e =: int((min(b1 b2) * n) / max(b1 b2)) - - to-num(goal < b1 < b2) + (goal < b1 < b2):N moves =: 2 * (n + e) if goal < b1: ret: moves, start, b2 ret: moves, 2, 0 -defn ret(moves goal other): - -{'moves' moves, 'goalBucket' goal, 'otherBucket' other} defn gcd(x y): if((x % y).? gcd(y (x % y)) y) defn lcm(x y): (x * y) / gcd(x y) +defn ret(moves goal other): + -{'moves' moves, 'goalBucket' goal, 'otherBucket' other} diff --git a/exercises/practice/two-bucket/GNUmakefile b/exercises/practice/two-bucket/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/two-bucket/GNUmakefile +++ b/exercises/practice/two-bucket/GNUmakefile @@ -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)) diff --git a/exercises/practice/two-fer/.meta/Makefile b/exercises/practice/two-fer/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/two-fer/.meta/Makefile +++ b/exercises/practice/two-fer/.meta/Makefile @@ -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) diff --git a/exercises/practice/two-fer/GNUmakefile b/exercises/practice/two-fer/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/two-fer/GNUmakefile +++ b/exercises/practice/two-fer/GNUmakefile @@ -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)) diff --git a/exercises/practice/word-count/.meta/Makefile b/exercises/practice/word-count/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/word-count/.meta/Makefile +++ b/exercises/practice/word-count/.meta/Makefile @@ -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) diff --git a/exercises/practice/word-count/.meta/word-count.ys b/exercises/practice/word-count/.meta/word-count.ys index 1617acd..a9c1ae9 100644 --- a/exercises/practice/word-count/.meta/word-count.ys +++ b/exercises/practice/word-count/.meta/word-count.ys @@ -1,6 +1,8 @@ !yamlscript/v0 defn count-words(sentence): - lc(sentence).split(/[^a-z0-9']+/) - .map(\(replace _, /(^'|'$)/, '')) - .remove(empty?).frequencies() + frequencies: + lc(sentence) + .split(/[^a-z0-9']+/) + .map(\(_.replace(/(^'|'$)/))) + .remove(empty?) diff --git a/exercises/practice/word-count/GNUmakefile b/exercises/practice/word-count/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/word-count/GNUmakefile +++ b/exercises/practice/word-count/GNUmakefile @@ -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)) diff --git a/exercises/practice/yacht/.meta/Makefile b/exercises/practice/yacht/.meta/Makefile index ba39335..08aff24 100644 --- a/exercises/practice/yacht/.meta/Makefile +++ b/exercises/practice/yacht/.meta/Makefile @@ -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) diff --git a/exercises/practice/yacht/.meta/yacht.ys b/exercises/practice/yacht/.meta/yacht.ys index 9c26b93..af58a28 100644 --- a/exercises/practice/yacht/.meta/yacht.ys +++ b/exercises/practice/yacht/.meta/yacht.ys @@ -7,7 +7,7 @@ defn score(dice category): defn- do-yacht(dice): eq(dice*) && 50 defn- same-number(n): - fn(dice): dice.filter(\(_ == n)).sum() + fn(dice): dice.filter(eq(n)):sum do-ones =: same-number(1) do-twos =: same-number(2) @@ -18,17 +18,17 @@ do-sixes =: same-number(6) defn- do-full-house(dice): freqs =: frequencies(dice) - when freqs.#.eq(2) && freqs.vals().has?(2): - sum(dice) + when freqs.#.eq(2) && freqs:vals.has?(2): + sum: dice defn- do-four-of-a-kind(dice): - freqs =: frequencies(dice).set/map-invert() + freqs =: frequencies(dice):V:reverse:M mul 4: freqs.get(4) || freqs.get(5) || 0 defn- do-little-straight(dice): - dice.sort() == (1 .. 5) &&: 30 + dice:sort == (1 .. 5) &&: 30 defn- do-big-straight(dice): - dice.sort() == (2 .. 6) &&: 30 + dice:sort == (2 .. 6) &&: 30 defn- do-choice(dice): sum(dice) diff --git a/exercises/practice/yacht/GNUmakefile b/exercises/practice/yacht/GNUmakefile index 381cd29..e8fb5be 100644 --- a/exercises/practice/yacht/GNUmakefile +++ b/exercises/practice/yacht/GNUmakefile @@ -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)) From 3cb86e673dcde18f53a6b4cbf2d4ae30ddff6867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Fri, 13 Sep 2024 21:42:22 -0700 Subject: [PATCH 2/4] Implement exercise 'resistor-color-duo' --- config.json | 8 ++ config.yaml | 7 + .../resistor-color-duo/.docs/instructions.md | 33 +++++ .../.meta/.yamlscript/exercise.mk | 1 + .../resistor-color-duo/.meta/Makefile | 28 ++++ .../resistor-color-duo/.meta/config.json | 23 ++++ .../.meta/resistor-color-duo-test.ys | 43 ++++++ .../.meta/resistor-color-duo.ys | 11 ++ .../resistor-color-duo/.meta/tests.toml | 31 +++++ .../.yamlscript/exercise.mk | 1 + .../.yamlscript/exercism-ys-installer | 127 ++++++++++++++++++ .../practice/resistor-color-duo/GNUmakefile | 49 +++++++ .../practice/resistor-color-duo/Makefile | 8 ++ .../resistor-color-duo-test.ys | 36 +++++ .../resistor-color-duo/resistor-color-duo.ys | 4 + 15 files changed, 410 insertions(+) create mode 100644 exercises/practice/resistor-color-duo/.docs/instructions.md create mode 100644 exercises/practice/resistor-color-duo/.meta/.yamlscript/exercise.mk create mode 100644 exercises/practice/resistor-color-duo/.meta/Makefile create mode 100644 exercises/practice/resistor-color-duo/.meta/config.json create mode 100644 exercises/practice/resistor-color-duo/.meta/resistor-color-duo-test.ys create mode 100644 exercises/practice/resistor-color-duo/.meta/resistor-color-duo.ys create mode 100644 exercises/practice/resistor-color-duo/.meta/tests.toml create mode 100644 exercises/practice/resistor-color-duo/.yamlscript/exercise.mk create mode 100644 exercises/practice/resistor-color-duo/.yamlscript/exercism-ys-installer create mode 100644 exercises/practice/resistor-color-duo/GNUmakefile create mode 100644 exercises/practice/resistor-color-duo/Makefile create mode 100644 exercises/practice/resistor-color-duo/resistor-color-duo-test.ys create mode 100644 exercises/practice/resistor-color-duo/resistor-color-duo.ys diff --git a/config.json b/config.json index 9997457..68cd37d 100644 --- a/config.json +++ b/config.json @@ -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", diff --git a/config.yaml b/config.yaml index 1d66694..607a0e6 100644 --- a/config.yaml +++ b/config.yaml @@ -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 diff --git a/exercises/practice/resistor-color-duo/.docs/instructions.md b/exercises/practice/resistor-color-duo/.docs/instructions.md new file mode 100644 index 0000000..4ae694d --- /dev/null +++ b/exercises/practice/resistor-color-duo/.docs/instructions.md @@ -0,0 +1,33 @@ +# Instructions + +If you want to build something using a Raspberry Pi, you'll probably use _resistors_. +For this exercise, you need to know two things about them: + +- Each resistor has a resistance value. +- Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read. + +To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. +Each band has a position and a numeric value. + +The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number. +For example, if they printed a brown band (value 1) followed by a green band (value 5), it would translate to the number 15. + +In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands. +The program will take color names as input and output a two digit number, even if the input is more than two colors! + +The band colors are encoded as follows: + +- black: 0 +- brown: 1 +- red: 2 +- orange: 3 +- yellow: 4 +- green: 5 +- blue: 6 +- violet: 7 +- grey: 8 +- white: 9 + +From the example above: +brown-green should return 15, and +brown-green-violet should return 15 too, ignoring the third color. diff --git a/exercises/practice/resistor-color-duo/.meta/.yamlscript/exercise.mk b/exercises/practice/resistor-color-duo/.meta/.yamlscript/exercise.mk new file mode 100644 index 0000000..2506034 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/.yamlscript/exercise.mk @@ -0,0 +1 @@ +YS_VERSION := 0.1.75 diff --git a/exercises/practice/resistor-color-duo/.meta/Makefile b/exercises/practice/resistor-color-duo/.meta/Makefile new file mode 100644 index 0000000..08aff24 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/Makefile @@ -0,0 +1,28 @@ +SHELL := bash + +BASE := $(shell pwd) + +export YS_VERSION := 0.1.79 + +YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION) + +YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin + +YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION) + +TEST_FILE ?= $(wildcard *-test.ys) + + +export PATH := $(YS_LOCAL_BIN):$(PATH) + +export YSPATH := $(BASE) + + +default: + +test: $(YS_BIN) + prove -v $(TEST_FILE) + +$(YS_BIN): + curl -s https://yamlscript.org/install | \ + BIN=1 VERSION=$(YS_VERSION) PREFIX=$(YS_LOCAL_PREFIX) bash >/dev/null diff --git a/exercises/practice/resistor-color-duo/.meta/config.json b/exercises/practice/resistor-color-duo/.meta/config.json new file mode 100644 index 0000000..a69fd7e --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "ingydotnet" + ], + "files": { + "solution": [ + "resistor-color-duo.ys" + ], + "test": [ + "resistor-color-duo-test.ys", + "GNUmakefile", + "Makefile", + ".yamlscript/exercise.mk", + ".yamlscript/exercism-ys-installer" + ], + "example": [ + ".meta/resistor-color-duo.ys" + ] + }, + "blurb": "Convert color codes, as used on resistors, to a numeric value.", + "source": "Maud de Vries, Erik Schierboom", + "source_url": "https://github.com/exercism/problem-specifications/issues/1464" +} diff --git a/exercises/practice/resistor-color-duo/.meta/resistor-color-duo-test.ys b/exercises/practice/resistor-color-duo/.meta/resistor-color-duo-test.ys new file mode 100644 index 0000000..6144672 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/resistor-color-duo-test.ys @@ -0,0 +1,43 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: resistor-color-duo + +test:: +- name: Brown and black + code: value(["brown" "black"]) + want: 10 + uuid: ce11995a-5b93-4950-a5e9-93423693b2fc + +- name: Blue and grey + code: value(["blue" "grey"]) + want: 68 + uuid: 7bf82f7a-af23-48ba-a97d-38d59406a920 + +- name: Yellow and violet + code: value(["yellow" "violet"]) + want: 47 + uuid: f1886361-fdfd-4693-acf8-46726fe24e0c + +- name: White and red + code: value(["white" "red"]) + want: 92 + uuid: b7a6cbd2-ae3c-470a-93eb-56670b305640 + +- name: Orange and orange + code: value(["orange" "orange"]) + want: 33 + uuid: 77a8293d-2a83-4016-b1af-991acc12b9fe + +- name: Ignore additional colors + code: value(["green" "brown" "orange"]) + want: 51 + uuid: 0c4fb44f-db7c-4d03-afa8-054350f156a8 + +- name: Black and brown, one-digit + code: value(["black" "brown"]) + want: 1 + uuid: 4a8ceec5-0ab4-4904-88a4-daf953a5e818 + +done: 7 diff --git a/exercises/practice/resistor-color-duo/.meta/resistor-color-duo.ys b/exercises/practice/resistor-color-duo/.meta/resistor-color-duo.ys new file mode 100644 index 0000000..e10d0fe --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/resistor-color-duo.ys @@ -0,0 +1,11 @@ +!yamlscript/v0 + + +colors =: + zipmap _ range(): + qw(black brown red orange yellow + green blue violet grey white) + +defn value([c1 c2]): + colors.$c1 * 10 +: colors.$c2 + diff --git a/exercises/practice/resistor-color-duo/.meta/tests.toml b/exercises/practice/resistor-color-duo/.meta/tests.toml new file mode 100644 index 0000000..9036fc7 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.meta/tests.toml @@ -0,0 +1,31 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[ce11995a-5b93-4950-a5e9-93423693b2fc] +description = "Brown and black" + +[7bf82f7a-af23-48ba-a97d-38d59406a920] +description = "Blue and grey" + +[f1886361-fdfd-4693-acf8-46726fe24e0c] +description = "Yellow and violet" + +[b7a6cbd2-ae3c-470a-93eb-56670b305640] +description = "White and red" + +[77a8293d-2a83-4016-b1af-991acc12b9fe] +description = "Orange and orange" + +[0c4fb44f-db7c-4d03-afa8-054350f156a8] +description = "Ignore additional colors" + +[4a8ceec5-0ab4-4904-88a4-daf953a5e818] +description = "Black and brown, one-digit" diff --git a/exercises/practice/resistor-color-duo/.yamlscript/exercise.mk b/exercises/practice/resistor-color-duo/.yamlscript/exercise.mk new file mode 100644 index 0000000..2506034 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.yamlscript/exercise.mk @@ -0,0 +1 @@ +YS_VERSION := 0.1.75 diff --git a/exercises/practice/resistor-color-duo/.yamlscript/exercism-ys-installer b/exercises/practice/resistor-color-duo/.yamlscript/exercism-ys-installer new file mode 100644 index 0000000..ae3fa01 --- /dev/null +++ b/exercises/practice/resistor-color-duo/.yamlscript/exercism-ys-installer @@ -0,0 +1,127 @@ +#!/env/bin/env bash + +set -euo pipefail + +intro-prompt() ( + cat <<... +-------------------------------------------------------------------------------- + +This YAMLScript Exercism exercise requires the YAMLScript version $version +interpreter command file to be installed here: + + $prefix/bin/ys + +You can install it by pressing Enter now, or by running this command: + + $make install-ys + +This should only take a few seconds and you only need to do this once. +Other exercises will use the same file. + +See https://yamlscript.org/doc/install/ for more YAMLScript installation info. + +-------------------------------------------------------------------------------- + +Would you like to install the 'ys' file now? + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r +) + +main() { + setup "$@" + + install-from-local + + $auto && intro-prompt + + installed || install-from-release || true + installed || install-from-build || true + installed || + die "Installing '$installed' failed. Giving up." \ + "Consider filing an issue at: $gh_issue_url" + + echo + echo 'Success!' + echo "$installed is now installed." + echo +} + +installed() { + [[ -f $installed ]] +} + +install-from-local() { + local path + path=$(command -v "$ysfq") || true + if [[ -f $path ]]; then + mkdir -p "$bin" + cp "$path" "$bin"/ + ln -fs "$ysfq" "$bin/ys-0" + ln -fs "$ysfq" "$bin/ys" + (installed && $auto) && exit + true + fi +} + +install-from-release() ( + set -x + curl -s https://yamlscript.org/install | + BIN=1 VERSION="$version" PREFIX="$prefix" bash +) + +install-from-build() ( + cat <<... + +The binary release installation failed. +We can attempt to build and install $ysfq now. +This can take from 1 to 5 minutes to complete. + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r + + [[ -d /tmp && -w /tmp ]] || + die "Can't write to /tmp" \ + 'Giving up.' + + set -x + + rm -fr "$yamlscript_clone" + + git clone --branch="$version" "$yamlscript_repo" "$yamlscript_clone" + + "$make" -C "$yamlscript_clone/ys" install PREFIX="$prefix" +) + +setup() { + version=$1 + prefix=$2 + make=$3 + auto=false + [[ ${4-} ]] && auto=true + + [[ $version =~ ^0\.1\.[0-9]+$ ]] || + die "Invalid YS_VERSION '$version'" + + bin=$prefix/bin + ysfq=ys-$version + installed=$bin/$ysfq + + if installed; then + echo "'$installed' is already installed." + exit + fi + + yamlscript_repo=https://github.com/yaml/yamlscript + yamlscript_clone=/tmp/yamlscript-exercism + gh_issue_url=https://github.com/exercism/yamlscript/issues +} + +die() { + printf '%s\n' "$@" >&2 + exit 1 +} + +main "$@" diff --git a/exercises/practice/resistor-color-duo/GNUmakefile b/exercises/practice/resistor-color-duo/GNUmakefile new file mode 100644 index 0000000..e8fb5be --- /dev/null +++ b/exercises/practice/resistor-color-duo/GNUmakefile @@ -0,0 +1,49 @@ +SHELL := bash + +BASE := $(shell pwd) + +export YS_VERSION := 0.1.79 + +YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION) +ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok)) +YS_LOCAL_PREFIX := $(shell cd .. && pwd -P)/.local/v$(YS_VERSION) +endif + +YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin +YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION) + +YS_INSTALLER := .yamlscript/exercism-ys-installer +YS_INSTALLER_CMD := \ + bash $(YS_INSTALLER) $(YS_VERSION) $(YS_LOCAL_PREFIX) $(MAKE) + +TEST_FILE ?= $(wildcard *-test.ys) + +export PATH := $(YS_LOCAL_BIN):$(PATH) +export YSPATH := $(BASE) + + +#------------------------------------------------------------------------------- +default: + @echo " No default make rule. Try 'make test'." + +test: $(YS_BIN) + prove -v $(TEST_FILE) + +install-ys: + @$(YS_INSTALLER_CMD) + +uninstall-ys: + rm -fr $(YS_LOCAL_PREFIX) + + +#------------------------------------------------------------------------------- +ifdef EXERCISM_YAMLSCRIPT_GHA +$(YS_BIN): + +else ifeq (/mnt/,$(dir $(BASE))) +$(YS_BIN): + +else +$(YS_BIN): + @$(YS_INSTALLER_CMD) auto +endif diff --git a/exercises/practice/resistor-color-duo/Makefile b/exercises/practice/resistor-color-duo/Makefile new file mode 100644 index 0000000..06b6f00 --- /dev/null +++ b/exercises/practice/resistor-color-duo/Makefile @@ -0,0 +1,8 @@ +# This Makefile is a decoy to attempt to detect when a non-GNU make is being +# used and alert the user. + +test: + @echo "You appear to be using a non-GNU version of the 'make' program." + @echo "The YAMLScript Exercism track requires you to use GNU make." + @echo "Please try 'make $@' again using GNU make." + @exit 1 diff --git a/exercises/practice/resistor-color-duo/resistor-color-duo-test.ys b/exercises/practice/resistor-color-duo/resistor-color-duo-test.ys new file mode 100644 index 0000000..e585128 --- /dev/null +++ b/exercises/practice/resistor-color-duo/resistor-color-duo-test.ys @@ -0,0 +1,36 @@ +#!/usr/bin/env ys-0 + +require ys::taptest: :all + +use: resistor-color-duo + +test:: +- name: Brown and black + code: value(["brown" "black"]) + want: 10 + +- name: Blue and grey + code: value(["blue" "grey"]) + want: 68 + +- name: Yellow and violet + code: value(["yellow" "violet"]) + want: 47 + +- name: White and red + code: value(["white" "red"]) + want: 92 + +- name: Orange and orange + code: value(["orange" "orange"]) + want: 33 + +- name: Ignore additional colors + code: value(["green" "brown" "orange"]) + want: 51 + +- name: Black and brown, one-digit + code: value(["black" "brown"]) + want: 1 + +done: 7 diff --git a/exercises/practice/resistor-color-duo/resistor-color-duo.ys b/exercises/practice/resistor-color-duo/resistor-color-duo.ys new file mode 100644 index 0000000..b164164 --- /dev/null +++ b/exercises/practice/resistor-color-duo/resistor-color-duo.ys @@ -0,0 +1,4 @@ +!yamlscript/v0 + +defn value(colors): + # Implement the 'value' function. From 1f6ce583a2db32043d3a009fcbe7a19fe46cb689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Tue, 1 Oct 2024 10:21:50 -0700 Subject: [PATCH 3/4] Fix some duplication in sample exercises --- exercises/practice/allergies/allergies.ys | 21 ------------------- exercises/practice/bottle-song/bottle-song.ys | 3 --- exercises/practice/leap/.meta/leap-test.ys | 18 ++++++++-------- exercises/practice/leap/.meta/leap.ys | 2 +- exercises/practice/leap/leap-test.ys | 18 ++++++++-------- exercises/practice/leap/leap.ys | 3 ++- .../perfect-numbers/perfect-numbers.ys | 9 -------- exercises/practice/pig-latin/pig-latin.ys | 15 ------------- .../robot-simulator/robot-simulator.ys | 9 -------- exercises/practice/two-fer/two-fer.ys | 2 +- 10 files changed, 22 insertions(+), 78 deletions(-) diff --git a/exercises/practice/allergies/allergies.ys b/exercises/practice/allergies/allergies.ys index f67bffb..8bbd62a 100644 --- a/exercises/practice/allergies/allergies.ys +++ b/exercises/practice/allergies/allergies.ys @@ -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. diff --git a/exercises/practice/bottle-song/bottle-song.ys b/exercises/practice/bottle-song/bottle-song.ys index e76bcf7..45b980a 100644 --- a/exercises/practice/bottle-song/bottle-song.ys +++ b/exercises/practice/bottle-song/bottle-song.ys @@ -2,6 +2,3 @@ defn recite(start-bottles take-down): # Implement the 'recite' function. - -defn recite(start-bottles take-down): - # Implement the 'recite' function. diff --git a/exercises/practice/leap/.meta/leap-test.ys b/exercises/practice/leap/.meta/leap-test.ys index e50b57d..484fc40 100644 --- a/exercises/practice/leap/.meta/leap-test.ys +++ b/exercises/practice/leap/.meta/leap-test.ys @@ -6,47 +6,47 @@ use: leap test:: - name: Year not divisible by 4 in common year - code: is-leap-year(2015) + code: leap-year(2015) want: false uuid: 6466b30d-519c-438e-935d-388224ab5223 - name: Year divisible by 2, not divisible by 4 in common year - code: is-leap-year(1970) + code: leap-year(1970) want: false uuid: ac227e82-ee82-4a09-9eb6-4f84331ffdb0 - name: Year divisible by 4, not divisible by 100 in leap year - code: is-leap-year(1996) + code: leap-year(1996) want: true uuid: 4fe9b84c-8e65-489e-970b-856d60b8b78e - name: Year divisible by 4 and 5 is still a leap year - code: is-leap-year(1960) + code: leap-year(1960) want: true uuid: 7fc6aed7-e63c-48f5-ae05-5fe182f60a5d - name: Year divisible by 100, not divisible by 400 in common year - code: is-leap-year(2100) + code: leap-year(2100) want: false uuid: 78a7848f-9667-4192-ae53-87b30c9a02dd - name: Year divisible by 100 but not by 3 is still not a leap year - code: is-leap-year(1900) + code: leap-year(1900) want: false uuid: 9d70f938-537c-40a6-ba19-f50739ce8bac - name: Year divisible by 400 is leap year - code: is-leap-year(2000) + code: leap-year(2000) want: true uuid: 42ee56ad-d3e6-48f1-8e3f-c84078d916fc - name: Year divisible by 400 but not by 125 is still a leap year - code: is-leap-year(2400) + code: leap-year(2400) want: true uuid: 57902c77-6fe9-40de-8302-587b5c27121e - name: Year divisible by 200, not divisible by 400 in common year - code: is-leap-year(1800) + code: leap-year(1800) want: false uuid: c30331f6-f9f6-4881-ad38-8ca8c12520c1 diff --git a/exercises/practice/leap/.meta/leap.ys b/exercises/practice/leap/.meta/leap.ys index 838d5e7..24799a5 100644 --- a/exercises/practice/leap/.meta/leap.ys +++ b/exercises/practice/leap/.meta/leap.ys @@ -1,6 +1,6 @@ !yamlscript/v0 -defn is-leap-year(year): +defn leap-year(year): (year % 4):zero? &&: (year % 100):pos? ||: (year % 400):zero? diff --git a/exercises/practice/leap/leap-test.ys b/exercises/practice/leap/leap-test.ys index c040473..b5371cc 100644 --- a/exercises/practice/leap/leap-test.ys +++ b/exercises/practice/leap/leap-test.ys @@ -6,39 +6,39 @@ use: leap test:: - name: Year not divisible by 4 in common year - code: is-leap-year(2015) + code: leap-year(2015) want: false - name: Year divisible by 2, not divisible by 4 in common year - code: is-leap-year(1970) + code: leap-year(1970) want: false - name: Year divisible by 4, not divisible by 100 in leap year - code: is-leap-year(1996) + code: leap-year(1996) want: true - name: Year divisible by 4 and 5 is still a leap year - code: is-leap-year(1960) + code: leap-year(1960) want: true - name: Year divisible by 100, not divisible by 400 in common year - code: is-leap-year(2100) + code: leap-year(2100) want: false - name: Year divisible by 100 but not by 3 is still not a leap year - code: is-leap-year(1900) + code: leap-year(1900) want: false - name: Year divisible by 400 is leap year - code: is-leap-year(2000) + code: leap-year(2000) want: true - name: Year divisible by 400 but not by 125 is still a leap year - code: is-leap-year(2400) + code: leap-year(2400) want: true - name: Year divisible by 200, not divisible by 400 in common year - code: is-leap-year(1800) + code: leap-year(1800) want: false done: 9 diff --git a/exercises/practice/leap/leap.ys b/exercises/practice/leap/leap.ys index 266aecd..79f18a4 100644 --- a/exercises/practice/leap/leap.ys +++ b/exercises/practice/leap/leap.ys @@ -1,3 +1,4 @@ !yamlscript/v0 -defn is-leap-year(year): nil +defn leap-year(year): + # Implement the 'leap-year' function. diff --git a/exercises/practice/perfect-numbers/perfect-numbers.ys b/exercises/practice/perfect-numbers/perfect-numbers.ys index a502283..ce02372 100644 --- a/exercises/practice/perfect-numbers/perfect-numbers.ys +++ b/exercises/practice/perfect-numbers/perfect-numbers.ys @@ -2,12 +2,3 @@ defn classify(number): # Implement the 'classify' function. - -defn classify(number): - # Implement the 'classify' function. - -defn classify(number): - # Implement the 'classify' function. - -defn classify(number): - # Implement the 'classify' function. diff --git a/exercises/practice/pig-latin/pig-latin.ys b/exercises/practice/pig-latin/pig-latin.ys index 0aeb6d6..5b934cf 100644 --- a/exercises/practice/pig-latin/pig-latin.ys +++ b/exercises/practice/pig-latin/pig-latin.ys @@ -2,18 +2,3 @@ defn translate(phrase): # Implement the 'translate' function. - -defn translate(phrase): - # Implement the 'translate' function. - -defn translate(phrase): - # Implement the 'translate' function. - -defn translate(phrase): - # Implement the 'translate' function. - -defn translate(phrase): - # Implement the 'translate' function. - -defn translate(phrase): - # Implement the 'translate' function. diff --git a/exercises/practice/robot-simulator/robot-simulator.ys b/exercises/practice/robot-simulator/robot-simulator.ys index 9549621..c4d48f0 100644 --- a/exercises/practice/robot-simulator/robot-simulator.ys +++ b/exercises/practice/robot-simulator/robot-simulator.ys @@ -5,12 +5,3 @@ defn create(position direction): defn move(position direction instructions): # Implement the 'move' function. - -defn move(position direction instructions): - # Implement the 'move' function. - -defn move(position direction instructions): - # Implement the 'move' function. - -defn move(position direction instructions): - # Implement the 'move' function. diff --git a/exercises/practice/two-fer/two-fer.ys b/exercises/practice/two-fer/two-fer.ys index 8d25db8..614b160 100644 --- a/exercises/practice/two-fer/two-fer.ys +++ b/exercises/practice/two-fer/two-fer.ys @@ -1,4 +1,4 @@ !yamlscript/v0 defn two-fer(name): - "" + # Implement the 'two-fer' function. From 69b51833bc74da0e8a5f660739dddccbd81b6e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingy=20d=C3=B6t=20Net?= Date: Tue, 1 Oct 2024 13:47:11 -0700 Subject: [PATCH 4/4] Tweak protein-translation.ys solution; vendethiel++ --- .../practice/protein-translation/.meta/protein-translation.ys | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/protein-translation/.meta/protein-translation.ys b/exercises/practice/protein-translation/.meta/protein-translation.ys index e5064c3..1fb58cc 100644 --- a/exercises/practice/protein-translation/.meta/protein-translation.ys +++ b/exercises/practice/protein-translation/.meta/protein-translation.ys @@ -4,7 +4,7 @@ defn proteins(strand): proteins =: strand.str('XX').partition(3) .map(join).map(translate-codon) - .take-while(/^(?!STOP)/) + .take-while(ne('STOP')) if proteins.has?('INVALID'): die: 'Invalid codon'