Skip to content

#181 Perfect Roots

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

181 Perfect Roots

Given a number n, find if its 2nd, 4th and 8th roots are all integers (perfect roots), return true if it exists, false if not.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/181 Perfect Roots.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//Given a number n, find if its 2nd, 4th and 8th roots are all integers (perfect roots), return true if it exists, false if not.
function perfectRoots(n) {
    return Number.isInteger(Math.sqrt(n)) && Number.isInteger(Math.pow(n, 1 / 4)) && Number.isInteger(Math.pow(n, 1 / 8))
}
import { assertEquals } from '../testHelper.js';
assertEquals(perfectRoots(256), true)
assertEquals(perfectRoots(1000), false)
assertEquals(perfectRoots(6561), true)
assertEquals(perfectRoots(12534), false)
assertEquals(perfectRoots(3455), false)
assertEquals(perfectRoots(65536), true)
assertEquals(perfectRoots(390625), true)
assertEquals(perfectRoots(1679616), true)
assertEquals(perfectRoots(6534561), false)
assertEquals(perfectRoots(253456), false)
assertEquals(perfectRoots(5764801), true)
assertEquals(perfectRoots(100000000), true)

Clone this wiki locally