Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Test cases project euler#1575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
pomkarnath98 wants to merge18 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
frompomkarnath98:test-cases-project-euler
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
b7309f0
📦 NEW: Added solution for ProjectEuler-007
omkarnathparidaOct 7, 2022
d3a3b33
🐛 FIX: Spelling mistake fixes
omkarnathparidaOct 7, 2022
e9b5a6a
👌 IMPROVE: changed variable name from `inc` to `candidateValue` and t…
omkarnathparidaOct 7, 2022
e99c722
👌 IMPROVE: Modified the code
omkarnathparidaOct 7, 2022
5ac898f
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 10, 2022
0f9f1ba
👌 IMPROVE: Added test case for ProjectEuler Problem001
omkarnathparidaOct 10, 2022
3caad5c
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 15, 2022
b7584fd
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 16, 2022
6693f9c
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 17, 2022
0830570
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 18, 2022
4d7149c
Merge branch 'TheAlgorithms:master' into master
pomkarnath98Oct 22, 2023
53e3938
👌 IMPROVE: Added test cases for Project Euler Problem 4
omkarnathparidaOct 22, 2023
96224e7
👌 IMPROVE: auto prettier fixes
omkarnathparidaOct 22, 2023
fefb3fb
🐛 FIX: fixed wrong code
omkarnathparidaOct 24, 2023
992c43b
👌 IMPROVE: added test cases for project euler problem 14 and problem 15
omkarnathparidaOct 24, 2023
ab2f4a2
Updated Documentation in README.md
Oct 24, 2023
99be4a3
Updated Documentation in README.md
Oct 24, 2023
cc1d73b
Merge branch 'test-cases-project-euler' of https://github.com/pomkarn…
omkarnathparidaOct 25, 2023
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
2 changes: 1 addition & 1 deletionBit-Manipulation/BinaryCountSetBits.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,7 @@ function BinaryCountSetBits(a) {

let count = 0
while (a) {
a &=(a - 1)
a &= a - 1
count++
}

Expand Down
1 change: 1 addition & 0 deletionsDIRECTORY.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -166,6 +166,7 @@
* [Area](Maths/Area.js)
* [ArithmeticGeometricMean](Maths/ArithmeticGeometricMean.js)
* [ArmstrongNumber](Maths/ArmstrongNumber.js)
* [AutomorphicNumber](Maths/AutomorphicNumber.js)
* [AverageMean](Maths/AverageMean.js)
* [AverageMedian](Maths/AverageMedian.js)
* [BinaryConvert](Maths/BinaryConvert.js)
Expand Down
2 changes: 1 addition & 1 deletionMaths/AutomorphicNumber.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,6 +35,6 @@ export const isAutomorphic = (n) => {
n = Math.floor(n / 10)
n_sq = Math.floor(n_sq / 10)
}

return true
}
16 changes: 8 additions & 8 deletionsMaths/test/AutomorphicNumber.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,19 +9,19 @@ describe('AutomorphicNumber', () => {
})

test.each([
{ n: -3, expected: false },
{ n: -25, expected: false },
{ n: -3, expected: false },
{ n: -25, expected: false }
])('should return false when n is negetive', ({ n, expected }) => {
expect(isAutomorphic(n)).toBe(false)
})

test.each([
{ n: 7, expected: false },
{ n: 83, expected: false },
{ n: 0, expected: true },
{ n: 1, expected: true },
{ n: 376, expected: true },
{ n: 90625, expected: true },
{ n: 7, expected: false },
{ n: 83, expected: false },
{ n: 0, expected: true },
{ n: 1, expected: true },
{ n: 376, expected: true },
{ n: 90625, expected: true }
])('should return $expected when n is $n', ({ n, expected }) => {
expect(isAutomorphic(n)).toBe(expected)
})
Expand Down
6 changes: 3 additions & 3 deletionsProject-Euler/Problem006.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
// https://projecteuler.net/problem=6

export const squareDifference = (num = 100) => {
let sumOfSquares = (num)*(num+1)*(2*num+1)/6
let sums = (num*(num+1))/2
let sumOfSquares = (num *(num + 1) * (2 *num + 1)) /6
let sums = (num *(num +1)) /2

return sums ** 2 - sumOfSquares // difference of square of the total sum and sum of squares
}
4 changes: 2 additions & 2 deletionsProject-Euler/Problem015.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,8 +7,8 @@ How many such routes are there through a 20×20 grid?
// A lattice path is composed of horizontal and vertical lines that pass through lattice points.

export const latticePath = (gridSize) => {
let paths
for (let i = 1, paths = 1; i <= gridSize; i++) {
let paths = 1
for (let i = 1; i <= gridSize; i++) {
paths = (paths * (gridSize + i)) / i
}
// The total number of paths can be found using the binomial coefficient (b+a)/a.
Expand Down
11 changes: 11 additions & 0 deletionsProject-Euler/test/Problem004.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
import { largestPalindromic } from '../Problem004.js'

describe('Largest Palindromic Number', () => {
test('if digit is 2', () => {
expect(largestPalindromic(2)).toBe(9009)
})
// Project Euler Condition Check
test('if digit is 3', () => {
expect(largestPalindromic(3)).toBe(906609)
})
})
26 changes: 26 additions & 0 deletionsProject-Euler/test/Problem014.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
import { findLongestCollatzSequence } from '../Problem014.js'

describe('Longest Collatz Sequence', () => {
test('sequence under 1', () => {
expect(findLongestCollatzSequence(1)).toBe(1)
})
test('sequence under 10', () => {
expect(findLongestCollatzSequence(10)).toBe(9)
})
test('sequence under 100', () => {
expect(findLongestCollatzSequence(100)).toBe(97)
})
test('sequence under 1000', () => {
expect(findLongestCollatzSequence(1000)).toBe(871)
})
test('sequence under 10000', () => {
expect(findLongestCollatzSequence(10000)).toBe(6171)
})
test('sequence under 100000', () => {
expect(findLongestCollatzSequence(100000)).toBe(77031)
})
// Project Euler Condition Check
test('sequence under 1000000', () => {
expect(findLongestCollatzSequence()).toBe(837799)
})
})
32 changes: 32 additions & 0 deletionsProject-Euler/test/Problem015.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
import { latticePath } from '../Problem015.js'

describe('Lattice Paths', () => {
test('if grid size is 2', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Such repetitive tests should usetest.each /it.each to reduce the boilerplate.

expect(latticePath(2)).toBe(6)
})
test('if grid size is 5', () => {
expect(latticePath(5)).toBe(252)
})
test('if grid size is 10', () => {
expect(latticePath(10)).toBe(184756)
})
test('if grid size is 15', () => {
expect(latticePath(15)).toBe(155117520)
})
test('if grid size is 16', () => {
expect(latticePath(16)).toBe(601080390)
})
test('if grid size is 17', () => {
expect(latticePath(17)).toBe(2333606220)
})
test('if grid size is 18', () => {
expect(latticePath(18)).toBe(9075135300)
})
test('if grid size is 19', () => {
expect(latticePath(19)).toBe(35345263800)
})
// Project Euler Condition Check
test('if grid size is 20', () => {
expect(latticePath(20)).toBe(137846528820)
})
})
48 changes: 24 additions & 24 deletionsRecursive/test/BinaryEquivalent.test.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
import { binaryEquivalent } from"../BinaryEquivalent";
import { binaryEquivalent } from'../BinaryEquivalent'

const tests = [
{
test: 2,
expectedValue:"10"
},
{
test: 0,
expectedValue:"0"
},
{
test: 543,
expectedValue:"1000011111"
},
{
test: 4697621023,
expectedValue:"100011000000000000000001000011111"
}
{
test: 2,
expectedValue:'10'
},
{
test: 0,
expectedValue:'0'
},
{
test: 543,
expectedValue:'1000011111'
},
{
test: 4697621023,
expectedValue:'100011000000000000000001000011111'
}
]

describe("Binary Equivalent", () => {
test.each(tests)(
"of $test should be $expectedValue",
({test, expectedValue}) => {
expect(binaryEquivalent(test)).toBe(expectedValue);
}
)
describe('Binary Equivalent', () => {
test.each(tests)(
'of $test should be $expectedValue',
({test, expectedValue}) => {
expect(binaryEquivalent(test)).toBe(expectedValue)
}
)
})
2 changes: 1 addition & 1 deletionSearch/InterpolationSearch.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,4 +36,4 @@ export function interpolationSearch(arr, key) {
}

return-1
}
}

[8]ページ先頭

©2009-2025 Movatter.jp