-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactorings based on Steffan153's work #40
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +1,5 @@ | ||
!yamlscript/v0 | ||
|
||
defn abbreviate(phrase): | ||
uc(phrase): | ||
.re-seq(/[A-Z']+/) | ||
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,12 @@ | ||
!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. | ||
|
||
cond: | ||
input-base < 2: die('input base must be >= 2') | ||
output-base < 2: die('output base must be >= 2') | ||
digits.some(neg?) || digits.some(ge(input-base)): | ||
die: 'all digits must satisfy 0 <= d < input base' | ||
|
||
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 \(%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 | ||
quot: num output-base | ||
else: digits | ||
defn rebase(input digits output): | ||
when input < 2: die('input base must be >= 2') | ||
when output < 2: die('output base must be >= 2') | ||
when-not digits.every?(\(0 <= _ <= input.--)): | ||
die('all digits must satisfy 0 <= d < input base') | ||
|
||
loop n reduce(\((%1 * input) + %2) 0 digits), res []: | ||
if n.?: | ||
=>: recur(quot(n output) res.cons(n % output)) | ||
res |||: -[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
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,20 +1,9 @@ | ||
!yamlscript/v0 | ||
|
||
allergen-map =: | ||
zipmap _ range():: | ||
- eggs | ||
- peanuts | ||
- shellfish | ||
- strawberries | ||
- tomatoes | ||
- chocolate | ||
- pollen | ||
- cats | ||
|
||
defn allergic-to(item score): | ||
bit-test score: allergen-map.$item | ||
list-allergens(score).has?(item) | ||
|
||
defn list-allergens(score): | ||
keep _ allergen-map: | ||
fn([allergen num]): | ||
bit-test(score num) &&& allergen | ||
(0 .. 7).filter(P(bit-test score)) | ||
.map(qw(eggs peanuts shellfish strawberries | ||
tomatoes chocolate pollen cats)) |
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,12 +1,10 @@ | ||
!yamlscript/v0 | ||
|
||
dict =: | ||
zipmap (\\a .. \\z): \\z .. \\a | ||
|
||
defn encode(phrase): | ||
lc(phrase): | ||
.replace(/[^a-z0-9]/).escape(dict) | ||
lc(phrase):decode: | ||
.replace(/[^a-z0-9]/) | ||
.partition(5 5 '').map(join):joins | ||
|
||
defn decode(phrase): | ||
phrase.replace(' ').escape(dict) | ||
m =: (\\a .. \\z).zipmap(\\z .. \\a) | ||
phrase: .replace(' ').escape(m) |
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,50 +1,28 @@ | ||
!yamlscript/v0 | ||
|
||
account =: atom(nil) | ||
closed =: 'closed' | ||
closed? =: P(== closed) | ||
|
||
defn reset-test-state(): | ||
reset! account: nil | ||
|
||
defn bank-account(operations): | ||
last: | ||
for operation operations: | ||
operation | ||
.operation | ||
.str('do-' _) | ||
.call(operation) | ||
|
||
defn- do-open(op): | ||
when deref(account): | ||
die: 'account already open' | ||
reset! account: 0 | ||
|
||
defn- do-close(op): | ||
when-not deref(account): | ||
die: 'account not open' | ||
reset! account: nil | ||
|
||
defn- do-balance(op): | ||
balance =: deref(account) | ||
if-not balance: | ||
die: 'account not open' | ||
else: balance | ||
|
||
defn- do-deposit(op): | ||
when-not deref(account): | ||
die: 'account not open' | ||
swap! account +: op:get-amount | ||
|
||
defn- do-withdraw(op): | ||
balance =: deref(account) | ||
when-not balance: | ||
die: 'account not open' | ||
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: | ||
die: 'amount must be greater than 0' | ||
else: amount | ||
reduce _ closed operations: | ||
fn(bal op): | ||
case op.operation: | ||
'open': | ||
if closed?(bal): 0, die('account already open') | ||
'close': | ||
if closed?(bal): die('account not open'), closed | ||
'balance': | ||
if closed?(bal): die('account not open'), bal | ||
'deposit': | ||
cond: | ||
closed?(bal): die('account not open') | ||
op.amount <= 0: die('amount must be greater than 0') | ||
else: bal + op.amount | ||
'withdraw': | ||
cond: | ||
closed?(bal): die('account not open') | ||
op.amount <= 0: die('amount must be greater than 0') | ||
op.amount > bal: die('amount must be less than balance') | ||
else: bal - op.amount |
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,13 +1,9 @@ | ||
!yamlscript/v0 | ||
|
||
defn find(array value): | ||
loop low 0, high array.--: | ||
when low > high: | ||
die: 'value not in array' | ||
mid =: (high + low).quot(2) | ||
item =: array.$mid | ||
|
||
cond: | ||
value == item : mid | ||
value < item : recur(low mid.--) | ||
else : recur(mid.++ high) | ||
when array.#.!: die('value not in array') | ||
mid =: array.#.--.quot(2) | ||
case compare(array.$mid value): | ||
0: mid | ||
1: find(take(mid array) value) | ||
-1: find(drop(mid.++ array) value) + mid.++ |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a net negative. This loses the spirit of the exercise. The tests need to adjusted.