IPA IP 2026 Question 88

A question IPA Japan published in 令和8年度 ITパスポート試験 公開問題 問88, translated into English. ITPEC is based on the same exams.

There is a robot that, by being programmed, can raise and lower a pen, move straight ahead, and change direction by turning clockwise. A program that makes this robot draw a regular hexagon with sides of 1 m was created. Which of the following is the appropriate combination of values to be inserted into A and B in the regular hexagon drawing program below?

[Regular hexagon drawing program]

(1)Lower the pen.(2)Set A in the counter for the number of times processed.(3)Execute the following processes in order. ·Move straight ahead 1 m. ·Change direction clockwise by B degrees. ·Add 1 to the counter for the number of times processed.(4)If the counter for the number of times processed is less than 6, return to (3).(5)Raise the pen.
OptionAB

Explanation

A: 0, B: 60 — the robot must draw six sides, turning by the hexagon's exterior angle after each.

Counter: the check in step (4) comes after the counter is increased, and the loop continues while the counter is less than 6. Starting from 0, the counter reads 1, 2, 3, 4, 5, 6 after each pass, so step (3) runs six times and six sides are drawn. Starting from 1 it would stop after five passes.

Angle: walking round a regular polygon, the turns add up to one full turn of 360°. With six equal turns, each is 360 ÷ 6 = 60 degrees, the exterior angle. The interior angle of a regular hexagon is 120°, but the robot turns by the angle it changes direction, which is 180° − 120° = 60°.

Running the program: with A = 0 and B = 60 the sixth side ends back at the start, closing the hexagon.

Answer (a)

Why not others:

  • •(b) — turning 120° each time draws an equilateral triangle, traced twice over six sides
  • •(c) and (d) — starting the counter at 1 runs the loop only five times, leaving the figure one side short (with 60°, an open hexagon; with 120°, a triangle and two sides)

Key rule: To draw a regular n-gon, turn by the exterior angle 360 ÷ n, not the interior angle; and count loop passes at the boundaries to check the start value of a counter.

Algorithm and Programming · AI-written, may contain errors

This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.