Skip to content

Commit dfc8a73

Browse files
tidy
1 parent d948f8e commit dfc8a73

File tree

12 files changed

+51
-45
lines changed

12 files changed

+51
-45
lines changed

exercises/practice/atbash-cipher/.meta/example.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ decode:
1515

1616
process:
1717
mov x3, x2 /* remaining letters in group */
18-
mov w6, 32 /* space */
19-
mov w7, #122 /* 'z' */
18+
mov w6, #' '
19+
mov w7, #'z'
2020

2121
.read:
2222
ldrb w4, [x1], #1 /* load byte, post-increment */
2323
cbz w4, .end
2424

25-
sub w5, w4, #48 /* '0' */
25+
sub w5, w4, #'0'
2626
cmp w5, #10
2727
blo .accept /* unsigned < */
2828

2929
orr w5, w4, #32 /* force lower case */
30-
sub w5, w5, 97 /* 'a' */
30+
sub w5, w5, #'a'
3131
cmp w5, #26
3232
bhs .read /* unsigned >= */
3333

exercises/practice/bob/.meta/example.s

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ response:
1818
ldrb w1, [x0], #1 /* load byte, with post-increment */
1919
cbz x1, .select_response
2020

21-
cmp x1, #32 /* space */
21+
cmp x1, #' '
2222
ble .read
2323

2424
mov x2, x1 /* non-whitespace character */
25-
sub x1, x1, #65
25+
sub x1, x1, #'A'
2626
cmp x1, #26 /* upper case? */
2727
cinc x3, x3, lo /* increment on unsigned < */
2828

@@ -42,7 +42,7 @@ response:
4242
add x3, x3, :lo12:calm
4343
adrp x4, whoa
4444
add x4, x4, :lo12:whoa
45-
cmp x2, #63 /* question mark */
45+
cmp x2, #'?'
4646
csel x0, x3, x4, eq
4747
ret
4848

@@ -51,7 +51,7 @@ response:
5151
add x3, x3, :lo12:sure
5252
adrp x4, whatever
5353
add x4, x4, :lo12:whatever
54-
cmp x2, #63 /* question mark */
54+
cmp x2, #'?'
5555
csel x0, x3, x4, eq
5656
ret
5757

exercises/practice/isbn-verifier/.meta/example.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ is_valid:
1515
beq .loop
1616

1717
sub x1, x1, #1 /* decrement number of digits remaining */
18-
sub x3, x2, #48 /* '0' */
18+
sub x3, x2, #'0'
1919
cmp x3, #10
2020
bhs .non_digit /* unsigned >= */
2121

@@ -28,7 +28,7 @@ is_valid:
2828
cbnz x1, .reject
2929

3030
mov x3, #10
31-
cmp x2, #88 /* 'X' */
31+
cmp x2, #'X'
3232
beq .add
3333

3434
.reject:

exercises/practice/isogram/.meta/example.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ is_isogram:
1212
cbz x3, .accept
1313

1414
orr x3, x3, #32 /* force lower-case */
15-
sub x3, x3, #97
15+
sub x3, x3, #'a'
1616
cmp x3, #26
1717
bhs .loop /* unsigned >= */
1818

exercises/practice/largest-series-product/largest_series_product_test.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,82 +15,82 @@ void tearDown(void) {
1515
}
1616

1717
void test_finds_the_largest_product_if_span_equals_length(void) {
18-
TEST_ASSERT_EQUAL_INT(18, largest_product(2, "29"));
18+
TEST_ASSERT_EQUAL_INT64(18, largest_product(2, "29"));
1919
}
2020

2121
void test_can_find_the_largest_product_of_2_with_numbers_in_order(void) {
2222
TEST_IGNORE();
23-
TEST_ASSERT_EQUAL_INT(72, largest_product(2, "0123456789"));
23+
TEST_ASSERT_EQUAL_INT64(72, largest_product(2, "0123456789"));
2424
}
2525

2626
void test_can_find_the_largest_product_of_2(void) {
2727
TEST_IGNORE();
28-
TEST_ASSERT_EQUAL_INT(48, largest_product(2, "576802143"));
28+
TEST_ASSERT_EQUAL_INT64(48, largest_product(2, "576802143"));
2929
}
3030

3131
void test_can_find_the_largest_product_of_3_with_numbers_in_order(void) {
3232
TEST_IGNORE();
33-
TEST_ASSERT_EQUAL_INT(504, largest_product(3, "0123456789"));
33+
TEST_ASSERT_EQUAL_INT64(504, largest_product(3, "0123456789"));
3434
}
3535

3636
void test_can_find_the_largest_product_of_3(void) {
3737
TEST_IGNORE();
38-
TEST_ASSERT_EQUAL_INT(270, largest_product(3, "1027839564"));
38+
TEST_ASSERT_EQUAL_INT64(270, largest_product(3, "1027839564"));
3939
}
4040

4141
void test_can_find_the_largest_product_of_5_with_numbers_in_order(void) {
4242
TEST_IGNORE();
43-
TEST_ASSERT_EQUAL_INT(15120, largest_product(5, "0123456789"));
43+
TEST_ASSERT_EQUAL_INT64(15120, largest_product(5, "0123456789"));
4444
}
4545

4646
void test_can_get_the_largest_product_of_a_big_number(void) {
4747
TEST_IGNORE();
48-
TEST_ASSERT_EQUAL_INT(23520, largest_product(6, "73167176531330624919225119674426574742355349194934"));
48+
TEST_ASSERT_EQUAL_INT64(23520, largest_product(6, "73167176531330624919225119674426574742355349194934"));
4949
}
5050

5151
void test_reports_zero_if_the_only_digits_are_zero(void) {
5252
TEST_IGNORE();
53-
TEST_ASSERT_EQUAL_INT(0, largest_product(2, "0000"));
53+
TEST_ASSERT_EQUAL_INT64(0, largest_product(2, "0000"));
5454
}
5555

5656
void test_reports_zero_if_all_spans_include_zero(void) {
5757
TEST_IGNORE();
58-
TEST_ASSERT_EQUAL_INT(0, largest_product(3, "99099"));
58+
TEST_ASSERT_EQUAL_INT64(0, largest_product(3, "99099"));
5959
}
6060

6161
void test_rejects_span_longer_than_string_length(void) {
6262
TEST_IGNORE();
63-
TEST_ASSERT_EQUAL_INT(INSUFFICIENT_DIGITS, largest_product(4, "123"));
63+
TEST_ASSERT_EQUAL_INT64(INSUFFICIENT_DIGITS, largest_product(4, "123"));
6464
}
6565

6666
void test_reports_1_for_empty_string_and_empty_product_0_span(void) {
6767
TEST_IGNORE();
68-
TEST_ASSERT_EQUAL_INT(1, largest_product(0, ""));
68+
TEST_ASSERT_EQUAL_INT64(1, largest_product(0, ""));
6969
}
7070

7171
void test_reports_1_for_nonempty_string_and_empty_product_0_span(void) {
7272
TEST_IGNORE();
73-
TEST_ASSERT_EQUAL_INT(1, largest_product(0, "123"));
73+
TEST_ASSERT_EQUAL_INT64(1, largest_product(0, "123"));
7474
}
7575

7676
void test_rejects_empty_string_and_nonzero_span(void) {
7777
TEST_IGNORE();
78-
TEST_ASSERT_EQUAL_INT(INSUFFICIENT_DIGITS, largest_product(1, ""));
78+
TEST_ASSERT_EQUAL_INT64(INSUFFICIENT_DIGITS, largest_product(1, ""));
7979
}
8080

8181
void test_rejects_invalid_character_in_digits(void) {
8282
TEST_IGNORE();
83-
TEST_ASSERT_EQUAL_INT(INVALID_CHARACTER, largest_product(2, "1234a5"));
83+
TEST_ASSERT_EQUAL_INT64(INVALID_CHARACTER, largest_product(2, "1234a5"));
8484
}
8585

8686
void test_rejects_negative_span(void) {
8787
TEST_IGNORE();
88-
TEST_ASSERT_EQUAL_INT(NEGATIVE_SPAN, largest_product(-1, "12345"));
88+
TEST_ASSERT_EQUAL_INT64(NEGATIVE_SPAN, largest_product(-1, "12345"));
8989
}
9090

9191
void test_large_span(void) {
9292
TEST_IGNORE();
93-
TEST_ASSERT_EQUAL_INT(131681894400, largest_product(17, "98765432123456789"));
93+
TEST_ASSERT_EQUAL_INT64(131681894400, largest_product(17, "98765432123456789"));
9494
}
9595

9696
int main(void) {

exercises/practice/nucleotide-count/.meta/example.s

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ nucleotide_counts:
1212
ldrb w2, [x1], #1 /* load byte, post-increment */
1313
cbz w2, .report
1414

15-
cmp w2, 'A'
15+
cmp w2, #'A'
1616
beq .adenine
1717

18-
cmp w2, 'C'
18+
cmp w2, #'C'
1919
beq .cytosine
2020

21-
cmp w2, 'G'
21+
cmp w2, #'G'
2222
beq .guanine
2323

24-
cmp w2, 'T'
24+
cmp w2, #'T'
2525
beq .thymine
2626

27-
mov w2, -1
27+
mov w2, #-1
2828
strh w2, [x0], #2
2929
strh w2, [x0], #2
3030
strh w2, [x0], #2

exercises/practice/pangram/.meta/example.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ is_pangram:
1212
cbz x3, .return
1313

1414
orr x3, x3, #32 /* force lower-case */
15-
sub x3, x3, #97
15+
sub x3, x3, #'a'
1616
cmp x3, #26
1717
bhs .loop /* unsigned >= */
1818

exercises/practice/pig-latin/.meta/example.s

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ vowels:
1111
# | -------- | ------------ | ------- | --------------------------------------- |
1212
# | `x0` | input/output | address | output pointer |
1313
# | `x1` | input | address | beginning of word(s) |
14-
# | `x3` | temporary | byte | previous letter in word |
15-
# | `x4` | temporary | byte | current letter in word |
16-
# | `x5` | temporary | byte | second letter in word |
17-
# | `x6` | temporary | byte | non-zero when current letter is a vowel |
18-
# | `x7` | temporary | byte | 'a' |
19-
# | `x8` | temporary | byte | 'y' |
14+
# | `w3` | temporary | byte | previous letter in word |
15+
# | `w4` | temporary | byte | current letter in word |
16+
# | `w5` | temporary | byte | second letter in word |
17+
# | `w6` | temporary | byte | non-zero when current letter is a vowel |
18+
# | `w7` | temporary | byte | 'a' |
19+
# | `w8` | temporary | byte | 'y' |
2020
# | `x9` | temporary | address | vowels table, minus 'a' |
2121
# | `x10` | temporary | address | position in current word |
2222
# | `x11` | temporary | address | end of current word |

exercises/practice/raindrops/.meta/example.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ convert:
4141
mov x5, x1
4242
udiv x1, x5, x3 /* divide value by 10 */
4343
msub x6, x1, x3, x5 /* remainder, i.e. output digit */
44-
add w6, w6, #48 /* '0' */
44+
add w6, w6, #'0'
4545
strb w6, [x2], #1 /* store, post-increment */
4646
cbnz x1, .write /* loop until value is 0 */
4747

exercises/practice/rotational-cipher/.meta/example.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ rotate:
88
ldrb w4, [x1], #1 /* load byte, post-increment */
99
and w7, w4, #32 /* 32 if lower case, 0 if upper case */
1010
sub w5, w4, w7 /* force upper case */
11-
sub w5, w5, 65 /* subtract 'A' to obtain index in alphabet */
11+
sub w5, w5, #'A' /* index in alphabet */
1212
cmp w5, #26
1313
bhs .write /* unsigned >= */
1414

15-
add w5, w5, 65 /* 'A' */
15+
add w5, w5, #'A'
1616
add w5, w5, w2 /* shift */
1717
sub w6, w5, #26
18-
cmp w5, #90 /* 'Z' */
18+
cmp w5, #'Z'
1919
csel w5, w5, w6, le /* w5 if <= 'Z', otherwise w5 - 26 */
2020

2121
orr w4, w5, w7 /* rotated letter, with original case */

exercises/practice/square-root/.meta/example.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
/* extern uint64_t square_root(uint64_t radicand); */
55
square_root:
66
mov x1, x0 /* radicand */
7-
mov x0, #1 /* initial guess */
7+
8+
clz x0, x1 /* count leading zero bits */
9+
mov x2, #64
10+
sub x0, x2, x0 /* number of bits, excluding leading zero bits */
11+
lsr x0, x0, #1 /* number of bits, halved */
12+
mov x2, #1
13+
lsl x0, x2, x0 /* initial guess */
814

915
.loop:
1016
mov x2, x0 /* current guess */

generators/exercises/largest_series_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ def gen_func_body(prop, inp, expected):
3333
expectations["span must be smaller than string length"] = "INSUFFICIENT_DIGITS"
3434
expected = expectations[expected["error"]]
3535

36-
return f"TEST_ASSERT_EQUAL_INT({expected}, largest_product({span}, \"{digits}\"));\n"
36+
return f"TEST_ASSERT_EQUAL_INT64({expected}, largest_product({span}, \"{digits}\"));\n"

0 commit comments

Comments
 (0)