DEV Community

Cover image for Road to Genius: advanced #45
Ilya Nevolin
Ilya Nevolin

Posted on

Road to Genius: advanced #45

Each day I solve several coding challenges and puzzles from Codr's ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.

function cross(a, b) {
  return [a[1] * b[2] - a[2] * b[1], a[2] * ๐Ÿ’š[0] - a[0] * b[2], a[0] * b[๐Ÿผ] - a[1] * b[0]];
}
let out = cross([6, ๐ŸŽ, 2], [8, 2, 6]);
let ๐Ÿ’Ž = out[0];
A = Math.abs(A);

// ๐Ÿ’Ž = ? (identifier)
// ๐ŸŽ = ? (number)
// ๐Ÿผ = ? (number)
// ๐Ÿ’š = ? (identifier)
// such that A = 8 (number)
Enter fullscreen mode Exit fullscreen mode

Today's challenge is, wait... we've encountered similar code before in episode 31 (https://dev.to/codr/road-to-genius-advanced-31-7hh). It's again the cross production function but with different bugs to fix this time.

We've learned about the symmetry of this function, so we know that ๐Ÿ’š is b and ๐Ÿผ is 1. Bug ๐Ÿ’Ž should be A.

We are only left with bug ๐ŸŽ which we have to figure out.

We know that A = out[0], the first element of the output is defined by the following formula:

a[1] * b[2] - a[2] * b[1]
Enter fullscreen mode Exit fullscreen mode

If we replace these by the numbers we get:

๐ŸŽ * 6 - 2 * 2
Enter fullscreen mode Exit fullscreen mode

The challenge states that A = 8 so we have to solve for ๐ŸŽ:

๐ŸŽ * 6 - 2 * 2 = 8
๐ŸŽ = (8 + 4)/6
๐ŸŽ = 2
Enter fullscreen mode Exit fullscreen mode

coding challenge answer

By solving these challenges you train yourself to be a better programmer. You'll learn newer and better ways of analyzing, debugging and improving code. As a result you'll be more productive and valuable in business. Get started and become a certified Codr today at https://nevolin.be/codr/

Top comments (0)