Roberto Selbach

Random thoughts

Euler 7

So the other night I was a bit bored and decided to do something to pass the time. I first came across Project Euler a while ago, but had never gone further than problem #1. Boredom is a great motivator and I went through problems #2 thru #9 last night and I decided to post my solutions in search of better ones. Feel free to comment with your suggestions.

Project Euler’s Problem #7 statement is —

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10001st prime number?

It’s a straightforward problem to solve using brute force, but I went with a mixed approach doing some math instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/python
import math

def is_prime(n):
    return not (n < 2 or any(n % x == 0 for x in xrange(2, int(n ** 0.5) + 1)))

currentMax =0
primes = 1
counter = 3

while (primes < 10001):
    if (is_prime(counter)):
        currentMax = counter
        primes+=1
        counter+=2

print currentMax

I initially used a dumb brute-force which ended up running fast enough. But reading about primes, I came across this property by which if a number cannot be divided by any number smaller than sqrt(n), it is a prime. That required significantly less tests to be performed inside is_prime, but then again, it had to perform a square root calculation for every number we need to test. In the end, the algorithm above performed slightly better (0.02s to be exact.)

Updated: Thanks to Eduardo Habkost for pointing out the fact that I had mistakenly pasted the wrong version of the script. I fixed the text to reflect that.

Why can’t people buy newer cars in Argentina?

This is part of a series of posts about Argentina and the City of Cordoba. These are little facts I wish I knew about before I came here as an expat.

One of the first things I noticed when I arrived in Cordoba, Argentina, was the amount of old cars going around. And I’m not talking about 10-year-old cars, I’m talking about 30 years or so!

You can really find some rarities such as the Citroën 3cv happily racing around town all the time. As a consequence of all that, you can also find a disproportionate amount of cars stalled on the streets, people trying to do something under the hood. It’s really amazing how many broken down cars you’ll see every day.

Citroën 3cv

I used to wonder why that was. Now I understand.

There is no credit in Argentina. Well, technically there is, but it’s so expensive that it’s as if it doesn’t exist. That’s why people normally need to buy stuff with cash upfront. Cars, of course, happen to be expensive and most people can’t save enough to buy newer cars like that. The same is true for several other goods, but cars happen to be the most visible symptom.

From time to time, coincidently around election time, the federal government creates some credit program. These programs are temporary and limited in the number of people who can apply.

And then there’s a second problem—informality. In order to avoid taxes and benefits, most companies hire people either with no documentation or with phoney pay information, e.g. if someone’s salary is, say, $1,000, the companies would register the employee as being paid $250 instead, thus being able to pay less taxes.

And thus even with those government credit programs, most people can’t even qualify as they can’t show enough income.

How can I get rid of (not so) old books?

I’m not a big believer in keeping books forever, even though I do keep some. Most books, however, I just want to read and pass along.

It just so happens that I have a ton of books that I want to get rid of. I could throw them away, but it somehow feels wrong. Also, I could donate them to some school, but considering where I live now, I assume this too will bring me one hell of a bureaucratic nightmare. Also, most of the books are either in English or Portuguese, so schools would probably not use them anyway.

With very few exceptions, all the books are either mathematics, economics, programming, or scifi. I thought I’d simply take the books to the office and give them away to anyone who’d like to have them.

But then my wife gave me an idea. Instead of taking the books and giving them outright, I started sending random emails to a mailing list with geeky questions, often related to the book topic. Whoever answers correctly first, gets the book.

This worked amazingly well.

  1. It created a fun environment for all involved. People actually want to get the answers right. Others learn by, well, learning the winning answer.

  2. For books that normally no one would care about, the fact that you have to win to get it suddenly adds value. It’s no longer a book no one wants, it now is an award.

  3. All of a sudden everybody loves me 😉

Had I just announced I had a bunch of books, people would get by, pick a few they cared about and that would have been it. No fun. So every now and then I take a few books from home and then give them away to quiz winners.

It’s actually lots of fun.

Why do things take so long in Argentina?

Coincidences have a way of catching one’s attention, haven’t they? Yesterday I was riding the bus home with a colleague from work. I was telling him how my life here wasn’t perfect because I couldn’t buy a car. It turns out that I would need to hold a national ID card (called DNI) to purchase a car. Actually, one needs to obtain the DNI to do pretty much anything like opening a bank account. Interestingly enough, you need the DNI for small, simple tasks like ordering cable TV, phone lines, Internet access, etc, but one can easily buy a house – or many houses – without the DNI.

The process of obtaining the DNI is simple. If you’re a citizen, your parents will have used your birth certificate to get your first DNI, which is mandatory from a very early age. Over the years, you are required to update your DNI when you reach certain ages (8, 16, 25, if I’m not mistaken) and everytime you change address. All you need is the original DNI and some address verification and you’re done. If you’re an expat like myself, you need your passport, your resident visa, and some address verification. Again, very simple. You go, apply and wait for the document to be ready. And that’s where the problem resides… in parts of the country, the DNI takes years to be ready. Even in Buenos Aires, it can take more than one year for your DNI to be ready for pick-up.

Now how could such a simple and yet much needed document take so long to be manufactured?

So there I was, talking to this colleague about all of this. He told me that when he had to change his at 16, it took two years. And he’s a national. He told me it’s usually because government workers don’t have the incentive to work harder. He’s probably right, as this is the case everywhere else in the world. Still, this might explain why a simple document can take 2-3 weeks to be created, but not years. When I stepped out of my ride, I bumped into a girl who lives in our building. She told me she was frustrated because she had lost her DNI a couple of years back and the new one wasn’t ready yet. She had just went to the Identification Office to check. Coincidences… I then told her about my story and she told me so other tales of horror and I shared some of my own, like when I needed a document notarized and it took a month to do it. And that was it.

Fast forward a day.

My wife is currently having classes and she asked me to get her a textbook she needs. I went to this bookstore on my way to work. I strolled into the store and worked my way to the textbooks section and quickly found the one my wife needed. I picked it up and headed to the checkout, content that I wouldn’t have to hunt for the book in other stores. I held the book and the cash in my hand. “I’d like to take this” I told the lady at checkout, who in turn looks around and goes “Did you pick a number?”

What. Fucking. Number.

“What number?” I asked, confused. She then pointed me to this little thingamajig near the entrance. “I’m sorry, I don’t get it…” And then she half-mockingly explained to me that I had to pick the number and wait my turn for a salesperson to help me. “But I don’t need any help. I have the book and the money right here!”

No use. I had to pick a number and wait for one of the two saleswomen to call it. So there I was, holding the book I wanted, with the cash to pay for it, standing by the checkout – where the lady was doing nothing by the way – and waiting for someone to “help me.” In any half-civilized place our business would have been over by now. The store would have made money and I would be on my way to work. Simple.

Twenty!!!!!!!” shouted a lady. It was my number. So I went to her – looking pissed, I’m sure. I told her I’d like to please take this textbook. “Oh, certainly!” So she goes to a computer terminal and asks if I’m paying with a credit card. I wave the cash and say “efectivo” to make sure she gets it. Then she asks what the book is for. For reading, duh! I tell her that it’s for a course, then she types something and asks which school. “Lady, sorry but all I want to to take this textbook with me. I have the cash right here. I’ve had both the book and the cash in my hands for like 15 minutes already. All that’s missing is for that lady at checkout to get the money so I can get out of here.” And yes, I was pissed and I didn’t really sounded friendly and half the store was staring at me. She said apologetically, “I’m sorry, but I need to register who purchased the book and where it will be used.”

Why?!?!

“Lady, seriously, I don’t want to give any more information. I want to buy this book and that’s it. You either take my money or not. Your choice. Just let me know so I can get out of here.”

The whole store was following our exchange. Everyone surely thinking that I was the mean foreigner who’s going to explore them and steal their water (it’s a local thing.) She told me to go to the checkout I had been to 15 minutes earlier. The lady took my money and asked if I wanted a receipt. D-U-H!

So I realized it has to be a cultural thing. Bureaucracy is so entrenched in their lives that they don’t even realize it anymore. They just think it’s the best way of doing things. The problem I had to get a document notarized is a perfect example. I went to a notary, who then notarized my document. It took two days, which is already ridiculous, but still… the problem is that after he notarizes it, he has to send the document to the Notary Guild Office so that they in turn can verify that the notarizing notary was in fact a certified notary and that the notarization was correctly notarized. I am not even kidding.

Argentina has a lot of great things. Things that I actually love. But in terms of bureaucracy, it’s really, really a mess. And the very people have been “infected” by it so that they are bureaucratic at heart. It’s actually really sad.

Suquia Creek

imageThings are starting to get busier on my new project. It is, alas, still listed as Restricted Secret, which means I cannot really talk about its details. Nor could I even reveal its codename, even though codenames reveal nothing about what a project really is. For the sake of making referring to it slightly less annoying for me, I’ll refer to it using a made-up codename in the best traditions of the company’s history of naming things for lakes, peaks, creeks, and towns. So the secret project shall henceforth be known as Suquia Creek (being the creek across from my house.)

Since I cannot give any details on Suquia Creek, what could I possibly talk about? A lot, it turns out. I can talk about things I’m learning while working on the project.

Ah boy, am I learning!

It turns out Suquia Creek is going to be the longest, most complex project I’ve worked on. Until SC came along, the longest project of my life had been Lava Peak, which ran for about two years. But that included post-launch activities. We managed to go from ideation to shipping in just under a quarter (I even won an award because of that back in 2007.) Suquia Creek, on the other hand, is scheduled to ship in 2014! That’s nearly half a decade of work.

As well, for earlier projects I only had to worry about software. Suquia Creek, however, is also hardware. And on the software side, off the top of my head, it involves —

  • Processor µcode

  • Chipset code

  • BIOS extensions

  • Firmware code

  • Drivers

  • An SDK

  • User-level apps

  • And a few other things I can’t say without revealing more than I should.

Bottom line: it’s huge as far as I’m concerned! And we should support multiple versions of Windows and one distro release of Linux. It also involves several cross-functional, geographically-dispersed teams based mainly in Argentina and the US, but also with some smaller efforts coming out of China, India, and Israel. That amounts to six different timezones, for a current maximum time difference of 17 hours.

And then we come back to schedule. I have no idea what I’ll be doing at home during this weekend, but I have to have a rough idea of what we’ll be delivering on, say, week 41 of 2013! That assumes the world will not end in 2012, of course.

This week we had our first engineering meeting to plan on a tentative schedule. Late next month I’ll be flying around between Silicon Valley and Silicon Forest to work out the (semi-)hard schedule. By then, we’ll actually have one internal alpha release in place already. After that, we’ll have another alpha before our first “release”, an internal proof of concept, which will then be used by customer as part of a (quasi-confidential) pilot. The customer? One of the world’s largest… well, can’t say what is their industry yet. It’s huge though.

After that pilot I expect to be able to open up a bit on what the project actually does. In the meantime, I’m going to be sharing my learning experience.

It’s going to be an exciting half-decade for me :–)

A Decade as a Linux Pro

After I recently accepted my old age, I was talking to some friends who, to their own surprise, found they were old too. We were talking about when each of us started working with Linux and a friend noticed he had been working with Linux for 10 years. That’s when I realized it’s been a decade since I was first paid to work with the operating system.

I had been using Linux for a little while. My first contact with it was in mid 1995. I had bought a computer magazine from the UK that had this pink CD-ROM with something called Linux-FT.

One of the cool things about Linux-FT was that it had a licensed copy of the Motif window manager, which was pretty cool at the time. I had been using some RISC boxes in college running CDE, so I felt right at home.

infomagicNot long after that, a friend who was an administrator at a new ISP let me borrow his Walnut Creek CD-set containing Slackware 2.1 or 2.2 (I’m not sure anymore. Old age, remember?) Then I purchased a copy of the wonderful InfoMagic 5-CD set containing Slackware, Red Hat, mirrors of some FTP site and another distro I can’t remember either (Shit! I’m old…)

Then in 1999 I was hired to help this company migrate from Windows to Linux. It was the first time I was ever paid to do anything related to Linux.

I went to work at Conectiva the next year, where I learned I didn’t know anything. What the heck do I do now? That’s also where I learned like never before, made lots of friends, and found the love of my life. (No, not another Linux distribution! I mean my wife! What’s wrong with you?)

In 2004 I left Conectiva and started working with one of the company’s founders on another Linux project. The work itself was interesting, but it was also my first contact with something that I would see a lot more in the future: the downright dishonesty of Linux entrepreneurs in Brazil. Of course, I then thought it was an isolated thing and decided I didn’t want to be a part of that and left the company in 2005.

That’s when I came to Intel to work at the CSO, a “personal” project of Andy Grove. CSO had a simple mission: to foster Linux usage by financing and providing engineering to business with good ideas. How great is that? I was going to work on my passion (Linux) and meet all kinds of people who shared it with me. What could possibly go wrong?

Oh boy.

In the following year I’d see things that would still make me sick years later. From businesspeople to self-appointed free software leaders, all I saw was guile and greed. It was such a disappointment that I requested a change. I stopped working with Brazilian businesses and projects completely, moving to support projects in other countries. Things were much better, which is another disappointment and one of the reasons why I hold us Brazilians in such low regard as a people.

Outside Brazil things were very different and despite some funny things here and there, I am proud of the Linux work I’ve done, especially the megalarge project with the government of Venezuela. I even met Hugo Chavez, which is funny considering my political stand 🙂

Regardless, I was also getting disappointed at other things as well. After years developing projects such as KDE, I was bored to death. I started witnessing things being done on other platforms and suddenly the Linux desktop just felt stale to me. It was dull and lifeless and at the same time I was doing all these cool stuff on Windows.

Add to all that the fact that KDE started getting full of kids adding more and more useless features… and politics… ever heard the one about the moppet who decided that all KDE About boxes should contain a thank-you note to American troops worldwide? And he wasn’t even American? You know what?

Screw Linux.

I dropped it like you wouldn’t believe. And it felt good. Not having to edit configuration files to do something simple made stuff pleasant again. I was introduced to Mac OS X and I loved it. It was Linux on steroids. All the good stuff without the kludge.

No more politics. No more GNU Slash Linux. No more open source vs. free software. No revolutionary-audio-framework-of-the-month. No juvenile cockiness. No rWindoze. No Micro$oft.

Just fun.

After nearly 15 years, I’m truly free.

The Grumpiest Post I’ve Ever Written

So today I was called grumpy, which was inconsiderate and uncalled-for, so I did what every stable adult man would do. I complained to the one person who’s required by God and Country to always be supportive: my wife. “Who the hell does she think she is calling me grumpy?” I asked. And my wife went “well, you totally are,” which was an inconsiderate and uncalled-for answer. “Hey! You’re my wife! You’re supposed to love me!” and she was “I do love you! And that’s why I need to be honest.”

Crap.

It’s not that I could not live with the idea of being grumpy. It’s just that I don’t see myself like that. Or rather I didn’t. Now I kind of do.

There are a couple of young kids who are all high on the whole GNU Fucking Slash Linux. Not unusual. When we’re young, the world does seem a lot more black and white. That’s fine. Kids will rebel and Linux… Ops, sorry! GNU Slash Linux provides an outlet from which all the rebellion that a young nerd can muster. I mean, it’s not like these kids get invited to the parties where popular kids do their rebelling, right? Again, that’s all fine and dandy. Been there.

But then these kids—high as they are on GNU Slash Kool-aid—forget that they’re the new kids on the block. I mean, seriously people, Linux isn’t new anymore. There is a lot of people who came before you kids came out of daddy’s place. No shit.

Let’s face it, this is part of being young. You feel like you have all the answers and everyone else in the world failed to see The Truth. No problem with that. Except…

Except that shit means I’m now officially old!

Motherfucker.

Today I see a friend commenting about Linux and one of these cocky, know-it-all kids jumped on his case like he was some kind of newbie or something. Hell, that actually got me angry. And then it hit me.

Doesn’t that make me grumpy?

So. Fucking. Be. It. I hereby accept the label of grumpy and shall sport it with pride.

Grumpiness

So my friend works with and improves Linux for years and then a kid comes out of nowhere—having never done more than tweeting about Linux—and dares berate the guy? Go suck an egg, son! The guy I’m talking about knows more Linux—and note how I dropped that slash shit and I don’t even care—on his pinky toe than all your friends together. Kid!

Goddammit.

-rst.

P.S.: I’m not really angry. Or am I?

The Delusion of Not Being Deluded

Ever came across someone who wanted to show off how independent and free their own thinking was? I have, many times. Discussing with these people is an amusing and yet wretched event. It’s like goping to a funny dentist. She may be funny, but she’s still going to bore a deep hole in your tooth. And boy, will it hurt! At least one of you will be laughing, right?

I happen to know a couple of people who have got such strong conviction of their own uniqueness in being free from delusion that they cannot avoid being delusional themselves. Both are on this righteous crusade to extricate people from their self-foisted enslavement in the hands of evil Apple. Wait, what? Yes, that’s right. From Apple! Apparently to some people, the operating system or the phone we use is the wrong one and we are pulling the wools over our own eyes into thinking otherwise. Fortunately for all of us, there are these cavaliers in shiny armor who will rescue us from ourselves. Dude, seriously? How much more fucked-up delusional can one get?!

image

I don’t know if those guys did too much role-playing in their lives (and I don’t mean in bed) or it’s just too much World of Warcraft. I don’t really know. But if there is one thing I do know, it’s that it’s delusional. Why is this so? It’s really a synthesis of a couple of things —

  • Belief that one is right about something. Being fair, we are all like this. If you ponder about it, this is the very definition of having an opinion. Nobody thinks they are wrong about their opinions.

  • Self-aggrandizement. Again, to a variable degree, we’re all like that. We all love to think we are more than what we really are. Probably a defense mechanism. Without that, we’d all have killed ourselves by the time we reached puberty. Or maybe not all of us, because I am super awesome.

  • Strong illusions.

What exactly is a delusion? A delusion is the belief that an illusion is real. We all have illusions, but a few go farther. They have such strong illusions that they begin believing in them.

These people actually believe that there is a war going on. A struggle between good and evil. A conflict between freedom and slavery. And let’s face it, everyone wants to be one of the good guys. Except supervilains. Supervilains want to be on the wrong side. Always.

Once you are set on the idea that (a) there is something like black-and-white good and evil, and that (b) the fucking clash is on, there’s really no stopping you. You need to fight to Good Fight. But since there really isn’t a war going on, the only way to fight it is by making up stuff as you go. So you pick your villains (say, Microsoft and Apple) and your heroes (say, Google and GNU) and you go out saving us ignorant civilians. From ourselves. And from Apple. Because Apple is, like, super evil. Ah, if everyone was like Google…

Holy. Shit. People. Grow the fuck up!

Let’s all pretend for a moment that there really is a war going on. That Google is out there fighting for our rights to free goodies in exchange for nothing at all. That Microsoft really owns the world’s Secret Cabal and Bill Gates sits down everyday to plan what evil deed needs to be done that day. Let’s say all of this is real. Wouldn’t it be a lot more productive for you to focus on your enemies and leave us civilians alone? Go ahead, wear your fancy penguin costume and take pictures of yourself peeing on the Microsoft logo. A lot of people will love that. And more importantly, you will feel like you’ve finally accomplished something! You won a battle for the good guys! Hooray!

But please leave the rest of us alone.

-rst.

P.S.: a friend just sent me this picture, which says a lot. I think the message is: Dude, don’t be a fag!

image