Archive for the ‘Programming’ Category
First 50 problems of projecteuler.net in python
I have been doing projecteuler.net challenges lately.
Here are my solutions in Python for the first 50 challenges. First 10 are in Python 2, others in Python 3. Each of them takes under 2 seconds to run. I can see how many of them could be optimized further, but they are already fast enough. About 1300 lines in total.
I have separated common functions into EulerLib library which is given at the end of the file.
PySchools and CodingBat
As an effort to practice python, I have been doing CodingBat and PySchools challenges.
Finally, today I finished all the challenges, totally there were more than 250 in these two combined. I don’t know how justified is that, but I am now in the first place of PySchools worldwide ranking )
The guy who made CodingBat is Nick Parlante, the same person who made the Google Python Class videos which were my gateway into learning python. He is making other cool things too, for example this.
Some interesting modern programming languages
There is a ton of various new programming languages nowadays, but here are the ones that I found interesting:
Clojure: LISP-like, compiles to JVM
XLR: very new, not famous at all. Concept-programming, syntax similar to python, but even cleaner. Aims to make path from concept to implementation as short as possible. I really hope that this takes off.
Erlang: (distributed). Apparently it is easy to write parallel, distributed applications using Erlang. As far as i know, Facebook chat is written in Erlang.
Scala (scalable, compiles to JVM). Twitter was originally written in Ruby, but then they switched to Scala. So if you are the size of Twitter you should consider it ). Nowadays new startups like to use Scala because it makes them appear more scalable to venture funds. They also use NoSQL databases like Cassandra or MongoDB for the same reason.
Processing: graphical. As far as I understood, you get a plane and you can draw there algorithmically using processing programming language. This seems to be popular with designers.
HaXe: Syntax is similar to Javascript and ActionScript. The code written in HaXe can compile to C++, ActionScript, JavaScript, Flash, PHP, and soon hopefully even Java and C#. This “code once, deploy everywhere” idea is very nice, though I don’t like HaXe syntax much.
J: A descendant of APL but without all those non-ascii characters(which actually makes J even less readable than APL). J is write-only language ). It is easy to write programs, as you don’t need to type a lot. But it is damn hard to read others code. To mess with your brain even more, J is read from right to left.
Here is an example of J one-liner. You decide for yourself whether you like it or not )
quicksort=: (($:@(<#[) , (=#[) , $:@(>#[)) ({~ ?@#)) ^: (1<#)
Python
So I was thinking, which new programming language to learn?
The first language that I ever learned was PASCAL, and since then I was missing the beautiful PASCAL syntax in other languages like C and Java. Now I want to learn a very high level programming language with simple and concise syntax, and the best match for these requirements is Python. It truly is a wonderful language, and their ideology of “There should be only one and obvious way to do it” is what I like the most.
However it appears that Python development has been split into two: Python 2.x and Python 3.x, where 3.x is backwards incompatible with 2.x. The mainstream web development platform “Django” for Python is not compatible with 3.x yet, and so if I write my programs in 3.x, then I will not be able to use functionality of Django. On the other hand, if I write my programs in 2.x, then I will not be able to use new coming 3.x programs. This is a disadvantage for me, but since I don’t have other options, I guess I will try to learn 2.x for now. And then, when Django is converted into 3.x (in a couple of years probably), I will switch to Python 3.x as well.