Skip to content

Instantly share code, notes, and snippets.

@Gerst20051
Gerst20051 / findRectangles.js
Last active November 21, 2020 18:54
Find Rectangles
const image = [
[0, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 1],
[1, 0, 1, 1, 1, 1, 1],
[1, 0, 1, 0, 0, 1, 1],
[1, 1, 1, 0, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 0],
];
@Gerst20051
Gerst20051 / PalindromeCreator.js
Last active September 8, 2021 10:48
Palindrome Creator
function PalindromeCreator(str) {
const isStringPalindrome = isPalindrome(str);
if (isStringPalindrome) return 'palindrome';
const palindrome = findPalindrome([{
str,
chars: [],
}], 2, 0);
return palindrome && palindrome.str.length > 2 ? getRemovedCharsForPalindrome(palindrome) : 'not possible';
}
@Gerst20051
Gerst20051 / WordSplit.js
Last active August 24, 2021 19:47
Word Split
function WordSplit(strArr) {
const word = strArr[0];
const substrings = generateSubstrings(word);
const words = substrings.filter(substring => strArr[1].includes(substring));
const pairs = generatePairs(words);
const pair = pairs.find(pair => pair.join('') === word);
return pair ? pair.join(',') : 'no pair';
}
function generateSubstrings(str) {
@Gerst20051
Gerst20051 / age_counting.php
Created November 21, 2020 05:02
PHP Age Counting
<?php
// Your goal is to count how many items exist that have an age equal to or greater than 50, and print this final value.
$ch = curl_init('https://coderbyte.com/api/challenges/json/age-counting');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
@Gerst20051
Gerst20051 / maxPoints.py
Last active November 21, 2020 04:27
Max Points
#!/bin/python3
#
# Complete the 'maxPoints' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts INTEGER_ARRAY elements as parameter.
#
def maxPoints(elements):
@Gerst20051
Gerst20051 / countSubarrays.py
Last active November 21, 2020 04:42
Count Subarrays
#!/bin/python3
#
# Complete the 'countSubarrays' function below.
#
# The function is expected to return a LONG_INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY numbers
# 2. INTEGER k
#
@Gerst20051
Gerst20051 / getShiftedString.py
Created November 21, 2020 03:27
Get Shifted String
#!/bin/python3
#
# Complete the 'getShiftedString' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. STRING s
# 2. INTEGER leftShifts
# 3. INTEGER rightShifts
@Gerst20051
Gerst20051 / shouldSaveForUserToday.js
Created November 20, 2020 20:03
Should Save For User Today
const data = require('./data.json');
// jq '[ .transactions[].amount ]' data.json
function shouldSaveForUserToday(data) {
const balanceThreshold = .2;
const accountBalance = data.accounts[0].balance.available;
const transactionAmounts = data.transactions.map(transaction => transaction.amount);
const transactionAverage = transactionAmounts.reduce((sum, amount) => sum + amount, 0) / transactionAmounts.length;
return transactionAverage < 0 && Math.abs(transactionAverage) < (accountBalance * balanceThreshold);
@Gerst20051
Gerst20051 / canFindZero.js
Created November 20, 2020 20:02
Can Find Zero
const digits = [3, 7, 0, 2, 8, 3, 7, 6];
const digits_empty = [];
function canFindZero(values, startIndex, checkedIndexes) {
checkedIndexes.push(startIndex);
if (values[startIndex] === 0) {
return true;
}
const leftIndex = startIndex - values[startIndex];
const leftIndexValue = values[leftIndex];
@Gerst20051
Gerst20051 / splitString.js
Created November 19, 2020 20:55
Split String
const sample = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ligula massa, pretium nec sagittis posuere, ornare in augue. Integer porta sapien quis diam tempor, id commodo lorem tempor. Vestibulum ac semper erat, eget venenatis risus. Pellentesque enim nisl, dignissim quis ullamcorper sed, pretium ac ligula. Etiam in dui ipsum. Mauris nisi lorem, facilisis at feugiat non, tristique pretium eros. Donec ultricies nibh urna, egestas iaculis nulla aliquet eget. Phasellus vitae tellus sagittis, viverra elit vel, porta neque. Pellentesque enim augue, malesuada ut risus nec, eleifend fringilla purus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Curabitur luctus, leo vitae interdum varius, lacus sapien imperdiet erat, eget aliquam orci mauris sit amet risus. Pellentesque maximus nibh id diam elementum aliquam eget vitae nisl. Morbi maximus eu sem sed posuere. Nullam aliquam ut dui nec tempus. Phasellus eget justo facilisis, lacinia quam at, sagittis tortor. Ma