Skip to content

Instantly share code, notes, and snippets.

@croespino
croespino / issue-299-of-rendezvous-with-cassidoo.java
Created May 10, 2023 05:09
Sum the odd-square numbers less than a given integer n.
public class Main {
public static void main(String[] args) {
assert oddSquareSum(1) == 0;
assert oddSquareSum(2) == 1;
assert oddSquareSum(9) == 1;
assert oddSquareSum(10) == 10;
assert oddSquareSum(44) == 35;
assert oddSquareSum(0) == 0;
assert oddSquareSum(7569) == 105995;
assert oddSquareSum(Integer.MAX_VALUE) == 16585052009610L;
@croespino
croespino / issue-298-of-rendezvous-with-cassidoo.ts
Last active May 2, 2023 04:47
Given a non-empty array containing only non-negative integers, return the list with trailing and leading zeroes removed.
import { equal } from "https://deno.land/x/equal/mod.ts";
function getArrayWithZeroesRemoved(arr, startIndex, endIndex) {
const arrayWithZeroesRemoved = new Array(endIndex - startIndex + 1);
let i = 0;
while (startIndex <= endIndex) {
arrayWithZeroesRemoved[i] = arr[startIndex];
i++;
startIndex++;
}
function getAllDigits(arr) {
const digits = [];
for (const number of arr) {
if (number === 0) {
digits.push(0);
continue;
}
let remainingOfNumber = Math.abs(number);
while (remainingOfNumber > 0) {
const digit = remainingOfNumber % 10;
function maxPointsOnLine(points: number[][]): number {
if (points.length === 1) {
return 1;
}
const pointPairs = [];
for (let i = 0; i < points.length; i++) {
for (let j = i + 1; j < points.length; j++) {
pointPairs.push([points[i][0], points[i][1], points[j][0], points[j][1]]);
}
}