Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
set -e
set -o pipefail
set -u
aoeu=a/o/e/u
echo "aoeu=${aoeu}" # aoeu=a/o/e/u
echo "aoeu%/*=${aoeu%/*}" # aoeu%/*=a/o/e
echo "aoeu%%/*=${aoeu%%/*}" # aoeu%%/*=a
setup() {
. "${BATS_TEST_DIRNAME}/bash-inject.shlib"
}
@test "should default to defining function" {
assert_equal "$(declare -F fn)" ''
@inject "${BATS_TEST_DIRNAME}/fn.sh"
run echo "$(declare -f fn)"
#!/usr/bin/python3.8
import argparse
import math
def memoize(f):
memo = {}
#!/usr/bin/python3
import argparse
def sum_of_sequence(n):
return n * (n + 1) / 2
def sum_of_squares_of_sequence(n):
#!/usr/bin/python3
from typing import TextIO
try:
triangle: TextIO = open('triangle.txt')
tree = [[int(s) for s in line.split()]
for line in [line.rstrip() for line in triangle.readlines()]]
#!/usr/bin/python3
from collections import Counter
from enum import Enum
from functools import total_ordering
from typing import List, TextIO, Dict
@total_ordering
class Card:
class Triple {
public final int a;
public final int b;
public final int c;
private Triple(final int a, final int b, final int c) {
this.a = a;
this.b = b;
this.c = c;
}
enum Coin {
ONE_P(1),
TWO_P(2),
FIVE_P(5),
TEN_P(10),
TWENTY_P(20),
FIFTY_P(50),
ONE_L(100),
TWO_L(200);
public class Solution {
private Map<Integer, Integer> factorialMemo = new ConcurrentHashMap<Integer, Integer>();
private int factorial(final int n) {
final Integer f = factorialMemo.get(n);
if (f != null) {
return f;
}
if (n == 0) {
class Entry {
public final long base;
public final long exponent;
public Entry(long base, long exponent) {
// 2⁷ > 100 so we start from the sixth power
for (int e = 6; e > 1; --e) {
final double pow = Math.pow(base, 1.0 / e);
final long roundedPow = Math.round(pow);