Skip to content

Commit

Permalink
finish p22 in c
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 4, 2024
1 parent d257de0 commit b77ea65
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Olivia's Project Euler Solutions
+------------+--------------------------+--------+-------------------+
| Language | Version | Solved | Status |
+============+==========================+========+===================+
| C | C99+ in: |clang|, |br| | 20 | |Ci| |br| |
| C | C99+ in: |clang|, |br| | 21 | |Ci| |br| |
| | |gcc|, |pcc|, |tcc| |br| | | |C-Cov| |br| |
| | C11+ in: |msvc| [1]_ | | |CodeQL| |
+------------+--------------------------+--------+-------------------+
Expand Down
11 changes: 5 additions & 6 deletions c/src/p0022.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ unsigned long long p0022() {
do {
while (fstring[i] && fstring[i] != ',')
i++;
const size_t len = i - pi;
names[idx] = (char *)malloc(len - 1);
memcpy(names[idx], fstring + pi + 1, len - 2);
names[idx++][len - 1] = 0;
const size_t len = i - pi - 2;
names[idx] = (char *)malloc(len);
memcpy(names[idx], fstring + pi + 1, len);
names[idx++][len] = 0;
pi = ++i;
} while (fstring[i]);
qsort(names, sizeof(names)/sizeof(*names), sizeof(*names), cmpstr);
qsort(names, sizeof(names)/sizeof(*names), sizeof(*names), cmpstr);
for (idx = 0; idx < name_count; idx++) {
unsigned long score = 0;
for (i = 0; names[idx][i]; i++) {
score += names[idx][i] - 'A' + 1;
score += names[idx][i] & 0x3F;
}
answer += score * (idx + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion c/test_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
15: 137846528820,
16: 1366,
17: 21124,
# 22: 871198282,
22: 871198282,
34: 40730,
76: 190569291,
836: b"aprilfoolsjoke",
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`21` | | | | |:py-d:`0021`| |
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`22` |:c-i:`0022` | |:cs-d:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`|
|:prob:`22` |:c-d:`0022` | |:cs-d:`0022`|:js-d:`0022`|:py-d:`0022`|:rs-d:`0022`|
+-----------+------------+------------+------------+------------+------------+------------+
|:prob:`23` | | | | |:py-d:`0023`| |
+-----------+------------+------------+------------+------------+------------+------------+
Expand Down

0 comments on commit b77ea65

Please sign in to comment.