Thursday, December 15, 2011

5 hours @ ICPC Asia Regionals Amritapuri

  At 8:30 am On 12th December, Aditya Prajapati, Arth Patel and myself or in other words Team Zion wwere sitting in the Computer Lab of Amrita University waitingo for the ACM ICPC Asia Regionals to start.
  Going back 2 days, 10th December morning, we were completing our final examination of the 5th Semester. Just after the exam we rushed to the printers for our tickets, then went to railway station to catch a 4pm train to Mumbai then a 5am flight to Kochi and finally a car ride to the campus. We were exhausted but we had a night to partially recharge our batteries.
  Anyways, the contest time, we idiotically didnot get Kevin sir's "notebook" printed and that was our first of several mistakes to come. We were without practice anyways. Then the questions arrived. I read question A, Aditya read question B and Arth was reading question E. I realised question A was the 2D version of one of the online round questions and hence found it easy to code. By that time Arth had already started coding for question E. He made the code and ran it for some test cases, working! We thought, yeah! He submitted it! Wrong Answer! There it was staring at our faces! Then Aditya Jumped in and realised Arth had read the question wrong! I then saw that question G was being submitted pretty quickly so we went for it and submitted it at 27 or so minutes. Relief! Then I returned to testing the algorithm for A and Arth and Aditya tried to find a proper algorithm for E. We all spent more than an hour just trying to figure out the algorithm! Then I finally showed Aditya my algorithm, we then coded and submitted it. Wrong Answer! Aw man! Arth then read the question E again and then realised that they were reading it wrong entirely! The reaction that we had after Arth said it! We had spent 2.5 hours trying to solve a question that we had read wrong! We finally coded it properly and submitted it it finally was correct! Meanwhile I had found the trivial case for my algorithm in A and had moved to problem J as Arth was coding for E.
     The question seemed very simple to solve but turned out all our optimization algorithms were failing and we had 5 TLE submissions! The last one was 2 seconds before the end! At the end we ended up being 94th after solving 2 questions. We were not happy but the bigger realization dawned next! We had not submitted question A! I had found out the trivial case and made the necessary change! But since we were to occupied with E we made A wait and rest is history! Angry at ourselves we got out of the room, sulked for some time but then the closing ceremony started in came C J Hwang and we forgot about our performance!
    All in all we had a fun time at ICPC Amritapuri but next time we may go to Coimbatore or Kanpur for a change!

  

Monday, November 7, 2011

An afternoon with canvas

   Today I returned to my hostel after a 2 week long Diwali Break. Well, since it was Diwali it was obvious that I wouldnot be doing a single bit of coding and I am not complaining, but the last 3 days at home were free so I thought of getting in the mood slowly. So I picked up an old painting application that i had developed.
   The previous one was a simple jQuery based application and did not have a feature to save your work so all the Davincis and Picassos out there could not show others their creations. So I thought of making the same app but on HTML Canvas element as it was very easy to save what you did!
   This time again it was very easy to make the JQuery code that was used to paint. While it took me a long time setting up the positioning of the objects.Let me share some code needed to get the canvas up and running.

HTML: 
<canvas id="can" width="500" height="500">

CSS:
#can
{
   border:1px solid black;
}


JQuery/Javascript
var dodraw = false;


var size=15;

var canvas = document.getElementById("can");

var ctx = canvas.getContext('2d');

ctx.StrokeStyle="blue";

ctx.lineCap="round";

$("#can").mousedown(function(e){dodraw=true;





ctx.lineWidth=size;

ctx.beginPath();

ctx.moveTo(e.PageX,e.PageY);

ctx.lineTo(e.PageX-1,e.PageY-1);

ctx.stroke();}});




$("#can").mousedown( dodraw=false;)






$("#can").mouseover(function(e){
   if(dodraw==true)
  {
      ctx.lineWidth=size;
      ctx.beginPath();
      ctx.moveTo(e.PageX,e.PageY);
      ctx.lineTo(e.PageX-1,e.PageY-1);
      ctx.stroke();
  }});

This code should be enough to get your canvas be able to draw stuff. You can further add features and modify the code as required.
I have currently added eraser,brush,save, new and size +/- buttons to the page.
The demo is available here:Open World

  

Sunday, October 16, 2011

ICPC 2011 Where do we stand?

  First of all, sorry that I have not been posting anything lately. Have a lot to share but unfortunately higher priorities coming up!
  So, today was the online selection round of ICPC 2011 for Amritapuri regionals. Now, as the dates for Regionals at Kanpur clashes with that of our end-sem exams, that was ruled out! So, we HAD to perform well to get selected(no option,none at all)! That meant, good hands on practice. But, that was not part of our plans! On past monday I realized the contest was just a week away! Then started frenzied practice sessions!
   Anyways, cut to the contest time. The contest started at 9 am and after 15 or so login attempts, we were finally able to login and see the questions. At first we thought there were 3 easy questions, one medium and one hard. After one "Time LImit Exceeded" submission for problem A we realised that it was actually difficult to solve (eventually only 8 teams all India could solve it!) While Arth was coding the first question, I and Aditya made the algo for problem B and C. The problem B was accepted without any issue and C had one minor glitch. We were so excited after the second submission that we actually screamed "ACCEPTED!" Just 5-6 minutes after that Arth submitted problem D and we again screemed "ACCEPTED!". But, that was the end of all of our screams. We submitted 3 questions at the end of the first hour and then no submission for the next 3 hours!
     After 2.5 hours, me and Adi left all hope of solving problem E and were just sitting there watching Arth try and solve the questions. We ended up being 3rd in our college and somewhere in the 120s or 130s all India. The final result will come on Tuesday. Fingers crossed!
     BTW Shrey Agarwal has shared algorithms for some questions at http://allaboutalgorithms.wordpress.com/

  

Thursday, September 1, 2011

Old game new interface

   Since last week or so I had a strange craving to play the games that I used to play when I was in school. Those were all small and short games unlike the Most Wanteds or the Counter Strikes and all. Surprisingly, the only long running game that I used to play was Age Of Empires-II. A single regicide match would last for 15+ hours but not in a single stretch ofcourse.
   Now, coming back to the point, ever seen an alcoholic when he is unable to get alcohol? Well, that was my condition when I realised that I had lost the CD in which the games were there! What now??
   *LightBulb!* I suddenly remembered I had already developed the mobile version of Battleship! Why not a mobile version of one of these games? So I started testing my memory to check how much of what game did I remember. Eventually, I ended up deciding to make the mobile version of the K-tour a simple chess board based game. You have to move your knight on all 64 squares of the chess board without repeating at any location.
    Simple to make, I coded it in very little time. I hated my code when I looked at it because it had too many conditions, well to help me out there, my friend simplified the checking algorithm and hence helped me(Felt it worth mentioning).
   Anyways, there was no point in simply doing what I had already played and also there was no point in changing the game play as that would beat the purpose of recreation. Solution?? Change the interface. Added a few tweaks here and there and well, the app was ready!
  Will post it on Open World soon! Till then stay tuned to this space for updates and more posts!
  

Wednesday, August 17, 2011

timetable.sh for lazy people like me

   It is always very difficult for me to remember the time-table, especially for the first few weeks of semester. The condition was worse this semester, so I HAD to find a solution for this.I know, taking a photograph of the timetable would do it but I thought of doing something new (yeah!!)
 
   Since, the start of this semester, I had started using Linux and so I thought of making a shell script to help me.Well, fortunately I stuck to this idea and hence after about an hour of Googling, I was able to learn enough of shell scripting to help me here.Well, to save u from even one hour of googling, I am sharing the skeleton of the program:

#! /bin/bash

if [ "$#" == "0" ]
then
 
   set `date +%u`
if [ "$1" -eq "1" ]
then
   echo -e "Monday's timetable\n"

else if [ "$1" -eq "2" ]
then
   echo -e "\nTuesday\n"
else if [ "$1" -eq "3" ]
then
   echo -e "\n Wednesday\n"
  
else if [ "$1" -eq "4" ]
then
   echo -e "\n Thursday\n"
  
else if [ "$1" -eq "5" ]
then
   echo -e "\nFriday\n"
 fi
 fi
 fi
 fi
 fi
  
else

if [ "$1" == "1" ]
then
      same thing again


fi

fi


So, why did I use $# here?
  $# tells me the no of arguments passed. So if we passed a day number as an argument, then show that day's timetable, otherwise find the day of the week and then display the timetable.

why echo -e?
   Normally, echo doesnot support escape sequences so we need to add -e for them.

and date +%u gives u  the day of the week

We use the set command to give the value to the variable $1. $1 and all are special variables used in Shell script.

U can use == or -eq for checking the comparison. And it is visible that u need to end each if statement using fi!!

Anyways, now I have a shell script to tell me the timetable whenever I need it. Now all I need to do is make it autorun everyday in the morning and also turn it into a linux command. Will do that, and let u know :)

Enjoy this code till then. Yes, u are also welcome to tell me how to do the above!
  

Friday, July 8, 2011

Pixel Paint:what ,how and how much?

   Ever since I heard about jQuery, I wanted to use it,explore it and play with but due to some other reason(or in other words procrastination!) I was unable to do so. Finally, last Friday and set and learnt it from w3schools, the best available tutor I guess. Now, coming to the topic:
What?
Well Pixel paint is an under development painting tool that I have created and uploaded to OpenWorld . You can try it there. The painting stuff is completely based on jQuery as that is what I wanted to practise while creating this. I will be adding more features as and when I am able to develop them. Currently, because of poor internet connectivity I am unable to add the latest eraser tool that I just created but anyways, the current pen tool is just fine.I think the tool is the best explanation of what it is.

How?
Like I mentioned it above, I was learning jQuery and wanted to practise it. Coincidentally, Google+ came out the same week. With it's excellent UI and vibrant colors, it inspired me to add more color to what all stuff I made. I was thinking on what new animations could be done and suddenly light Bulb! The idea of an online painting tool just popped up to me.Making of the first version of Online Paint needed just 1 hour of jQuery designing and testing. A few more hours of designing and the first version was out! Coming to the next point:

How much?


As talked above, the version 0.2.3 had just dot painting facility, now the online version is 1.3.3 which has an addition of pen tool which enables you to draw lines. The one in my laptop is 2.4.3 which has the same UI but with an addition of eraser tool which is still a bit buggy, also one of the bugs of the previous versions have been removed. I wish to add a load more number of  features but I need to improve my skills and may eventually have to change the coding completely.

Anyways, that's all about Pixel paint that I can share with you right now. Will post more updates and will notify you people too!

  

Sunday, June 26, 2011

Boosting Mozilla Firefox's speed

 
     This post is continuation of one of my old post . Firefox lets us tweak it in a large number of ways and hence there is always a scope of your getting a better performance out of the browser. For eg, if you are contnuously online and if suppose you donot frequently visit same pages, you may limit the cache size on the disk or ram to reduce the memory usage of the browser to a lower value without much problems. Anyways, coming back to the post.
     Last time I talked about changing the disk and memory cache size of the browser.But, these are not of much use during offline viewing of pages. Certain pages having smart javascripts can make use of the offline caching facility of the browser to serve you better. To provide these with larger size, you just need to increase the size of browser.cache.offline.capacity to a larger value, 100000 in my case.
     It might happen that your browser may have browser.cache.offline.enable false i.e off. So you better turn it on!Just by double clicking it!
     You may also increase the value of image.cache.size Though I donot feel the need to do it. Also one thing should be taken care of. Providing large cache to Firefox will help to a certain extent. Beyond that it will only cause memory related issues.
   These were a few tweaks at the background level of the browser. There is another way to increase the speed also!  Just don't install add-ons without thinking. It may cause the browser to go slow.Also, it is recommended that you constantly update your browser and add-ons.
   There is a known issue with Java Console that while installing new versions, it forgets to remove the older ones so you will have to personally remove them.
   Will meet you soon with new updates, till then keep coding and stay tuned to the blog!