RogerBW's Blog

The Weekly Challenge 356: Kolakoski Wins 18 January 2026

I’ve been doing the Weekly Challenges. The latest involved sequence generation and sports score analysis. (Note that this ends today.) Only a few languages this time, since I was doing other things over Christmas.

Task 1: Kolakoski Sequence

You are given an integer, $int > 3.

Write a script to generate the Kolakoski Sequence of given length $int and return the count of 1 in the generated sequence. Please follow the wikipedia page for more informations.

This is a fiddly one, a sort of self-describing sequence: term N (starting at 1) is the length of the Nth run of identical values, and all values must be 1 or 2.

So given an initial 1, the first run must be of length 1, so the next term is 2. That means the next run is of length 2, so so far we have 1, 2, 2, 1. The next run will also be of length 2, and it starts with that last 1, so we have 1, 2, 2, 1, 1, 2. And so on.

Since this is always to a set length, I could use a fixed-length array. Raku:

sub magicalstring($a) {

Initialise the sequence.

  my @s = 0 xx ($a * 2);
  @s[0] = 1;

Set last value, sequence index, and new entry position.

  my $l = 1;
  my $n = 0;
  my $ic = 0;

We only need a entries in the sequence.

  while ($ic < $a) {

If it's a run of 2, insert a value after the current one.

    if (@s[$n] == 2) {
      @s[$ic + 1] = $l;
      $ic++;
    }

Flip to the alternate value, and insert that.

    $l = 3 - $l;
    $ic++;
    @s[$ic] = $l;

Increment the sequence index.

    $n++;
  }

Prune the list (in case any extra values were generated) and count 1s.

  splice @s, $a;
  @s.grep({$_ == 1}).elems;
}

Task 2: Who Wins

It's NFL playoff time. Since the 2020 season, seven teams from each of the league's two conferences (AFC and NFC) qualify for the playoffs based on regular season winning percentage, with a tie-breaking procedure if required. The top team in each conference receives a first-round bye, automatically advancing to the second round.

The following games are played. Some times the games are played in a different order. To make things easier, assume the order is always as below.

Week 1: Wild card playoffs

  • Team 1 gets a bye
    • Game 1: Team 2 hosts Team 7
    • Game 2: Team 3 hosts Team 6
    • Game 3: Team 4 hosts Team 5
  • Week 2: Divisional playoffs
    • Game 4: Team 1 hosts the third seeded winner from the previous week.
    • Game 5: The highest seeded winner from the previous week hosts the second seeded winner.
  • Week 3: Conference final
    • Game 6: The highest seeded winner from the previous week hosts the other wommer You are given a six character string containing only H (home) and A away which has the winner of each game. Which two teams competed in the the conference final and who won?

I built this one with a hashset for each round's participants. In Rust:

fn whowins(a: &str) -> String {
    let mut round2 = HashSet::new();
    let mut round3 = HashSet::new();
    for (i, c) in a.chars().enumerate() {
        match i {

Game 1, team 2 or team 7.

            0 => {
                if c == 'H' {
                    round2.insert(2);
                } else {
                    round2.insert(7);
                }
            }

Game 2, team 3 or team 6.

            1 => {
                if c == 'H' {
                    round2.insert(3);
                } else {
                    round2.insert(6);
                }
            }

Game 3, team 4 or team 5.

            2 => {
                if c == 'H' {
                    round2.insert(4);
                } else {
                    round2.insert(5);
                }
            }

Game 4, team 1 or highest-numbered participant in round 2.

            3 => {
                if c == 'H' {
                    round3.insert(1);
                } else {
                    round3.insert(*round2.iter().max().unwrap());
                }
            }

Game 5, one of the other participants in round 2.

            4 => {
                let mut k = round2.iter().collect::<Vec<_>>();
                k.sort();
                let _ = k.pop();
                if c == 'H' {
                    round3.insert(*k[0]);
                } else {
                    round3.insert(*k[1]);
                }
            }

Game 6, one of the participants in round 3.

            5 => {
                let mut k = round3.iter().collect::<Vec<_>>();
                k.sort();
                if c == 'H' {
                    return format!("Team {} defeated Team {}", k[0], k[1]);
                } else {
                    return format!("Team {} defeated Team {}", k[1], k[0]);
                }
            }
            _ => {}
        };
    }
    String::new()
}

Full code on github.

Add A Comment

Your Name
Your Email
Your Comment

Note that I will only approve comments that relate to the blog post itself, not ones that relate only to previous comments. This is to ensure that the blog remains outside the scope of the UK's Online Safety Act (2023).

Your submission will be ignored if any field is left blank, but your email address will not be displayed. Comments will be processed through markdown.

Search
Archive
Tags 1920s 1930s 1940s 1950s 1960s 1970s 1980s 1990s 2000s 2010s 2300ad 3d printing action advent of code aeronautics aikakirja anecdote animation anime army astronomy audio audio tech aviation base commerce battletech bayern 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 crystal cthulhu eternal cycling dead of winter disaster doctor who documentary drama driving drone ecchi economics en garde espionage essen 2015 essen 2016 essen 2017 essen 2018 essen 2019 essen 2022 essen 2023 essen 2024 essen 2025 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 horrorm science fiction hugo 2014 hugo 2015 hugo 2016 hugo 2017 hugo 2018 hugo 2019 hugo 2020 hugo 2021 hugo 2022 hugo 2023 hugo 2024 hugo 2025 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 mpd museum music mystery naval noir non-fiction one for the brow openscad opera parody paul temple perl perl weekly challenge photography podcast poetry politics postscript powers prediction privacy project woolsack pyracantha python quantum rail raku ranting raspberry pi reading reading boardgames social real life restaurant review reviews romance rpg a day rpgs ruby rust scala 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 typst 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