You are on page 1of 3

Programming Test

Do as many as you can within the time limit. Each question has a different weight. For numbers
1-9 provide a solution on programming.

1. (20 Point) A company has 3 different capacities for a milk bottle, and the milk bottle
capacity is a prime number between 0 to 30 liters (0 < Bottle x < 30).

How many bottles from each different capacity does the company need to contain X
litters of milk (100 < X < 10000000) such that the total number of bottles needed is the
fewest?

Example:
Bottle 1 = 5 litter
Bottle 2 = 7 litter
Bottle 3 = 11 liter
X = 100
Answer:
Bottle 3 = 9 bottles, Bottle 1 = 1 bottle, Bottle 2 = 0 bottle, total = 10 bottles
or
Bottle 3 = 9 bottles, Bottle 1 = 0 bottle, Bottle 2 = 1 bottle, total = 10 bottles

Answer:
<?php
$ganjil = 0;
$genap = 0;
$literSusu = 5000;
$botol = [];
do {
    for ($i = 0; $i < 30; $i++) {
        if ($i % 2 != 0) {
            $literSusu -= $i;
            if ($literSusu >= 0) {
                array_push($botol, $i);
            }
        }
    }
}while ($literSusu >= 0);

var_dump(array_count_values($botol));
?>
2. (30 Point) An adult man needs 400 grams of carbohydrates each day. Following is some
of the food for 100 grams:

Rice 28 grams Cal


Corn 21 grams Cal
Potato 17 grams Cal

For each day, the price of each food per 100 grams is changing. Thus make a program to
solve such that the cost of food is kept minimum (lowest) while still maintaining ~400
grams of carbohydrate needed for the body.
Answer:

3. (10 Point) Given the Fibonacci sequence which starts from X and Y where X and Y > 0.
Find the sum of even numbers, and a sum of odd numbers in the sequence from the N
number of a sequence where 2 < N < 1000000.

Example:
X=2
Y=3
N=3
2, 3, 5
Sum of even = 2
Sum of odd = 8
Answer:
<?php
$ganjil = 0;
$genap = 0;
for ($i = 3; $i < 1000000; $i++) {
    if ($i % 2) {
        $genap++;
    }else{
        $ganjil++;
    }
}
echo "ganjil: ".$ganjil."genap: ".$genap;
?>
4. (10 Point) Given a random string, count the occurrence of each character in the string
and sort them according to UTF-8.

5. (15 Point) Given 5 boxes arranged from left to right.

A B C D E
An object is put into the box randomly. For each step, the object is moving to another box
adjacent to the current box randomly.
Example: B > A or B > C, C > D or C > B
Make a solution such that you can find the object within 7 steps. You can only use 1
pointer/selector to find the object.

6. (30 Point) Two players play a game with rules:


1. The game starts with a number of piles where piles: 2 < N < 1000
2. Each pile consists of matches with number: 0 < M < 1000
3. The player alternative takes the matches from 1 pile with the maximum they can take
is 3, and the minimum is 1.
4. Players cannot take the match from the different piles in the same turn.
5. The player who takes the last matches will win the game.
Write a program for this game that is automatically played (bot, randomly) and announce
the winner and the steps taken.

7. (30 Point) A mall wants to make a royalty program. For every 1,000,000 rupiahs spent
on a mall tenant, will award a 10,000 rupiahs voucher to the registered customer. To get
the voucher, the customers need to show the tenant invoice. This invoice will have a
unique transaction ID and can only be used once. This voucher has a unique code that can
only be used once. Each voucher has expired time for 3 months. Make a program and
database to distribute and redeem the voucher (including registration and transaction).

8. (10 Point) From 3 6-side-dice, find the probability to find the sum of three dices number
is equal to X where 2 < X < 19.

9. (10 Point) Given 2 matrix with sizes MxN and NxM. Make a program to multiply the
matrix where 3<M<100 and 3<N<100.

10. (5 Point) How many days and how much do you need to clean windows from a building?

You might also like