import itertools
def generate_n_primes(n):
"""
Generate n prime numbers using a modified Sieve of Eratosthenes.
The algorithm keeps track of a list of primes found so far,
and a corresponding list of 'multiples', where multiples[i] is a multiple of primes[i],
(multiples[i] is initially set to be primes[i]**2, see the optimisations section below).
The main loop iterates over every integer k until enough primes have been found,
with the following steps:
- For each prime found so far
- While the corresponding multiple is smaller than k, increase it by steps of the prime
- If the multiple is now the same as k, then k is divisible by the prime -
hence k is composite, ignore it.
- If, for EVERY prime, the multiple is greater than k, then k isn't divisible by any
of the primes found so far. Hence we can add it to the prime list and multiple list!
There are a few optimisations that can be done:
- We can insert 2 into primes at the start, and only iterate over every odd k from there on
- When we're increasing the multiple, we can now increase by 2*prime instead of 1*prime,
so that we skip over even numbers, since we are now only considering odd k
- When we find a prime p, we add it to the prime and multiple list. However, we can instead add
its square to the multiple list, since for any number between p and p**2, if it's
divisible by p then it must be divisible by another prime k < p
(i.e. it will be caught by an earlier prime in the list)
"""
# Insert 2 into primes/multiples
primes = [2]
multiples = [4]
# Iterate over odd numbers starting at 3
for k in itertools.count(3, 2):
# If we've found enough primes, return!
if len(primes) >= n:
return primes
# For each prime found so far
for i in range(len(primes)):
# Increase its corresponding multiple in steps of 2*prime until it's >= k
while multiples[i] < k:
multiples[i] += 2 * primes[i]
# If its corresponding multiple == k then k is divisible by the prime
if multiples[i] == k:
break
else:
# If k wasn't divisible by any prime, add it to the primes/multiples list
primes.append(k)
multiples.append(k ** 2)
return primes
Some might find the docstring as well as comments too much - I find the comments help relate the code to the docstring. Open to suggestions!
I'd be willing to bet that the majority of results you find in that search will be men talking about how much women care about money... of course some women do, but far far from all of them
Well its not about money per se, rather power, competence and whatever it translates to. This is almost a daily sight in any society if you know what to look for, and basis of who we were and who we are also today. I don't see any problems with it, there is good logic and history behind it and it explains a lot of behavior of various folks.
Certain age usually brings this 'seeing' effortlessly and you actually become annoyed by additional layer of personalities that you see (since you can't escape it anymore facts that a lot of people of both sexes are just badly broken or simply not good people to the core), you just need to grind through enough people/stories around you like any other skill.
Beneath the large obvious green 'Subscribe' button there is some low-contrast grey text ('Continue reading') that, when clicked, hides the box. This is on Substack's side, not the author of the article.
Workman [0] was designed to be used on an ortho keyboard, though it is also usable on a normal keyboard. I suppose it's tricky to design for many modern features as they are not yet standardised between keyboards.
I use Colemak-DH (modified version of Colemak that has less lateral hand motion - found I was getting slight wrist strain with normal Colemak). I find it more comfortable than Qwerty. I have not had any issue with keyboard shortcuts - Ctrl-Z/X/C are in exactly the same spot and Ctrl-V is shifted over by one key. Most shortcuts are placed to be memorable (e.g. Ctrl-F for Find), not to be ergonomic, so the keyboard layout doesn't really matter. The only place I've really had to customise is Vim, where I've remapped the motion keys back to where they are in Qwerty (actually shifted over by one to j/k/l/;).
On Gnome, switching keyboard layout is very quick and easy - there's an icon in the top bar by default - so I can use that when other people want to use my computer. When I use others' computers, I have to look at the keyboard but it is not too much hassle for me as I don't do this very often.
The main issue I've actually had is remapping Caps Lock to Back Space - not trivial to do in Gnome (required creating my own layout in XDG).
There are certain operations that only "kernel" packages are allowed to do. If that weren't the case, then this would indeed be little more than an obscure quirk.
Ah I see. So non-kernel packages do not have access to native modules at all? I believe in Elm native modules were still possible, just not publishing them to the package database. But in this case I guess you wouldn't be able to put a native module in a GitHub repository and then pull this in as a dependency, which is equally rubbish.
Elm doesn’t allow kernel code in externel packages. Gren is performing the exact same check, it’s just that Gren uses Git as a package manager and so has to do it in a different way.
- Fuzzy file search - I can't find a way to do this in nano? Where you can search a whole directory by name for the file you want to open. This is very useful in larger projects when you need to jump about a lot.
- LSP and all its uses - jump to definition is a big one.
- Window management - while you can use a multiplexer, using one session allows copy/paste to work, saves your file/search/command history, etc.
- While often overstated, it is undeniably more efficient... once you've learnt it.
However, if you are not doing programming, but are just editing e.g. Linux config files, then I would probably stick to nano (in fact, I usually use nano for these jobs, since getting my neovim config to work when running as sudo failed).
> While often overstated, it is undeniably more efficient... once you've learnt it.
And on this note, I'd recommend not jumping in and trying to learn everything. Too easy to get overwhelmed.
Start with the bare basics and treat it like nano with syntax highlighting, then start learning and getting used to its broader functionality in small bursts.