Ubuntu Forum beginners challenge #9

I wrote the following short program as a response to a ‘beginners programming challenge’ on the Ubuntu forum. I just got so tired of all the terminal-based solutions and chided the contestants that even phones had GUIs these days! It was kind of difficult separating original entries from rehash/error-correction but the tallies (by the time enthusiasm seems to have got lost) was:

PHP 11
C 4
Java 4
Python 4
Bash 2
C++ 1
Gambas 1
Haskell 1
Lisp 1
OO Spreadsheet 1
Perl 1
Scheme 1
Userland/awk 1

I didn’t see much evidence of ‘beginners’ in the entrants.

Anyway the brief was:
Your program should be able to open a text file and read its contents. The file will consist only of LOWERCASE letters and numbers 0-9. The file will be formatted such that there is only one alphanumeric character per line.
Your program must read each line and store the data in a data structure of your choice. Parse through your structure and print out the following information:

1. The sum of all the individual digits.
2. How many times each character appeared in the file.

I have put the code in a page on the right. It just needs a few standard objects on the form: a filechooser (default name filechooser1), a listbox (listbox1), a button named btnExit and a button named btnRun. If any real ‘beginner’ needs help to get this going, just shout.

It is easy enough to cut and paste from the blog although I have also put the source code as a tar.gz at Prog Challenge Source.

Gambas also does a good job at compiling run-time versions of applications and I have put a Debian package installer at Prog Challenge Installer.


4 Responses to “Ubuntu Forum beginners challenge #9”

  1. Bubexel Says:

    Well, i’m creating a mmorpg game, linux client made in gambas and windows/mac client in python. And i have to say that gambas is 100 times faster than python. Linux client works around 900 frames per second and python at 20 frames per second, and its a big perfomance problem. Sad that gambas doesnt work on windows đŸ˜¦

    congratulations for your blog, i love this kind of webpages for beginners.

    • charlesg628 Says:

      Thank you for your comment. The standard answer (in the Windows world) to slow software is to hit it with a bigger hammer. The result is a pile of servicable but obsolete computers the world over. The hardware manufacturers rub their hands in glee as the software becomes progressively less efficient. Or is it the other way round. In any event it is not a grand use of earth resources.

      My admin Linux box at work is a ten year old Athlon (not even 64) that I bought new with Windows ME (yuurrggh!). By todays’ standards it’s a bit noisy but still brings home the bacon. On Linux that is.

  2. raydeen Says:

    Very nice site I was one of the entrants in the contest mentioned (and definitely a beginner in that I haven’t really done much programming since the late 80’s and 90’s). While Python is still my current focus, I just gave Gambas a quick try and I must say I was able to grok it and come up with a quick app MUCH faster than Lazarus. Definitely going to be giving Gambas more attention (I was raised on BASIC – Atari and GW). Now if only there was as nice a setup for Python…

    • charlesg628 Says:

      Thanks for your comments. I cannot think of a programming environment which would suit MY requirements better than Gambas. I must admit that Python too is a fine, elegent and economical language. It gets better and better the closer you need to be to the heart of the operating system. Not my problem: I just munch numbers in the name of commerce.

      If someone could just write a gui ide for Python that is half the quality of the Gambas ide, then Python would be unstoppable.

      My intention in responding to the challenge was to show that Gambas is a contender. If you (as you seem to suggest) accept that premise, then I am a happy chappy. I resent the challenge being turned into a speed contest but will confess that the Gambas program ran the challenge with a text file of 1,000,000,000 lines in 18sec on a six year old Athlon 64. Not bad for a gui program.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: