Got the Classic from two weeks ago correct, although I hadn’t got the closed-form solution; I needed to spend more time playing with toy examples, but I’m not sure I would have discerned the pattern anyway. It’s neat though.
This week’s Express is not too difficult (please don’t let me get it wrong!). The thing that surprised me on thinking about it is that the total number of combinations of shires is only 1024. That’s 210, since there are 10 shires, each of which can be in or out of any particular subset.
Half of the possibles combinations of shires don’t have enough votes to win, and of those combinations that do, many of them could lose a shire and still win, so they can be ignored as well.
My 33 lines of code will print out an answer in about a millisecond. I assume in Haskell it could be done in about four lines! I should take a look at that language sometime.
In Riddler City, the city streets follow a grid layout, running north-south and east-west. You’re driving north when you decide to play a little game. Every time you reach an intersection, you randomly turn left or right, each with a 50 percent chance.
After driving through 10 intersections, what is the probability that you are still driving north?
I take an interest in what the UK’s Office for National Statistics puts out, especially around employment and the economy. I’m also learning Jupyter and the Python DS tools, so I’ve taken one of their data series and tidied it up to use in Pandas.
Per Wikipedia, the Mandelbrot set is the set of complex numbers for which the a particular function does not diverge from the origin when iterated. The particular function is: fc(z) = z2 + c
The important facts are that the space is the complex plane, and the colour-coding normally seen corresponds to the number of iterations required for the new value of c to be seen to diverge (have an absolute value above 4). My code for checking and colouring was:
def iter_score(re, im): x = 0 y = 0 iters = -1 while iters < ITERATION_LIMIT and x * x + y * y < 4: next_x = x * x - y * y + re y = 2 * x * y + im x = next_x iters += 1 return iter
Could have been more inventive on the colouring, or at least switched the rendering to greyscale. As it is, it’s RGB, but only giving greys:
Main Python note was the issue around getting PyPNG installed so I could “import png”. Perhaps nor surprisingly, it matters which environment is active when you pip-install something. Presumably the environment includes an indicator of which packages are installed (perhaps a directory name?). Anyway, installing a package with the conda environment running doesn’t help when you’re trying to use the package in PyCharm with its own venv! Lesson learned.
Someone asked me recently about managing outsourced piecework, where people outside your company are paid by the number of tasks performed. I did this on various projects for over a year with a previous employer. Our trial-and-error approach had quite a few errors, but we did eventually establish a stable system. This is an outline of that successful system, with a few notes about things we tried that didn’t work.