Skip to content

Commit 7231ef2

Browse files
authored
Provide an auto-sync script (#879)
1 parent cef8de8 commit 7231ef2

File tree

35 files changed

+354
-133
lines changed

35 files changed

+354
-133
lines changed

bin/auto-sync.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
scriptDirectory="$( dirname "$0" )"
4+
if [[ "$#" != 0 ]]; then
5+
forwardedParameters=( "$@" )
6+
else
7+
forwardedParameters=( -o -u -y --docs --filepaths --metadata )
8+
fi
9+
10+
exitWithFailure() {
11+
echo "$1"
12+
exit 1
13+
}
14+
15+
isPracticeExercise() {
16+
[ -d "exercises/practice/$1" ]
17+
}
18+
19+
reportUnknownExercise() {
20+
echo "Unknown practice exercise: $1"
21+
}
22+
23+
isNoPracticeExercise() {
24+
isPracticeExercise "$1" || {
25+
reportUnknownExercise "$1"
26+
return 0
27+
}
28+
return 1
29+
}
30+
31+
reportRepeatedExercise() {
32+
echo "Repeated exercise slug: $1"
33+
}
34+
35+
syncPracticeExercise() {
36+
local exerciseSlug="$1"
37+
38+
bin/configlet sync -v q -e "$exerciseSlug" "${forwardedParameters[@]}"
39+
}
40+
41+
main() {
42+
local -A uniqueSlugs=()
43+
local -a exerciseSlugs
44+
local exerciseSlug
45+
46+
# Refresh 'problem-spec' cache once
47+
bin/configlet info || exitWithFailure "configlet not ready to run offline"
48+
49+
mapfile -t exerciseSlugs < "$scriptDirectory/auto-sync.txt"
50+
51+
for exerciseSlug in "${exerciseSlugs[@]}"; do
52+
if [[ "${uniqueSlugs[$exerciseSlug]}" == "set" ]]; then
53+
reportRepeatedExercise "$exerciseSlug"
54+
else
55+
uniqueSlugs[$exerciseSlug]="set"
56+
isNoPracticeExercise "${exerciseSlug}" && continue
57+
syncPracticeExercise "${exerciseSlug}"
58+
fi
59+
done
60+
}
61+
62+
main

bin/auto-sync.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
acronym
2+
affine-cipher
3+
all-your-base
4+
allergies
5+
alphametics
6+
anagram
7+
armstrong-numbers
8+
atbash-cipher
9+
bank-account
10+
binary-search
11+
binary-search-tree
12+
bob
13+
book-store
14+
bowling
15+
change
16+
circular-buffer
17+
clock
18+
collatz-conjecture
19+
connect
20+
crypto-square
21+
darts
22+
diamond
23+
difference-of-squares
24+
dnd-character
25+
eliuds-eggs
26+
etl
27+
food-chain
28+
grade-school
29+
hamming
30+
house
31+
isbn-verifier
32+
isogram
33+
killer-sudoku-helper
34+
kindergarten-garden
35+
knapsack
36+
largest-series-product
37+
leap
38+
list-ops
39+
luhn
40+
matching-brackets
41+
meetup
42+
micro-blog
43+
minesweeper
44+
nucleotide-count
45+
pangram
46+
pascals-triangle
47+
phone-number
48+
pig-latin
49+
protein-translation
50+
raindrops
51+
resistor-color
52+
resistor-color-duo
53+
resistor-color-trio
54+
reverse-string
55+
rna-transcription
56+
robot-simulator
57+
roman-numerals
58+
rotational-cipher
59+
run-length-encoding
60+
scrabble-score
61+
secret-handshake
62+
sieve
63+
space-age
64+
spiral-matrix
65+
state-of-tic-tac-toe
66+
strain
67+
sublist
68+
two-bucket
69+
two-fer
70+
yacht
71+
zebra-puzzle

exercises/practice/affine-cipher/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Create an implementation of the affine cipher, an ancient encryption system crea
44

55
The affine cipher is a type of monoalphabetic substitution cipher.
66
Each character is mapped to its numeric equivalent, encrypted with a mathematical function and then converted to the letter relating to its new numeric value.
7-
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the atbash cipher, because it has many more keys.
7+
Although all monoalphabetic ciphers are weak, the affine cipher is much stronger than the Atbash cipher, because it has many more keys.
88

99
[//]: # " monoalphabetic as spelled by Merriam-Webster, compare to polyalphabetic "
1010

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Instructions
22

3-
Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target.
3+
Given a target word and one or more candidate words, your task is to find the candidates that are anagrams of the target.
44

55
An anagram is a rearrangement of letters to form a new word: for example `"owns"` is an anagram of `"snow"`.
66
A word is _not_ its own anagram: for example, `"stop"` is not an anagram of `"stop"`.
77

8-
The target and candidates are words of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
9-
Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `StoP` is not an anagram of `sTOp`.
10-
The anagram set is the subset of the candidate set that are anagrams of the target (in any order).
11-
Words in the anagram set should have the same letter case as in the candidate set.
8+
The target word and candidate words are made up of one or more ASCII alphabetic characters (`A`-`Z` and `a`-`z`).
9+
Lowercase and uppercase characters are equivalent: for example, `"PoTS"` is an anagram of `"sTOp"`, but `"StoP"` is not an anagram of `"sTOp"`.
10+
The words you need to find should be taken from the candidate words, using the same letter case.
1211

13-
Given the target `"stone"` and candidates `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, `"Seton"`, the anagram set is `"tones"`, `"notes"`, `"Seton"`.
12+
Given the target `"stone"` and the candidate words `"stone"`, `"tones"`, `"banana"`, `"tons"`, `"notes"`, and `"Seton"`, the anagram words you need to find are `"tones"`, `"notes"`, and `"Seton"`.

exercises/practice/atbash-cipher/.docs/instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Instructions
22

3-
Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
3+
Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East.
44

55
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards.
66
The first letter is replaced with the last letter, the second with the second-last, and so on.

exercises/practice/atbash-cipher/.meta/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
".meta/example.php"
2121
]
2222
},
23-
"blurb": "Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.",
23+
"blurb": "Create an implementation of the Atbash cipher, an ancient encryption system created in the Middle East.",
2424
"source": "Wikipedia",
2525
"source_url": "https://en.wikipedia.org/wiki/Atbash"
2626
}
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Instructions
22

3-
Correctly determine the fewest number of coins to be given to a customer such that the sum of the coins' value would equal the correct amount of change.
3+
Determine the fewest number of coins to give a customer so that the sum of their values equals the correct amount of change.
44

5-
## For example
5+
## Examples
66

7-
- An input of 15 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) or [5, 10]
8-
- An input of 40 with [1, 5, 10, 25, 100] should return one nickel (5) and one dime (10) and one quarter (25) or [5, 10, 25]
9-
10-
## Edge cases
11-
12-
- Does your algorithm work for any given set of coins?
13-
- Can you ask for negative change?
14-
- Can you ask for a change value smaller than the smallest coin value?
7+
- An amount of 15 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5 and one coin of value 10, or [5, 10].
8+
- An amount of 40 with available coin values [1, 5, 10, 25, 100] should return one coin of value 5, one coin of value 10, and one coin of value 25, or [5, 10, 25].
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Introduction
2+
3+
In the mystical village of Coinholt, you stand behind the counter of your bakery, arranging a fresh batch of pastries.
4+
The door creaks open, and in walks Denara, a skilled merchant with a keen eye for quality goods.
5+
After a quick meal, she slides a shimmering coin across the counter, representing a value of 100 units.
6+
7+
You smile, taking the coin, and glance at the total cost of the meal: 88 units.
8+
That means you need to return 12 units in change.
9+
10+
Denara holds out her hand expectantly.
11+
"Just give me the fewest coins," she says with a smile.
12+
"My pouch is already full, and I don't want to risk losing them on the road."
13+
14+
You know you have a few options.
15+
"We have Lumis (worth 10 units), Viras (worth 5 units), and Zenth (worth 2 units) available for change."
16+
17+
You quickly calculate the possibilities in your head:
18+
19+
- one Lumis (1 × 10 units) + one Zenth (1 × 2 units) = 2 coins total
20+
- two Viras (2 × 5 units) + one Zenth (1 × 2 units) = 3 coins total
21+
- six Zenth (6 × 2 units) = 6 coins total
22+
23+
"The best choice is two coins: one Lumis and one Zenth," you say, handing her the change.
24+
25+
Denara smiles, clearly impressed.
26+
"As always, you've got it right."
Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
11
# Instructions
22

3-
The Collatz Conjecture or 3x+1 problem can be summarized as follows:
4-
5-
Take any positive integer n.
6-
If n is even, divide n by 2 to get n / 2.
7-
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
8-
Repeat the process indefinitely.
9-
The conjecture states that no matter which number you start with, you will always reach 1 eventually.
10-
11-
Given a number n, return the number of steps required to reach 1.
12-
13-
## Examples
14-
15-
Starting with n = 12, the steps would be as follows:
16-
17-
0. 12
18-
1. 6
19-
2. 3
20-
3. 10
21-
4. 5
22-
5. 16
23-
6. 8
24-
7. 4
25-
8. 2
26-
9. 1
27-
28-
Resulting in 9 steps.
29-
So for input n = 12, the return value would be 9.
3+
Given a positive integer, return the number of steps it takes to reach 1 according to the rules of the Collatz Conjecture.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Introduction
2+
3+
One evening, you stumbled upon an old notebook filled with cryptic scribbles, as though someone had been obsessively chasing an idea.
4+
On one page, a single question stood out: **Can every number find its way to 1?**
5+
It was tied to something called the **Collatz Conjecture**, a puzzle that has baffled thinkers for decades.
6+
7+
The rules were deceptively simple.
8+
Pick any positive integer.
9+
10+
- If it's even, divide it by 2.
11+
- If it's odd, multiply it by 3 and add 1.
12+
13+
Then, repeat these steps with the result, continuing indefinitely.
14+
15+
Curious, you picked number 12 to test and began the journey:
16+
17+
12 ➜ 6 ➜ 3 ➜ 10 ➜ 5 ➜ 16 ➜ 8 ➜ 4 ➜ 2 ➜ 1
18+
19+
Counting from the second number (6), it took 9 steps to reach 1, and each time the rules repeated, the number kept changing.
20+
At first, the sequence seemed unpredictable — jumping up, down, and all over.
21+
Yet, the conjecture claims that no matter the starting number, we'll always end at 1.
22+
23+
It was fascinating, but also puzzling.
24+
Why does this always seem to work?
25+
Could there be a number where the process breaks down, looping forever or escaping into infinity?
26+
The notebook suggested solving this could reveal something profound — and with it, fame, [fortune][collatz-prize], and a place in history awaits whoever could unlock its secrets.
27+
28+
[collatz-prize]: https://mathprize.net/posts/collatz-conjecture/

0 commit comments

Comments
 (0)