Tab CompletionTab Atkins Jr.firstname.lastname@example.org://www.xanthir.comhttp://www.xanthir.com/2016-02-06T19:39:24+00:00All content is published in the public domain, or optionally may be licensed under the CC0 license.http://www.xanthir.com/b4fU0SpaceChem Bonders Explained2016-02-06T19:39:24+00:002016-01-28T15:54:53+00:00<p>I just finished SpaceChem (a great, frustrating puzzle game!), and toward the end I looked up solutions to a few puzzles, but got frustrated that they didn't work for me. It always failed somehow at the "bonders", spots you can move around that will bond atoms together into a molecule. Eventually I got frustrated by an <i>intermittent</i> failure in a level, and looked up the details. Because it was hard to find the <i>full</i> behavior details of bonders, I thought I'd reproduce them here, to help spread the data.<p>Each bonder has a hidden "priority" number, which can't be determined except by experimentation. Each bonder is tested <i>in priority order</i> to see if it can affect a molecule bond. Once a bonder is chosen, it looks <i>down and right</i> only, checking for a second bonder <i>in priority order as well</i>. This continues through all the bonders.<p>So, when you hit a Bond+, SpaceChem first checks the 1 bonder: it looks down and right to see if the 2 bonder is there, then to see if the 3 bonder is there, etc. Once it's run through the list of bonders, it checks the 2 bonder: it looks down and right to see if the 1 bonder is there, then to see if the 3 bonder is there, etc. And this continues through all the bonders; at the end, every bonder link will have been checked.<p>The bonder priority is always the same when you start a level - if there are 4 bonders in a square, the order is:<pre class='code'>1 2
4 3</pre><p>If there are 8 bonders arranged vertically, the order is:<pre class='code'>1 2
8 7</pre><p>I'm not sure what the priority order is of the levels where there are only 2 bonders, or 8 bonders arranged horizontally.<p>Apparently, if you roll your mousewheel over a bonder it will change the priority, but nobody has any details on how this works.http://www.xanthir.com/b4fQ0Pandemic:Legacy Fantasy Reskin2016-02-10T06:45:05+00:002016-01-24T08:36:34+00:00<p><b>WARNING: THIS CONTAINS MAJOR PANDEMIC:LEGACY SPOILERS. READ ONLY IF YOU'VE ALREADY PLAYED PANDEMIC:LEGACY, OR ARE OKAY WITH BEING SPOILED ON IMPORTANT GAMEPLAY REVEALS.</b><p>(This first part will just cover the sorts of things you'd get from a normal Pandemic game, so it shouldn't be spoilery. The bad stuff comes a little bit later. I'll have one more warning before then.)<p>Pandemic:Legacy is an update/refresh of the classic 2008 cooperative boardgame Pandemic, which has the players controlling a team of scientists from the CDC as the world is rocked by four simultaneous plagues. Pandemic:Legacy adds "legacy" mechanics to the game, a newish game-design trait where the game is permanently changed across plays, with game components being added, removed, or defaced over time. This update adds wonderful flavor to the game, suggesting a world declining into chaos as the plagues strike again and again.<p>For some reason I often get the urge to reskin cool games into fantasy themes, and Pandemic was no exception. Legacy just makes me even more excited!<h2>Basic Premise</h2><p>Centuries ago, the Lich-lord Gaxkang threatened our beautiful kingdom with his demon hordes. He was too powerful to be permanently killed, but a party of brave adventurers were able to seal him away, and with him the demons he had summoned. Unfortunately, Gaxkang's shadow has fallen across our kingdom yet again. For some yet-unknown reason the seals on his prison are weakening, and demons are escaping to wreak havoc and unleash their master. <br><p>Your task, brave adventurers, is to seek out magical artifacts linked to ancient mystical sites in our kingdom, which have been scattered and lost in the centuries since they were last used, and with them channel enough power to restore the seals guarding Gaxkang's prison.<p>You all start at your Guildhall. Each turn, you can take up to four actions:<ul><li>fight demons in your area (remove one cube)<li>move between areas<li>teleport between Guildhalls (you start with one)<li>use up an artifact to Direct Teleport from anywhere to the artifact's matching area (you can't Direct Teleport in or out of a area that is rioting or worse) <li>use up an artifact to True Teleport from the artifact's matching area to anywhere (you can't True Teleport in or out of a area that is rioting or worse)<li>found a new Guildhall by using up the artifact matching that area (normally tying a Guildhall into the local mana networks takes years of careful work; with the local artifact it can be done immediately)<li>if you and another party member are both in the area matching an artifact one of you has, give/take the artifact to/from the other person (artifacts are mystically bound to the person who found them; rebinding them to another soul can only be done in the area they're linked to)<li>if you have 5 artifacts of the appropriate type, and are in a Guildhall, restore the corresponding Seal</ul><p>Then you draw two new artifacts from the Artifact Deck (possibly triggering a demon surge), and then turn over new cards from the Invasion Deck to see where to add more demons. Play then passes to the next character.<p>If the Invasion deck would add a 4th demon to an area, it instead triggers a Tear In The Veil - the demons have reached a critical mass, weakening the local weave of reality so much that demons can temporarily pour forth more freely. Add one demon of the corresponding type to all neighboring areas (possibly triggering more Veil Tears), that area goes up one panic level, and you increase your Tear Count by 1. If any characters are in the area, they gain a Scar.<ul><li>If you get 8 Veil Tears in a single game, the prison is weakened enough to allow Gaxkang to escape, losing you the game. <br><li>If you need to place a demon on the board for any reason, but there are no cubes of that demon type left in the supply, enough of a demon army has broken through to tear open Gaxkang's prison, losing you the game.<li>If you attempt to draw from the Artifact Deck but there are no more artifacts to draw, enough time has passed that Gaxkang has broken from his prison himself, losing you the game.<li>If you can Restore all four Seals before either of the previous conditions occur, you've (temporarily) secured Gaxkang's prison, and won the game.</ul><h2>Characters</h2><p>You start with five characters available:<ul><li>Paladin (previously Medic): This holy warrior is superb at demon-slaying. When they fight demons, they kill <i>all</i> the demons of a given type from an area. After a Seal has been Restored, the weakened demons are <i>automatically</i> destroyed by the paladin simply being in the area, without the Paladin spending an action, and also prevented from spawning the Paladin's area.<li>Monk (previously Researcher): Monks train to resist all external influences, including the spiritual. Artifacts never bond to the Monk, allowing them to Trade their artifacts to another player without having to be in the matching area. This applies whenever the Monk <i>gives</i> an artifact to another player, or another player <i>takes</i> an artifact from the Monk. The Monk and the other player still have to be in the same location, as normal.<li>Rogue (previously Generalist): The Rogue has no special magical talents, instead focusing on flexibility and action. The Rogue can take 5 actions per turn, rather than 4, and can accept 4 character upgrades, rather than 2.<li>Wizard (previously Dispatcher): While this magic-user can blast demons as well as the next, their specialty is teleportation magic. As an action, the Wizard can move any other character's token as if it were their own, or teleport any character (including themselves) to the same location as another character. (If movement would require spending an artifact, such as Direct Teleporting to an area or entering a collapsing area, they must come from the Wizard's hand. If the location of the moving pawn matters, such as Full Teleporting out of a city, it's the location of the other player's pawn that matters.)<li>Cleric (previously Scientist): This battle-priest's faith and devotion allows them to draw on their gods' power to help in restoring seals. The Cleric only needs 4 artifacts to Restore a Seal, rather than 5.</ul><h2>Additional Miscellaneous Things</h2><p>When a Seal has been Restored, the demons of its color are weakened. A character taking the Fight Demons action can choose to remove <i>all</i> demons of the Restored Seal's color, rather than just one. If there are several colors of demons, the character must still Fight Demons once for each Restored color to destroy those demons.<p>If the last demon of a Restored Seal's color is destroyed, that color of demon has been Eradicated. Eradicating demons is not required to win, but when areas of an Eradicated color are Invaded, no new demons are placed there. Destroying the last demon of an unrestored Seal has no special effect.<p>"Funded Events" are additional magic artifacts, not linked to an area, with special powers. They can be used at any time, even if it's not your turn. (These need to be reskinned, but I haven't taken the time to do so yet.)<p>Two Scars need reskinning:<ul><li>Spiritually Scarred (previously Insomniac): Reduce your hand limit by 1.<li>Chaotic Aura (previously Fear Of Small Planes): Discard an artifact to teleport between Guildhalls.</ul><p><b>SPOILER ALERT: AFTER THIS POINT I'LL START TALKING ABOUT THINGS RELATED TO THE GAME'S PLOT EVENTS</b><h2>Game End Upgrades</h2><p>At the end of each game the players can choose up to two upgrades, to reflect their growing experience and help from the powers-that-be.<p>If a demon type was Eradicated in the game, you can learn from that experience:<ul><li>Level 1, Familiarity: You understand the basics of restoring this seal, and no longer need the libraries and equipment of a Guildhall to do it - Restoring can be done anywhere if you have the correct artifacts.<li>Level 2, Efficiency: Restoring this Seal has become almost routine - you can Restore at any time without spending an action, even on other player's turns, if you have the correct artifacts.<li>Level 3, Mastery: You're so skilled at restoring this seal that you can do it with much less power than it would normally require - Restoring this Seal takes 1 less artifact than normal.<li>Level 4, Suppression: You've mastered the seal to such a degree that you can partially restore it without any artifacts, weakening the demons linked to it. When any character Fights Demons, they destroy all demons of this color from their area.</ul><p>Character upgrades are mostly fine as they are. A few that need reskinning:<ul><li>Inspiring Leader (previously Local Connections): Once per turn you can Fight Demons in a neighboring area.<li>Teleportation Expert (previously Pilot): Don't discard an artifact when doing a Direct Teleportation, just show it from your hand.<li>Seer (previously Forecaster): At the start of your turn, look at the top 2 Invasion cards.</ul><p>Some later upgrades, just because I don't remember exactly when they showed up:<ul><li>Elven Training (previously Veteran): You may take the Hidden Paths action. If you're human, you also count as an elf for effects that care about such things.<li>Attuned With Nature (previously Local Pressure): If you are in an Elven Grove, you may Strengthen The Veil in an adjacent area with the Strengthen action.<li>Elven Escort (previously Paramilitary Escort): Whenever you leave an area with a Ravage demon, destroy 1 Ravage demon from that area. Only Elves can use this upgrade.<li>Infiltrator (previously Chopper Pilot): Cross any Totem Ward without discarding an artifact.</ul><p>Unfunded Events represent upgrades and tweaks you make to artifacts, increasing their functionality. I haven't reskinned these yet either.<p>Permanenting a Guildhall needs no reskinning.<h2>January Changes</h2><p>After your second Demon Surge, you find that one of the demon types is far stronger than the others. Calling themselves Endless Ravage, they've also done something strange to their Seal, preventing it from being Restored. Fighting the Ravage takes an additional action, and you can't Restore their Seal. Your goal is now to just Restore the other three Seals.<h2>February Changes</h2><p>The neighboring Elven kingdom has responded to our requests for help, and sent a hero of their own to aid you:<ul><li>Elven Mystic (previously Quarantine Specialist): Once per turn, the Mystic can Strengthen The Veil anywhere on the board. If the veil is strengthened in the area she's in, nothing weakens it.</ul><p>All characters can now spend an action to Strengthen The Veil in their area. If the veil is strengthened in an area, the next time demons would be placed there, instead the veil is weakened to normal, removing the Strengthened marker.<p>This was just in time, as the Ravage has gotten stronger, and can no longer be Fought at all.<p>Also you can now add Backstory to your characters:<ul><li>"Friends with" (previously "Family members with"): The two of your work well together, and complement each other's efforts. If you start your turn in the same area as your friend, gain 1 extra action. <li>"Family members with" (previously "Coworkers with"): The souls of family members are very similar, and the artifact bond can be easily shifted between them, taking the artifact with it. You can Trade an artifact with a family member as long as at least one of you is in the artifact's area - the other character can be in a different area entirely. (The Monk can pass any artifact.)<li>"Fate-bonded with" (previously "Friends with"): The two of you have fates mystically intertwined for some reason, and this occasionally grants you flashes of insight of the near future when you are together. If you start your turn in the same area as your fate-bond, you can look at (but not rearrange) the top two cards of the Artifact deck.<li>"Rivals with" (unchanged): Whenever your rival discards an artifact for any reason, you can discard two artifacts to pick it up.</ul><h2>March Changes</h2><p>More Elven assistance, in the form of the Elven Druid:<ul><li>Elven Druid (previously Operations Expert): Using his deep connection to the land, the Druid can weave Guildhalls into the local mana network without using up an artifact. He can also establish Elven Groves, a new Elf-only structure that is not removed by unrest in the area. Finally, the druid can use up an artifact to teleport from <i>any</i> structure to anywhere on the board.</ul><p>Elven characters can now use the Hidden Paths action, which lets them teleport between Elven Groves as an action, similar to the Guild Teleport.<p>Two new optional objectives as the demon hordes grow worse: Eradicate one type of demon, or establish Elven Groves in all six regions of the kingdom.<h2>April Changes</h2><p>Shit. Gets. Bad.<p>After your second Demon Surge, Eternal Ravage unleashes a new ability - it Taints any area it shows up in. Tainted areas only spawn Ravage demons, and strengthen them - any character starting their turn in an area with a Tainted Ravage demon takes a Scar. While this is initially limited to the Ravage's area of the kingdom, if a Veil Tear occurs and spreads Ravage demons to other areas, the Taint spreads as well.<h2>May Changes</h2><p>In response to the Taint, the Elves send a new ally to the cause:<ul><li>Elven Barbarian (previously Colonel): As long as there is an Elven Grove in the region of the kingdom, the Barbarian can Fight the Ravage. The Barbarian can also pass through Totem Wards without spending artifacts. However, the Barbarian is terrible at Restoring Seals, and needs 2 additional artifacts to do so.</ul><p>The elves also teach you how to build Totem Wards, which block all movement between any two adjacent areas. Veil Tears no longer spread demons along that route. However, you can't move across wards easily either - you must use up an artifact to move between areas with a Totem Ward between them.<p>The Ravage have altered their Seal in some terrible way, as well - whenever an artifact of their Seal is found, add a Ravage demon to that artifact's area.<p>New optional objective added: Have 7 Tainted areas Strengthened at once.<h2>June Changes</h2><p>You can now upgrade artifacts on the fly to help you with new abilities. Your own artificers have developed some upgrades you can apply in your Guildhalls (defensive spells, or things that aid in Restoring), while the Elves have developed their own that must be applied in Elven Groves (offensive spells, or spells letting them move around in our kingdom more easily).<p>The elves also send another hero to help the cause:<ul><li>Elven Spiritblade (previously Soldier): The Spiritblade has magical stealth, and does not take a scar for starting his turn in an area with Ravage demons. He can also restore any artifact that has been upgraded, calling it back to his hand from the discard pile. However, he cannot Restore a Seal at all.</ul><h2>July Changes</h2><p>A renowned demonologist, presumed dead, was spotted in a Tainted area. You must find her, as she might have insights in how to fight the Ravage!<p>Now you have a Search board, and must find the Demonologist before their trail goes cold. Searching requires you to use up an artifact of the same color as the area you're searching; using the matching artifact searches even better. Rumors place them in an area with a Guildhall, and searching is easier if the veil is Strengthened, as there's less demon threat. Every Demon Surge makes it less likely you'll find them, though.<p>If you do find them, they reveal that they've returned from retirement and have been studying the Ravage. They believe they can discover a weakness, but need to find their demon-hunter ally, who they were separated from in a rioting area.<h2>August Changes</h2><p>Now you're searching for the Demon-Hunter, in some Tainted rioting area. Humans in the area help the search.<p>You also develop a new action - Blood Sacrifice. Any character can voluntarily take a Scar as an action to skip the Invade step this turn.<p>If you find the Demon-Hunter, they tell you they <i>can</i> find the Ravage's weakness, but they need more resources. First they need someone to study the Ravage's behavior (which the Demonologist has done, if you found them). Second, it looks like the Ravage didn't develop their powers themselves - some group has been aiding them. The Demon-Hunter needs to discover which group has been enhancing the Ravage. Finally, the Demon-Hunter needs more information about the Taint and its properties.<p>Also, the elves offer up a dark ritual they know of. It drains one area of all its mana, permanently, in order to completely cut off another area from the spiritual realm. This kills all demons in the area and prevents them from <i>ever invading there again</i>, but being completely cut off from the gods panics the area and immediately makes it fall (level 5 panic). (This is a reskin of the Nuclear Option one-time event.)<h2>September Changes</h2><p>An elven warrior has been spreading panic in a Tainted area, telling all who will listen that it's hopeless, and the Ravage will take over the world. You have to find him and stop him. New search track - look in a Tainted area with an Elven Grove, and more elves help the search.<p>If you find the warrior, he reveals that he was part of a conspiracy in the upper echelons of Elven government, to weaken the seals on Gaxkang's prison and cause chaos in our kingdom, then infiltrate and take over the area themselves. Not all elves are part of this plot, but one elven character is a traitor sent to sabotage us. The Ravage's strength, and the Taint, are both the result of elven rituals empowering the demons.<p>You find and execute the traitor, then turn to stopping the elven conspiracy. You throw out the "establish Elven Groves in each region" objective, and replace it with "destroy two Elven Groves". You gain a new Sabotage action - if you're in the area of an Elven Grove, and have the artifact matching the area, you can spend it to tear down the Grove.<p>The warrior's testimony gives the Demon-Hunter the information about which group has been helping the Ravage.<p>Also, the Demonologist has recovered from her injuries, and now joins your party.<ul><li>(Human) Demonologist (previously Virologist): Can spend an artifact of the Ravage's color to destroy one Ravage demon anywhere in the world. Can spend the artifact matching the area they're in to destroy all Ravage demons in the area.</ul><p>At the end of the game, now that the elven conspiracy has been revealed, they're openly invading. You must add a permanent Elven Grove to the first area that you add demons to during setup.<h2>October Changes</h2><p>The search for the last piece of the puzzle is on - the Demon-Hunter needs to find the original source of the Taint. New search track - look in the original Tainted city, with an Elven Grove in the city helping the search. If you complete the search, you find the wellspring of the Taint - an ancient elven temple ruin, abandoned for centuries.<p>If you've found all the information the Demon-Hunter needs, the elven conspiracy is finally clear. Centuries ago, these were elven lands. Humans coveted them and invaded, driving the elves out and eventually founding your kingdom. The elven gods at that time were local theurges, bound to the land, and were left behind when the elves fled. This god, though diminished, still dwelled among the temple ruins, at least until the conspirators bound him and twisted his power to their devious ends, empowering the Ravage and creating the Taint.<p>With this information, the Demon-Hunter can craft the weapons needed to fight the Ravage - charms against the ancient god that empowers them. You open Box 7 and get a number of new things:<ul><li>Enchanting Halls (previously Vaccine Factories) - these new structures generate one charm per turn. They follow the same rules as Guildhalls: they can only be built in non-rioting cities, and humans can teleport between two Enchanting Halls, or between them and Guildhalls.<li>Charms (previous Vaccine Doses) - charms are produced at Enchanting Halls. A player in the same city as some charms can pick up as many as they want as an action.<li>Cleanse action (previously Immunize) - if a player has one or more charms, they can Cleanse the area they're in. If there are any Ravage in the area, this kills one Ravage demon. Otherwise, it cleanses the area, permanently removing the Taint and preventing it from returning. Ravage demons are never placed in Cleansed areas. (Cleansed cities in non-Ravage colors revert to generating normal demons of their color; cleansed Ravage-color cities no longer generate anything at all.) Cleansing takes an additional action for each Elven Grove in the area, as the charms have to fight harder against the stronger background of elven magic.<li>Demon-Hunter (previously Immunologist) - this skilled demon-slayer can wield the charms more effectively than anyone else. When he Cleanses, he can kill all the Ravage demons in an area by spending multiple charms (one per Ravage), similar to how the Paladin kills multiple demons with a single Fight action. Once per turn, he can Cleanse an adjacent area.</ul><p>With the tools to fight the Ravage now in your hands, it's no longer important to just contain them - destroy the "Quarantine 7 Tainted cities" objective. In return, you gain two new objectives: "Have 3 Enchanting Halls Built", and "Cleanse 6 Tainted Cities". After achieving the latter one, tear it up at the end of the game.<h2>November Changes</h2><p>Nothing new introduced, just an ominous warning from the Elven Conspiracy that they're on to you.<p>At the end of November, if you hadn't yet opened boxes 6 and 7, a secondary team of adventurers has found the information for you, so you can open the boxes now.<h2>December Changes</h2><p>The Elven Conspiracy is taunting you - even if you do defeat the Ravage, they're boring directly into Gaxkang's prison as they speak. All your work is for nothing if the Lich-lord is released!<p>At this point, you <i>tear up all your current objectives</i>. Instead you now have two mandatory objectives: Cleanse all Tainted cities, and bind Gaxkang permanently. No half-measures this time!http://www.xanthir.com/b4fM0Things That Aren't Other Things, Monad Edition2016-01-25T02:53:55+00:002016-01-21T02:11:32+00:00<p>An intuitive example of something that's a Functor but not an Applicative is a tagged value, where you have a value that's associated with some arbitrary "tag". This is a functor - given a function f and a tagged value ("tag1", v), you can map over it to get the result ("tag1", f(v)). But it's not an applicative: for one, there's no "default" tag, so it's not Pointed, but also given ("tag1", f) and ("tag2", v), the result should have a value of f(v), but what would the tag be? There's no automatic way to generate a tag from two existing tags. <p>An intuitive example of something that's an Applicative (a Traversable, really) but not a Monad is a ZipList. Given [f1, f2] and [v1, v2, v3], you'll end up with [f1(v1), f2(v2)], so it's Applicative. But implementing join is impossible in general - given [[a1, a2], [b1], [c1, c2, c3]], the obvious way to collapse it into a single ziplist is to take the Nth element of the Nth list. But there's no b2 element! Fixed-length or infinite-length ziplists <i>are</i> Monads, though. (Why can't you just stop at the first one that fails, returning [a1]? It violates the monad laws! Usually associativity, depending on exactly what you implement.)<p>Needed: an intuitive example of something that's Applicative but not Traversable.<p>Interesting side-note: the Writer monad is almost identical to the tagged value - it's conceptually a value paired with a "logging value". The difference is that the logging value <i>is not arbitrary</i> - it's required to be a monoid. This gives us a default value, so it's Pointed, and a way to combine logging values, so ("log1", f) and ("log2", v) can be combined into ("log1log2", f(v)). So Writer is Applicative, and in fact a full Monad.http://www.xanthir.com/b4fL0Creating ASCII-Sortable Strings from Numbers, Redux2016-01-20T21:27:13+00:002016-01-20T07:30:22+00:00<p>(I wrote about this a while ago. I'm revisiting it for fun, and to run thru it in a more reasonable order.)<p>Sometimes you have a lot of files with numerical names, and you want to name them such that a stupid ASCIIbetical sort (that is, something that sorts letter-by-letter according to ASCII ordering) will sort them in order. Just numbering them won't work right - "10.txt" will come between "1.txt" and "2.txt". Zero-padding works for most practical purposes, but it requires you to guess how many entries there will be ahead of time, and come on now.<p>What if you had <i>no idea</i> how many files there were going to be, but maybe it'll be a <i>whole bunch</i>? Then there are a few schemes that'll work.<h2>Unary Numbers</h2><p>First, let's talk about unary numbers. Normal numbers are "positional" - the value of a digit depends on its position in the number. Unary numbers are non-positional, so digits are worth the same no matter where they are. You already know of one common type - Roman numerals. An X is always worth 10 no matter where it shows up.<p>It turns out that, if they satisfy two criteria, numbers written in unary always sort correctly, no matter how long they are. These criteria are:<ol><li>The number must be written in "greedy form", where you always use as many of the largest possible digit first, before trying any smaller digits. For example, in Roman numerals 16 must be written XVI, not VVVI or XIIIIII.<li>The digits must sort correctly themselves. Roman numerals do not do this - I, V, and X sort correctly, but C (100) goes before all of them.</ol><p>Here's a simple system that does satisfy those two constraints: the letters A-Z, where A stands for 1, B for 2, etc until Z is for 26. Then a number like 100 is written ZZZV. I'll use this for the rest of the post.<p>The problem with unary numbers is that they grow linearly with the size of the number. If I double the number, I double the <i>length</i> of the number too. The length of positional numbers grow with the log of the value, which is much much smaller - doubling the value of a binary number only increases its length by 1.<p>So we can't quite have everything. Positional numbers grow slowly, but don't sort right. Unary numbers sort right, but grow quickly. In combination, tho!<h2>Unary Prefix</h2><p>Positional numbers <i>do</i> sort correctly <i>as long as they have the same length</i>. All 2-digit numbers (10-99) will correctly sort themselves ASCIIbetically, for example. This is why zero-padding works - it changes all the numbers to be the same length.<p>By taking advantage of this, we can get the best of both worlds. The first way to write numbers that'll sort correctly as they get infinitely large is to write the number normally, then prefix it with an unary number listing its length. <br><p>For this to work correctly, the unary number must use a different set of digits from the "normal" number, and those digits must sort after the "normal" digits. These are both true of the A-Z system.<p>So, the number 5 is written "A5". The number 99 is written "B99", while 100 is "C100". All 2-digit numbers will sort after the 1-digit numbers (because B > A) but before the 3-digit numbers (because B < C), and whenever 2-digit numbers are compared, they'll match on their B digit and then sort correctly on their remaining value.<p>This system adds a single character of overhead for all numbers below 10^27, or two for more numbers below 10^53, more than long enough for all practical purposes. But what if we want <i>really</i> big numbers? A 100-digit number will have 4 digits of overhead. A 1000-digit number will have 39. A million-digit number will have almost 40 <b>thousand</b> characters of overhead. Can we do better?<p>Of course.<h2>MOAR POSITIONALS</h2><p>So our problem is that the prefix grows linearly with the length of the number (the log of the value). This is fine for normal numbers, but if you get <i>really</i> big numbers, the prefix gets too big. Unary numbers just aren't good at representing large numbers, you need positionals for that. But how do we integrate more positional values without running into the sorting problem again?<p>Recall what the purpose of the prefix was - to correctly sort the strings so that they were grouped with same-length prefixes that sorted properly even tho they were positional. Assigning each set of suffixes to a different group can be done fine with any number, so let's use positional numbers for it instead, so 1 million (1000000, 7 digits long) is written as "71000000".<p>Now we're back in the positional hole, because a 10-digit number like 1 billion will start with a "10" prefix, and sort before 1 million. So let's return to unary, and use it to sort the <i>prefixes</i> into correctly-sorting same-length groups - if the <i>prefix</i> is 1 digit, further prefix it with an A, if the prefix is 2 digits, further prefix it with a B, etc. With this, 1 million is written "A71000000", and 1 billion is written "B101000000000", and everything sorts correctly again.<p>This forces us to pay a <i>little</i> bit extra prefix tax for small numbers - ten is written "A210", whereas before it was just "B10". But it quickly overcomes the previous scheme - previously, a 10^105 was "ZZZZA10000..." (5 chars of prefix) while now it's "C10510000..." (4 chars of prefix). A million-digit number previously had about 40 thousand chars of prefix, while now it has <b>8</b> ("G1000000"). That's great! But what if our numbers are <i>really</i> big - can we do even better?<p>Of course.<h2>Stacks On Stacks</h2><p>A million digit number (like 10^million) is handled great by the previous form, and is so stupendously large that there's no possible way any larger sorting scheme could be needed. But we're just playing around here - what if we wanted to encode a number like 10^10^million? Then the positional prefix is a million characters long, and the unary part is another 40 thousand.<p>The obvious solution here is to just repeat the previous step: have the second prefix be positional as well, and then have the final unary prefix be the length of the second prefix. So our 10^10^million number's prefix would be "A710000...", a million and two characters long.<p>But that's kinda inelegant. It's thematically similar to zero-padding - you have to guess ahead of time how many levels of prefix you need. If you guess too low, the excess gets soaked up into a big unary prefix (10^10^10^million would still have a 40k unary prefix). If you guess too high, you end up saddling "low" numbers with several levels of unnecessary prefix (ten is written as "A1210").<p>Instead, let's produce prefix levels <i>dynamically</i>. Start with the original prefix - the length of the number, written positionally. If this prefix is 2 or more chars long, add another prefix level indicating how long it is. Repeat as needed until you get to a single-char prefix. At the end we still need an unary prefix to make it all work, but we'll encode the <i>number of levels</i> with it. It's a little non-obvious, but you can show without too much difficulty that this correctly sorts all numbers. <p>So, a few of the numbers we were talking about previously:<ul><li>ten: "A210" (2 prefix chars) <li>billion: "B2101000000000" (4 prefix chars)<li>10^million: "B71000000100000..." (9 prefix chars)<li>10^10^million: "C71000000100000...10000....." (1000009 prefix chars)</ul><p>For any finite number of levels, the total prefix length is: log^1 + log^2 + ... + (log^N)*2, where N is the number of levels.<p>In our final scheme, the length is instead: log^1 + log^2 + ... + log^N + N, where N is the log* of the number. log* is the <i>iterated log</i>, the number of times you have to apply the log function before you hit <=1. log* stays <i>ridiculously</i> small for all numbers you can conceive of.<p>Can we go further? Yeah, of course. For unbelievably huge numbers, the number of levels might get large enough for the unary prefix to start mattering. In that case, you can extend it to use multiple positional levels to indicate the number of levels, with the unary prefix indicating the number of those super-levels. But extensions are very mechanical at this point, and only matter for numbers so large that they're difficult even write down. Stopping at this level is good enough for anything ever in reality.http://www.xanthir.com/b4ej0How To Pronounce Hexadecimal Numbers2015-12-15T01:43:04+00:002015-12-15T01:43:04+00:00<p>A few months back, <bzarg.com> posted a guide on <a href="http://www.bzarg.com/p/how-to-pronounce-hexadecimal/" title="">how to pronounce hex numbers</a>, inspired by a funny scene from <a href="https://www.youtube.com/watch?v=_zTpwNR5Bf4" title="">Silicon Valley</a>.<p>The basics of any English-like number-naming system are:<ol><li>Digit names.<li>"Teen" names, for numbers of the form 1x.<li>"Xty" names, for numbers of the form x0.<li>Place names, for grouping larger sets of numbers, like "hundred", "thousand", and "million".</ol><p>When hex numbers are composed of just decimal digits, #1-#3 are identical to decimal numbers. "45" is still read as "forty five". Similarly, if a "letter" digit shows up in the ones place, it's just read as the letter - "4B" is "forty bee". (The full set of English spellings is "ae", "bee", "cee", "dee", "ee", and "eff".)<h2>Xty names</h2><p>The Silicon Valley clip provided an example for #3 - "fleventy", presumably for Fx numbers. Bzarg expanded that out to a full set of six:<ul><li>A0: atty<li>B0: bibbity<li>C0: city<li>D0: dickety<li>E0: ebbity<li>F0: fleventy</ul><p>So a number like "f5" is read as "fleventy five", or "BC" as "bibbity cee".<h2>Teen names</h2><p>They extrapolated those into #2, teen names, too:<ul><li>1A: abteen<li>1B: bibteen<li>1C: cleventeen<li>1D: dibbleteen<li>1E: eggteen<li>1F: fleventeen</ul><p>(These are hard because of the near-homonyms of "A" and "8", and "C" and "6". I like the names they ended up with!)<h2>Place names</h2><p>Finally, they suggested a place name for when you go past two digits - "bitey" (because two hexits comprise a byte). So "100" is pronounced "one bitey", "ABC" is "ae bitey bibbity cee", etc.<p>They don't suggest in the post what higher place names should be, but they do implement some in the spelling toy - "halfy" for 4 digits, and "worddion" (with a spread-out, j-like "dd", to blend into the "yun" sound at the end of "million") for 8. They reuse "halfy" for 6, which seems confusing and probably unintentional.<p>I don't like these, tho. The size of a "word" changes over time, to match the "size" of the processor - it used to be 2 bytes, and it's commonly 8 bytes these days, rather than the 4 bytes suggested by the naming toy. This also doesn't extend well.<p>I suggest instead adopting a scheme vaguely similar to English, but with a splash of newness. Start with "bitey" for a byte, but at four hexits, use "bi-bitey", similar to "billion". Then at 6, <i>combine</i> them to be "bi-bitey bitey", and only at 8 do you introduce a new "tri-bitey" term. Continue combining for 10 (tri-bitey bitey), 12 (tri-bitey bi-bitey), and 14 (tri-bitey bi-bitey bitey), and at 16 go up to quad-bitey.<p>In general, you group into bytes, find the index of the place you're trying to name, and write it in binary - the 1s get pronounced with an appropriate name. So, 12 hexits is 6 bytes. 6 in binary is 110. The third and second bits are 1, so the name for that place is "tri-bitey bi-bitey".<p>This system extends for quite a while, and covers all the numbers we'll ever really have to worry about. It also has a nice extra-binary feel to it, which I like.<p>I'll put together a naming toy for this in a bit and link it into here.