Chris' explanation about decomposition is really beautiful. I call things as beautiful if they are logical :D I usually make my code quite long and after understanding the pattern, I make sub-blocks. But the better way to do it is to understand the problem first and then create sub-block.
Wednesday, April 28, 2021
Decomposition
One of Chris' slides about decomposition, infinite time of lathering and rinsing since there is no stop command. I think ghosting works that way, you will fall into infinite iterations since you don't know what went wrong and the other person just vanished into thin air. I know it's bad but sometimes ghosting is the easiest way out, no confrontation.
Anyway, back to coding ... After studying Karel the robot to understand the basic idea of programming (control flow, logic and decomposition), this week we move to Python. The main difference (for me) is that in this Python world, we play with more types and functions, which usually scared me. I used to be overwhelmed with different types integer, string, numeric and others, how to write and other details. But since I started the python journey by playing, I really enjoy the journey.
Chris' explanation about decomposition is really beautiful. I call things as beautiful if they are logical :D I usually make my code quite long and after understanding the pattern, I make sub-blocks. But the better way to do it is to understand the problem first and then create sub-block.
Thursday, April 22, 2021
Code in Place 2021
Super excited to join this course!!! I have been wanting to learn python for quite some time and until now, I kind of did it, on and off. Most of the reason I discontinued my Py learning was due to the process of understanding the 'world' of Py through different types of character i.e numeric, integer, string and others, whereas what I interested the most in coding is the logic. The Code in Place starts with exactly what I want, a robot named Karel, a beeper, 4 basic commands (move, turn_left, pick_beeper, put_beeper) and 20 conditions that I can play with when creating loops and conditions.
I have done all my obligatory assignments, but still struggling in solving "the Fence Post Problem" when trying to solve the hospital assignment as a bonus point.
So here is my code:
def main():
"""
A code to build a hospital using 6 beepers and stop without creating a bug. Haven't succeeded yet :(
"""
if beepers_present():
buildhospital()
while front_is_clear():
findbeep()
buildhospital()
else:
while front_is_clear():
findbeep()
buildhospital()
def buildhospital():
turn_left()
move()
put_beeper()
move()
put_beeper()
turn_right()
move()
put_beeper() #4,3 second tower
turn_right()
move()
put_beeper() #4,2 second beeper second tower
move()
put_beeper()
turn_left()
def findbeep():
move()
while no_beepers_present():
move()
def turn_right():
for i in range(3):
turn_left()
if __name__ == '__main__':
run_karel_program('HospitalKarel2.w')
While my code works perfectly in a world where the last beeper of a hospital has a space before a wall (Fig 2 below), my code breaks when it has no space (Fig 3). What a bugger!
Subscribe to:
Posts (Atom)
Untuk Papa
Papa … Kini senyum itu tak bisa lagi kulihat Kebaikan itu tak bisa lagi kudapat Tapi jasa papa tetap melekat Hangat itu tetap mendekap ...