RogerBW's Blog

The Weekly Challenge 169: The Brilliance of Achilles 15 June 2022

I’ve been doing the Weekly Challenges. The latest involved more numerical series. (Note that this is open until 19 June 2022.)

Task 1: Brilliant Numbers

Write a script to generate first 20 Brilliant Numbers.

I.e. numbers with exactly two prime factors, of the same (base-10) length. So what I want to do is generate all the primes of a length, multiply them together pairwise, and if I don't have enough values add one to the length and do it again. I use a technique similar to the one in #167 two weeks ago, generating each set of length-N primes as a group. Python:

def brilliant(ct):
  base = 1
  out = set()
  while True:

Generate one digit-count's worth of primes (e.g. 1..9, 10..99, etc.)

    pl = [x for x in genprimes(base * 10) if x >= base]

Doubly iterate over the range, for each distinct multiplicative combination.

    for ai in range(len(pl)):
      for bi in range(ai,len(pl)):
        out.add(pl[ai] * pl[bi])

If I've got enough results, leave and process them.

    if len(out) >= ct:
      break

Otherwise, add a digit and continue.

    base *= 10

Convert the results into a list, sort it, and return the first ct entries of it.

  o = list(out)
  o.sort()
  return o[0:ct]

Task 2: Achilles Numbers

Write a script to generate first 20 Achilles Numbers.

These are numbers which are powerful (prime factorisation has no terms of power = 1) but imperfect (are not a perfect power, i.e. have no integer roots).

This can be resolved purely by looking at the exponents of the prime factorisation:

  • there must be at least two terms

  • the lowest term must be at least 2

  • the greatest common divisor of the terms is 1

I already have prime factorisation code, and indeed for the languages that don't have it built in (most of them) a gcd function. Raku:

sub achilles($ct) {

Initialise output list and candidate.

    my @o;
    my $n = 1;
    while (True) {

Increment candidate.

        $n++;

Get the list of exponents.

        my @pv = primefactor($n).values;

If there are at least two terms, and

        if (@pv.elems > 1 &&

the lowest term is at least 2, and

            min(@pv) >= 2 &&

the gcd is 1 (using the syntax for a built-in infix operator)

            @pv.reduce(&infix:<gcd>) == 1) {

then this is a valid Achilles number. If we have enough, exit.

            push @o,$n;
            if (@o.elems >= $ct) {
                last;
            }
        }
    }
    return @o;
}

Full code on github.

See also:
The Weekly Challenge 167: Circling the Gamma

Comments on this post are now closed. If you have particular grounds for adding a late comment, comment on a more recent post quoting the URL of this one.

Search
Archive
Tags 1920s 1930s 1940s 1950s 1960s 1970s 1980s 1990s 2000s 2010s 3d printing action aeronautics aikakirja anecdote animation anime army astronomy audio audio tech aviation base commerce battletech beer boardgaming book of the week bookmonth chain of command children chris chronicle church of no redeeming virtues cold war comedy computing contemporary cornish smuggler cosmic encounter coup covid-19 crime cycling dead of winter doctor who documentary drama driving drone ecchi economics espionage essen 2015 essen 2016 essen 2017 essen 2018 essen 2019 essen 2022 existential risk falklands war fandom fanfic fantasy feminism film firefly first world war flash point flight simulation food garmin drive gazebo genesys geocaching geodata gin gkp gurps gurps 101 gus harpoon historical history horror hugo 2014 hugo 2015 hugo 2016 hugo 2017 hugo 2018 hugo 2019 hugo 2020 hugo 2022 hugo-nebula reread in brief avoid instrumented life javascript julian simpson julie enfield kickstarter kotlin learn to play leaving earth linux liquor lovecraftiana lua mecha men with beards museum music mystery naval noir non-fiction one for the brow opera parody paul temple perl perl weekly challenge photography podcast politics postscript powers prediction privacy project woolsack pyracantha python quantum rail raku ranting raspberry pi reading reading boardgames social real life restaurant reviews romance rpg a day rpgs ruby rust science fiction scythe second world war security shipwreck simutrans smartphone south atlantic war squaddies stationery steampunk stuarts suburbia superheroes suspense television the resistance the weekly challenge thirsty meeples thriller tin soldier torg toys trailers travel type 26 type 31 type 45 vietnam war war wargaming weather wives and sweethearts writing about writing x-wing young adult
Special All book reviews, All film reviews
Produced by aikakirja v0.1