Skip to content

Computer and Related Things

This blog thing seems to have become a monthly affair. I blame having a job and having a new computer.

Oh, didn’t I say? I have a new computer now. It was so long since I had a proper computer that I forgot what it’s like. The hard drive (clickety-clack) and the keyboard (flimsy plastic) are shite but the rest is great.

I briefly considered buying Windows 7 – not for moral reasons, but because I assumed pirating an OS had become too much of a hassle. Then I remembered I’m Swedish.

Every time I get a new computer there is that period where I have to set things up and install things and put things from the old computer into folders called “Crap from Old Computer” or such and then forget about them. They’re starting to nest rather annoyingly.

Having a computer that doesn’t get emo from 3D graphics has made me consider checking out some games. The old crack was a given, but I’ve also considered Skyrim and Portal 2 and all those peculiar indie games they keep mentioning in PC Gamer.

And programming.

Oh, I know. Programming at my level requires a calculator or possibly an abacus at most, but now I have a reason to program; I am trying out this whole “education” thing again. Millionth time’s the charm.

The course in question is the imaginatively named Computers and Programming. Figuring out its contents is left as an exercise for the reader. It’s for 10 credits (I finally learned the nomenclature in English. Aren’t I S-M-R-T?) and runs a semester, giving it a speed of 33%.

The good thing about the course is that I should be able to pass it easily.

The bad thing is that the online portal thingy were we get the course material looks like it’s made by a new-to-the-interwebs highschooler from the 90s. Comic Sans and clip art everywhere. It’s shockingly ugly.

It’s something I’ve noticed before. That people interested in programming are almost never good at making homepages. They always look like the shit you did before you realised that just because you can doesn’t mean you should.

Another bad thing is that it’s on C++. I’ve never liked C++. It comes from C, a simple, clean and small language, but is an ugly behemoth. C++ tries too hard to incorporate every single programming paradigm in existence, going against the “make things that do one thing but does that thing well” philosophy of the Unix world, whence C spawned.

As much as I dislike certain things about C++, I’ve started to really like the others, such as the STL. Dynamically resizing lists are so fucking convenient I’m prepared to forgive the rest of the language its horribleness.

Now we just have to see if I can maintain the self-discipline needed to actually finish the course.

Ageing, Technology

At work I encounter people who have little to no grasp of technology on a daily basis. This is to be expected. What’s interesting is which metaphors people know and which they don’t. Everyone knows “icon”, “button”, “menu” and so forth. “Start menu” has started to fade from their understanding, now that it doesn’t actually say “Start” on it. You learn not to say “window”; you say “box” about everything (it sounds slightly more reasonable in Swedish). I’ve even learned never to say “at the bottom right corner of your screen, by the clock”, since people can’t grasp the concept of a digital clock.

“Screen”, by the way, is the most baffling/infuriating metaphor of them all. People never, ever understand that the screen is not the active window. If you say “computer screen” the chances improve marginally. I just don’t get it. A screen is a big piece of hardware. How can you not know what it is?

Mac users are funny too. They never know that the menus for the currently active window are always at the top of their screen. They can hardly ever find files on their hard drive. They often don’t know what their file browser is called or that it exists and how to use it. After a few weeks of supporting people with Macs I already had more know-how than the rabid fanboys calling in.

Linux users were horrible at first but now it’s alright. They’re either powerusers or old people who either believe the hype with fervor but without knowledge, or old people whose grandchildren forced Linux upon them after getting tired of ridding their steam-powered Babbage engines of toolbars and malware.

What is the most curious though is the difference between young tech-illiterates and old ones. Even if the young ones have computer knowledge edging towards the negative, they can more often than not see what’s important on a web page; they can discern that buttons and links are where it’s at. Not so with old people. To them every web page is a jumble of colours and shapes. Nothing stands out to them. They have to read every single thing – but only if you’re talking to them.

It got me dreading my ageing. Will I be one of those people hopelessly out of touch with technology, grumbling that in my day, we used the internet and computers like normal people, not this new-fangled neuro-implant-copied-subset-personalities business you kids are using? (Yeah, I kind of forgot that sentence was originally a question too.)

This my fear of slipping in understanding is not shared by anyone at my work. They’re all very convinced that we will never turn out like that since we have grown up with technology. I’m not so sure. I keep coming back to something my father sometimes tells me (he’s a father; he repeats all his stories) that when he was young he had to help his grandmother make long-distance calls, in eerie analogue of how we help our elders now.

When we sit at the retirement home, having LAN parties instead of bridge nights, the orderlies will no doubt roll their eyes and without words say old people, eh? to each other.

It’s thoughts like these that have made me more afraid of ageing than anything before. Even though I understood on an intellectual plane that I would decrepit and die and my mind along with me, I never really knew it. The worst part is that I will probably become like the old people who infuriate me now; thinking I’m still “clear-minded” and “spry” and “alert”, while being gaga and confused. Nothing’s more horrible than thinking you’re sharp while people around you play along out of pity.

Since I’m too lazy to do anything about it, it’s just another scrap on the mounting heap of angst.

I’m a hoarder of sorts.

Time, Time, You Never Had It

Turns out that working takes time away from spewing mindless crap on the interwebz. Who’da thunk it?

But seriously: a whole fucking month and more since last post. Like the best pun says: “Time flies like an arrow, fruit flies like a banana.”

(Technically) Reading through Pratchett’s latest. I bought it when I needed a book for two times a journey by train, since I can’t sleep on trains or buses and you can’t see anything outside the window at night. Not sure what I think of it yet. Didn’t care much for his previous one either. That time it was because it felt so disjointed, this time it’s because I’m not convinced that Vimes out of town is a good idea.

Well, hundred or so pages to go. Might turn out alright.

Also I’ve recently read Embassytown by China Miéville and it was a great book. Miéville has a lovely command of the English language but it can become too much, like eating an entire cake at once. That was what turned me off Iron Council halfway through.

Like often when reading I started getting ideas of my own, for something about a diseases that kills no-one infected but everyone else by proxy, making war by brainwashing the enemy into love. Something like that.

If I will get around to writing it?

Ha ha!

Don’t be fucking ridiculous.

Clerks’ Mind

Since I found a job I’ve had less time to think and since I’ve had less time to think I’ve not come up with any quasiphilosophical bullshit and since quasiphilosophical bullshit is like half of this blog, there’s been a sharp decline in the amount of posts lately.

(The other half is me whining about not being able to write. I’m a complex man.)

Nevertheless I got to thinking about something I think about a lot: What is a mind?

Way back when I toyed with the idea of using paper as the storage medium in a teleporting scenario. This was meant to highlight how ridiculous teleportation is to me.

On the other hand, I have no real difficulty accepting intelligence in other than biological media. When you accept that matter is matter, no matter (ahaha) if it’s part of an organism or not, then there are few arguments against intelligence and/or consciousness appearing in other substances than carbon, hydrogen and whatever else we humans are made of (biology fo lyfe yo). It is not unreasonable to imagine life based on silicon, even if it might be somewhat far-fetched.

So the specific elements involved are unimportant. Then what is? The interactions, the structures and the continuous change of those structures. I fully accept that a simulation of a human mind would in all things important be a human mind. Which is why I’m so unnerved by research that has as its aim to create such a simulation.

But if we accept that a computer juggling electrons can contain a consciousness, then we also have to accept those electrons as being equally coincidental as the organic matter of the earlier paragraph.

That’s when I started thinking about the difference engine and of steampunk computers. If we can replicate the function of a brain in electronic computer then why not by mechanical means? I mean, that’s what the brain does; knocking particles against each other and whatnot. Remember, the medium is unimportant, only the structure is important.

Such a simulation would be very slow, but it would be a conscious mind. Gear boxes instead of neurons, chains and wires instead of synapses, but still a mind. Just because the machine has no electronics doesn’t make it less capable of containing an AI than a regular old super-computer.

This in itself was fascinating, but I got to thinking that perhaps we could take it one step further, which is where the teleportation thing comes back. In that example I imagined it all very steampunk, with ocean liners and typed sheets of paper and so on.

Now imagine that we have a huge office complex. In this complex we have an immense number of clerks working. As in all large offices, we would have divisions. Let’s imagine the divisions are connected via an internal mailing system. Not all divisions would be connected to all others, but only to those they need to deal with regularly.

Let’s further imagine that every division is in fact reenacting the function of a neuron in the brain, that the mailing system stands in for the synapses. Each individual clerk does their job according to the rules and regulations they’ve been instructed in.

This would be a mind and a consciousness.

I’ve been thinking about it before, the emergence of a consciousness from components, each following a simpler set of rules. For example, I’ve sometimes wondered what would happen when humanity reaches numbers of hundreds of billions, spread across the stars. I considered the neuron and what it is. In the most generic terms, it’s a unit that inputs, processes and outputs data sent to it by other similar units.

How is that different from people taking in information, digesting it and passing it on to others? The main difference is complexity and scale, of both time and distance.

So with enough people communcating, could there arise a consciousness that we, as mere components, would not even sense? A mind that would think across of millennia or more, while its human parts would die and multiply, replacing themselves.

The analogy breaks apart somewhat; the cells of our bodies aren’t close to being sentient, so we can’t really expect this supermind to look upon us as we do single cells. On the other hand we should probably be careful about predicting the behaviour of something of a higher complexity than ourselves.

The most interesting question is of course: Has this already happened? I mean, it’s not given that a supermind built from separate sentients would need the same amount of components as a mind built from non-sentient parts.

Is this what a culture is? Is this what a crowd is? Is breaking up a crowd murder of a supermind? Or is it just putting it to sleep?

How many minds is each of us part of?

Ominous Scenes of Space Set to Classical Music

Where I live there are two movie theaters. One shows mainstream films, the other artsy-fartsy stuff. Don’t get me wrong – I’ve seen several good films at Regina. It’s where I was introduced to the awesome The Man Without a Past. It’s where I saw The Princess and the Warrior (although in honesty I hardly remember anything of it). It’s where I saw The Journey to Melonia (a father left huffed with his son and a refund because the focus kept slipping).

Regina is small enough to only have one projector, so that the projectionist has to splice the film into one huge reel instead of the several it arrives in, then cut it up again before sending it along. This theater is located in a former boiler-room in the basement of a house where all sorts of low-grade cultural things are going on. It is run entirely by volunteers. They give you a discount if you’re a student or unemployed. The sink in the roomy restroom has an eerie It-like feeling to it.

Quite early this year I was intrigued by two probably-pretentious pieces of cinema: The Tree of Life and Melancholia, neither of which appeared at the mainstream theater. I should have expected them to appear at Regina, and at least one of them did, Melancholia. (The other one might have been or will perhaps be shown; I am not very attentive.) Still, I was pleasantly surprised when I heard it did.

I had mixed feelings about it as I watched it. The start was pretty hypnotic and ominous, with classical music and slo-mo scenes everywhere. Then it turned into a standard Scandinavian drama of the “everyone is horrible and life is dark, empty road to oblivion” variety. The wedding party had me playing a game of Spot the Swede (I found three) which was amusing.

It felt a bit long in places but the last scene was fucking awesome. Still, I felt somewhat disappointed as I made my hurried a-gentleman-will-walk-but-never-run to the bus. I guess I was expecting more dazzle of the sort found in the prologue. I didn’t regret watching it, though.

(I am quite shallow when it comes to consumption of culture.)

The other night I downloaded and watched The Tree of Life. Like with Melancholia, I was taken in by the start. Like Melancholia, it had space scenes set to classical music, albeit less boding ones. That part was amazing. Then – again, like Melancholia – it turned from cosmic to close, but unlike Melancholia it kind of stayed there. It never really left that claustrophobic suburb of horrible people, even with the intermezzos of a harried Sean Penn sleep-walking through his life of suited success.

It felt like it wanted to be cosmic and all-encompassing but it got stuck on the ground, while Melancholia managed to hint at larger things while starting smaller. Even the space scenes and the time-scale follow this: in Melancholia, we meet the planet in the solar system, in TToL we’re seeing galaxies; in Melancholia, the reach is months, years at most, in TToL we go from the Big Bang onwards until today.

I realise it’s not a perfect contrast, but I can’t shake the notion that the film that wanted to be grand in its reach was small, while the film that was small reached much further. Why is it not a perfect contrast? Because I suspect Melancholia wanted to reach far too, but didn’t feel the need to make a fuss about it.

Watching Melancholia, in a few places I got the feeling I was missing what the film was trying to tell me, that I lacked some crucial piece of the code. No biggie. This happens to me a lot. I could still enjoy it. (I’m sure I whined about this before.)

Watching The Tree of Life, I got that all the time, once the awe of visuals died down. The creation/evolution montage was beautiful but I didn’t understand what it had to do with anything else. Those badly CGI’d dinosaurs? Fuck knows. Everyone at the beach? Don’t ask me. Those short voice-overs that seemed vaguely religious? I shrug in your general direction.

I felt very disappointed. Half-heartedly I tried to read praise to understand what I missed (like I did with Mulholland Drive). People called it poetry and impressionistic and I still didn’t see what they saw. And I though I liked impressionism.

Then I noticed something interesting.

Every time I think back to Melancholia, it seems to have grown in my mind in some way. I increasingly find myself wanting to rewatch it. Maybe it was because the bleak ending is so much more in line with my default state of mind than the weird everyone-is-happy-in-heaven thing of TToL. (TToL felt like it had a happy ending but I just couldn’t figure out why.) Maybe it’s a Nordic thing to like melancholic things (even if von Trier is a Dane, the jovials of the Nordics).

It got me wondering if I will grow to like The Tree of Life as well.

Probably not.

Primo Victoria

Few weeks back a co-worker of mine recommended I’d check Project Euler out, so I did. It’s based around an ever-increasing number of mathematical/computational problems. When you’ve solved one of them, you get a link to a forum thread where people share and/or discuss their solutions. Older problems have their threads locked, though; to prevent down-bogging and repetition, one would assume.

The problems are quite interesting but rather difficult. I just assumed my Swedish education was to blame, but after solving some of them I found I had employed more elegant solutions than some – and, to be fair, less elegant than some.

Some of the problems can be solved with brute force but I always suspect there to be less computationally expensive ways. Sometimes that pays off, like in problem 16. In case you are linkophobic, the problem was to calculate the sum of the digits of 21000 when written in a non-potency form.

People well versed in Python or otherwise having a casual relationship to boundless integers did one-liner solutions which just brute-forced it by actually calculating the answer, converting to a string and adding the digits together.

Me, I hadn’t been exposed to bignum libraries, although I guess I should have known they existed somewhere. I had previously dabbled in converting 64-bit numbers to strings using 16-bit code, so I had a hazy understanding of how such a thing would be done. However, writing a bignum library – even a skeletal one – in C didn’t seem clever enough, somehow.

Luckily I quickly realised that since we’re always multiplying by two, we’re really just bitshifting the number. From that, it follows that 21000 is a 1 followed by a thousand zeroes when written in binary. So instead of calculating the number, I could just store it like that from the beginning. That way, the only calculations would be the divisions needed to convert it to decimal.


%include "string\str.mac"
%include "io\io.mac"
%include "useful.mac"

org 0x100
    mov bx, 10               ; the radix is ten
    xor bp, bp               ; store the sum of all digits in BP
    segmov es, ds            ; make sure DI and SI are operating in the same segment

    xor dx, dx
    mov si, numbers          ; SI should point to the big number
    mov di, numbers          ; dito DI

    mov cx, 63
    lodsw                    ; DX:AX / BX -> AX mod DX
    div bx                   ; and put the answer back for the next round
    stosw                    ; modulus will never be more than radix, which we divide by
    loop .each_digit         ; making overflow impossible

    add bp, dx               ; add modulus (= decimal digit) to total

    test ax, ax
    jnz while_not_zero

    word2str s, bp, 10       ; print total to screen
    putsline s

; we'll store 2^1000 in big-endian for simplicity's sake
numbers        dw    256
times    62    dw    0

%include "string\word2str.asm"
%include "io\putsline.asm"

section .bss
    s        resb 128

(The code is macro- and library-augmented, as you may have noticed.)

I felt rather pleased with that one.

Anyway. Onward to the problem I was actually going to talk about.

I haven’t solved a lot of the problems (just seven so far) but I’ve noticed a curious regularity of prime-related problems. I figured I had to tackle primes sooner or later, so I decided to start with one I perceived as being on the easier end of the scale; problem 7.

I started by reading up on primes a bit. Though easily confused by the Wikipedia articles on the subject, I gathered some information on finding primes. There are several sieves for finding primes, but sieves have some logistical difficulties. They would be more suited for when you want to find all primes below a certain number, since you can’t know (I think; maybe wrong on this) beforehand how many primes will be in a given range.

So I would have to devise some sort of checking algorithm. Between starting to think about this problem and actually solving it, I did another – also prime-related. Even before doing that one, I had suspected that all non-primes can be expressed as the product of primes. Turns out that hunch/forgotten-and-half-remembered-knowledge was right.

How did this help then? Read on, not-yet-asleep reader.

The initial mechanism is fairly straight-forward: have a counter that increases for each run of a loop. Check if that counter is a prime. If it is, add to the list. If not, ignore. Either way, increase counter, redo loop until we have the number of primes we wanted.

From the get-go I had the feeling that checking a number against all previous numbers would be a rather horrible, if working, solution. I can’t remember if it was the first refinement I did, but it’s one of the most obvious ones: only check odd numbers. That is, seed the first position in the primes list with 2 and start the counter at 3, then increase the counter by 2 for every loop. Because no even number can ever be a prime.

But it gets better. Since all non-primes are the product of primes, we only have to check the counter against previously known primes, i.e. the list we so far have compiled. This cuts down the number of checks dramatically.

I had also managed to realise that we don’t even have to check against all primes preceding the counter. I figured that since no number can be evenly divisible by anything greater than half of itself, we could put a limit at counter/2 for checking against.

That’s the point at which I ran and achieved the correct answer.

Upon reading the thread of solutions, I was reminded of something I had read but forgotten: that we can limit ourselves to far lower numbers. Namely, the square root of the counter, inclusive (or plus one, as I did below). I’m still a bit fuzzy on the specifics of this, but apparently it’s true. Incorporating this made for dramatic increases in speed.

Another hindsight tweak was to never start checking against the first prime, 2, since we already skipped all even numbers.

So I arrived at this piece of code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
    int *primes;
    int found_primes = 1;
    int currnum = 3;
    int i, isprime, lim;
    int numprimes;

        printf("Number of primes to find: ");
        scanf("%d", &numprimes);
    } while (numprimes < 1);

    primes = (int *) malloc(sizeof(int) * numprimes);
    primes[0] = 2;

    while (found_primes < numprimes)
        isprime = 1;
        lim = sqrt(currnum) + 1;

        // if we're testing against primes larger than the square root of currnum plus one, it must be a prime
        // we can start with the second prime, since we're already skipping all even numbers
        for (i = 1; primes[i] < lim; i++)
            // if modulus is non-zero, it must be a non-prime
            if (currnum % primes[i] == 0)
                isprime = 0;

        if (isprime)
            primes[found_primes++] = currnum;

        currnum += 2;

    printf("%d: %d\n", numprimes, primes[numprimes - 1]);

//  for (i = 0; i < numprimes; i++)
//      printf("%d: %d\n", i + 1, primes[i]);

    return 0;

Pew pew.

The best part is of course that I now have a way of making primes for future problems.

When’s Happening?

The other night I watched a documentary about time and how it only goes one way and how that’s remarkable. Coupled with a throwaway line in the book I’m reading it got me thinking about events. Mind you, none of these so-called insights are revolutionary in any other place than in my own brain.

In that book we have people who have developed faster-than-light travel, so one evening at a particular place they look up in sadness at the light of a battle they as a society fought 800 years ago. The throwaway line was something to the effect of that event happening at that observed instant, relativistically speaking.

It got me thinking and I realised in a way it was right.

What is an event? How do we know something has happened? The obvious answer is that we know it when we see it. The question is then: Has the event happened before we observed it?

A no-nonsense approach would be to say that even though we hadn’t seen it yet, it still happened. It seems fairly obvious; just imagine an observer closer to the event, so that they knew about it before us. Or, you know, the epicentre of the event itself.

Far as I know, information cannot travel faster than the speed of light in vacuum, which makes for interesting scenarios.

The Sun is about eight light-minutes from Earth (or vice versa if you want to be heliocentric about it). All sunlight we see is eight minutes old. Anything that happens on the Sun won’t affect us until at least eight minutes after it happened there.

Now imagine that the Sun somehow disappeared. Just vanished. We would not see this for another eight minutes, that seems intuitive enough, once we’ve accepted that light is not instantaneous.

What’s rather peculiar, though, is that the Earth would still follow its curved path around the Sun for another eight minutes. Even though the Sun would no longer exist, we would still be pulled towards it for another eight minutes.

If it was not so, then Earth would abandon its curved path for a linear one the very instant the Sun vanished. And if that was so, then information would have reached us before light did. We would observe the sky change is unexpected ways before we would see and feel the light and the heat go out.

But nothing can travel faster than light, not even information like that.

This means that there is no way that something can affect us before light could have reached us. There is no way something can causally influence anything else before that imagined sphere of light has reached the “observer.”

Does this mean that the timing of events is purely subjective?


Think of our vanishing Sun again. Up until we see the Sun go out, all our readings and all our observations would say that the Sun was still there. We would enjoy its heat, its light, its gravity.

Things get really interesting once we imagine someone on Venus, ~6 light-minutes from the Sun. They would experience this event before we did. However, the information of the Sun’s disappearance would reach us at the same time as the information about Venus’ receiving that same information. So all planets closer to the Sun would appear to us as going linear at the exact same time.

(This assumes that all planets are lined up; they seldom are.)

Mars would be even more interesting. Mars is ~13 light-minutes from the Sun, so information about the disappearance would not affect it until about five minutes after we would us. And then it would take about five more minutes for that information to reach us.  We would observe Mars following an orbit around a star we would already have seen disappeared.

That’s fucking mind-blowing.

It also makes me think that events don’t really happen at a particular instant but rather at a certain point in time and forever onwards.

Which every physicist in the world probably already knows and which probably is the whole fucking point of those neat theories of Einstein’s.