(Five Jack) SE Online Test

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Question 1.

In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers.

For any positive integer n, define d(n) to be n plus the sum of the digits of n.

For example, d(75) = 75 + 7 + 5 = 87.

The number n is called a generator of d(n).

Some numbers have more than one generator: for example, 101 has two generators, 91 and 100.

A number with no generators is a self-number.

There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97.

- Write a program to sum of all self-numbers which are bigger than 0 and smaller than 5000.

Question 2.

There is a room with n rows and n columns, and there are gunmen in the room.

A gunman can see vertical or horizontal way, and cannot see over the wall or diagonal.

If a gunman see another gunman, they will shoot each other and only one man will survive.

We want all gunmen to be alive.

■: Wall

□: Empty space

♂: Gunman

For example, there is a room with 4 rows and 4 columns,

■■■□

□□□□

□■□□

■■■□

we can place 3 gunmen like below.

■■■□

□□□♂

♂■♂□
■■■□

However, we cannot place gunmen like below, because they are in the same line horizontally, one man
will die.

■■■□

□♂□♂

□■□□

■■■□

We can place maximum 4 gunmen in this room, and there are 2 ways to achieve this.

■■■♂

□♂□□

♂■♂□

■■■□

■■■□

□♂□□

♂■♂□

■■■♂

- Write a program to calculate

1. The maximum number of gunmen we can place in the room below.

(FYI, 14 is not the answer)

2. The number of ways to place gunmen in question 1?

(You should answer both question 1 and 2)


□■□■□■□■

□□□□□■□□

■□■□□■□■

□□□□□□□□

□□□■□□□□

□□□□□■□■

□■□□□□□□

□□□□■□■□

You might also like