Category Archives: Algorithms

Where do you wake up from a bed in Minecraft?

After issuing many /time set night commands, I can tell you the waking-location algorithm for Minecraft. This presumably also affects your spawn point.

Two locations are checked, and if they fail to select an acceptable location the pillow-location is used regardless of consequences of picking this location. An acceptable location is on the same level as the bed, and has two transparent-non-solid blocks above it (i.e. you will be standing next to the bed without your head or body embedded in something that’s killing you).

The process is the same for each of the two locations:

Sweep x-1 to x+1:
  Sweep z-1 to z+1:
    if the location is acceptable, we're done

The locations are checked in the order: pillow-part-of-bed, non-pillow-part-of-bed. The effect is:
From the Minecraft wiki:

For a bed to be usable as a spawn point, the player must be able to stand next to the bed at the same level as it. There must be a solid block at the same ‘floor’ level as the bed, with 2 transparent blocks of space (for example, air) for the player to stand in, in one of the ten blocks that surround the bed. It doesn’t matter if the bed itself has blocks above it.

Political donations are not the problem

Corrupt politicians have recently been in the Australian news.

It has been observed that money, in the form of political donations, is a corrupting influence. This causes hand-wringing, as banning donations is considered to hinder the freedom of political expression.

As a response to this demand for cash to finance political expression, suggestions are made that private funding of politics be replaced by public funding – basically an increase on the funding which parties already receive (something of the order of $2.48 per primary vote in lower house seats in the last federal election, for example). This grates those with a strong dislike of politicians and the political process. In addition, the current funding model of retrospective funding (based on votes received) disenfranchises new political views – it locks in the existing players by funding them, allowing them to campaign for votes that will fund them; those outside the system will not be able to break in.

To allow new entrants into the political system to be funded on an equitable basis, some kind of on-going polling could be done and a funding stream allocated on proportionate support in non-electoral polls.

However, switching to purely taxpayer-funded funding isn’t necessary, even if in effect the tax-deductibility of political donations makes them taxpayer subsidised.

Political donations are not the problem, the problem is that donors can be identified by the political party and and expectation of quid pro quo is raised. Beyond that, large donations from a single donor are also a problem – even if political party donations were anonymised and repudiable the donation’s existence could be inferred by the velocity of money flowing out of any anonymising system.

Let’s say you’re trying to run a corrupt political party under an annoymised donation system. Someone comes to you and says “I will give your corrupt party $10m, and I expect you to make this corrupt thing happen.” You’d then donate the $10m, and your donation would be pooled along with the hundreds of other donations made to the party. The Donor Anonymising Service (DAS) would then hand over a certain amount of money to the party, but it would not be $10m. It would be the stipend that the party had requested from the DAS, along with advice that the current amount held in reserve is enough to last at least X days, where X was the same number (give or take a couple of days) as it was yesterday. You don’t know if the $10m donation was actually made, all your party knows is that it’s got enough money to last X+2 days. You could up the rate of the stipend, but the DAS would scale back the reported window so that no extra information is revealed by the reported minimum duration the reserves will last. You’d limit the rate and number of times the stipend could be changed to discourage probing. Naturally, it would be illegal to make a political party aware of a donation or its amount.

Of course, then you have all the fun and games associated with loaning money to political parties, and with corrupt administration of a Donor Anonymising Service, but you get the gist of where we could go with this idea.

ABC’s Labor bias: Vote Compass

I am a single issue voter. I’m not proud to admit being so shallow, but there it is.  If there was a party that wanted to cut greenhouse gas emissions by 50% by 2020 and also drown kittens, I’d be in like Flynn – and not because I dislike kittens either. Perhaps it’s because I take a root-cause view of the world.  Immigration problems?  Address climate change or it’s going to get much, much worse. Not spending enough on education? Not much point in edumacation if the climate collapses around us and we’re up to our ears in climate refugees. Wrong telecommunications plan? Choosing between having enough food and downloading porn faster than you can watch it doesn’t seem to be much of a choice to me.

So, naturally I thought that the ABC’s Vote Compass wouldn’t have much trouble pigeonholing me. Except, it tells me my views align more closely with the ALP.  Although at one stage in its questioning it allows you to weight the importance of issues (which I gave as 1-3 for most, 4 for a couple and 10 for environmental) this clearly… doesn’t carry any weight. The anemic 5% by 2020 cut embraced by the two major parties means neither will get my vote, regardless of the technique to “achieve” such a “challenging” target.

And yet Vote Compass thinks I’d make a good ALP voter.  I think not.  The ABC’s Labour bias at it again.

Chrome doesn’t sandbox the CPU; Goggle docs waits really hard

Chrome doesn’t attempt to sandbox CPU consumption. I just closed an inactive Google docs spreadsheet, and saw CPU fall from pegged-at-100% to bubbling along at 10%.

Does it really need each available CPU cycle to wait for the other end to do something? Apparently so, in the way it’s coded.

Google: not as clever as the press release makes out.

Weird bug

Let’s say, for example, that a system supplies you the time of some event in UTC, you convert it to local and shove the date/time up on the display. Say, for argument’s sake, you also include the Day Of Week, ending up with a format of DD/MM, DOW HH:MM. Everything looks fine, until someone notices that the Day Of Week is wrong. The 28th of May is a Wednesday, not a Thursday.

What happened?

The date conversion routine that generates the DOW string does a bunch of odd stuff, but seems to work correctly; it certainly works in other parts of the code, and generates the right string there.

WTF?

The UTC time seemed to be converted to local time twice, but that wasn’t the culprit; surprisingly, no-one is killed in an explosion of silicon splinters when that code is double-executed. Whatever.

Could it be that the system supplying you the time of that event in UTC is off by a year? One year into the future. That would give you that behaviour.

Check it.