Placed project C Programming Made a Game on github


I placed the project for which I had made my old blog on github. I had the versions backed up but not via git. Back then I didn’t know about versioning software like git and mercurial. I was cleaning up my codebase and thought that converting the code dumps of previous versions of the software into git would make it much easier to manage the whole thing if I needed.

I also added the C++ programs’s source code which I had used for the project into the github repository. They had helped me back then take care of repetitive tasks a lot. That was kinda the project where I understood the real value of automating tasks and one of the reasons I started using Python.

I don’t think I am going to update it anymore but good to have that on github. It gets backed up. I am thinking about adding the setup files that I have for various versions on github or not. Still not decided on that.

If I ever thought of continuing the project I’ll do that from scratch in Python/PySide which I have been learning for some time.

If anyone’s interested in seeing what the project was just have a look at the old blog.

Excuse for cleaning up my code base


I finally got an excuse for cleaning up my code base – Upgrading from Python 2 to python 3. After exactly 2 months with Python 2 I decided to upgrade to Python 3 after a discussion on comp.lang.python. I am glad I am doing that.

I used this excuse to finally merge me C and Python repo that I wanted to do but just wasn’t doing because I didn’t want to do a huge merge without a reason. Now most of my Python code will go through a round of cleaning. All the code that I wrote a complete newbie would be cleaned. I am really glad. That will help me organize my codebase in the long run. I will finally be able to go with the proper timing analysis of my functions and break the big chunk of functions into smaller efficient modules.Learning a lot from all this.

Enjoying it a lot. Python is really great.

Automating tasks in Python – Deleting files


I have decided to use Python for automating some tasks that I do regularly and which consume a lot of time.

I have started with deleting useless files from my code base. I have been using github as a backup for my codebase. I need to upload the files on github server. When I am programming in C many executables and object files(.exe and .o) are generated. I need to delete these everytime before I commit my code base to github because backing up these files is of no use to me.

My git repo containing the full script can be viewed here. I’ll keep it updated there. I am placing the code here also but no updates guaranteed here.

import os

cur = os.getcwd() + "\\..\\..\\..\\git_repo\\C\\"
extensions = ['.exe', '.o']
exclude = ['.git']

def delete_or_not(name):
    for i in extensions:
        if name.endswith(i):
            return True

    return False

def cur_files(files):
    for name in files:
        if delete_or_not(name):
            yield name

def main(startpath):
    for path, folders, files in os.walk(startpath, True):
        for folder in exclude:
            if folder in folders:
                folders.remove(folder)

        for name in cur_files(files):
            os.remove(path + "\\" + name)main(cur)

The script is simple. The things that anyone would need to change are at the beginning. These are cur, extensions and exclude.

  1. cur is the path of the folder, in which you start deleting files, relative to the script. If you want to put absolute path you need to take out os.getcwd(). Files in its subfolders are also deleted.
  2. extensions are the file extensions which you want to delete.
  3. exclude are the folder which you want to exclude from this deletion script’s scope. Generally you would want the hidden folders to be excluded. I included one folder which I did not want the script to go through.

After making these changes you can simply double click to delete files if you have Python installed. I use Python 2 but this should be easy to convert to Python 3 also.

Next time I’ll make a script to run a group of Python scripts. That’ll help me to make any number of different scripts and choose what I need to run at different times like at startup, shutdown, before uploading files etc.

My experience with Python and C so far


I started Python on 18th May 2013 after I discovered that doing project euler problems via C(my primary language) wasn’t easy for me. Using Python doing those problems were quite easy. I started neglecting C and went ahead with Python with zeal. That has been helpful as using Python I have been able to solve 59 problems on project euler so far.

My project Euler progress so far.

Using C I went ahead to solving problems 11 and then felt discouraged. Maybe I wasn’t focusing on the logic so much.

By Python I have been able to do some things that I couldn’t do using C. Like making solutions easily to some problems. Using scripting in Python I found out that looking into files, copying them and many other things can be extremely easy.

  • I wrote scripts for finding whether I had done a particular thing in C but not in Python and vice versa. I arranged the files in folders for using this script but organizing code is always nice.  What was taking me a lot of time manually now can be done by a simple double-click now.
  • Writing a lot of functions in a single file was starting to be confusing. I wrote up a script for finding the function signatures. Took out a lot of confusion.
  • Check my github repo if you want to have a look at any of these scripts/

I am thinking about breaking down the file containing all the functions into many different files. That is the only way to go forward if I want to keep writing. Then I am thinking of making a GUI that I can use to separate all the functions by tags. I don’t know much how to do that as of now but I think I’ll use wxPython but that isn’t final.

I found that there are always a lot of new things that can be learned in programming and that stackoverflow can be a great resource. Check out my list of favourite questions and my own questions on stackoverflow. Maybe you’ll find something that you are looking for.

I have found out that using online judging can be a great thing. I have been using codechef for practicing C and Python. By using this I discovered that I will need to learn many algorithms and that there a lot more things to learn in any programming language that I choose to learn. It has been really helpful and the community is good. I started reading other people’s code thanks to codechef and stackoverflow. It has been helpful to me. I discovered that I can discover many different ways of doing things by looking at other people’s code. I initially joined github for the the same reason – looking at other people’s code. But I discovered that looking at other people’s code also helps if there is a large vvariety of code and their time and memory usage is available.

I  tried spoj for 2-3 days. I think there are more problems for practice than on codechef but I will need to learn more algorithms before I seriously try to solve them.

Solving codechef’s problems I discovered that the simple program of factorial that I usually wrote in C wouldn’t work even for factorials of 100. I later found out a way to calculate factorials of any number. It will be needing some polishing and final touches but I found a way.

I have placed Python on hold for past few days. I use it now and then but I am shifting focus back on C. I have started the MIT’s course Introduction to algorithms whose I have placed with a lot of other programming links. It is nice. I have finally overcome my fear of sorting algorithms. They are kind-of-basic things in programming but I couldn’t do them properly. While using linked lists, stacks etc. was something that I could do sorting was difficult for me. But now I am able to write insertion sort, selection sort, bubble sort and merge sort easily. Reading Cormen’s Book of algorithm is a challenge that I have taken up. It is more than 1300 pages book so it is a huge challenge but I believe that it can bridge a lot of gaps in my knowledge.

Using codereview is helpful. It helped me in changing a lot of formatting problems and bad coding practices that I was using. I have decided to get code reviewed for all algorithms that I use. Writing review is helpful. Looking up someone’s code and trying to give suggestions is good as experience.

I have some things to do this week. I’ll try to do programming in spare time. I’ll keep my focus on C and learning algorithms. I believe it would be helpful in the long run.

Finally getting a hang of codechef Judging


My exams are nearly done and I am finally starting to understand the codechef Judging. I was messing up my submissions and in some cases I simply needed a better algorithm. I solved some practice problems and even two of the June Challenge 2013 problems. Here’s my profile showing solved problems.

As I have solved 2 of the 10 problems I’ll finally be getting ranks for competitions for which I have been waiting for quite some time. I uploaded the solved practice problems on github, will upload the competition solutions after the competition is over.

I have been continuing to solve Project Euler problems. Reached 45 problems

When I was solving the codechef problems I realized that I’ll be needing to do much practice before I’ll  be able to solve all the problems. I will also need to read the Python documentation completely. I didn’t knew that some tools existed. So I’ll start with going back to Python documentation. Stackoverflow helped me a lot to solve the practice problems.

Been following project euler, started codechef problems


Project Euler

It’s been some days since I wrote last here. My exams started so I stopped writing on the blog. I have been doing problems of project euler. Completed 25 problems although not in sequence. I uploaded all in the Python repository on Github.com. Following the tutorials provided by Python.org I have been able to optimize many functions that I have been using. I have been doing this in spare time during exam preperations.

Codechef.com

I started using codechef.com for practice. It contains a lot of practice problems. I have done a few problems. It’s taking me some time understanding why certain test cases are failing as it’s my first time with online judges.

Python Challenge

It does not seem like it will lead to much progamming practice. This is starting to seem like trick questions instead of much programming.