Advances in Sensors, Signals, Visualization, Imaging and Simulation

A systems approach to visualization of the problem solved algorithms and the programming language LOGO

MICHAL MUSILEK, STEPAN HUBALOVSKY Department of Informatics University of Hradec Kralove Rokitanskeho 62, Hradec Kralove CZECH REPUBLIC [email protected], [email protected], http://www.musilek.eu/michal

Abstract: - One of the most important tasks in teaching of algorithm development and programming is to use a suitable method of developing theoretical knowledge of this area. Drawing on their experience, the authors have found that the best method to be used is the system approach. This method, described in the paper, is presented through the simulation and visualization of two real processes – brain teaser and decrypting of the Daisy cipher. The solution is demonstrated step by step – it starts with the problems definition, then the strategy solution analyses are shown and finally visualization of the processes is presented in illustrative form in LOGO programming language.

Key-Words: Algorithmic thinking, LOGO programming language, system approach, multidisciplinary learning, , education, computer simulation and modeling, visualization, turtle geometry.

1 Introduction The process can be understood as series of The term algorithm can be also connected with transformations that changes the input values to the terms system, model, simulation, output values. From the system point of view the multidisciplinary approach, which are important in process is dynamic system in which the values of current approach to scientific, technological and the characteristic of the system elements are professional practice. Many universities are changed under the influence of the external realizing that modeling and simulation is becoming elements. an important tool in finding the strategy for solving The models are always only approaching of the and understanding numerous and diverse problems. reality, because the real systems are usually more The examples can be found e.g. in [1], [2], [3]. complex than the models are. The model is always In this paper we first briefly introduce the theory to be understood as simplification of the original. If of system approach, modeling and simulation as a the relation of isomorphism is between the model method of multidisciplinary and system approach to and real system the original model we could not education of algorithm development. distinguish between the model and the original, Secondly we introduce a case study illustrating which is discussed e.g. in [4], [5], [6]. step by step process of algorithm development and computer simulation of a two real processes – solving of Tower of Hanoi brain teaser and 1.2 Simulation decrypting of the Daisy cipher. The process of modeling closely relate to the simulation. Simulation can be understood as process of executing the model. Simulation enables 1.1 Modeling representation of the modeled real system or real Modeling is a method that is often used in process and its behavior in real time by means of professional and scientific practice in many fields of computer. The simulation enables also visualization human activity. and editing of the model. The main goal of modeling is not only describing A typical simulation model can be described both the content, structure and behavior of the real through specialized programming languages that system, which representing a part of the reality, but were designed specifically for the requirements of also describing the processes. simulations, or the simulation model can be created

ISBN: 978-1-61804-119-7 205 Advances in Sensors, Signals, Visualization, Imaging and Simulation

in standard programming languages. The computer simulation of the case studies will From the above considerations, it is clear that be realized and visualized in LOGO programming simulation is in many cases a process that runs on language. the computer. In some publications, therefore, can be found the term ”computer simulation“. It generally is valid that computer simulation is a 2 Solution of problem of visualization computerimplemented method used for exploring, in the programming language testing and analysis of properties of the conceptual (mathematical or process) models that describe the LOGO The term visualization is closely related to the term behavior of the real systems or real process which simulation. Visualization is a technique that cannot be solved using standard analytical tools, se transforms, selects and shows the output data and e.g. [8]. data obtained from the simulation, allows the The simulation models represented by executable investigation, analysis and interpretation. Among computer program have to be isomorphic with the the commonly used tools in scientific visualization conceptual model that is a representation. It means are 2D and 3D charts, tables, flowcharts, animated that the mathematical model and simulation model diagrams and others. have to represent the real system, its elements, internal interactions and external interaction with the environment in the same way. 2.1 A programming language developing logical and creative thinking - LOGO 1.3 Significant function of the simulation The first programming language designed to Simulation has from the scientific point of view teaching and to developing logical and creative several functions – see e.g. [8]. thinking at all in both children and adult students is We will focus two of them in this paper and they the language LOGO. Its creation was influenced by are: the work of Swiss developmental psychologist and replacement the real process; spiritual father of the constructivist school in theory development of educational process. of education Jean Piaget (1896 1980). LOGO Replacement of the real process was designed by Seymour Papert (* 1928), Piaget's This is an important and indispensable feature of student, one of the pioneers of artificial intelligence, simulations and simulation model because it allows known American mathematician, computer scientist realize a situation of the process that cannot be and educator. Papert worked with Piaget in the years investigated conventionally. The main advantage of 1958 to 1963 at the Geneva University. "Nobody understands my ideas as well as Papert," Piaget simulations is that simulations model allows said. Pappert created LOGO programming language providing rather big number of the process steps in in 1967 after his arrival at MIT (Massachusetts relatively short time, changing of input parameters Institute of Technology). LOGO is partially based and its visualization and optimization of the process. on the LISP programming language (called Development of educational process "artificial intelligence language"), from which it The simulation is very useful from educational took over working with lists. A completely new idea point of view. Using the simulation model and was the socalled turtle geometry. visualization of simulation results on the screen, students can better understand the basic features of the processes and systems and develop their 2.2 Tower of Hanoi brain teaser intuition. It is also essential that the teaching by The challenge is to find a suitable solution to means of simulation is much cheaper and faster than visualize the wellknown Tower of Hanoi. the teaching carried by real experiment. In some This puzzle was devised by French mathematician cases providing the real experiment cannot be Édouard Lucas (1842 – 1891) in 1883. The brain feasible. teaser consists of three pins, which can be pulled on Above mentioned functions of simulation will be circular disks of different radii. represented in following part of the paper by two All n disks are deployed on the left pin at the case studies Tower of Hanoi brain teaser and beginning, where they are sorted from the largest to Transposition cipher determined by the figure – the smallest disk. The task of the solver is to move the Daisy cipher all the discs on the middle pin, while the right pin is

ISBN: 978-1-61804-119-7 206 Advances in Sensors, Signals, Visualization, Imaging and Simulation

used as an auxiliary storage space. It is necessary to observe the following rules: a) You can relocate only one disc in one move. b) A move consists of taking the upper disk from one tower and placement on top of another tower. c) It is forbidden to put a bigger disk on a smaller one. Simple and elegant solution can be found on the Internet [7]: to move :n :from :to :via if :n = 0 [stop] move :n-1 :from :via :to (print [Move disk from] :from [to] :to) move :n-1 :via :to :from end Fig. 1 The daisy cipher with countingout game

move 4 "left "middle "right to overedge :b :a

if (:b <= :a) [output :b] But this solution is not at all illustrative, if (:b > :a) [output sum mod :b :a 1] because it provides a textonly output. It is end possible and necessary to build on this simple recursive solution of a system of interconnected to daisycipher :n :k :text :countingout components. make "outward list 1 2 make "i 2 repeat :n-2 [make "i :i+1 2.3 A Transposition Cipher Determined make "outward lput :i :outward] by the Figure – The Daisy Cipher make "i 0 make "position 1 Figure 1 shows the daisy cipher with countingout make "counter 0 rhymes. For decryption of this cipher we start with repeat :n the letter at the top (0 ° azimuth) and then expect [make "i :i+1 other letters in a clockwise direction using counting make "outward replace :outward :position out rhymes. We scratch the used letters and they are item :i :text not used repeatedly. Therefore, we must check each make "j :position letter and, if used, we cannot count it further. repeatuntil Program to create daisy consists of function [make "j overedge :j+1 :n overedge and own procedure daisycipher for if number? item :j :outward [make creating a daisy – see Figure 1. "counter :counter+1]] [or :counter = :k :i =:n] make "position :j make "counter 0] print :outward cs setfontsize 20 setfontjustify [1 1] make "i 0 repeat :n [rt 360/:n*:i make "i :i+1 fd 150 rt 90 repeat 120 [fd 1 lt 3] pu lt 90 fd 20 setheading 0 label item :i :outward home pd] setfontsize 14 pu bk 215 label :countingout fd 15 end

ISBN: 978-1-61804-119-7 207 Advances in Sensors, Signals, Visualization, Imaging and Simulation

3 Solution of problem In this section the case study of Tower of Hanoi brain teaser will be extended by visualization in LOGO and the case study Transposition Cipher Determined by the Figure – The Daisy Cipher Fig. 3 An advance in solving the puzzle will be reached on new procedure for decrypting and its visualization.

3.1 Visualisation of solution Tower of Hanoi brain teaser Which are the interconnected components in our system solution Tower of Hanoi brain teaser? The first is the aforementioned recursive core. The Fig. 4 Target position of solving the puzzle second component of system govern the current storage of the composition of the three towers into three lists. The third component, based on LOGO Next procedure move is the key, used to language and turtle graphics, is used for rendering perform one move and includes two recursive current assembly of each tower. calls to itself. The last procedure hanoi then The program is implemented the following just set the default lists and graphics, and starts four procedures. The procedure rectangle the process of solution. draws a rectangle with unusual way from the center of bottom side. The procedure Procedure move: drawtower draws tower based on the current to move :n :from :on :via list of discs. The individual discs are if (:n = 0) [stop] represented by rectangles, which are also filled move :n-1 :from :via :on with colors for clarity – see Figures 2, 3 and 4. if (:from = 1) [make "top last :lefttower to rectangle :a :b make "lefttower butlast :lefttower] right 90 forward :a/2 left 90 if (:from = 2) forward :b left 90 forward :a left 90 [make "top last :middletower forward :b left 90 forward :a/2 left 90 make "middletower butlast :middletower] end if (:from = 3) [make "top last :righttower to drawtower :a make "righttower butlast :righttower] if not (:a = []) if (:on = 1) [make "lefttower lput :top [make "base first :a :lefttower] make "residue butfirst :a if (:on = 2) [make "middletower lput :top make "width :base*20 :middletower] rectangle :width 20 if (:on = 3) [make "righttower lput :top pu fd 10 setpc :base fill fd 10 pd :righttower] setpc black drawtower :residue] cs end pu setXY -150 0 pd drawtower :lefttower pu setXY 0 0 pd drawtower :middletower pu setXY 150 0 pd drawtower :righttower ht wait 30 st move :n-1 :via :on :from end

Procedure hanoi: Fig. 2 First steps of solving the puzzle to hanoi :n make "lefttower []

ISBN: 978-1-61804-119-7 208 Advances in Sensors, Signals, Visualization, Imaging and Simulation

make "i 0 pu Repeat :n setxy difference :x*20 (:n+1)*10 minus [make "i :i+1 210 make "lefttower fput :i :lefttower] setheading 0 pd setpc 0 make "middletower [] label :letter wait 40 make "righttower [] end cs pu setXY -150 0 pd drawtower :lefttower to countingoutgame :n :k :text ht wait 60 st cs setfontsize 20 setfontjustify [1 1] move :n 1 2 3 make "i 0 end repeat :n [rt 360/:n*:i make "i :i+1 fd 150 rt 90 repeat 120 [fd 1 lt 3] 3.2 Visualization of decrypting the Daisy pu lt 90 fd 20 setheading 0 cipher label item :i :text home pd] Much more interesting then creation of daisy cipher make "outward list item 1 :text figure is however the system of procedures for item :k+1 :text visualizing solution of daisy cipher. The procedure make "used list 1 :k+1 fillcircle is used to visualize the scratching a make "thelast :k+1 specific letter – see Figure 5. Competent circle is fillcircle :n 0 filled with orange color and has also not counted for writeletter 1 :n item 1 :outward next rounds. The procedure writeletter gradually fillcircle :n :k writes individual letters of the plaintext obtained by writeletter 2 :n item 2 :outward applying countingout rhymes. The main procedure, make "x 2 managing the decryption system is called repeat :n-2 countyngoutgame. [make "counter 0 make "j 0 make "x :x+1 repeatuntil [make "j :j+1 if not member? overedge :thelast+:j :n :used [make "counter :counter +1]] [:counter = :k] make "outward lput item overedge :thelast+:j :n :text :outward fillcircle :n overedge :thelast+:j-1 :n make "used lput overedge :thelast+:j :n :used make "thelast overedge :thelast+:j :n writeletter :x :n item :x :outward] print :outward ht Fig. 5 Partially deciphered daisy cipher figure end to fillcircle :n :f pu home rt 360/:n*:f setpc orange 4 Conclusion repeat 12 [fd 13 wait 4] pd There are various approaches how to provide repeat 15 [fill fd 1] make "i 0 repeat 15 [make "i :i+1 circle :i] training in algorithms, how to introduce and fd 1 make "i 0 develop basic algorithmic thinking of students. repeat 15 [make "i :i+1 circle :i] The paper offered one of the kinds of the end possible teaching / learning strategies using the system approach. The system approach can be to writeletter :x :n :letter set as the default paradigm for a wide

ISBN: 978-1-61804-119-7 209 Advances in Sensors, Signals, Visualization, Imaging and Simulation integration of the principles of the algorithm Mathematics and Computers in Simulation. development into education. The paper 2012, roč. 6, č. 1, s. 3445. ISSN 19980159. emphasizes the fact that the algorithm [7] http://rosettacode.org/wiki/Towers_of_Hanoi# development of the real processes should be Logo. supported by computer simulation and visualization. Solution of the process of The Tower of Hanoi and The Daisy Cipher has been chosen as two possible case studies of how to present the application of the system approach.

Acknowledgment This research has been partially supported by the Specific research project of the Faculty of Education of University of Hradec Kralove No. 2102.

References: [1] Šedivý, J. Multimedia support of parametric modeling. In: Recent Researches in Engineering Education and Software Engineering, Proceedings of the 9th WSEAS International Conference on Engineering Education (EDUCATION '12), WSEAS Press, 2012, ISBN: 9781618040701 [2] Hubálovský, Š. , Jelínek, J., Šedivý, J. Mathematical modeling and computer simulation of optimal reaction time of the Lupine protein hydrolysis using fermented whey. International journal of mathematical models and methods in applied sciences. North atlantic university union, 2012. 8s. ISSN: 1998 0140. [3] Hubalovsky, S., Mastermind – method of the system approach in the algorithm development and computer simulation. In: Applied Informatics and Computing Theory (AICT’11), Praha, WSEAS Press, 2011, s. 152 – 157, ISBN 9781618040343. [4] Hubalovsky, S., Modeling and computer simulation of real process – solution of Mastermind . International Journal of Mathematics and Computers in Simulation. 2012, roč. 6, č. 1, s. 107118. ISSN 19980159. [5] Hubalovsky, S., Milkova, E.,Modelling of a real situation as a method of the algorithmic thinking development. In: WSEAS/IASME International Conference on Educational Technologies (EDUTE’10), Kantoui, WSEAS Press, 2010, s. 6872, ISBN 978960474186 1. [6] Hubalovsky, S., Rectification column mathematical modeled and computer simulated real system. International Journal of

ISBN: 978-1-61804-119-7 210