-
-
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 625d0fc
Showing
161 changed files
with
337 additions
and
305 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
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
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
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,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
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
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
3 changes: 2 additions & 1 deletion
3
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,5 @@ | ||
!yamlscript/v0 | ||
|
||
defn is-armstrong-number(number): | ||
number ==: map(\(_ ** str(number).#) digits(number)).sum() | ||
ds =: digits(number) | ||
number ==: ds.map(\(_ ** ds.#)):sum |
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
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
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
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,22 +1,22 @@ | ||
!yamlscript/v0 | ||
|
||
defn recite(start-bottles take-down): | ||
lines: | ||
join "\n": | ||
map verse: start-bottles .. (start-bottles - take-down).++ | ||
nums =: start-bottles .. | ||
(start-bottles - take-down).++ | ||
nums: .map(verse).join("\n"):lines | ||
|
||
defn- verse(num): | | ||
$uc1(bottles(num)) hanging on the wall, | ||
$uc1(bottles(num)) hanging on the wall, | ||
And if one green bottle should accidentally fall, | ||
There'll be $bottles(num - 1) hanging on the wall. | ||
There'll be $bottles(num.--) hanging on the wall. | ||
|
||
dict =: | ||
nums =: | ||
zipmap (2 .. 10): | ||
qw(two three four five six seven eight nine ten) | ||
|
||
defn- bottles(num): | ||
case num: | ||
0 : 'no green bottles' | ||
1 : 'one green bottle' | ||
else : "$(dict.$num) green bottles" | ||
else : "$(nums.$num) green bottles" |
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.++) |
Oops, something went wrong.