Skip to content

[pull] master from TheAlgorithms:master #26

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2023
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
4 changes: 2 additions & 2 deletions Hashes/SHA256.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ function chunkify(str, size) {
}

/**
* Rotates string representation of bits to th left
* Rotates string representation of bits to the right
*
* @param {string} bits - string representation of bits
* @param {int} turns - number of rotations to make
* @return {string} - string representation of bits after rotation
*
* @example
* rotateLeft("1011", 3); // "1101"
* rotateRight("1011", 3); // "1101"
*/
function rotateRight(bits, turns) {
return bits.substr(bits.length - turns) + bits.substr(0, bits.length - turns)
Expand Down
9 changes: 3 additions & 6 deletions Project-Euler/Problem006.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// https://projecteuler.net/problem=6

export const squareDifference = (num = 100) => {
let sumOfSquares = 0
let sums = 0
for (let i = 1; i <= num; i++) {
sumOfSquares += i ** 2 // add squares to the sum of squares
sums += i // add number to sum to square later
}
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
}