Sunday, March 12, 2023

Codeforces Round 405 (rated, Div. 2, based on VK Cup 2017 Round 1) - 791 A Bear and Big Brother solution

After years, maybe 9 or 10, of being away from competitive programming, I'm finally back, and glad :)

I love competitive programming. I missed it. I missed those days in 2013 and 2014 when I would be listening to music in the background and would be coding. Finally, I'm back. This time I think I have brought with me the different skill set: Linux and Emacs. 

Anyway, let's get to the business. This is the solution for Codeforces Round 405 (rated, Div. 2, based on VK Cup 2017 Round 1) - 791 A Bear and Big Brother. 


  1. #include <stdio.h>
  2.  
  3. int main() {
  4. #ifndef ONLINE_JUDGE
  5. freopen("input.txt", "r", stdin);
  6. freopen("output.txt", "w", stdout);
  7. #endif
  8.  
  9. int a, b, c=0;
  10. scanf("%d %d", &a, &b);
  11. while(a<=b) {
  12. a=a*3, b=b*2, c++;
  13. }
  14. printf("%d\n", c);
  15. return 0;
  16. }

Tuesday, February 7, 2023

Solution for Robozzle puzzle no 291 - Huh? part 2

I want to solve Robozzle puzzle number 291 - Huh? Part 2.

You can see it raw in the image below. You need to collect the stars without falling out of the given grid. You are the rocket on top-left corner of the grid; starting point is red cell here.

Robozzle 291 raw

You give certain commands to the rocket and it obeys them. The less command, the better. Commands for this puzzle are shown below.

Robozzle 291 given commands

Commands are displayed on right side. From top to down they are: go straight, turn left, turn right; call F1 function, call F2 function, call F3 function; change colour of the current cell to green, change colour of the current cell to blue; execute this command no matter what the colour of cell is, execute this command in red cell, execute this command in green cell and execute this command in blue cell.

Each time it starts with F1 function. If you don't call F2 function in F1 then it will not execute commands in F2. Same applies for F3; if you don't call it, it won't be executed.

Let me show you how to play this game in another easy puzzle.

robozzle stairs blank

This puzzle is called "Stairs." You can see the commands and given function on the bottom right corner again. They are blank. If I click on Go! nothing happens because there are no commands given in function.

Now, let's fill in the function with some necessary commands.

Robozzle Stairs with commands but no iteration or recursion

You can see where robot stays. It hasn't collected all the stars. Function was called but it was executed just once. Why? Because there is no iteration (or recursion) or repetition of commands.

Remember we need to collect all the stars, so let's call F1 function again at the end of commands so that it iterates (or recurses) or repeats itself.

stairs completed

The rocket has collected all the stars because F1 was called again at the end so that it repeatedly goes beginning when it finishes executing all the commands. At the bottom you can see what the next steps are such as turn left, go, turn right and F1. This was completed in 5 commands.

Now, hoping that you understood how to solve this puzzle I'm returning back to my puzzle in question; I was able to collect only one star in the centre (in green cell) by calling only 2 functions: F1 and F3. However, that's not enough to solve the puzzle. Remember, I needed to collect all the stars.

Robozzle 291 only green star collected

Now, with the image below, there is still no solution. It just does repetitious U-turn between the green cells in the centre. What I did was to turn right after red cell and colour the cell to green on the corner. I wanted to utilise those green cells on the corners when I return back from the star in the middle. I need to collect the star on the upper left corner also. But, it didn't work.

291 still no solution

There are a lot of possible solutions for this puzzle. One way is to collect the star behind the rocket (on the upper left corner) first and then collect the star in the middle. For this one you don't need to use colour changes as far as I know because I have read the comments in that website: comments for Robozzle 291.

And there is another solution: you collect the star in the middle and colouring the corners (or just the cell near the corner, like red one was) to utilise them when returning back. I thought about colouring the cell after you turn right, so that it acts as milestone when returning back. So that you turn left after green when returning back from the middle; as you did turn right after red when going forward to the middle. It is shown below.

291 green after turn

Still, I couldn't solve it. I have been dealing with this puzzle for more than 3 days and I think more than when a person spends more than a day or two is enough for asking help from others. There are a lot of solutions for these puzzles and they are fun. You can see my another question in this website where I got a lot of nice answers each of them being quite different: Shorter solution for Robozzle puzzle no 132 - Split. Thanks beforehand.

I asked this question in Puzzling website of Stack Exchange network: https://puzzling.stackexchange.com/q/119678/64563

Friday, January 27, 2023

Shorter solution for Robozzle puzzle no 132 - Split

I wonder a shorter solution for Robozzle puzzle number 132, "Split."

Puzzle is shown below. I have solved it but I'm wondering shorter solution for this and there many exist.

Basically, the rocket has to collect stars.

robozzle puzzle 132 "split" blank

You give certain commands to the rocket and it obeys them. The less command, the better. Commands for this puzzle are shown below.

Commands are displayed on bottom right corner. From top to down they are: go straight, turn left, turn right; execute F1 function, execute F2 function; execute this command no matter what the colour of cell is, execute this command in red cell and execute this command in green cell.

Each time it starts with F1 function. If you don't call F2 function in F1 then it will not execute commands in F2.

robozzle "split" with commands

Let me show you how to play this game in another easy puzzle.

robozzle stairs blank

This puzzle is called "Stairs." You can see the commands and given function on the bottom right corner again. They are blank. If I click on Go! nothing happens because there are no commands given in function.

Now, let's fill in the function with some necessary commands.

Robozzle Stairs with commands but no iteration or recursion

You can see where robot stays. It hasn't collected all the stars. Function was called but it was executed just once. Why? Because there is no iteration (or recursion) or repetition of commands.

Remember we need to collect all the stars, so let's call F1 function again at the end of commands so that it iterates (or recurses) or repeats itself.

stairs completed

The rocket has collected all the stars because F1 was called again at the end so that it repeatedly goes beginning when it finishes executing all the commands. At the bottom you can see what the next steps are such as turn left, go, turn right and F1. This was completed in 5 commands (or steps).

Now, hoping that you understood the fundamentals of this puzzle let me show you my longer solution for Robozzle puzzle number 132 - "Stairs". It contains 11 commands (or steps).

Split long solution

I screenshot it during the execution of commands so that you can see the upcoming steps (or commands) on bottom command line. I directly called F2 because F1 was very short. In F2 I turned 180 degree back, stepped forward, turned 180 degree back again, and stepped forward twice. I repeated these steps as long as the cells were blue. After blue cells I put turn right on green and go straight on any colour.

Basically, I stepped back once and stepped forward twice. Repeated this action (or recalled F2) as long as the rocket was in blue cells. Since there were a lot of blue cells, the F2 called itself again and again postponing the commands (or steps) I entered after F2 there: turn right on green and go straight on any colour. As far as I know this is called "stacks" (or "stacking") in programming. You can see them piled up on the command line at the bottom of the image. When the rocket arrives at the green cell it gives up calling F2 and executes the stack or piled steps after F2: it turns right on the green cell and goes straight. It ignores turn right on green afterwards. Why? Because there are no green cells except the corner.

My solution contains 11 commands (or steps). I'm looking for a shorter solution for this Robozzle "Split" puzzle: http://www.robozzle.com/js/play.aspx?puzzle=132.

There exist 7 command (or 7 step) solution.

Thanks for your time and efforts beforehand!

 I asked this question Puzzling Stack Exchange website: https://puzzling.stackexchange.com/questions/119505/shorter-solution-for-robozzle-puzzle-no-132-split

Tuesday, December 13, 2022

Bazen korkak olmak hayat kurtarır.

Yeni aldığım scooterda iki defa düştüm, hem de 5 dakika arayla. 

Cumartesini Pazara bağlayan gece (11.12.2022) saat 2:00 civarları Esenyurt İnnovia 2 ve Reyap hastanesi yanlarında oldu. Hafif yağmurlu geceydi, tekerim yazlıktı, 1 Aralık'ta kış teker uygulaması hayata geçmesine rağmen hala taktırmamıştım. Gerçi scooteri daha yeni almıştım (08.12.2022). Daha motor ehliyetim (A2) bile yok ve motoru nasıl kullanmam gerektiğini bile bilmiyorum. O yüzden kullanmayı öğrenmek için gece trafiğin az olduğu saatleri tercih ettim, iyi ki de öyle yaptım yoksa yaptığım kazaları biraz acı ve çiziklerle atlatacağıma üzerime gelen araçlarla atlatmak zorunda kalabilirdim, Allah korumuş. 

Neyse, o gece İnnovia'ların yanından yokuş aşağı iniyorum, sola dönmem lazım, sinyal verdim ve dönmeye başlayacakken scooter kaydı, soluma yıkıldım. Sevgilimin öğretmenler günüm için hediye aldığı mavi kazağı yırtıldı.

 


Aşağıda polis arabası vardı, elim acıyordu ama polis gelip sorguya çekmesin, ehliyetimi sormasın diye zor da olsa ayağa kalktım. Yanımdan geçen araba ve sonrasında gelen polis arabası da iyi olup olmadığımı, istersem 112yi arayıp acil yardımı çağırabileceklerini söylediler. Yeter ki polis ehliyet sormasın modunda olduğum için iyiyim deyip ayağa kalktım ve scooterimi de kaldırdım. Araba ehliyetim vardı, ama motor için sürücü kursuna kaydolalı 1 ay geçmesine rağmen ne dersler başladı ne de sınava aldılar. Zaten ilk önce teorik ders, sonra ise uygulamalı sürüş dersleri olur, ve en sonunda da sınav olur. Ben daha önce araba sürüş için trafik teorisini okuduğum için artık ona gerek kalmadı. 
Scootere bindim, ufak bozuklukları düzeltip hafiften sürmeye başladım. Geldim Reyap hastanesi yolundan aşağı inmeye. Çok yavaş iniyorum. Çünkü zaten az önce kaza yapmışım, korkuyorum. Gece yolda ışık yetersiz, önümde ufak bir çukur belirdi, ben de etrafından dolanmak için manevra yapacaktım ki scooter altımdan kaydı gitti. Kalçamın üzerine düştüm, sonra da sağ koluma. Sürüklendim. Çok acıtmıştı, kalçam, bedenim, kolum çok ağırıyordu. Daha düşeli 5 dk bile geçmeden 2.defa düşmüştüm. Allahtan kask falan almıştım, yoksa kafam da zarar görecekti. Kaskın içerisinde acıdan dayanamayıp bağırıyordum. İyi tarafı trafik yok denecek kadar azdı. Yoldan geçen iki kişi beni hafifçe kollarımdan tutup yolun kenarına getirdiler. Hala belim çok acıyordu. Kararımı vermiştim, artık motor binmeyecektim. Scooterimi de ya satacak ya da kiraya verecektim. Onlar motorumu da kaldırıp getirdiler. Birisi sordu, motorun sağ kol (ön taraf) freni yok mu diye.

Arjantin Hırvatistan 2022 Dünya kupası yarı final maçı başlayacağı için yazıma ara veriyorum, sonra devam ederim :) Hadi Modric, başarılar! 13.12.2022 22:00

21.12.2022 16:30. Arjantin ve Messi 2022 Dünya kupasını kazandı. Efsane bir final maçı oldu. Messi fanı dostum skor 2-0dan 2-2ye gelince ağlamaya hazırlandı :) ama Arjantin penaltılarda kazanmayı başardı. Arjantin'in terbiyesiz kalecisi Emiliano Martinez'i de hatırlamadan geçemeyeceğim. İyi kurtarışlar yaptı ama terbiyesizdi.

Neyse, konumuza geri dönelim. Ben motosikletten düştüm ve iyi ki de korkarak yavaş sürmüşüm diyorum yoksa çok daha kötü şeyler olabilirdi. Sağ kalçam hala ağırıyor. Motosikleti taksitli sattım. Artık binmem muhtemelen.

Tuesday, September 27, 2022

The power of asking stupid questions.

 Asking stupid questions is important. I know you might be asking: "How come?" Pay attention, without stupid questions we would not have had right questions. You never know what question is right or wrong to ask. You learn it is right after getting the answer to the questions. 

Is the world flat? This question is stupid right now but it wasn't millenia/milleniums ago. In ancient times people believed the Earth to be flat. But the question came to mind. And, I think Greek philosophers asked this question and they took action. They carried out an experiment and found out that the Earth was not flat, instead it was and is round or oval sphere. 

Now, the questions about God or religion could be stupid but the coming millenia will show that they are not. 

People say that I am a stupid (or do they acknowledge this fact, LOL 😀) and I maybe. However, I think what they wanted to state was that I was saying stupid things or unusual things that they were never accustomed to face in their life. 

They need to learn that claiming someone is stupid is very rude way of action. Instead, they may attack that "bad" idea, explain why that idea is horrible and provide a better solution. The people who do this win my heart. You never attack a person because of their ideas. Especially if you aren't acquainted with them. You have no say in their life unless they disturb others with their ideas or actions. 

OK, let's go back to saying stupid or unusual things. It is good to be able to ask stupid questions. You may come up with interesting answers. It is sometimes good to practice the idea muscle (I learned it from James Altucher, he is a great man. Thank God, I accidentally found him on iPhone podcasts.). I remember sometimes doing the stupid talk sessions with some of my close friends. We keep talking just about anything, saying gibberish stuff for like 20 minutes or so. This practice frees a person from the burden of ever-perfectionism. You don't need to be 100% perfect all the time. You let go yourself. You commit mistakes on purpose. You strengthen that idea muscle and when you need a bit creativity will visit you inevitably. 

My friend Hemra is joining to restaurant. He never asks stupid questions to his boss. He thinks his boss will give Hemra the money Hemra earns from his share in that restaurant business. This is a very bad approach for business. I think 90% of the time Hemra or people like him are doomed to fail because they never talk to their bosses or business partners. That's a business; you have to be a little bit harsh and be able to ask stupid questions like "when I get first paycheck? How much money I will make? How much do I need to contribute to this business? What if we don't get on well and I want to get out of this partnership?" Those questions sound harsh but they are the realities every business partner faces in their work life. 

I have some stupid questions on my own. For instance, I want to ask "Is there a turkmen girl on Onlyfans? If there is, then who is she?" etc. People will criticise me, especially turkmens because they deem these things as taboos, cultural taboos. 

However, there are some other questions as well. For instance, building a turkmen school abroad for turkmens living abroad. That's a great idea put forth by Doc. Dr. Serdar Nurmedov. When I met him we talked about realising this turkmen school in Istanbul but people online criticised me when I asked them for their ideas about the school. Well, they are not used to these things in real life. There is no turkmen school outside Turkmenistan for turkmen people. There might be in Iran or Iraq but there are local turkmens have been living there for centuries. I am talking about Istanbul. Here in Turkey we have thousands of turkmens working and studying. Basically staying for a few years. In this context, what seems stupid to some is great and beneficial to others. 

I want to finish this article with Steve Jobs' "Stay foolish, stay hungry" quote.

27.09.2022, Istanbul. Written in Testing and Evaluation unit of Istanbul Gelisim University, a place where I work currently and I love my job. T. B. or BST.

Saturday, October 23, 2021

Loly Läle

 Asyl loly Lälemi, ýa gyňaçly "erkeklermi?"

Läle geçen hepde ejesini jaýlap gaýtdy. Özi ýetim ulaldy; ol entäk çaga wagty; kakasy, Aşgabatda işläp ýörkä, gurluşyk kranynyň aşagynda galyp, ölýär. Sowet döwrü bolansoň dul galan ejesine ölmez-ödi posobiýa kömek puly berýärler. Ogulsona hem çagalaryna başardygyndan ýetimligi bildirmän ýetişdirýär. Oba arçyny bu dul aýala käwagt gytak göz bilen garap öz erbet pygyllaryny amala aşyrmak üçin öz wezipesini we täsirini ulanýar. Elbetde, beýle wysalyň Ogulsona bilen arçynyň arasynda bolup geçendigi nämälim, yöne bir zat welin anyk: obada ol aýala "künti" diýilýärdi. Hat-da, ýaş oglanlaryň "Ogulsona, hemme erkekden dogursana," diýşip, onuň üstünden gülenleri hem kem däldi. We bularyň aglabasam erkeklerdi, töhmediň asyl düýbi hem arçynyň bet pälinden başlapdy.

Indi Läle ulaldy; eklenç başa düşende türke gaýtmaly boldy. Indiki hepdä bilet alyp, äri, çagalary we ejesi bilen hoşlaşjak wagty, ol ejesini däl-de, ejesi, Ogulsona daýza ony taşlap gidiberdi. Ölen bilen ölünmeýär. Käbesini iň soňky ýola ugradyp, türke gaýtdy. 

Mähriban ene heý-de öz balasynyň açlygyna döz gelermi? Ony asyl köseýän kesekileriň paýyş sözleri däldi; eziz perzendiniň açlygy ony has kyn güne goýýardy. 

Eýsem, Läläniň gyzyna hem ejesi we mamasynyňka meňzeş agyr ykbal garaşýarmyka?

(Hekaýa doly dynmady. 23-nji Oktýabr 2021, Stambul.)

Monday, October 18, 2021

Benim saçma düşüncelerim or my mediocre aphorisms.

 Hi, here I will write my aphorisms. Or they may belong to others, as well. I will write the person who quoted when I know the origin.

Buraya kendi saçma sözlerimi veya düşüncelerimi yazabilirim.

1 - "Zaten bu hayat boktan iken insanların bir hayat daha istemeleri saçma değil mi? Hem de sonsuz hayat." T. B. (or B. S. T in other words :) 18 Oct 2021, Istanbul.


2 -  İnsanlara kendi kalbini fazla açma. Kırmaktan çekinmezler, özellikle de sanal ortamda. T. B. 27.09.2022, İstanbul.


3 - Kötü insanlarla tartışmak seni yorar. T. B. 27.09.2022, İstanbul.


4 - Özgüvenini başka insanlara bağlama, kolay kırılır. Sende kalsın ki onlar seni aldatsa bile özgüvenin zedelenmesin. 27.09.2022, İstanbul.


5 - Bazı insanları kötü sanıyoruz, belki onlar o kadar da kötü değil. 27.09.2022, İstanbul.


6 - Tecrübe ile öğrenmek çok pahalı. 13.12.2022, İstanbul. Motosiklet (scooter) kazasından sonra yazdım.


7 - İyi olursan maç kazanırsın, efendi olursan gönülleri kazanırsın. 13.12.2022, İstanbul. Arjantin Hollanda dünya kupası çeyrek final sonrası yazıldı. İlk önce Hollandalı futbolcular Arjantinlilere çirkeflik yapıyor, penaltı vuruşları sonrası kazanan Arjantin de bu sefer benzer çirkeflikle karşılık veriyorlar. O yüzden bu gece (30 dk sonra başlayacak) olan Hırvatistan Arjantin maçında efendi Modric'in takımının kazanmasını istiyorum. :) Bakalım kim kazanacak?


8 - İnsanlarla uğraşmak çok yorucu. 25.08.2023 İstanbul.


9 - Okullararası zeka yarışmasında (Türkmen-Türk liseler arası 2.bulmaca yarışması, Mart 2004, Aşkabat, yer: Turgut Özal türkmen türk lisesi) şampiyon oldum (bireysel sıralamada 120+ puan farkla 1.oldum; ben 620 falan, 2.de 490 falandı galiba; yıllar geçti, zar zor hatırlıyorum) ve okulumu da (okullar sıralamasında Bayramali türkmen türk lisesi de 1.oldu) şampiyon yapmıştım. Ve bunu sosyal medyada (twitter) profilime yazdım. Buna rağmen orada insanlar bana "salak" demeye devam etti. Tek bir kişi bile hatırlamıyorum bana "zeki" diyen. Sosyal medya çok kırıcı. Hele kalbinizi açarsanız onu parçalamaktan geri durmayan topluluk var. O yüzden belki de kaliteli yalnızlık sosyal medyadan daha iyidir diye düşünüyorum son zamanlar. 25.08.2023 İstanbul.


10 - Kaliteli yalnızlık kalitesiz ilişkilerden iyidir. 25.08.2023 İstanbul.


11 - Bir insanın gelişimi için belki de yalnız ve acı yoldan geçmesi gerekiyordur. Belki sadece geçmesi değil, sanki geçtikten sonra topluluğa karışacakmış gibi his uyandırmasın, ömürboyu o yolda yalnız yürümesi gerekiyordur. 25.08.2023 İstanbul.


12 -