25.8.10

C++ and Project Euler

A couple weeks ago I decided that I wanted to learn C++. Not out of any kind of fascination about programming, (though I have enjoyed it over the years) but mainly because there is a program I want that doesn't exist. Well... that's not entirely true, parts of it exist spread about but none of them are perfect, and that's the problem. The program is a mix of a dock program combined with possibly a keystroke launcher and would also probably replace the alt tab feature. It would also allow me to quickly and easily turn off my computer. Needless to say, having just barely started learning C++, I am very far from this goal. It doesn't matter so much however as I'm sure it will be useful at some point, and I'm enjoying it.

Over the weekend I went up to Salt Lake to hang out with my dad for a couple days. His company was having a party at Lagoon and he had invited me to go up. I of course immediately said I would, because I mean, hey, it's Lagoon! Since I had woken up at something like four o'clock that afternoon, I decided to go up to his place and spend the night to ensure I would be awake in time to go. I didn't arrive until pretty late but I still got to talk a lot with my dad, mostly about his work. He kept apologizing for it, but I didn't mind because I was really interested. His main problem he was working on had to do with some of the files of the program he works on not getting sent to the translator when changing it to a different language, leading some of the program to still be in English. He had figured out it was because of the name of the files and the way another part of the program chose the files to send to get translated. It got late though so we both went to bed.

The next morning I got to go to work with him, something I have always very much enjoyed, though I couldn't tell you exactly why. He introduced me to most of the people there and I got to listen to him talk 'shop' with some of the other programmers and even sit in on a scrum meeting. When he was talking to one of the programmers he mentioned that I was teaching myself C++ and they talked a little bit about different programming languages before we took off. It got me thinking about whether I made the right choice on the programming language to learn. So, a couple days ago I went about to find the answer.

Naturally, the first step was to google 'what programming language should I learn'. I clicked on one of the first links and read a blog post that it was essentially determined by what you wanted to do. It didn't really list C++ on it anywhere but it did mention C# for Windows programming. I'm not sure I'm going to stick with a Windows operating system forever though, so I figured I might as well stick with C++ since it is portable to Linux. I got distracted however, by a link to Project Euler. It's a site with a lot of math and computer programming problems dealing with numbers so large that you generally need a computer to solve them. (e.g. finding the sum of all prime numbers below 2 million, which is over 100 billion) So far I've solved 10 of them, though one of the latest (the one I just mentioned) I'm sure I could have done better as they are supposed to take no more than 1 minute for the computer to solve, but my program took over 15 minutes. I've been happy so far though with my progress and it's been fun. The favorite thing it's led to so far is the program I wrote to determine if a number is prime or not. My solution is pretty inefficient as it divides the number by everything from 1 to itself, but it works and that was cool. (I tried having it divide the number by everything from 1 to half of itself but for some reason it kept saying 4 was a prime number, probably because of a < instead of a <= but mneh, how often do I need to calculate all the primes between 1 and 2 million anyways? )

2 comments: