-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f731bf2
commit 5183315
Showing
48 changed files
with
217 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
!yamlscript/v0 | ||
|
||
defn abbreviate(phrase): | ||
uc(phrase).re-seq(/[A-Z']+/).map(first).str(*) | ||
uc(phrase): | ||
.re-seq(/[A-Z']+/) | ||
.map(first).join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
!yamlscript/v0 | ||
|
||
defn rebase(input-base digits output-base): | ||
:: Converts a sequence of digits given in input-base into a sequence of | ||
digits in the desired output-base. | ||
:: Converts a sequence of digits given in input-base | ||
into a sequence of digits in the desired output-base. | ||
|
||
cond: | ||
input-base < 2: die('input base must be >= 2') | ||
input-base < 2: die('input base must be >= 2') | ||
output-base < 2: die('output base must be >= 2') | ||
digits.some(neg?) || digits.some(\(_ >= input-base)): | ||
digits.some(neg?) || digits.some(ge(input-base)): | ||
die: 'all digits must satisfy 0 <= d < input base' | ||
|
||
digits.every?(zero?) || digits.! :: [0] | ||
digits.every?(zero?) || count(digits).eq(0) :: [0] | ||
|
||
else: digits | ||
.digits-to-decimal(input-base) | ||
.decimal-to-digits(output-base) | ||
|
||
defn digits-to-decimal(digits input-base): | ||
reduce \((%1 * input-base) + %2): 0 digits | ||
reduce \(%2 + (%1 * input-base)): digits | ||
|
||
defn decimal-to-digits(number output-base): | ||
loop digits nil, num number: | ||
if num > 0: | ||
recur: | ||
conj: digits (num % output-base) | ||
conj digits: num % output-base | ||
quot: num output-base | ||
else: digits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
exercises/practice/armstrong-numbers/.meta/armstrong-numbers.ys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
!yamlscript/v0 | ||
|
||
defn is-armstrong-number(number): | ||
number ==: map(\(_ ** str(number).#) digits(number)).sum() | ||
eq number: | ||
sum: | ||
map \(_ ** digits(number).#): | ||
digits(number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
exercises/practice/collatz-conjecture/.meta/collatz-conjecture.ys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
!yamlscript/v0 | ||
|
||
defn steps(number): | ||
when-not pos?(number): | ||
die('Only positive integers are allowed') | ||
number > 0 ||: | ||
die: 'Only positive integers are allowed' | ||
|
||
loop num number, steps 0: | ||
cond: | ||
num == 1: steps | ||
even?(num): recur((num / 2), steps.++) | ||
else: recur((num * 3).++, steps.++) | ||
num.eq(1) : steps | ||
num.even?() : recur(num.div(2), steps.++) | ||
else : recur(num.mul(3).++, steps.++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
!yamlscript/v0 | ||
|
||
defn isogram(string): | ||
string.! ||: | ||
empty?(string) ||: | ||
lc(string) \"Want to be case insensitive" | ||
.split() \"Split string into chars" | ||
.filter(\(/^\w$/)) \"Keep letters only" | ||
.filter(/^[a-z]$/) \"Keep letters only" | ||
.distinct?(*) \"Check if distinct letters" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
!yamlscript/v0 | ||
|
||
defn is-leap-year(year): | ||
(year % 4).! &&: (year % 100).? || (year % 400).! | ||
(year % 4).eq(0) &&: | ||
(year % 100).pos?() || | ||
(year % 400).eq(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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().vec() | ||
.conj(0).partition(2).map(munge) | ||
.flat().sum().mod(10).eq(0) | ||
|
||
defn munge([a b]): | ||
b =: 2 * b | ||
vector a: | ||
if b > 9: (b - 9) b | ||
b *=: 2 | ||
vector: | ||
a |: | ||
if b > 9: (b - 9) b |
8 changes: 4 additions & 4 deletions
8
exercises/practice/matching-brackets/.meta/matching-brackets.ys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
!yamlscript/v0 | ||
|
||
defn is-pangram(sentence): | ||
sentence.lc().replace(/[^a-z]/ '') | ||
.sort().distinct().len().eq(26) | ||
eq 26: | ||
len: lc(sentence) | ||
.replace(/[^a-z]/) | ||
.distinct() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.