This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.8 | |
import argparse | |
import math | |
def memoize(f): | |
memo = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse | |
def sum_of_sequence(n): | |
return n * (n + 1) / 2 | |
def sum_of_squares_of_sequence(n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
NewerOlder