Khiryanov Timofey Fedorovich


The algorithm in the KuMir language is written as follows:

alg algorithm_type algorithm_name (description of arguments and results)
a condition_of_applicability_of_algorithm is given
you need the target_of_execution_of_algorithm
early
command sequence
con

The description of the algorithm consists of:
  • header (part before official word beginning),
  • the body of the algorithm (the part between the words start and end).
The parts "given", "should", as well as "type of algorithm" and "description of arguments and results" may be missing.

The simplest algorithms

Let's consider the following auxiliary algorithm for the executor Draftsman.

Algorithm Example

alg square
early
lower the pen
move vector(0,2)
move vector(2,0)
shift by vector(0,-2)
move vector(-2,0)
raise the pen
con

It allows you to draw a 2x2 square (starting from the lower left corner). To do this, you need to use in the main program call command auxiliary algorithm, which will look like:

Algorithms with arguments

In order to draw squares of different sizes, you can use the algorithm with arguments.

Algorithm Example

alg square (arg res)
early
lower the pen
shift by vector(0, a)
shift by vector(a, 0)
shift by vector(0, -a)
shift by vector(-a, 0)
raise the pen
con

The word arg means that the algorithm has argument(a) and thing is that the argument is of the real type. The command to call such an algorithm may look like

(in this case a 2x2 square will be drawn) or, for example,
(in this case, a 5x5 square will be drawn).

Algorithms with results

The algorithm can not only receive information, but also give it away. For this, a special type of quantity is used - results.

Example algorithm with results

alg hypotenuse (res a, b, res res c)
given a >= 0 and b >= 0 | lengths of the legs of a triangle
need | c = length of the hypotenuse of this triangle
early
c:= sqrt(a ** 2 + b ** 2)
con

Here is the official word cut indicates that the value c is the result and its value will change in the course of the algorithm. For example, after calling

hypotenuse(3, 4, c)

The value c will take the value 5.

Algorithms-procedures and algorithms-functions

The examples discussed above are algorithms-procedures. In Kumir there are also function-algorithms. Algorithm function after execution returns the result value.
Description rules algorithms-procedures and algorithms-functions have two differences.
First, for algorithms-functions in place algorithm_type one of the simple types must be specified algorithmic language(thing, integer, etc.) that defines the type of values ​​that this function returns.
Secondly, in the body of the algorithm-function it is necessary to use the service value value, which is assigned the computed value of the function. Its description is the title of the algorithm, but otherwise the value val is used in the same way as any other intermediate value. (In the body of the algorithm-procedure, use the value it is forbidden.)
Calling an algorithm-procedure is a separate command of the algorithmic language and has the form:
Executor Control Robot in the KUMIR system

The robot exists in a certain environment (rectangular checkered field). Walls can be located between some cells of the field. Some cells may be shaded (Fig. 3.11).

The robot occupies exactly one cell of the field.

On commands up, down, left and right, the Robot moves to the next cell in the specified direction. If there is a wall on the way, then a failure occurs - a message is displayed about the impossibility of executing the next command.

On command to paint over, the Robot paints over the cell in which it stands. If the cell has already been painted over, it will be painted over again, although no visible changes will occur.

The robot can only execute correctly written commands. If you write down instead of the command down, then the Robot will not understand this entry and will immediately report an error.

O
errors: 1 syntactic; 2. logical

Scene descriptions are stored in text files special format (.fil format).

Current- the environment in which the Robot is in this moment(including information about the position of the Robot).

Home- the environment in which the Robot is forcibly placed at the beginning of the execution of the program using the Robot.

Operating procedure:


  1. Ask starting environment according to the task:
Menu Tools → Change the starting environment of the Robot (draw the environment according to the task condition, give a name, save in the Personal folder)

2. Specify the Contractor:

Insert Menu →Use Robot

3. Write an algorithm for solving the problem.

4. Run the algorithm (Menu Run → Run continuously / F9)

The system of commands of the executor Robot in the KUMIR system


Team

Action

up

The robot moves up 1 cell

way down

The robot moves down 1 cell

to the left

The robot moves 1 cell to the left

right

The robot moves 1 cell to the right

paint over

The robot paints the cell in which it is

right free

The robot checks the execution of the corresponding simple terms

left free



top loose



bottom loose



the cell is shaded



cage clean



Cyclic algorithms

Cycle organization of repeating actions until a certain condition is true .

Loop body - a set of repeatable actions.

Condition - boolean expression (simple or complex (compound))
Cycle types:

1.Loop "Repeat n times" 2. Loop "Bye"
nc n times nts bye
. . Loop body. . Loop body
kts kts

Example: nts bye right free


General view of the cycle "Repeat n times:

REPEAT n TIMES

THE END
kts

General view of the while loop:

WHILE TO DO

THE END
Compound conditions formed from one or more simple conditions and service words AND, OR, NOT.


Compound condition A and B(where A, B are simple conditions) is satisfied when each of the two simple conditions included in it is satisfied.

Let A - free on top AT - free on the right then the compound condition A and B- free on top AND free on the right.


Compound condition A OR B is satisfied when at least one of the two simple conditions included in it is satisfied: top free OR right free
Compound condition NOT A- met when condition A is not met.

Example: Let A be a shaded cell (simple condition).

P Checking the compound condition NOT A:

a) A - done, NOT A (NOT shaded) - not done.

b) A - not done, NOT A (NOT shaded) - done.


Branch command

Branching - a form of organization of actions in which, depending on the fulfillment or non-fulfillment of a certain condition, either one or another sequence of actions is performed.

General view of the IF command:

IF THEN OTHERWISE

THE END

In the KUMIR language:

Full branching: Partial branching:
if then if then

otherwise

all all

Helper Algorithm- an algorithm that solves some subproblem of the main problem.

In the KUMIR system auxiliary algorithms are written at the end of the main program (after the service word con) are called for execution in the main program by name.

AT surveys and assignments

1. Give all the algorithms of the three commands that will move the Robot from its original position to cell B.

Is there an algorithm for this task, during which the Robot does:

a) two steps b) four steps; c) five steps; d) seven steps?


  1. Petya made an algorithm that transfers the Robot from cell A to cell B with some cells painted over. What should Kolya do with this algorithm in order to obtain an algorithm that takes the Robot from B to A and fills in the same cells?


7. Two auxiliary robot algorithms are known

Draw what happens when the Robot performs the following basic algorithms:


a)

nc 5 times


pattern_1

right; right;


b)

nc 7 times


pattern_2

right; right


in)
right; right; right

up; up

right; right; right

way down; way down


G)
right; right
right; right

8. Create algorithms under which the Robot will paint over the specified cells:



9. It is known that somewhere to the right of the Robot there is a wall. Make up an algorithm, under the control of which the Robot will paint over a number of cells up to the wall and return to its original position.

10. It is known that somewhere to the right of the Robot there is a shaded cell.

FROM leave the algorithm, under the control of which the Robot will paint a number of cells up to the shaded cell and return to its original position.

11. It is known that the Robot is located near the left entrance to the horizontal corridor.

12. It is known that the Robot is somewhere in the horizontal corridor. None of the cells of the corridor is painted over.

Make up an algorithm, under the control of which the Robot will paint over all the cells of this corridor and return to its original position.


13. In a row of ten cells to the right of the Robot, some cells are shaded.

FROM leave the algorithm that paints the cells:

a) below each shaded cell;

b) above and below each shaded cell.


14. What can be said about the correctness of the following fragment of the algorithm?

nts bye the cell is shaded

IF right free THEN

right; paint over

to
c

15. Write a program with which the Robot can get to cell B in all three mazes.


16. Write a program, following which the Robot will be able to go along the corridor from the lower left corner of the field to the upper right. The corridor has a width of one cell and stretches in the direction from left-bottom-right-up. An example of a possible corridor is shown in the figure.

W

adachi GIA


  1. Corridor1. The robot is somewhere in the vertical corridor. None of the cells of the corridor is painted over. Create an algorithm under which the Robot will paint over all the cells of this corridor and return to its original position.

  1. To
    Necessary

    Given
    corridor2. The robot is located in the upper cell of a narrow vertical corridor. The width of the corridor is one cell, the length of the corridor can be arbitrary.

A possible variant of the initial location of the Robot is shown in the figure (the Robot is indicated by the letter "P")

Write an algorithm for the Robot that fills all the cells inside the corridor and returns the Robot to its original position. For example, for the above picture, the Robot should paint over the following cells (see picture):


  1. There is a long horizontal wall on the endless field. The length of the wall is unknown. The robot is in one of the cages directly above the wall. The initial position of the Robot is also unknown. One of the possible positions:
H


Necessary

Given
Write an algorithm for the Robot that paints all the cells above and adjacent to the wall, regardless of the size of the wall and the initial position of the Robot. For example, for the given drawing, the Robot must paint over the following cells:

The final position of the Robot can be arbitrary. When executing the algorithm, the Robot should not be destroyed.



  1. There is a long vertical wall on the infinite field. The length of the wall is unknown. The robot is in one of the cages located directly to the right of the wall. The initial position of the robot is also unknown. One of the possible positions of the robot is shown in the figure (the robot is marked with the letter “P”): Write an algorithm for work that paints over all the cells adjacent to the wall: on the left, starting from the top unpainted and through one; on the right, starting from the bottom shaded and through one. The robot must paint over only the cells that satisfy this condition. For example, for the above figure, the robot must fill in the following cells (see figure): The final location of the robot can be arbitrary. The algorithm must solve the problem for an arbitrary wall size and any valid initial position of the robot. When executing the algorithm, the Robot should not collapse.


Write an algorithm for the Robot that paints all cells located to the left of the vertical wall and above the horizontal wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above picture, the Robot must paint over the following cells (see picture).


H write an algorithm for the Robot that paints the cells adjacent to the wall, from above and below, starting from the left and through one. The robot must paint over only the cells that meet this condition. For example, for the given figure a) the Robot must paint over the following cells (see Fig. b).

The final position of the Robot can be arbitrary. The algorithm must solve the problem for an arbitrary wall size and any valid initial position of the Robot.



R

  1. There is a long vertical wall on the infinite field. The length of the wall is unknown. The robot is in one of the cages located directly to the left of the wall. The initial position of the robot is also unknown. One of the possible positions of the robot is shown in the figure (the robot is marked with the letter "P"):
Write for work an algorithm that paints over all the cells adjacent to the wall:

  • all on the left;

  • on the right, starting from the top unpainted and through one.
The robot must paint over only the cells that meet this condition.

B
1102_GIA2011

There are two horizontal walls on the infinite field. The length of the walls is unknown. The distance between the walls is unknown. The robot is located above the bottom wall in a cage located at its left edge. Write an algorithm for the Robot that paints all the cells located above the bottom wall and below the top wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above drawing, the robot must fill in the following cells (see figure):

The final location of the robot can be arbitrary. The algorithm must solve the problem for an arbitrary field size and any admissible location of walls inside a rectangular field. When executing the algorithm, the Robot should not collapse.


AT
1103_GIA_2011


There is a horizontal wall on the infinite field. The length of the wall is unknown. From the right end of the wall, a vertical wall extends downward, also of unknown length. The robot is located above a horizontal wall in a cage located at its left edge. The figure shows one of possible ways the location of the walls and the Robot (the Robot is indicated by the letter "P").

Write an algorithm for the Robot that paints all the cells located above the horizontal wall and to the right of the vertical wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above picture, the Robot must paint over the following cells (see picture).

Practical work"Executor Draftsman. Using Helper Algorithms with Arguments"

Task A. The auxiliary algorithm we need (which draws a square of a certain length) can be written as follows:

alg square( arg thing a)
early
. lower the pen
. shift by vector(0,a)
. shift by vector(a,0)
. shift by vector(0,-a)
. shift by vector(-a,0)
. raise the pen
con

Record " alg square( arg thing a)" means that the "square" algorithm has one argument (arg) "a", which can be an arbitrary real (real) number. In order to call this algorithm, you need to write, for example, "square (2)" - we get a square with side 2 or "square (3)" - we get a square with side 3, etc. Some specific value "a" will receive only while the program is running during the corresponding auxiliary algorithm. And everywhere instead of "a" this number will be substituted by the computer.

The program for drawing this picture can be like this:

use Drawer
alg squares
early
. move to a point(1,1)
. square(2)
. move to a point(4,1)
. square(3)
. move to a point(8,1)
. square(4)
. move to a point(13,1)
. square(5)
. move to a point(0,0)
con
alg square( arg thing a)
early
. lower the pen
. shift by vector(0,a)
. shift by vector(a,0)
. shift by vector(0,-a)
. shift by vector(-a,0)
. raise the pen
con

Task B. Let's teach the Draftsman new commands. Let one of the commands be called " line(arg th x1,y1,x2,y2)» – to draw a line from point (x1,y1) to point (x2,y2).

alg line( arg thing x1, y1, x2, y2)
early
. move to a point(x1,y1)
. lower the pen
. move to a point(x2,y2)
. raise the pen
con

Task B. Let the second command be called " rectangle(arg th x1,y1,x2,y2)' to draw a rectangle. The point (x1,y1) is one point of the AC diagonal of the rectangle, the point (x2,y2) is the opposite one. Before writing the algorithm, you need to understand what the coordinates of the other two points are.

A helper algorithm might look like this:

alg rectangle( arg thing x1, y1, x2, y2)
early
. move to a point(x1,y1)
. lower the pen
. move to a point(x2,y1)
. move to a point(x2,y2)
. move to a point(x1,y2)
. move to a point(x1,y1)
. raise the pen
con

Task G. Now using these commands we will draw a house:

use Drawer
alg house
early
. rectangle(2,1,8,5)
. rectangle(3,2,5,4)
. rectangle(6,1,7,4)
. line(1,4,5,8)
. line(5,8,9,4)
con
alg line( arg thing x1, y1, x2, y2)
early
. move to a point(x1,y1)
. lower the pen
. move to a point(x2,y2)
. raise the pen
con
alg rectangle( arg thing x1, y1, x2, y2)
early
. move to a point(x1,y1)
. lower the pen
. move to a point(x2,y1)
. move to a point(x2,y2)
. move to a point(x1,y2)
. move to a point(x1,y1)
. raise the pen
con

Note: of course, along with these commands, we can use the standard draftsman commands (move to a point, move to a vector ...).

Task D. Draw yourself what the Drawer will draw by executing the algorithm:

use Drawer
alg spiral
early
. move to a point(3,3)
. lower the pen
. coil(1); coil(3); coil(5); coil(7); coil (9)
. raise the pen
con
alg coil( arg thing a)
early
. shift by vector(a, 0)
. shift by vector(0, -a)
. shift by vector(-a-1.0)
. shift by vector(0, a+1)
con.

SCHEME OF THE LESSON OF INFORMATICS

Topic of the lesson

"Using Helper Algorithms for the Draftsman"

Age of students

1 2 years (grade 6)

Lesson type

Assimilation of new knowledge

Lesson Form

Modular lesson

The purpose of the lesson:

To form students' understanding of the concept of "auxiliary algorithm" as one of the optimization methods program code

Lesson objectives:

    develop students' perceptions of performers

    consolidate the idea of ​​the algorithm as a model of the performer's activity

    introduce auxiliary algorithms

    consolidate the skills of managing the performer

Planned results

subject - the ability to develop algorithms for managing the performer;

metasubject - the ability to independently plan ways to achieve goals; correlate their actions with the planned results, exercise control over their activities, determine the methods of action within the framework of the proposed conditions, adjust their actions in accordance with the changing situation; evaluate the correctness of the educational task; the ability to break a task into subtasks; experience in decision-making and management of performers using algorithms compiled for them;

personal - the ability to link educational content with one's own life experience, to understand the importance of developed algorithmic thinking for a modern person.

Material and technical equipment (didactic tools, etc.)

Teacher: lesson presentation; Handout

Student: ballpoint pen, pencil, ruler, textbook, workbook

UMK (video sequence)

multimedia presentation, handout for each student: lesson flow chart, application sheet

Used materials

Informatics: a manual for grades 5-6 / L.L. Bosova, A.Yu. Bosova. – M.: Binom. Knowledge Lab, 2014

Informatics: Textbook for grade 6 / L.L. Bosova, A.Yu. Bosova. – M.: Binom. Knowledge Lab, 2013

Informatics: Workbook for grade 6 / L.L. Bosova, A.Yu. Bosova. – M.: Binom. Knowledge Lab, 2013

Topic: Helper Algorithms for Draftsman

Routing(module) lesson

Rating score

(max. score)

UE - 0

2 minutes.

Integrating goal: programmers have a list of good style rules, one of these rules is "don't repeat yourself", which means that you need to avoid duplicating sections of code multiple times. Today in class:

    you will get acquainted with one of the ways to optimize the program code

    you will improve your skills in the KuMir programming environment

    you will develop logical thinking, a critical attitude to the information received

UE - 1

Updating of basic knowledge.

Target : update the acquired knowledge

Exercise 1.

a) move to the point (5,2) __________

b) move to the vector (3,4) _______

c) move to the point (1,4) __________

Task 2.

use Draftsman

alg

early

    move to point (2,4)

    move to point (4,1)

    move to point (0,0)

con

use Draftsman

alg

early

    lower the pen

    shift by vector (0,3)

    move vector (3,0)

    shift by vector (0,-3)

    move a vector (-3.0)

con

Read carefully the goal of UE - 1

Work in pairs

Check yourself with the answers written on the board.

Correctly completed task 1 is estimated at 3 points, 1 point for each item (a, b, c)

Correctly completed task 2 is estimated at 2 points, 1 point for each item (a, b)

Maximum amount points for work with UE-1 =5

____________

UE - 2

Learning new material.

13 min.

Target: get acquainted with the concept of an auxiliary algorithm, expand the range of tasks that can be solved using an auxiliary algorithm, learn to compose a main and auxiliary algorithm for a draftsman

In the last lesson, you made an algorithm for the draftsman, executing which he draws one star.

    Determine the disadvantages of such an algorithm:

_________________________________

_________________________________

_________________________________

_________________________________

    How can these difficulties be avoided?

_________________________________

_________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

______________________________________

Carefully read the goal of UE - 2

Individual work with tasks 1 - 3

For item 4, use the material in paragraph 18 of your textbook (pp. 123-125), the teacher's presentation

Discussion of points 1 - 4 - group work in frontal mode

Task 5 - 6 do individually

9

Assignment evaluation

Task 1-2 completed correctly for 1 point

____________

Task 3 indicates at least 3 shortcomings - 1 point

_____________

Task 4 shows how to solve the problem:

1 way = 1 point, 2 ways = 2 points

_____________

Task 5. There are 6-8 stars on the coordinate plane, the size of which corresponds to the "Asterisk" - 1 point

____________

The main algorithm "Cosmos" was compiled - 3 points

____________

UE - 3

Practical work

Target: To form the ability to work with auxiliary algorithms in the KuMir programming environment

Exercise 1. Implement the algorithm you have compiled in the KuMir programming system

Task 2 (creative). Think about what kind of aircraft can be in space:

a) draw it on the coordinate plane next to the stars on paper

b) supplement your algorithm with the aircraft code, implement it in the KuMir programming system

Carefully read the goal of UE - 3

Individual work with assignments

Report the completion of each task to the teacher for control

An example can be seen in Appendix 1

The maximum number of points for work with UE-2 =6

Correctly completed task 1 is estimated at 2

Task 2 (creative) fully completed is estimated at 4 points

_____________

UE - 4

Reflection

Target: Review your progress in class

Give an answer to each question

1. Read the objectives of the lesson again.

2. Have you achieved your goals?

__________________________________

3. What prevented the achievement of goals?

__________________________________

4. What did you find most difficult?

__________________________________

5. What did not cause difficulties?

__________________________________

6. How do you rate your work?

7. Did you score less than 20 points? (if yes, then work at home and you have a chance to retest). Good luck!

Homework:

Review all the notes made in the lesson.

§18(3), no.6 on p. 128; No. 216.

Read carefully the goal of UE-4

Answer the questions

Calculate the number of points, rate yourself (Appendix 2, Appendix 3)

APPS

Attachment 1

An example of a completed task

Annex 2

Control sheet

Surname, Name ______________________________________________

Annex 3

17 -19

(85 – 99%)

high

You are just great!

15 - 16

(75 – 84 %)

average

A little more and it will be "5"

10 - 14

(50 – 74%)

short

Be careful

1 - 9

(0,7 – 49%)

very low

And what do you think about in class?

null

You didn't attend the lesson?

Answers

UE - 1

Exercise 1. The initial position of the Draftsman is point A, to which point he will move by executing the command:

a) move to the point (5,2) ____F ______

b) move to the vector (3,4) __C ______

c) move to the point (1,4) ____A ______

Task 2. The initial position of the Draftsman is the origin of coordinates, the pen is raised. Run the algorithm and determine what shape it will draw.

a) NOTHING, THERE WAS NO COMMAND TO DOWN THE PEN

use Draftsman

alg

early

    move to point (2,4)

    move to point (4,1)

    move to point (0,0)

con

b) SQUARE

use Draftsman

alg

early

    lower the pen

    shift by vector (0,3)

    move vector (3,0)

    shift by vector (0,-3)

    move a vector (-3.0)

con

UE - 2

    How should the algorithm change if the Draftsman needs to draw a starry sky with 20, 50, 1000 stars?

It will have more teams

    How many rows will the algorithm take for 10 stars?

    Determine the disadvantages of such an algorithm: cumbersome, duplication, high probability of making a mistake

    How to avoid these difficulties: use an auxiliary algorithm, they can also call a cycle

    On the coordinate plane, place 6 - 8 stars, the size of each should correspond to the asterisk that you drew in the last lesson

    Write the main "Space" algorithm using the "Asterisk" algorithm as the auxiliary algorithm

use Drawer

alg space

early

move to point (1,1)

star

shift by vector (2, 2)

star

move a vector (-2, 2)

star

shift by vector (2, 2)

star

rocket

move to point (13,1)

star

move a vector (-2, 2)

star

shift by vector (2, 2)

star

move a vector (-2, 2)

star

con

alg asterisk

early

lower the pen

set color ("yellow")

move vector(1,2)

shift by vector(1,-2)

shift by vector(-2,1)

move vector(2,0)

shift by vector(-2,-1)

raise the pen

con

alg rocket

early

move to point (6,1)

lower the pen

set color ("red")

move vector(0,1)

move vector(1,1)

shift by vector(0,4)

move vector(1,1)

shift by vector(1,-1)

shift by vector(0,-4)

shift by vector(1,-1)

shift by vector(0,-1)

shift by vector(-1,1)

shift by vector(-1,-1)

shift by vector(-1,1)

shift by vector(-1,-1)

raise the pen