# Wishful Coding

Didn't you ever wish your computer understood you?

## If Everyone Would Just...

While everyone was making new years resolutions for themselves, I was making new years resolutions for the world. Or rather, thinking how change happens.

It seems people are hardly able to change themselves, even if they set out to do so. So how can we even begin to think about changing humanity as a whole? It seems we just keep doing whatever is easiest/best/most comfortable, and change only happens when something easier/better/more comfortable comes around.

Sometimes you read about these civilizations that seemed to be really advanced for their time, but then just sort of died out. Looking back it is often obvious why, and you wonder if they did not see it coming. But what if they saw it coming all along, but were unable to change their ways?

The only mechanism we have for global change is governance. But as Douglas Adams explains

One of the many major problems with governing people is that of whom you get to do it; or rather of who manages to get people to let them do it to them: It is a well known fact, that those people who most want to rule people are, ipso facto, those least suited to do it. Anyone who is capable of getting themselves into a position of power should on no account be allowed to do the job.

Often times I have an idea to make something somewhere a little better. No grand plans to solve world hunger, just small things. Often by means of sharing or exchanging information or goods. Without exception, these ideas include the sentence “If everyone would just…” and you quickly learn about the Network Effect.

I’m just back from 32c3, where I saw a number of interesting art projects. Many of these projects used technology not to provide utility, but to convey a message. Thinking about all the above, I built The World Improvement Server; a caricature of global change.

Th World Improvement Server runs a program that speaks the SUN-RPC rwall protocol, listening for your world improvement ideas. These ideas are then broadcast over the QOTD protocol to anyone who cares to listen.

To start improving the world, simply run rwall 37.247.53.27 and type your idea, followed by EOF.

To learn more about ways to improve the world, simply telnet 37.247.53.27 17, which as of 2 January 2016 returns

\$ telnet 37.247.53.27 17
Trying 37.247.53.27...
Connected to 37.247.53.27.
Escape character is '^]'.

If everyone would just [...]
the world would be a much better place!

Submit global world improvement using rwall.

(/dev/pts/0) at 18:19 ...

If everyone would just use this service to make the world a better place
the world would be a better place.

Connection closed by foreign host.


## The relation between harmonics and parallel resistance

I’m building a simple synth on a breadboard, where the frequency is defined as $f=\frac{1}{RC}$, so by using different resistors with a row of buttons, different tones can be made. But what if you press two buttons simultaneously? You get 2 parallel resistors, giving:

I stumbled on this while playing with it, and the combined tones seem to be nice intervals sometimes. So I started to wonder if there was a connection.

In 12-tone equal temperament, the ratio of the frequency between two notes is $\sqrt[12]{2}$, so we could just plug it in and see what comes out. Take a series of notes:

And a series of a combined frequencies:

Plotting these in Matlab gives the following result

As can be seen, some combined tones are indeed quite close, but most not exactly. But then equal temperament does not have exact harmonics either. So we still do not know if we are generating actual harmonics, or just frequencies that happen to be close.

So what if instead of starting with $\sqrt[12]{2}$, we start with integer multiples of the base frequency and fold then back into one octave. This gives:

Plugging that into the parallel resistance equation, we can begin to search for exact harmonics giving exact harmonics.

 Combined Harmonic Name Button ratio Name 17 Minor second 9 Major second 9 Major second 5 Major third 19 Minor third 11 Tritone 5 Major third 3 Fifth 11 Tritone 7 Minor seventh 3 Fifth 2 Octave 2 Octave 1 Prime

And we can indeed verify that two resistors with a 2:1 ratio give a fifth (3:2):

Likewise a resistor ratio for a fifth gives a major third (5:3)

Math, music, physics. So beautiful.

Update:

As pointed out by Darius Bacon, this might not be a complete surprise, as there is a striking similarity between parallel resistance and the harmonic mean.

Wikipedia also has the following to say about the harmonic series:

Its name derives from the concept of overtones, or harmonics in music: the wavelengths of the overtones of a vibrating string are 1/2, 1/3, 1/4, etc., of the string’s fundamental wavelength. Every term of the series after the first is the harmonic mean of the neighbouring terms; the phrase harmonic mean likewise derives from music.

## Generating League of Legends item sets

I’m not a very dedicated League of Legends player, and after several months, I’m still unranked and basically build whatever is recommended on a champion.

When I saw the Riot API challenge, it seemed like a perfect opportunity to learn more about items and share this knowledge with other players. So I set out to make a tool that analizes item stats and generates optimal builds.

Easy enough right? Well, not really. Doing an exhaustive search on all item combinations is prohibitively expensive, and it’s not always clear what is “optimal” if you want both attack damage and armor.

The collection of problems where you try to find an optimal combination of something are called “optimization problems”, and when you have more than one thing you want to optimize, you have a “multi-objective optimization problem”.

I’m not exactly sure what this means, but insert some text about polinominal time and P=NP here. Basically, we don’t have any good solutions for problems like these. There are some heuristics though.

One of those heuristics is simulated annealing. This is something borrowed from another dicipline, so they use terms like “temperature” and “energy”. But really you have a function that randomly permutes a state, and a function that computes how “good” that state is. If the new state is better, continue. If the new state is worse, maybe continue. There is a decreasing variable which determines how likely maybe is. The idea is that you start bouncing around, slowly becomming more conservative, converging on an optimal solution.

It is worth noting that when you have two conflicting objectives, “better” becomes hard to define. If you sum their measures, you tend to find an extreme that only satisfies one of the two. Instead, what I do is that I only consider a set better if it’s better on all objectives. If it’s worse for one objective, it’s a definite maybe. This tends to generate fairly balanced results.

You might wonder why not simply pick the “best” items and add them together. This would surely be faster, right? Yes. This is called hill-climbing. The problem with it is that you might end up in a local maxima. A set of items that gets worse if you change one item, but that’s not the absolute best item.

Consider you have a sword with a ton of damage, an armor with tons of defense, and an item with a bit of both. The hill climbing is likely to continue picking the mixed item, while a build that consists of a mix of the first two items might be beter overall.

So after figuring this out, I downloaded the champion and item data from Riot and started writing objectives to optimise for. I started with damage per second and effective health. Damage per second is the product of your attack damage, attack speed and crit chance. Effective halth is the damage it would take to kill you give your healt and armor.

The first DPS build included two attack speed items like Phantom Dancer and Zephyr, with the rest filled with Infinity Edges. This does about 3K damage per second, but does not include any defense or life-steal. It also completely ignores the item abilities.

This lead me to modify the code to include each item only once. But it remains the case that no matter what, attack speed(2.5/s) and crit chance(100%) are nearly maxed out in all builds.

Effective health had a similar issue with Randuin’s Omen and Banshee’s Veil, in addition to Warmog’s Armor. Builds would include one or two Warmog’s Armor with the rest filled in with the other two, depening if you chose magic resist or armor.

Even after restricting to one item of each, builds include a lot of health in addition to armor/magic resist. One point of armor gives you 1% extra of effective health. So 100 armor doubles your health, but if you have 100 armor, Warmog’s suddenly give 1600 effective health!

But things start to get really interesting if you start to combine objectives. I learned about a lot of new items this way. There are quite some underused items that provide a combination of things. Itmes like Abyssal Scepter and Twin Shadows. Not even my brother (Platinum V) knew about Twin Shadows.

On the other hand, there where also instances where I showed my brother a set, and he knew a better item, or told me that item was not available on Summoners Rift. There where occasions when items like Lord Van Damm’s Pillager would show up, or Bloodthirster would be missing because its life-steal was not in the data.

To solve this problem, I created an “overlay” to which I could add data about an item. This works great, but there are still gaps in the data. Another issue is that some item abilities are hard to put a value on.

I also made some key functions multimethods that dispatch on various things. This allows me to encode things like Yasuo’s double crit change and Singed’s health from mana. But this is currently implemented for very few champions.

In its current state, it works fairly well for tanks and champions seeking raw damage output. It does not work so well for utility supports.

I don’t care a lot about the prizes, because I have an awesome keyboard already, but it would be fun to win, and I hope some people find it useful.