Kristian

HackerRank: Find the Point

HackerRank: Find the Point

I finally found the math problems on HackerRank which makes me so happy. So let’s getting cracking on the first one called Find the Point. It asks us to

Consider two points,  and . We consider the inversion or point reflection, of point  across point   to be a  rotation of point  around .

Given  sets of points  and , find  for each pair of points and print two space-separated integers denoting the respective values of  and  on a new line.

Continue reading →

Posted by Kristian, 0 comments
HackerRank: Utopian Trees

HackerRank: Utopian Trees

I found another fun little problem at HackerRank called Utopian trees. It is not an easy due to the input constraints. Given how small they are I am pretty sure it could be solved by bruteforce.  The problem description is

The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter.

Laura plants a Utopian Tree sapling with a height of 1 meter at the onset of spring. How tall will her tree be after n growth cycles?

Given that the number of test cases is smaller than 10 and the number of cycles are less than 60, it should be pretty obvious that it can be bruteforced. However, there is also a nice analytical solution to this.  Continue reading →

Posted by Kristian in HackerRank, 0 comments
Shenzhen I/O: Carbine Target Illuminator

Shenzhen I/O: Carbine Target Illuminator

Once again we are going to make equipment for military use. Someone in the company is not going to be happy about it. This time it is a Carbine Target illuminator, so we can see the bad guys before we shoot them. With the use of radar we are going to measure the distance to the bad guy by counting the number of cycles between output and input to the radar. Based on that we will turn on the laser sight and or the flood light in the following configuration.

Shenzhen I/O - Carbine target Illuminator - specification Continue reading →

Posted by Kristian in Shenzhen IO, 0 comments
Hackerrank: Forming a magic Square

Hackerrank: Forming a magic Square

I must admit that this problem actually took me a good while to solve. Once you have the right insight on forming a magic Square it is really straight forward. But until that point I was just stuck. Anyway, before rambling on lets get to the actual problem.

We define a magic square to be an  matrix of distinct positive integers from 1 to nwhere the sum of any row, column, or diagonal (of length n) is always equal to the same number (i.e., the magic constant).

Consider a  matrix, s, of integers in the inclusive range [1, 9]. We can convert any digit, a, to any other digit, b, in the range [1, 9] at cost .

Given , convert it into a magic square at minimal cost by changing zero or more of its digits. Then print this cost on a new line.

Note: The resulting magic square must contain distinct integers in the inclusive range [1, 9].

Continue reading →

Posted by Kristian in HackerRank, 0 comments
Shenzhen I/O: Personal Sandwich Maker

Shenzhen I/O: Personal Sandwich Maker

Yeah, this time we are going to make a personal sandwich maker. What could possibly go wrong when making food? Nothing right! This one took me a while to crack, or rather it was fairly easy to make solution. But it took me quite a few tries to make a good one.

The sandwich maker print board have an xbus input where it gets a number from 1 to 3 which is three different modes

  1. Normal sandwich
  2. Hold the cheese
  3. Extra mustard

Continue reading →

Posted by Kristian in Shenzhen IO, 0 comments
Shenzhen I/O: Token-Based Payment Kiosk

Shenzhen I/O: Token-Based Payment Kiosk

You are into history or at least history reenactment? That is what this puzzle is about, but apparently we are to make a Token-based payment kiosk…. just like they had in the good old days. Let us not fight over historical details, but let us take a look at this fun problem.

Oh and just a side note, by this time in the game we finally got the gen instruction. So now we can use it without problem.

The overall machine takes in a price as well as three simple inputs signifying three coin types of 1, 5 and 12 in value. We are then going to keep accepting coins until the price is reached. After which we must ring a bell for 4 seconds as well as give back change in 5 and 1 with the least possible coins.  Continue reading →

Posted by Kristian in Shenzhen IO, 3 comments
Shenzhen I/O: Unknown Optimization Device

Shenzhen I/O: Unknown Optimization Device

Poseidon-779 a Decentralized Autonomous Corporation has decided that we need to help them go into Thorium mining. And while I wont steer off a tangent telling you about Thorium reactors, although they are pretty cool, we should just make this unknown optimization device also known as 2A27.

We get two simple inputs x and y and have to deliver a simple output with a given value. That means we at least have to use 2 micro controllers. So we should not be able to make a solution for less than 6¥. Continue reading →

Posted by Kristian in Shenzhen IO, 0 comments

Shenzhen I/O: Color-Changing Vape Pen

Welcome back to china and our electronic building company. This time we got a contract with Cool Dad to make a color-changing vape pen – or rather millions for all his fans, so let’s see how we can implement that.

The specs here says that we will get a packet over radio which is either -999 which means that we should just sleep or it is four values with the meaning red, green, blue, duration. Which means the intensity of the 3 colors and the duration to hold it.

It also says that if we get a new instruction while we are currently running, we should override it. However, it only happens in the test set if the duration is 999. Otherwise it seems to run out. Continue reading →

Posted by Kristian in Shenzhen IO, 0 comments
Shenzhen I/O – Laser Tag Equipment

Shenzhen I/O – Laser Tag Equipment

I did not know that our company made weapons. But I guess as long as it is laser tag equipment it should be okay. This is in my opinion the hardest problem so far. We are asked to make a computer to control the equipment for a game of laser tag. And there are quite a few rules we need to take into consideration. Continue reading →

Posted by Kristian in Shenzhen IO, 0 comments
HackerRank: Between Two Sets in Python

HackerRank: Between Two Sets in Python

I found another really interesting problem on HackerRank called Between Two Sets. It is interesting because there was some math to be applied to the problem. The problem is a part of the implementation series on algorithms. The problem description is

Consider two sets of positive integers,  and . We say that a positive integer, x, is between sets A and B if the following conditions are satisfied:

  1. All elements in A are factors of x.
  2. x is a factor of all elements in B.

In other words, some x is between A and B if that value of x satisfies  for every  in A and also satisfies  for every  in B. For example, if  and  , then our possible x values are 6 and 12.

Given A and B, find and print the number of integers (i.e., possible x‘s) that are between the two sets.

There are some constraints given to the between two sets.  These constraints mean that it will be possible to make a bruteforce solution.  We could test every number between 1 and 100 to see if they satisfy the condition for all numbers in both A and B. However, we can also look at a little bit of math to find some properties of the numbers we are testing. Continue reading →

Posted by Kristian in HackerRank, 0 comments