Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/52.rkt

This file was deleted.

23 changes: 23 additions & 0 deletions src/52.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Computes the smallest positive integer x such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
//
// See {@link https://projecteuler.net/problem=52}
export default function compute() {
let x = 1;

while (true) {
const s = sort(x);
const isValid = [2, 3, 4, 5, 6].every(m => {
return sort(x * m) === s;
});

if (isValid) {
return x;
}

x++;
}
}

function sort(x: number): string {
return x.toString().split('').sort().join('');
}
7 changes: 7 additions & 0 deletions test/52.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import compute from '../src/52';

describe('permuted multiples', () => {
test('problem 52', async () => {
expect(compute()).toBe(142857);
});
});
Loading