Sunday, December 9, 2012

How To Build A Programme

Okay i just passed Algorithm & Programming [QBASIC] mid-semester test, the questions weren't too complicated but the time is pretty tight. So i choosed 2 question, one which was medium level and the easiest one. I want to explain the medium one. There was a song, sung like this :
4 bebek turun, mati 1 tinggal 3
3 bebek turun, mati 1 tinggal 2
2 bebek turun, mati 1 tinggal 1
1 bebek turun, mati 1 tinggal induknya
The number of duck which down to the street is a dynamic number refering to what user input, so it can be any number. Every time they down to the street there always be death for one of them *what a pity*, that's why i call it "Duck Genocide" application. So here's the troubleshooting.

1. Find the pattern

Every time you have a case of programming you should find the main idea of the programme, the pattern is really important. In this case is a decreasing number of duck population, every line is looped refering to first number of duck. Decreased line by line and when we have no duck left, there's only their mom. Per line there's two dynamic value, the duck number every time they down to the street and the one after the duck death. So mathematically *what the fuck do i say about math #Geez!* :
The First Line, Duck Number - Line  = Left Duck
Next Line, Left Duck - Line = Left Duck
The Latest Line, Left Duck - Line = Mommy Duck
On the other way, line also can be called by looping time. We can prove it with the song,
Line / Loop 1, 4 bebek turun, mati 1 tinggal 3
Line / Loop 2, 3 bebek turun, mati 1 tinggal 2
Line / Loop 3, 2 bebek turun, mati 1 tinggal 1
Line / Loop 4, 1 bebek turun, mati 1 tinggal induknya

2. Collect Variables We Need

There's a static data, there's the dynamic one. You have founded the pattern, what things we need to accommodate the dynamic value which are proccessed. The first duck number per line and duck number left after the death. We need two variables, just call it "A" for the first duck number per line and "B" for the other one. One more thing, "N" for the number which is input and "i" for the looping time / line number.

From the pattern we had there's a gap, "A" variable is doubtful, it should be one but there is more. We should join them, the first line is the duck number which is input by user and the decreased one from the next and latest line. To join them together on decreasing loop without loosing input value by user then we should increase it while decrease it, haha it's pretty confusing. 
4 bebek turun, mati 1 tinggal 3
3 bebek turun, mati 1 tinggal 2
2 bebek turun, mati 1 tinggal 1
1 bebek turun, mati 1 tinggal induknya
See the number i bold, if we just decrease it then the proccess will immedeately decrease the first number which is 4 to 3 so the song will be started with 3 ducks and in the same time "A" shouldn't reach null number while "B" does in looping. That's why "A" should be increased while being decreased. The formula should be like this, A = N - i + 1 and B = N - i meanwhile "B" and "A" almost have the same formula so we can change "A" formula to this A = B + 1 but "B" should be processed before "A" so computer will recognized the "B".

3. Mix It!

You have the pattern and the variables you need. So let's mix it! We build it using QBASIC.




Sunday, December 2, 2012

Santa Claus Is Coming To Town

Sebentar lagi natal, selalu merasa spesial di situasi natal dan kadang berkesan. Semua keluarga kumpul dan tidak ada yang lain selain keharmonisan keluarga besar. Itu jarang sekali didapatkan di jaman ini ketika semua orang mulai sibuk bahkan saudara terdekat kita sendiri. Gw tidak menyindir siapapun tapi begitulah hidup, tuntutan - tuntutan membawa kita menjauh dari apa kita sebenarnya tapi momen - momen seperti ini menyatukan semuanya kembali walaupun tidak benar - benar sempurna seperti dulu.

Hidup memang harus disyukuri, selalu ada yang lebih bagus untuk dimiliki dan selalu ada barang rusak lama yang kini dirindukan. Tidak akan pernah habis keinginan ini. Wew ini mulai melenceng dari tema natal kali ini, bagaimana rencana natal gw nanti? Nope, nothing, cuma menetap di rumah menyambut keluarga besar untuk kesini -- ke rumah keluarga besar Kaunang - Dumais. Sayangnya penyangga besar nama Kaunang dan Dumais di rumah ini sudah tiada, mereka sudah "tertidur". Cinta dari keluarga besarmu tidak akan pernah terlupakan Opa - Oma :D . Miris ketika mengingat gw menulis artikel mengenai kondisi Opa kemarin yang tidak kritis namun menyakitkan dan tidak berselang beberapa lama setelah gw selesai menuliskan itu lalu Beliau "tertidur", tidak mendapatkan sayang yang sepatutnya di hari - hari tuanya. Siapa yang paling menyayangi Beliau? Ternyata Tuhan menginginkannya lebih dari pada kami. Oma? Tidak berbeda, gw benci cara Tuhan mengambil manusia dari hidupnya dengan sakit. Tapi toh kita yang membuat itu.

Sebenarnya momen natal ini bukan saja perayaan, namun peringatan. Karena jujur saja kenapa gw membahas Opa karena Beliau meninggal pada tanggal 13 yang akan datang ini, nanti akan menjadi setahunnya Beliau meninggal. Santa, hey Santa bawa beberapa kado-mu kesini. Kami tidak memiliki cerobong asap, bahkan atap pun rapuh tapi mohon jatuhkan beberapa kadomu di rumah ini. Sebuah harapan, kasih. Buat keluarga besar kami berkumpul lagi tapi tidak dengan duka, memang dengan duka lebih efektif karena jika tidak menggunakan itu kadang yang lain masih sibuk sendiri. Semoga Santa datang ke Jakarta.