HN user

ArchieMaclean

282 karma
Posts13
Comments61
View on HN

My take on the prime example:

    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!

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.

I did this initially, but I believe it didn't work for all applications - some were still registering it as Caps Lock (e.g. VS Code IIRC).

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).

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.

Edit: EdwardDiego's answer clarified this for me

Learn Vim (2021) 3 years ago

- 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).

I use Colemak DH, and have done for a few years. I could never touch type very well on QWERTY anyway so using QWERTY I am no slower than I was originally (in fact, I'm probably faster, since I now use my fingers properly). As long as it isn't very frequent, using hunt-and-peck on any QWERTY keyboards you come across is fine, and touch typing a different layout won't affect it.

Lichess has a 'fishnet' of donated servers [0] that allow you to analyse using Stockfish on proper hardware. You can have up to 20 deep analyses a day.

The web client uses Stockfish compiled to WASM which is decently fast.

If you're not an IM/GM, it's "good enough"

[0] https://github.com/niklasf/fishnet

Weird English 5 years ago

I wouldn't really call Orcish / Dwarvish 'full languages' - they aren't developed that much. However, the two major Elvish languages (Quenya and Sindarin) are both a lot fuller.

CamelCase is built in to Plover! [1] symbols work too - they might have less intuitive memorisation, but you don't use that many anyway (unless you're in APL...but that doesn't work with normal keyboards either).

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...

It's because the paper they are referencing is testing the use of immunosuppressive therapy to treat myocarditis. The conclusion that was reached was that it doesn't work.

Needless to say, that's not how myocarditis is treated in hospitals.

The source it gives for the mortality of myocarditis is a paper titled "A clinical trial of immunosuppressive therapy for myocarditis" I.e. they were testing a possible treatment. The conclusion was "Our results do not support routine treatment of myocarditis with immunosuppressive drugs."

Referencing this as though it's the true mortality rate is woefully misleading. This is the mortality rate when using this experimental treatment.

In regards to the cardiac arrests and ambulance calls, it seems that the graph almost exactly follows the baseline, except for the two heatwaves. It doesn't say what the baseline is - I guess 2020 figures?

Edit: on further inspection - figures 1a,b,c are from a paper[1] and are showing an increase in cardiac arrest, unconsciousness, e.t.c. however this article ignores 2 graphs from the paper which show a decrease in chest pain and decrease in breathing difficulty, both of which are myocarditis symptoms.

I think this article is wilfully misleading.

[1] https://assets.publishing.service.gov.uk/government/uploads/...