Check my working (Musings)https://checkmyworking.com/en© 2010-2023 <a href="https://somethingorotherwhatever.com">Christian Lawson-Perfect</a> Fri, 08 Dec 2023 08:54:27 GMTNikola (getnikola.com)http://blogs.law.harvard.edu/tech/rss- This site is now sort of statichttps://checkmyworking.com/2016/11/this-site-is-now-sort-of-static/Christian Lawson-Perfect<p>checkmyworking.com has always been powered by WordPress, but every now and then it’s fallen victim to annoying hacks that manage to write some spam nonsense at the top of all my PHP files. From what I can tell, WordPress and the few plugins I use are such a labyrinthine mess of code that going through and closing security vulnerabilities would be a sisyphean task.</p>
<p>So, I’ve taken the nuclear option – this site, as served to the wider web, is now entirely made up of static files. Hopefully, that’ll stop the hacks – there’s no PHP to abuse, leaving only any vulnerabillities in Apache or Media Temple’s account management as potential ways of getting in.</p>
<p>The static files are generated by <a href="http://spress.yosymfony.com/">Spress</a>, which seems to be one of the least opinionated static site generators I’ve come across. It was very easy to make it produce pretty much exactly the same pages WordPress does.</p>
<p>I still wanted the nice editing interface WordPress provides, so I’ve made a plugin which exports posts from WordPress to the Spress source directory whenever I update them. I’ve got the WordPress installation hidden somewhere private, behind a very simple login script which stands in the way to make sure that nobody else can run WordPress code. This way, I can write posts in WordPress, and the plugin automatically rebuilds the site for me. The one compromise is that I can’t do comments any more – my current line of thought is that I’ll write a script to add comments to the WordPress database which would be simple enough to satisfy myself that it’s more secure than going through WordPress itself.</p>
<p>For the moment I’ve kept the layout of the site as it was, but it’s looking very old now so I’d like to redo it at some point. I don’t really post here any more, so it’s entirely possible that this’ll still be the top post in a few years’ time.</p>
<p>Next job is to do the same thing to <a href="http://aperiodical.com/">The Aperiodical</a>, which will take a lot more work!</p>musingshttps://checkmyworking.com/2016/11/this-site-is-now-sort-of-static/Tue, 29 Nov 2016 00:00:00 GMT
- All my new businesses!https://checkmyworking.com/2013/02/all-my-new-businesses/Christian Lawson-Perfect<p>I don’t mention it much, but I’m an entrepreneurial, go-get-’em, many-irons-in-the-fire, have-my-people-call-your-people kind of guy! Barely a day goes by when I don’t start a new business with a choice punning name and announce it on Twitter.</p>
<p>Twitter just switched the switch to let me download my tweets archive, so I immediately did that and grepped it for my many many new business names. Here they are:</p>
<p>
<!-- TEASER_END -->
</p>
<p><a href="https://twitter.com/christianp/status/307017618051723264">Buying jangly things for my new sensory stimulation and meditation chamber, “We have nothing to hear but here itself”</a></p>
<p><a href="https://twitter.com/christianp/status/304000582690160640">Locating premises for my new Newcastle-based cutlery steam-cleaning service, “Fog on the Tine”</a></p>
<p><a href="https://twitter.com/christianp/status/303486303725563904">Buying tiger balm for my new physiotherapy practice in Gosforth, “Knee Bother”</a></p>
<p><a href="http://twitter.com/christianp/statuses/300259772446412800">Buying cages for my new exotic birds shop, “Super Mario Plovers”</a></p>
<p><a href="http://twitter.com/christianp/statuses/296974605955002370">Buying a PRS licence for my new musical instruments shop, “If you’ve got it: flautist.”</a></p>
<p><a href="http://twitter.com/christianp/statuses/295972238069485568">Getting security clearance for my new spa strictly for defence officials, Intercontinental Holistic Missile.</a></p>
<p><a href="http://twitter.com/christianp/statuses/292199171673423872">Acquiring a PRS licence for my new cellar bar under the Newton Institute, “Fermat’s Last Beer-Room”</a></p>
<p><a href="http://twitter.com/christianp/statuses/290423205473177600">“The customer is always right.” That’s something we strongly believe in at my new pest extermination company, Sick Of Ants</a></p>
<p><a href="http://twitter.com/christianp/statuses/284310995466330113">Hiring bar staff for my new underground opera hall, “Grotto Voce”</a></p>
<p><a href="http://twitter.com/christianp/statuses/283899424265093120">Scouting for locations for my new concept café with a chess board at every table, “En Croissant”.</a></p>
<p><a href="http://twitter.com/christianp/statuses/281109739264413696">Buying stock for my new kids’ clothing shop, Newcastle upon Tiny.</a></p>
<p><a href="http://twitter.com/christianp/statuses/273916348848013313">Soupremum. Simpleggs. Identitea. All on the menu at my new mathematical bistrho.</a></p>
<p><a href="http://twitter.com/christianp/statuses/267995627076583424">Trying to get Fearne Cotton to endorse my new back scratcher design. I’ll call it the Fearne Itcher.</a></p>
<p><a href="http://twitter.com/christianp/statuses/246911364763881472">In Chinatown looking for premises for my new laser hair removal business, Singe-A-Pore</a></p>
<p><a href="http://twitter.com/christianp/statuses/238315230533406720">looking for angel investors for my new estate agency specialising in flipping run-down urban homes: Quain’t.</a></p>
<p><a href="http://twitter.com/christianp/statuses/232453674415296512">seeking funders for my new-Romantic fireworks show, “Sturm und Bang”.</a></p>
<p><a href="http://twitter.com/christianp/statuses/209722377364447232">now taking orders for my new range of Provençal crockery, S’il te Plate.</a></p>
<p><a href="http://twitter.com/christianp/statuses/184616066406821888">please buy my new range of plates featuring images of the abyss, a navel, the circle of life and the night sky: “ContemPlates”</a></p>
<p><a href="http://twitter.com/christianp/statuses/133247792381571072">looking for investors in my new chain of kosher Argentinian steakhouses, “Gaucho Marx”</a></p>
<p><a href="http://twitter.com/christianp/statuses/79473422803025920">Lost a favourite mallard recently? Then come down to my new duck cloning service, Quacksimile!</a></p>
<p><a href="https://twitter.com/christianp/status/343010268349079554">Meeting the pope later to discuss my idea for a convent based on an airship, called “Nun of the Above”</a></p>
<p><a href="https://twitter.com/christianp/status/345960627946266624">Drawing up a health and safety plan for my new plush toy cleaning service, Teddy Gross Felt</a></p>
<p><a href="https://twitter.com/christianp/status/347762285869154304">Flying to Wyoming to scout locations for my new convalescence home for introverts, Cheyenne Retiring</a></p>
<p><a href="https://twitter.com/christianp/status/401764884419207168">Buying leather and painting everything black for my new wedding parlour for goths, “Doom and Groom”.</a></p>
<p><a href="https://twitter.com/christianp/status/475955227129286656">Finalising the tasting menu at my new restaurant focused on taboo meats, “Horses, Four Courses”</a></p>
<p>Well, <em>I</em> like them.</p>musingshttps://checkmyworking.com/2013/02/all-my-new-businesses/Sat, 16 Feb 2013 00:00:00 GMT
- Some of my old BlitzMax gameshttps://checkmyworking.com/2013/01/some-of-my-old-blitzmax-games/Christian Lawson-Perfect<p>When I was in school I used to spend a lot of my time making games in Blitz Basic (and later BlitzMax). Eventually, as I got older and more boring, I ran out of ideas and started doing other things. I haven’t sat down and made a satisfying game in years. I used to really enjoy it though, and I made some things that I really liked. I used to think that maybe I would be a trendy game designer one day.</p>
<p>I was thinking about that this morning, so I decided to go through and play a few of my old games. I feel just as much a need to show them off now as I did when I made them, so I’ve recorded a few screencasts. Camtasia broke for Unknown Reasons and it turns out Jing is sort of terrible at recording games, so they’re really jerky and the volume’s quite low, but I’m not going to not share them now I’ve made them.</p>
<p>Here they are:</p>
<ul>
<li><a href="http://somethingorotherwhatever.com/blitzvideos/bubblyworlds.swf">Bubble worlds</a></li>
<li><a href="http://somethingorotherwhatever.com/blitzvideos/poption.swf">Poption</a></li>
<li><a href="http://somethingorotherwhatever.com/blitzvideos/trenchant.swf">Trenchant</a></li>
<li><a href="http://somethingorotherwhatever.com/blitzvideos/others.swf">Others</a></li>
</ul>
<p>I’m quite disappointed that a few of my favourites didn’t run. I’m sure if I recompiled them they’d work. All of my code is in <a href="https://github.com/christianp/warpycode">a repository on github</a>, and compiled versions of everything are on my original homepage, <a href="http://somethingorotherwhatever.com/">somethingorotherwhatever.com</a>. Here’s a list of links to the ones that work at least a little bit:</p>
<p><a href="http://somethingorotherwhatever.com/?thing=trenchant">Trenchant</a>, <a href="http://somethingorotherwhatever.com/?thing=poption">Poption</a>, <a href="http://somethingorotherwhatever.com/?thing=fencing">Fencing</a>, <a href="http://somethingorotherwhatever.com/?thing=bubbleworlds">Bubble worlds</a>, <a href="http://somethingorotherwhatever.com/?thing=trader">Trader</a>, <a href="http://somethingorotherwhatever.com/?thing=schroedingersghost">Schroedinger’s Ghost</a>, <a href="http://somethingorotherwhatever.com/?thing=beards">Beards</a>, <a href="http://somethingorotherwhatever.com/?thing=rowing">Rowing</a>, <a href="http://somethingorotherwhatever.com/?thing=surroundemup">Surroundemup</a>, <a href="http://somethingorotherwhatever.com/?thing=clockworkshooter">Clockwork Shooter</a>, <a href="http://somethingorotherwhatever.com/?thing=schizoman">Schizophrenic Pacman</a>, <a href="http://somethingorotherwhatever.com/?thing=museum">Museum</a>, <a href="http://somethingorotherwhatever.com/?thing=horsey">Horsey</a> (<a href="http://monkeycoder.co.nz/Community/topics.php?forum=1011&app_id=11">browser version</a>), <a href="http://somethingorotherwhatever.com/?thing=kleinsteroids">Kleinsteroids</a></p>musingsvideoshttps://checkmyworking.com/2013/01/some-of-my-old-blitzmax-games/Fri, 04 Jan 2013 00:00:00 GMT
- A huggermuggering nonannouncement of an overinvolved knickknackhttps://checkmyworking.com/2012/06/a-huggermuggering-nonannouncement-of-an-overinvolved-knickknack/Christian Lawson-Perfect<p>It’s odd, the process of waking up. Sometimes you can get out of bed and stumble around for an hour or two, maybe even get dressed and go to work, before your brain does anything to differentiate you from a patient in a highly mobile vegetative state. On other days it seems that your mental starter motor catches on the first try and before you’ve even opened your eyes all sorts of brilliantly original thoughts are competing for attention.</p>
<p>Today is one of those days. As I swung my big long legs out of bed the thought occurred to me that the word “cheese” has an awful lot of <em>E</em>s in it. (“Brilliantly original” is of course a subjective description, but this is my story so I say it qualifies). I wondered what word has the most <em>E</em>s in it. Now we’re beginning to move towards a decent notion.
<!-- TEASER_END -->
</p>
<p>After a little bit of coding, I can tell you that the English word with the most <em>E</em>s in it is <em>electrotelethermometer</em>. What a nice word! It bounces along so pleasantly. I bet it’s the letter E’s favourite word, or its biggest fan.</p>
<p>So I got my program to work out the other letters’ favourite words. I was expecting a lot of unappealing scientific words, and there are a few of those, but there are some alliterationist’s dreams, like <em>beblubber</em> and <em>pipestapple</em> and <em>taramasalata</em>. The word list I used has a lot of very uncommon words with dubious credentials, but they’re fun anyway. For example, I now know there’s a mountain called <a href="http://id.wikipedia.org/wiki/Pegunungan_Jayawijaya"><em>Pegunungan jajawijaja</em></a> (<em>jajawijaya</em> according to Wikipedia) in Indonesia, and one called <em><a href="http://en.wikipedia.org/wiki/Llullaillaco">Llullaillaco</a> </em>in the Atacama desert. I had to remove <a href="http://en.wikipedia.org/wiki/Llanfairpwllgwyngyll"><em>Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch</em></a> from the list because it was the favourite word of three different letters.</p>
<p>So, without further ado, here’s my list of each letter and its biggest fans:</p>
<p><strong>a (6):</strong> astragalocalcaneal, calcaneoastragalar, taramasalata<br>
<strong>b (4):</strong> beblubber, beerbibber, bubblebow, bubbybush, bumblebomb, flibbertigibbet, gibblegabble, nabobrynabobs<br>
<strong>c (6):</strong> micrococcocci, pneumonoultramicroscopicsilicovolcanoconioses, pneumonoultramicroscopicsilicovolcanoconiosis<br>
<strong>d (5):</strong> disdodecahedroid, dunderheadededness, fuddy-duddy<br>
<strong>e (7):</strong> electrotelethermometer, ethylenediaminetetraacetate<br>
<strong>f (4):</strong> chiffchaff, cuffuffle, cuffuffled, giffgaff, niffnaff, riffraff, tufftaffeta<br>
<strong>g (5):</strong> huggermuggering<br>
<strong>h (4):</strong> chichihaerh, choledochorrhaphy, chromophotolithograph, dichlorodiphenyltrichloroethane, hochhuth, ichthyophthalmite, ichthyophthiriasis, ichthyophthirius, ophthalmophthisis, phenolsulphonephthalein, photochromolithograph, rhamphorhynchus, shihchiachuang, thymolsulphonephthalein<br>
<strong>i (9):</strong> floccinaucinihilipilification<br>
<strong>j (4):</strong> jajawijaja<br>
<strong>k (4):</strong> akiskemikinik, kakkak, knickknack<br>
<strong>l (6):</strong> llullaillaco<br>
<strong>m (4):</strong> dynamometamorphism, hamamelidanthemum, immunocompromised, mammatocumulus, mammectomies, mammectomy, mammiform, mammilliform, mammogram, mammondom, mammonism, mammothermography, mammotomy, melammdim, mercuriammonium, mesembrianthemum, metagrammatism, metalammonium, methylenedioxymethamphetamine, mohammadanism, mohammedanism, monoammonium, muhammadanism, multimammate, mummiform, mummydom, tetramethylammonium, thalamomammillary, theomammomist, thermometamorphism<br>
<strong>n (6):</strong> nonannouncement, noncondescendingness<br>
<strong>o (9):</strong> pneumonoultramicroscopicsilicovolcanoconiosis<br>
<strong>p (4):</strong> aplopappus, haplopappus, hippopotomonstrosesquipedalian, hyperleptoprosopic, hypophypophysism, pepperproof, philippopolis, pimperlimpimp, pipestapple, pippapasses, posthippocampal, preapperception, proappropriation, protopappas, snippersnapper, uppropped, whippersnapper<br>
<strong>q (2):</strong> abqaiq, albuquerque, chiquichiqui, chiquinquira, circumquaque, colloquiquia, equivoque, harlequinesque, iquique, qaimaqam, qepiq, qiqihar, quadratosquamosal, quadriquadric, quaequae, quaquaversal, quasqueton, quasquicentennial, quelquechose, quiaquia, quinquagenarian, quirquincho, quisquous, quitaque, saqqara, semiquinquefid, seqq, sesquiquadrate, subquinquefid, tuquoque, zaqaziq, zaqqum<br>
<strong>r (4):</strong> archcorrupter, archmurderer, archtreasurer, armourbearer, arteriopressor, arteriorrhagia, arthrorrhagia, barothermohygrogram, briarberry, burrgrailer, cardiorespiratory, carryforward, circumterrestrial, corroborator, counterreformer, counterterror, crackerberry, erythrorrhexis, extracurricular, extraterrestrial, extraterritorial, ferroconcretor, ferrosoferric, forrarder, gastrohydrorrhea, gastrohysterorrhaphy, gerrymanderer, herrerasaur, horrormonger, hydrochlorofluorocarbon, hydroxydehydrocorticosterone, hyperterrestrial, infraterritorial, intercarrier, interterritorial, intertransversary, intraterritorial, kerrikerri, merrytrotter, microprogrammer, microrefractometer, narcoterrorism, noncorroboratory, partridgeberry, pericardiorrhaphy, precorridor, precurrer, preferrer, prehorror, prereferred, prereformatory, presurrender, preterregular, preterrestrial, preterritorial, preterscriptural,<br>
procarrier, prosurrender, protreasurer, pyrotritartric, pyrroporphyrin, rearranger, recarburizer, recarrier, recurrer, recurvirostra, referrer, refrigerator, rehrersburg, remirror, reperforator, reprographer, reredorter, resurrector, resurrender, retransferred, retroauricular, retrogradatory, retropresbyteral, retroreflector, retroserrate, retrotransfer, reverberator, rhyparographer, riroriro, ruppertsberger, semireverberatory, serrirostrate, serrurerie, straightforwarder, superarbitrary, supercarrier, superterrestrial, surrenderer, tartratoferric, terroriser, terrorproof, tetrahydropyrrole, thyrorroria, tirralirra, tirrwirr, transferrer, trinitroresorcin, turbosupercharger, ultraterrestrial, uncorroboratory, underperformer, underroarer, undersorcerer, underterrestrial, undertreasurer, ureteroradiography, ureterorrhagia, ureterorrhaphy, urethroblennorrhea, vertebroarterial, worcesterberry<br>
<strong>s (8):</strong> possessionlessness, stresslessnesses, successlessnesses<br>
<strong>t (5):</strong> anticonstitutionalist, antiinstitutionalist, counterattestation, ethylenediaminetetraacetate, hastatosagittate, intersubstitutability, tetrasubstitution, throttlebottoms, totipotentiality, transubstantiationist, turbinatostipitate, yttrotantalite<br>
<strong>u (9):</strong> humuhumunukunukuapuaa<br>
<strong>v (3):</strong> evviva, overconservative, overinvolve, oversurviving, overvivid, ovovivipara, vaginovulvar, vivarvaria, vivificative, vivisective, vulvovaginal<br>
<strong>w (3):</strong> bowwow, powwow, swallowwort, weewow, westnorthwestwardly, whillywhaw, whitlowwort, williwaw, willowware, willowweed, willowwood, willowworm, willowwort, willywaw, windowward, windwayward, www<br>
<strong>x (3):</strong> hexahydroxycyclohexane<br>
<strong>y (4):</strong> dacryocystosyringotomy, hyperpolysyllabically, polyhydroxybutyrate<br>
<strong>z (4):</strong> pizzazz, razzamatazz</p>
<p>And <a href="http://somethingorotherwhatever.com/faveletters.py">here’s the code that produced it</a>. If you don’t like the number of uncommon words I’ve used, you can run it on your own list. I did a bit of editing by hand after the script finished, to remove alternative forms of the same word as well a load of words beginning <em>quinque-</em> because there were far, far too many. The most disappointing thing is that I didn’t have a word with more than two <em>Q</em>s in it. If you know one, please tell me!</p>musingshttps://checkmyworking.com/2012/06/a-huggermuggering-nonannouncement-of-an-overinvolved-knickknack/Sat, 16 Jun 2012 23:00:00 GMT
- Fibonacci Gridshttps://checkmyworking.com/2012/06/fibonacci-grids-2/Christian Lawson-Perfect<p>I uploaded this video to YouTube last week but I forgot to make a post here. It’s about a moderately interesting fact about fibonacci numbers that David Cushing told me at MathsJam. I generalised it a bit, so I’ve been meaning to write a post for The Aperiodical or do a snappy video or something like that for ages. </p>
<p>I finally decided last week to just sit down and record myself going through the proof, so here’s that video. I deliberately didn’t prepare beforehand, so it’s just under an hour long and contains a lot of thinking out loud.</p>
<p><span class="embed-youtube" style="text-align:center; display: block;"><iframe class="youtube-player" type="text/html" width="640" height="390" src="https://www.youtube.com/embed/MMttZbVymh4?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent" frameborder="0" allowfullscreen="true"></iframe></span></p>musingshttps://checkmyworking.com/2012/06/fibonacci-grids-2/Sat, 16 Jun 2012 23:00:00 GMT
- Converting a stream of binary digits to a stream of base \(n\) digitshttps://checkmyworking.com/2012/06/converting-a-stream-of-binary-digits-to-a-stream-of-base-n-digits/Christian Lawson-Perfect<p>James Coglan asked on twitter:</p>
<p>https://twitter.com/jcoglan/status/212163174626115584</p>
<p>https://twitter.com/jcoglan/status/212163325579108353</p>
<p>So you have an infinite stream of uniform random binary digits, and want to use it to produce an infinite stream of uniform random base \(n\) digits.</p>
<p>The obvious really easy way to do it is to find the smallest \(k\) such that \(2^k>=n\), and generate numbers in the range \(0 \dots 2^k-1\).</p>
<p>If the number you generate is less than \(n\), yield it, otherwise chuck it away.</p>
<p>This works, but has the problem that you might go a long time before you generate a number that you don’t throw away.</p>
<p>So what can we do with the numbers that are thrown away?</p>
<p>Subtract \(n\) from them, and use them as a stream of infinite base \((2^k-n)\) digits.</p>
<p>You can then do the same trick of generating enough of those digits until you can generate numbers greater than or equal to \(n\). Numbers less than \(n\) are yielded; otherwise, the trick is repeated yet again!
<!-- TEASER_END -->
</p>
<h3>Example</h3>
<p>Here’s an example, generating base \(5\) digits:</p>
<p>The smallest power of \(2\) greater than \(5\) is \(2^3 = 8\). So take digits from the binary stream three at a time.</p>
<p>There are three unusable numbers we can generate: \(5,6,7\). So subtract \(5\) from those, giving \(0,1\) or \(2\), and treat them as digits from a stream of base \(3\) digits.</p>
<p>The smallest power of \(3\) greater than \(5\) is \(3^2 = 9\), so take digits from that stream two at a time. Numbers \(5,6,7,8\) from that range can’t be used, so subtract \(5\) from them, giving \(0,1,2\) or \(3\), and treat them as base \(4\) digits.</p>
<p>The smallest power of \(4\) greater than \(5\) is \(4^2 = 16\), so take digits from that stream two at a time. The offcasts from that stream should be considered as base \(16-5 = 11\) digits. \(11\) is bigger than \(5\) already, so take digits from that stream one at a time.</p>
<p>The offcasts from the base \(11\) stream look like base \(6\) digits. There’s only one unusable number from that range — \(5\) — which doesn’t give you any information, so stop being clever at that point and throw away those numbers.</p>
<p>Now, let’s use the binary stream \(110101011111001\)</p>
<p>My first three digits give \(\operatorname{rand}(0\dots2^3) = 110_2 = 4+2+0 = 6.\) That’s not a base \(5\) digit, so add \(6-5 = 1\) to the stream of base \(3\) digits.</p>
<p>My next three digits give \(\operatorname{rand}(0\dots2^3) = 101_2 = 4+0+1 = 5.\) Again, that isn’t a base 5 digit, so add \(5-5 = 0\) to the stream of base \(3\) digits.</p>
<p>We now have two base 3 digits, \(1\) and \(0\), which means it yields \(\operatorname{rand}(0\dots3^2) = 10_3 = 3+0 = 3\). That’s in the range we want, so yield it.</p>
<p>Now we need to take three more binary digits: \(\operatorname{rand}(0\dots2^3) = 011_2 = 0+2+1 = 3.\) That’s in the range we want again, so yield it.</p>
<p>More binary: \(\operatorname{rand}(0\dots2^3) = 111_2 = 4+2+1 = 7.\) Too big, so add \(7-5 = 2\) to the base \(3\) stream.</p>
<p>\(\operatorname{rand}(0\dots2^3) = 001_2 = 1.\) That’s fine, so yield it.</p>
<p>At the moment, our stream of base \(5\) digits is \([3,3,1]\) and we have a \(2\) in the stream of base \(3\) digits. We can keep generating numbers like this indefinitely, and we hardly ever throw information away. It would probably take a lot more steps to get to the point where we use the bigger accumulators.</p>
<h3>Working code</h3>
<p>I’ve written some Python code which implements the algorithm above to produce an infinite stream of digits of any base, from a stream of binary digits provided by Python’s random module.</p>
[gist id=2911970 file=basestream.py]
<p>The Python code has some debug lines in it – turn those on to get a narration of what it does.</p>
<p>I hope that answers your question, James!</p>
<p>I should mention that this method is based on the first bit of <a href="http://www.quadibloc.com/crypto/mi060305.htm">this page</a>. I couldn’t think of the right words to use to find a proper crypto textbook on the subject, which must surely exist.</p>computationmusingshttps://checkmyworking.com/2012/06/converting-a-stream-of-binary-digits-to-a-stream-of-base-n-digits/Sun, 10 Jun 2012 23:00:00 GMT
- Problems I’m currently thinking abouthttps://checkmyworking.com/2012/06/problems-im-currently-thinking-about/Christian Lawson-Perfect<p>I’ve been in a bit of a problem-posing mood recently. Hopefully I’ll do some problem-solving soon. Here are a few questions I’ve thought of but haven’t got solutions for. I haven’t done any literature searching, so these might have been done before.</p>
<p>All the problems are quite computery. Maybe I’m a computer scientist, really.
<!-- TEASER_END -->
</p>
<h3>Problem 1: Reordering the alphabet</h3>
<p>What reordering of the letters of the alphabet contains the most (contiguous) English words? This is a big search space problem. I did a little bit of tinkering in python, trying first of all to find the single word which contains the most smaller words.</p>
<script src="https://gist.github.com/2907425.js?file=alphabat.py"></script><noscript><pre><code class="language-python python">import sys
import pickle
import operator
import itertools
alphabet = 'abcdefghijklmnopqrstuvwxyz'
#test if a word uses letters at most once
def monoglyphic(word):
word = sorted(word)
for i in range(1,len(word)):
if word[i]==word[i-1]:
return False
return True
#make forwards and backwards trees of words
#forwards has all substrings (x1,..,xn),(x2,..,xn),... (xn) for words (x1,...,xn)
#backwards has all substrings (xn),(xn,xn-1),...,(xn,...,x1)
#use to calculate word overlaps
def make_prefs():
forwards = {}
backwards = {}
for word in words:
fbase = forwards
bbase = backwards
l = len(word)
for i in range(0,l):
fbase,fbucket = fbase.setdefault(word[i],({},[]))
bbase,bbucket = bbase.setdefault(word[l-i-1],({},[]))
fbucket.append(word)
bbucket.append(word)
return (forwards,backwards)
def gather(base):
l = []
for b2,bucket in base.values():
l += bucket
l += gather(b2)
return l
#return all words which overlap with the left of word
#eg 'dog' overlaps with 'ogle'
def left_overlaps(word,backwards):
overlaps = []
l = len(word)
base = backwards
for i in range(l,0,-1):
base,bucket = base[word[i-1]]
w2 = bucket[0][:l-i]+word
if monoglyphic(w2):
overlaps += bucket
overlaps += gather(base)
return overlaps
#
def calc_subs():
subs = {}
for word in words:
d = subs[word] = []
l=len(word)
for i in range(0,l-1):
j=i
base=forwards
while j<l and word[j] in base:
base,bucket=base[word[j]]
d+=bucket
j+=1
d.sort()
return subs
#load words with no repeated letters
words = [word.strip() for word in open('monoglyphs.txt').readlines()]
#compute spelling trees forwards and backwards (for prefix/suffix overlaps)
forwards,backwards = make_prefs()
#for each word, calculate a list of all the subwords it contains
subs = calc_subs()
if __name__=='__main__':
#sort words by the number of words they contain
ranking = sorted([(word,len(subs[word])) for word in words],key=operator.itemgetter(1)) #operator.itemgetter(1) means sort by the second part of the tuple
print('Top words')
for word,score in ranking[-10:]:
print('%s %i' %(word,score))
word,score=ranking[-1]
print(word+' contains '+', '.join(subs[word]))</code></pre></noscript>
<p>The output: (I can only apologise for the rather rude result!)</p>
<script src="https://gist.github.com/2907425.js?file=output"></script><noscript><pre><code class="language- ">Top words
blameworthy 16
cabinetwork 16
clothespin 16
discourage 16
housewarming 16
malnourished 16
metalworking 16
unprofitable 16
filamentous 17
motherfucking 17
motherfucking contains fuck, fucking, he, her, i, in, kin, king, mot, moth, mother, motherfucking, o, other, r, the, u</code></pre></noscript>
<p>My current line of thinking is that if you draw out the complete graph on 26 vertices (one for each letter), words are paths on that, and the question is to find the Hamiltonian cycle which traces over the most complete paths. Not sure if that helps matters or not.</p>
<h3>Problem 2: graph symmetries</h3>
<p>Suppose you have a graph \(G\) and its automorphism group \(Aut(G)\). In particular, suppose you know all the “lines of symmetry” of the graph – pairs of edges around a vertex which can be swapped, or pairs of vertices at the ends of an edge which can be reflected.</p>
<p>If you add an edge (or a vertex) to the graph, can you work out how the automorphism group changes?</p>
<p>This is probably a problem for a) 5 minutes on google scholar, b) 5 minutes on mathoverflow, or c) 5 minutes’ thinking.</p>
<h3>Problem 3: A princess kidnapped by a robot on a graph</h3>
<p>This is a further generalisation of the <a href="https://checkmyworking.com/2011/12/solving-the-princess-on-a-graph-puzzle/">princess in a castle puzzle</a>. The princess still inhabits a graph, but the way she moves is changed. In the classic puzzle she could move to any adjacent room. What if her movements are determined by a nondeterministic finite state automaton? If you know how the automaton works but not its input, for which graphs can you catch the princess?</p>
<p>FSAs, if you don’t care about what the input is, are equivalent to directed graphs, and extending the princess on a graph puzzle to directed graphs is already hard enough. But that’s a bit of a red herring, because if you draw out the transition diagram of the FSA, where “room the princess is in” is an extra bit of state, you have multiple vertices for each room. That might make things easier or just more complicated.</p>musingshttps://checkmyworking.com/2012/06/problems-im-currently-thinking-about/Sat, 09 Jun 2012 23:00:00 GMT
- Visualising the wrong data on the Guardian data bloghttps://checkmyworking.com/2012/03/visualising-the-wrong-data-on-the-guardian-data-blog/Christian Lawson-Perfect<p style="text-align: center;"><a href="http://www.guardian.co.uk/news/datablog/2012/mar/19/minimum-wage-housing"><img class="aligncenter size-full wp-image-772" title="Housing minimum wage map" src="https://checkmyworking.com/images/Housing-minimum-wage-map-007.jpg" alt="" width="460" height="276" srcset="/images/Housing-minimum-wage-map-007.jpg 460w, /images/Housing-minimum-wage-map-007-300x180.jpg 300w" sizes="(max-width: 460px) 100vw, 460px"></a></p>
<p><a href="http://www.guardian.co.uk/news/datablog/2012/mar/19/minimum-wage-housing">This visualisation</a> shows for each council or unitary authority how many hours a week you’d need to work, earning minimum wage, in order to pay the median rent for a one-bed flat. The minimum wage is a national constant.</p>
<p>No justification is given for using the median rent. In a fair world, the median rent should be paid by someone on the median income. Assuming that people earning the minimum wage are the lowest earners ((this isn’t true: people earning cash in hand, for example, might earn less than the minimum wage but they still have an effect on house prices)) and make up X% of the population, then an upper bound for rent paid by people earning minimum wage should be the Xth percentile, if housing is provided fairly ((another large assumption.)). If you’re not paying attention to this kind of thing, you might as well just say “average” instead of “median”.</p>
<p>Finally, there’s this:</p>
<blockquote><p>Note that these figures are dramatic simplifications, used for illustrative purposes only: in reality tax payments, tax credits, housing benefit, council tax, utility bills and more substantially alter these figures.</p></blockquote>
<p>So the figures are meaningless anyway – benefits might be so generous that very little of the lowest earners’ pay goes towards housing, or taxes might be so high that people really need to work many more hours than this statistic claims in order to keep a house.</p>
<p>Supposing that all of these problems are sorted out and we calculate a reasonable-sounding number of hours to work to earn rent each week, what should that number be? What if house prices plummeted but food became very expensive? I can’t think what these numbers are telling us that raw rent data aren’t already.</p>
<p>A question has occurred to me: would I be making life worse for those worse off me by living in a flat cheaper than I should be or, on the other hand, would spending a higher than average proportion of my income on rent drive prices up, having an effect on the bottom end of the market? I suppose taking a cheaper flat reduces the prices of nicer ones. This is why I don’t like economics.</p>musingshttps://checkmyworking.com/2012/03/visualising-the-wrong-data-on-the-guardian-data-blog/Mon, 19 Mar 2012 00:00:00 GMT
- Using a zero-knowledge protocol to prove you can solve a sudokuhttps://checkmyworking.com/2012/03/using-a-zero-knowledge-protocol-to-prove-you-can-solve-a-sudoku/Christian Lawson-Perfect<p>I’ve just uploaded to youtube a video I made with <a href="http://twitter.com/#!/stecks">Katie Steckles</a> to demonstrate why zero-knowledge protocols exist and how one works.</p>
<p><span class="embed-youtube" style="text-align:center; display: block;"><iframe class="youtube-player" type="text/html" width="640" height="390" src="https://www.youtube.com/embed/i0sffXfDCUI?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent" frameborder="0" allowfullscreen="true"></iframe></span></p>
<p>Katie is a habitual liar, so we followed the zero-knowledge protocol described in the paper, “Cryptographic and Physical Zero-Knowledge Proof Systems for Solutions of Sudoku Puzzles” which you can download from <a dir="ltr" title="http://www.mit.edu/~rothblum/papers/sudoku.pdf" href="http://www.mit.edu/~rothblum/papers/sudoku.pdf" target="_blank" rel="nofollow">http://www.mit.edu/~rothblum/papers/sudoku.pdf</a></p>
<p>By following this protocol, Katie can prove that she isn’t lying to me about being able to solve the puzzle, without revealing anything about how she solved it.</p>
<p>The paper I mentioned, “How to explain zero-knowledge protocols to your children” is an excellent explanation of the ideas behind zero-knowledge proof. You can get it from <a dir="ltr" title="http://pages.cs.wisc.edu/~mkowalcz/628.pdf" href="http://pages.cs.wisc.edu/~mkowalcz/628.pdf" target="_blank" rel="nofollow">http://pages.cs.wisc.edu/~mkowalcz/628.pdf</a></p>musingsvideoshttps://checkmyworking.com/2012/03/using-a-zero-knowledge-protocol-to-prove-you-can-solve-a-sudoku/Sat, 10 Mar 2012 00:00:00 GMT
- Fractal dimension in IKEAhttps://checkmyworking.com/2012/02/fractal-dimension-in-ikea/Christian Lawson-Perfect<p>A long time ago, I realised that IKEA’s shopfitters must be experts in fractal dimension – they manage to lay out their shop so that you have to walk past every single thing they’re selling. You can’t just nip into IKEA – you have to go through the whole hour-long “It’s A Small World” of affordably wobbly furniture even if all you want is some kitchen utensils from the bit at the end.</p>
<p>I’d been meaning to add something about this to the Maths in the City site but it required going in to IKEA and taking a picture of their floor plan for illustration. I just remembered this morning that I’ve already taken one of those pictures, so I spent half an hour writing up this article – <a href="http://www.mathsinthecity.com/sites/fractal-dimension-ikea" target="_blank">Fractal Dimension in IKEA</a>.</p>musingshttps://checkmyworking.com/2012/02/fractal-dimension-in-ikea/Fri, 24 Feb 2012 00:00:00 GMT