Skip to content

Instantly share code, notes, and snippets.

View ConnorBaker's full-sized avatar
⚱️
burnt out

Connor Baker ConnorBaker

⚱️
burnt out
  • Costa Mesa, CA
  • 00:05 (UTC -07:00)
View GitHub Profile
import Data.Maybe
fizzBuzzList :: Int -> Maybe String
fizzBuzzList n = list !! index where
list = [ Just "fizzbuzz"
, Nothing
, Nothing
, Just "fizz"
, Nothing
, Just "buzz"
@ConnorBaker
ConnorBaker / main.c
Created October 6, 2019 02:00
Cute collatz program. The header file contains only function prototypes (so that our global variable is able to deduce the function types at compile-time).
#include "./main.h"
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
static uint64_t (*steps[2])(uint64_t) = {&collatz_even_step, &collatz_odd_step};
uint64_t collatz_even_step(uint64_t n) { return n >> 1u; }
uint64_t collatz_odd_step(uint64_t n) { return 3u * n + 1u; }
@ConnorBaker
ConnorBaker / README.md
Created September 5, 2019 00:35
Possible Articles
@ConnorBaker
ConnorBaker / histogram.c
Created August 18, 2019 04:26
For a 6.7GB file, takes 2.2s. Compiled with clang -Ofast -Wall -Weverything -pedantic -std=c11 -fopenmp -flto=thin main.c.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <stdint.h>
#define BUFF_SIZE 1024*1024*16
#define UCHAR_MAX 255
int main(void) {
FILE *f = fopen("/home/connorbaker/storage/large_test_file-02", "r");
@ConnorBaker
ConnorBaker / BarChartOfOccurrences.java
Created August 17, 2019 20:24
Turns an ASCII file into a histogram.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.stage.Stage;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Map;
import java.util.function.Function;
time parallel --jobs 8 mawk -v "N={}" -f euclidsAlgo.awk ::: (seq 1 10000) | mawk -f removeGCD.awk | gsort -t "," -V | uniq | wc -l
myalgo
BEGIN{
for (i = 0; i < N; i++) {
printf "%d,%d,%d\n", sideA(N, i), sideB(N, i), sideC(N, i);
}
}
function sideA(m, n) {
@ConnorBaker
ConnorBaker / wrapper.sh
Created July 6, 2019 16:21
Computes the orbit of a number in (0,1] in a base in (1,\infty). Requires GNU awk
if [ $# -ne 4 ]; then
echo "Usage: bash wrapper.sh <precision> <number of iterations> <number to find orbit of> <base>"
exit 1
fi
gawk -M -v "PREC=$1" -v "ITER=$2" -v "NUM=$3" -v "BASE=$4" \
'BEGIN{
r = NUM;
pair[0] = 0.0;
pair[1] = 0.0;
@ConnorBaker
ConnorBaker / 7-10.hs
Created March 21, 2019 16:49
Programming in Haskell, 2nd ed.: Chapter 7: Problem 10
luhnDouble :: Int -> Int
luhnDouble n
| n <= 5 = 2 * n
| otherwise = 2 * n - 9
luhn :: [Int] -> Bool
luhn [] = False
luhn ns = mod (sum $ altMap luhnDouble id ns) 10 == 0
@ConnorBaker
ConnorBaker / 7-9.hs
Created March 21, 2019 16:48
Programming in Haskell, 2nd ed.: Chapter 7: Problem 9
altMap :: (a -> b) -> (a -> b) -> [a] -> [b]
altMap _ _ [] = []
altMap f g (x:xs) = f x : altMap g f xs
@ConnorBaker
ConnorBaker / 7-8.hs
Created March 21, 2019 16:48
Programming in Haskell, 2nd ed.: Chapter 7: Problem 8
channelNoisy :: [Bit] -> [Bit]
channelNoisy = tail
transmitNoisy :: String -> String
transmitNoisy = decodeWithParityBit
. channelNoisy
. encodeWithParityBit