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)
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]
If we replace these by the numbers we get:
๐ * 6 - 2 * 2
The challenge states that A = 8
so we have to solve for ๐:
๐ * 6 - 2 * 2 = 8
๐ = (8 + 4)/6
๐ = 2
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)