Children's fairy tale for the programmer at night

There is an interesting topic that, at first glance, has little to do with algorithms. It is "fabulous" on the one hand, and on the other hand, it has a consonance with the pressing problems of a programmer beginning his professional career.







Turnip - medal


Let's try to figure it out and have a little fun looking at these sides of the ancient algorithmic medal ...







A task



, , . . . . β€” β€” . . : " , ...".











kolobok Edition 1910.  Fig.  Elisabeth Boehm







. . . , , . , , . "". ́ " " ? ? , ?







, : .







? , ? , . , , β€” .







, , . , . "" ", ...". , ?







! , . . , .







. - ...









. , , . , :









, . ( β€” ), . , . , , .







? β€” .











Iteration







: . , .







. . β€” :







acc = []
while not condition:
    v=next_item()
    do_some(v)
    acc.append(v)
      
      







?







:







-   . 
 :
β€” , , !
      
      





, "". .







β€” . ? : , "" . ? ? .







. . "" :







  • ,
  • - ,
  • .


, .







, :







β€”   , ! 
   , β€”  
  :
β€”  , !
   ,
  ,
  ,
   ,
  ;
   ,
   ,
   ,
   ,
   ,
  , ,   !
      
      





, . . "" , , , . , -, " ".







"" , . , , " ", , . "" Z33.1 Β« : , . . Β».







"", . , " ": . , , -. , . !











Koloboks lead the investigation









. β€” .







"" . β€” , , " ".







-   ...
 -   
,    . 
      
      









Cockerel and bean seed







β€” . " ". " ".







, " " ( " ") , , . :







β€” , ,   
  . 
   , 
  , 
   , 
   : 
  
 .
      
      





, ( ""), . . : " ".







́ ? ? ?







? , - . . . , . , .







, . " ". "" . . . . . ( LIFO, - FIFO LIFO)!







, . . , , , .







, . , , . .









. !







:







  . 
  -...
      
      





"" -. , " " , β€” . , . " " , "" . , , ?







:







  • .
  • , .
  • , .


?! ? : . β€” . , , , .







Turnip







, , ? "" , β€” .







" " (" ") β€” . , , , , .







, . β€” . β€” .







, , . ? . . !









, . . "" . . , ? ? ? " " β€” . . ? ?







, !







. β€” . β€” , "" :







while true:
    pass
      
      





def f():
    f()
      
      





def f():
    g()

def g():
    f()
      
      





, :







 ...
      
      





, ?







 , 
       . 
     ...
      
      





?







  . 
     ...
      
      





.







 ,  
       . 
     ...
      
      









A still from the cartoon 'Koloboks are Investigating'







. , . killall fairytale_elephant



.







, . ?









, ? , - . ?







, ́ ?







. !







"" "", , . :







-   
    .
  , 
  - ...
      
      









Ryaba chicken







" " . , , - . , , "" .







, ́ :







 ,  -  .
 ,  -  .
      
      





. . , . ( ). . . , , .







, , , . , :







 ,  , 
   .
      
      





. β€” . β€” , .







" ", . NP- P. : P NP. , (" ") .









β€” , ...







, . . , . , .







, , . . . . . . , ? , , , , " " " ".







β€” . , β€” , ?







, , . . , .







, , . " ", , . - . : ...







.









, , .







, (, , ). , , . .












All Articles