282 karma · joined Jan 21, 2020 (6y ago) · 75 submissions
comment 1y ago · link · parent
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!comment 3y ago · link · parent
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).
comment 3y ago · link · parent
Edit: EdwardDiego's answer clarified this for me
comment 3y ago · link · parent
Seems more like a check to make sure the version of the JS is compatible with the version of gren than anything else.
[1] https://github.com/gren-lang/compiler/blob/e665e521367eeedec...
comment 3y ago · link · parent
- 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).
comment 3y ago · link · parent
Edit: the default 'phrases' are here: https://git.sr.ht/~geb/numen/tree/master/item/phrases
comment 3y ago · link · parent
17.
Show HN: PipeScore – FOSS Bagpipe Notation Software(pipescore.web.app ↗)
3 points · by ArchieMaclean · 3y ago · discuss
19.
Show HN: PipeScore – Free Bagpipe Notation(pipescore.web.app ↗)
4 points · by ArchieMaclean · 4y ago · discuss
25.
PipeScore – FOSS Bagpipe Notation(pipescore.web.app ↗)
1 points · by ArchieMaclean · 5y ago · discuss
comment 5y ago · link · parent
You can set up Vim-like navigation e.t.c. too (e.g. [2]), for moving about in code. I haven't tried it.
I think however that the benefits of coding with Plover aren't really great enough to justify the huge struggle it would be to get proficient with it.
[1] https://github.com/openstenoproject/plover/wiki/Dictionary-F...
[2] http://www.openstenoproject.org/stenodict/dictionaries/vim_d...
comment 5y ago · link · parent
As to switching on the fly, I can't see anything in the docs about it - this extension might work? [2]
[1] https://github.com/openstenoproject/plover/wiki/List-of-Avai...