Logic Programming Test v2.1
Logic Programming Test v2.1
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:
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.
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.
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?