Puzzles

homepage

If you enjoy puzzles, you've come to the right place

Shortest Path Sum

Floyd-Warshall graph algorithm

Given the hex string in the white box below. Construct a graph according to the following rules:

  • Each unique letter is a node.
  • Two nodes have an edge between them if they are adjacent in the string.
  • The weight of the edge between two nodes is the hex value of the two connected nodes.
  • If the same edge appears twice, ignore its second appearance.
  • The weight of an edge from a node to itself is zero.

Find the sum of every unique shortest path. Two shortest paths are unique if one of the paths contains at least one node that the other does not. The shortest path between two nodes is a series of edges along which one could travel to get from one node to the other.

Example The hex string 5d0d has 3 unique nodes 5, d, and 0. As we traverse the string from left to right, we find the following edges:

  • Edge 5d with value 5 + d = 5 + 13 = 18
  • Edge d0 with value d + 0 = 13 + 0 = 13
  • Edge 0d which is the same as d0, so we ignore it

We have 3 shortest paths to consider as follows:

  • Path 0 to d with a cost of 13
  • Path 0 to 5 with a cost of 31
  • Path d to 5 with a cost of 18
  • Note, the remaining paths would just be one of the above in reverse.

So, the answer to this example case is 13 + 31 + 18 = 62

61bffea9215f65164ad18b45aff1436c0c165d0d5dd2087ef61b4232ba6d2c1a

SUBMIT
CORRECT

Binary Search

binary search algorithm

Given the function below, find the largest integer n such that query(n) returns false and query(n+1) returns true. The answer is an integer between 1 and 80000000000 (80 billion!)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
function query(n) {
    let d1 = dist(n);
    let d2 = dist(n + 1);
    return d2 > d1;
}
function dist(v) {
    let c = (v + 28000000000)/10000000000;
    let t = c * Math.log(c)/2;
    let a = Math.pow(t - c, 2);
    let b1 = t + c;
    let b2 = c * Math.log(c);
    let b = Math.pow(b1 - b2, 2);
    return Math.sqrt(a + b);
}

SUBMIT
CORRECT

Odd and Even Numbers 😏

tricky logic

Find the missing value (hint: read the title):

  • 80618 = 4
  • 10792 = 2
  • 21643 = 3
  • 75335 = 0
  • 44713 = ?

SUBMIT
CORRECT

The Rabbit and the Chicken

algebra logic

There are n numbers of chickens and rabbits in the same room. We know that they have 35 heads and 94 feet in total. How many rabbits are there?

SUBMIT
CORRECT

Sequence Sum

basic math addition equation

Find the sum of the numbers from 1 to 100

SUBMIT
CORRECT
homepage