Thursday, 5 December 2013

কৈশরের প্রেম আমার C


প্রথমে নিজের পরিচয়টা দেই, আমি হাসিন। এ.আই.ইউ.বি তে পড়ছি সি.এস. ডিপার্টমেন্টে। কোডিং আর ফুটবল কে পাগলের মত ভালবাসি। এই তো আর কি, তো শুরু করা যাক। যেটার জন্য ব্লগ লেখাটার কথা মাথায় আসলো সেটা হচ্ছে কম্পিউটারের প্রোগ্রামিং নিয়ে ঘাটাঘাটি করছি বেশি দিন না কিন্তু যা টুকটাক শিখেছি সেগুলা একজায়গায় লিখে রাখা দরকার।

কিন্তু তার আগে কিছু কথা বলা দরকার মনে হচ্ছে...
আমি শুরু করেছিলাম  C দিয়ে। JAVA বা Python দিয়েও শুরু করে এমন অনেকেই আছে। যেই কদু সেই লাউ। কথাটা বেশি খাটে বিশেষ করে তাদের জন্য যারা কনটেস্টের জন্য নিজেকে রেডি করছে। ল্যাঙ্গুয়েজ যেটাই হোক লজিক নিয়েই আসল কাজ এখানে। এই একটা বিষয় নিয়ে অনলাইনে মেলা ব্লগ আছে। সাজেশন, কনটেন্ট ছড়িয়ে ছিটিয়ে আছে। এতো কিছুকে একাঠ্ঠা করার জন্য আমি বসিনি। বসলাম তাদের জন্য যারা স্বপ্ন ঠিকই দেখে ফেলেছে, কাজ শুরু করতে পারছে না অথবা চারদিকে দৌড়াচ্ছে আর টাইম নষ্ট করছে, যেই সময়টা দিতে পারতো প্রাকটিস করার পিছে। ভার্সিটির একটা ছেলেকে একদিন ACM  ক্লাসের পর কোচ জেমি ভাইয়া কে জিজ্ঞাস করতে শুনেছিলাম নাকি কোনো কোডেই AC ( accept ) পাচ্ছে না। একই কোড নাকি ১০-১২ বার সাবমিট করেও কাজ হচ্ছে না। সে জানতে চাচ্ছিলো তার ভুলটা কোথায়? সম্ভবত execution কোনো একটা গন্ডগোল করে ফেলছিলো। 

কিন্তু সমস্যাটা আসলে শুধু সেটাই? আমরা আসলে প্রোগ্রামিংকে কেন জানি সর্টকাট ভাবে শিখতেই বেশি আগ্রহী!! টাইম কোথায়? সব ২১ দিন না হয় ৩০ দিনের পিছে ছুটছি। প্রোগ্রামারদের পরিচয় কি তাদের কলেজ বা ভার্সিটি গ্রাজুয়েসনের সিজিপিএ? উত্তরে SUST এর এক ভাইয়া তামিম শাহরিয়ার সুবিন এর C শেখার বই থেকে একটা লাইন তুলে দিচ্ছিঃ

"প্রোগ্রামিং হচ্ছে একধরনের দক্ষতা (skill) এবং কেবল নিয়মিত অনুশীলনের মাধ্যমেই এই দক্ষতা অর্জন করা সম্ভব এর জন্য ভালো ছাত্র হওয়ার দরকার নেই, জিনিয়াস হওয়ারও কোনো দরকার নেই দরকার হচ্ছে প্রোগ্রামিংকে ভালোবাসা যখন তুমি প্রোগ্রামিং করতে বসলে খাওয়া দাওয়ার কথা ভুলে যাবে, রাতে কোনো প্রোগ্রামিং সমস্যা নিয়ে কাজ শুরু করলে আর কিছুক্ষণ পরে দেখবে বাইরে ভোরের আলো ফুটছে, কিংবা ভুলে বাথরুমের স্যান্ডেল পরে ক্লাসে চলে যাবে, তখন বুঝবে যে তুমি প্রোগ্রামার হয়ে যাচ্ছ"

আমি নিজেই এখনো দৌড়ানোর বৃত্ত থেকে ঠিক মত বের হতে পারিনি, কিন্তু যে এক/দুই আনা প্রোগ্রামিং শিখেছি সেটা কম্পাইলারে বসে নিজের মত উলটাপালটা লিখতে লিখতে। আমি বিশ্বাস করি ভুল না করে কোনো কিছু শেখা যায় না, আর ভুল যখন করতেই হবে, সে ভুল গুলা যেন এমন জায়গায় হয় যেখানে ভুলের জন্য সম্ভাব্য সবচেয়ে কম মাশুল গুনতে হয়। নিজের বাসার যে কম্পিউটার সবচেয়ে আপন তার থেকে ভাল জায়গা আর কি থাকতে পারে। ভুল করতে করতে কেউ যদি এক হাজারটা ভুল করে ফেলতে পারে, তাহলে সে একদিন মনে সাহস নিয়ে বলতে পারবে “আমি এক হাজারটা ভুল কে শুধরাতে পারি”।শুরুতে সেটাই বা কম কি? এই ভুল খুজতে গিয়ে শিখেছি কিভাবে “Hello world” লেখার পর নিজের মত করে কোডকে কথা বলা শিখাতে হয়। যখন দেখি এক্সিকিওটেড রেজাল্ট, আমি যেটা চাচ্ছি সেটা হচ্ছে না, গুগলে গিয়ে সময় গিয়েছি। আস্তে আস্তে আরো নতুন লাইব্রেরি ওয়ার্ড শিখছি। এদের ব্যবহার শিখছি। বই অথবা ভিডিও টিওটোরিয়াল একটা ল্যাঙ্গুয়েজের পরিচিতি দিতে পারে ঠিকই কিন্তু আসল কাজটা হচ্ছে এরপর কতক্ষণ লেগে থাকা যায় এটার পিছে। একভাবে বলা যায় প্রোগ্রামিং শেখাটা সেকেন্ড বা থার্ড কোনো কথা বলার ভাষা শেখার মত। paragraph  আর essay মুখস্থ(!) করে পাস করার পর কিন্তু আসল শেখার কাজটা হয় প্রাকটিকাল ইমপ্লিমেন্টের সময়।মানে হল যত প্রাকটিস তত ভাল পারফর্মেন্স। এই প্রাকটিসের টাইমলাইন নিয়ে গুগলের ডিরেক্ট অফ রিসার্চ পিটার নরভিগ একটা অসাধারণ আর্টিকেল লিখেছেন, Programming in ten years চাইলে পড়ে ফেলতে পারো।


ভূমিকাটা এই পর্যন্তই থাক। পরে কিছু মনে আসলে আবার লিখবো। আর যারা এই পর্যন্ত পরলেন, দোয়া করবেন এই দেশের জন্য আর পারলে আমার আর আমার টিমমেটদের জন্যও :)


#keepcoding

Friday, 22 November 2013

UVA sloved: problem number: 11805 - Bafana Bafana

Bafana Bafana <3
Team practice is very important not only for programming contest but also for football. By team practice players can learn cooperating with team mates.  For playing as a team improvement of passing skill is very important. Passing is a great way of getting the ball upfield and reduces the risk of giving the ball away.

Carlos Alberto Parreira, the coach of Bafana Bafana, also wants his players to practice passing a lot. That’s why, while in the training camp for soccer world cup 2010, every day he asks all of the players who are present in practice to stand in a circle and practice passing. If N players are in practice, he gives each of the players a distinct number from 1 to N, and asks them to stand sequentially, so that player 2 will stand in right side of player 1 and player 3 will stand in right side of player 2, and so on. As they are in a circle, player 1 will stand right to player N.

The rule of passing practice is, Parreira will give the ball to player K, and practice will start. Practice will come to an end after P passes. In each pass, a player will give the ball to his partner who is in his immediate right side. After P passes, the player who owns the ball at that moment will give the ball back to Parreira.

Parreira wants to be ensured that his players practice according the rule. So he wants a program which will tell him which player will give him the ball back. So after taking the ball from the same person he can be happy that, the players play according to the rules. Otherwise he will ask them to start from beginning.


Input
Input starts with an integer (T <= 1000), the number of test cases. Each test case will contain three integers, N (2 <= N <= 23), K (1 <= K<= N), P(1<=P<=200).

Output
For each test case, output a single line giving the case number followed by the Bafana player number who will give the ball to Parreira. See sample output for exact format.
Sample Input
Sample Output
3
5 2 5
6 3 5
4 1 3
Case 1: 2
Case 2: 2
Case 3: 4
Problemsetter: Md. Arifuzzaman Arif, Special Thanks: Muntasir Khan, Sohel Hafiz

_______________________________________________________________



solution:

#include<cstdio>
int main()
{
 int n,k,p,t,x=1;
 scanf("%d",&t);
 while(x<=t)
 {
  scanf("%d%d%d",&n,&k,&p);
  printf("Case %d: %d\n",x,(((k-1+p)%n)+1));
  x++;
 }
 return 0;
}

Thursday, 21 November 2013

UVA sloved: problem number: 11854 - Egypt

                                                                 
question:
                                                             Problem A: Egypt

A long time ago, the Egyptians figured out that a triangle with sides of length 3, 4, and 5 had a right angle as its largest angle. You must determine if other triangles have a similar property.


The Input
Input represents several test cases, followed by a line containing 0 0 0. Each test case has three positive integers, less than 30,000, denoting the lengths of the sides of a triangle.


The Output
For each test case, a line containing "right" if the triangle is a right triangle, and a line containing "wrong" if the triangle is not a right triangle.


Sample Input
6 8 10
25 52 60
5 12 13
0 0 0

Output for Sample Input
right
wrong
right

_____________________________________________________________________

solution:

#include<cstdio>

int main()
{
int a,b,c;
  while (scanf("%d %d %d",&a,&b,&c)==3)
        {
         if (a==0 && b==0 && c==0)
         break;
          if (a<=0 || b<=0 ||c<=0)
                     printf("wrong\n");
           else if (a*a==b*b+c*c)
                     printf("right\n");
          else if (b*b==a*a+c*c)
                     printf("right\n");
          else if (c*c==a*a+b*b)
                     printf("right\n");
          else
                     printf("wrong\n");
         }

}