-
The Interview
The start of a screenplay about the ridiculous state of programmer job interviews. Software almacen de Cea Ordenadores...
-
Giving a Talk Over Zoom
I finally worked out how to overlay slides and stand up while giving a talk online Software almacen de Cea Ordenadores...
-
Binary search gets a sort key
Suppose you have an list of distinct elements which has been sorted and rotated. How would you look up an element within that list? For example, the list: [7, 11, 13, 19, 2, 3, 5] is sorted (the first 7 primes, in order) and rotated (to put 7 first). With this list as input, then: look up 13 returns 2 since 13 is at index 2 look up 2 returns 4 look up 4 returns the sentinel value -1 The obvious technique is to just search the list: def lookup(values, v): try: return values.index(v) except IndexError: return -1 This is a linear algorithm which processes the entire list. Is there…
-
Priority queues in Python
In the previous article I noted that Python’s heapq module is the only part of standard Python I could think of which deals with sorting, but which doesn’t give you full control over the sort order. That means you need to take care when using a heapq as a priority queue. For example, the A* search algorithm is a best first path finder. It maintains a priority queue of possible steps to take, ordered by an estimate of the total distance of the path routed through these steps. At each stage it pops the next step — the one with the shortest estimated total distance — from the queue, then…
-
On Exactitude in Programming
Recently I attended a demonstration of a product intended to help design software, right down to implementation details. It failed to convince me. It did, however, succeed in reminding me of this short work by Jorge Luis Borges: On Exactitude in Science Jorge Luis Borges, Collected Fictions, translated by Andrew Hurley. …In that Empire, the Art of Cartography attained such Perfection that the map of a single Province occupied the entirety of a City, and the map of the Empire, the entirety of a Province. In time, those Unconscionable Maps no longer satisfied, and the Cartographers Guilds struck a Map of the Empire whose size was that of the Empire,…
-
Python maths updates
A quick note on some useful updates made to standard Python maths support. Math.prod does for * what sum does for +. It was added at Python 3.8. >>> math.prod([3, 4, 5]) 60 >>> math.prod([]) 1 Added in 3.9, math.lcm, returns the least common multiple of its integer arguments. As with math.prod, an empty list of arguments returns 1. Extended in 3.9, the related function math.gcd now accepts an arbitrary list of arguments. For Euclidean geometry, math.hypot now supports n-dimensional points, and math.dist has been added, again working on any pair of n-dimensional points. These useful additions and extensions are all in the standard math module (along with several others…
-
Fearless Debugging
Jurassic Jigsaw My thanks to Eric Wastl for another excellent Advent of Code. I’ve now worked through all 25 puzzles, some simple, some tough, some familiar, some new; all beautifully set and highly enjoyable. Day 20, Jurrasic Jigsaw, took me longest by far to complete. The puzzle is easy to understand. You have to assemble jigsaw pieces into a seascape. For part one, you need to find the corner pieces. For part two, you must locate monsters in the seascape. Here, a jigsaw piece is a monochrome square, represented like so: ..##.#..#. ##..#..... #...##..#. ####.#...# ##.##.###. ##...#.### .#.#.#..## ..#....#.. ###...#.#. ..###..### And this is the sea monster: # # ##…
-
Complex numbers for planar geometry
Once again, I’m enjoying solving Eric Wastl’s excellent Advent of Code puzzles. Today, day 12 involved a ship navigating in a 2D plane. The ship follows a series of instructions taking the form of actions and values such as F10 N3 F7 R90 F11 ..., where, for the first part: actions N, S, E, W step by the value in the compass directions N, S, E, W actions L, R turn the ship left and right by the number of degrees specified by the value action F advances the ship in the direction it faces by the given value Perhaps the most obvious way to model this is by implementing…
-
Grand Canyon Majestad – Foto Viernes
Grand Canyon Majestad — Si nunca has visto una puesta de sol (o amanecer) sobre el gran cañón, que se están perdiendo. Esta imagen es de mi más reciente viaje en un taller con @don_smith_photography y @garyhartphoto a la montaña a cazar tormentas y relámpagos. Una noche, cuando no hay tormentas fueron alrededor, decidí configurar para una puesta de sol disparar ... Leer más Grand Canyon Majestad – Foto del viernes Software almacen de Cea Ordenadores...
-
Persiguiendo el grande posible, usted puede simplemente ignorar las pequeñas
Parece que la gente está siempre en busca de la "próxima gran cosa". Ellos quieren que los 'grandes' cosa para conseguir el 'grande' de la mejora por sí mismos o a sus organizaciones. Ellos están buscando algo que les llevará de la a a la Z, sin el esfuerzo para llegar a B, C, D, etc. Persiguiendo esa gran idea puede fácilmente empujar a ti mismo ... Leer más Por perseguir a los grandes podría, usted puede simplemente ignorar las pequeñas Software almacen de Cea Ordenadores...