Advent of Code is a good idea to improve your coding skills. Good luck with switching careers. Here are some improvements.
Snake_Case vs CamelCase
In Ruby, modules and classes use CamelCase. You class name should be AdapterArray. Speaking of that, the class name is also not very speaking, maybe you can come up with something more descriptive?
Loading file in ...
It is not necessary to make a copy of seen when making a recursive call. Change seen before the recursive calls and then undo the change afterward.
def dfs(x, y, seen, word = ''):
Recursive Generator that performs a dfs on the word grid
seen = set of seen co-ordinates, set of tuples
word = word to yield at each recursive ...
Pre-compute your offset tuples for possible_directions
Use type hints
Use strings instead of character lists for immutable data
Those aside, you should really consider avoiding printing every single line of output if possible. The printing alone, at this scale, will have a time impact.
from typing import Set, Tuple, Iterable
Coords = Tuple[int, ...
This is fairly tight; I don't think there's much more performance to pull out without dropping into C. That said:
First, I would rename this to neighbors or successors; it's not really about direction but about the nodes in the graph that come next or are adjacent to your current node.
Second, you can reduce the number of branches and ...
You are calling s2.split() a lot. This seems wasteful.
Moreover, you are calling ' '.join(s2.split()[1:]) to get a string containing everything but the first word of s2. So not only are you repeatedly splitting the string, you're also rejoining the splits.
You're doing a lot of work, just to throw it away and redo it in subsequent ...
Your code allows partial acronyms which doesn't seem right. "I'm seeking a clean and efficient way to determine whether one string is an initialism/acronym of another."
recursive_split('aei', 'an example is this')
# [('a', 'an'), ('e', 'example'), ('i', 'is')]
A list comprehension being fed into a for loop is not ...
Just a review of a small portion of code:
PSet *pset = malloc(sizeof(PSet));
pset->data = malloc (sizeof(char *) * (1 << sset->size));
pset->data[pset->size] = calloc(2, 1);
pset->size is not yet assigned a value. pset->data[pset->size] is a Bug. @1201ProgramAlarm
sizeof(char *) --> Is that the correct size? I need to look ...
Avoid FP functions for integer problems.
sqrt(n) problems include potential inexact roots for perfect squares (it is a FP function, not an integer one) and rounding of the double argument when n > 254 or so.
Sample alternative; int_sqrt in C
Other: Only small stuff:
Minor: OK for a narrower type
//uint64_t m = n % 10;
unsigned m = n % 10u;
if (m == 1 || ...
Your m digit checking can be simplified and your do while loop can be replaced with the simpler for loop. The constants also seem excessive given that non-zero truthiness is baked into C.
int isPrimeNumber(uint64_t n)
if (n==2 || n==3) return 1;
if (n%2==0) return 0;
// Start near line x=y.
uint64_t x = (n / 2) + 2;
uint64_t y = n -...
You don't need this line:
requires (!std::invocable<UnaryPredicate, std::ranges::range_value_t<Range>>)
And your test cases miss a std::vector<std::string> as input, but your recursive_copy_if() works fine on those as well.
Just some minor things:
Use std::ranges::begin(), end() and size()
Make sure you consistently use the free-standing functions, instead of using member functions .begin(), .end(), their const counterparts, and .size().
This looks like a utility function, but it is used only once, and it kind of hides what it is actually calling. ...