Skip to content

Instantly share code, notes, and snippets.

View nathanburgess's full-sized avatar
🍕
Beep boop

Nathan Burgess nathanburgess

🍕
Beep boop
View GitHub Profile
def findPeak(input)
peaks = []
input.each_cons(3) do |x, y, z|
if x < y and y > z
peaks << y
end
end
if peaks.size > 1
puts "Found multiple peaks: #{peaks}"
def spiral(n)
center = n / 2
grid = Array.new(n) {Array.new(n, '██')}
grid[center][center] = "\e[34m██\e[0m"
x = center
y = center
dist = 0
dir = 4
done = false
@nathanburgess
nathanburgess / kata_12OCT2018.js
Created October 8, 2018 20:26
Check if a custom chessboard is colored in a valid configuration (i.e. no adjacent squares can have the same color)
const chalk = require('chalk')
const log = console.log
let board = process.argv[2].replace(/ /g, '').split(',')
let size = Math.sqrt(board.length)
let even = board[0]
log()
if (size % 2 !== 0) {
log(chalk`{red [ERROR]} {white You must enter an NxN sized board.}\n`)
@nathanburgess
nathanburgess / kata_05OCT18.py
Last active October 5, 2018 18:52
Tic Tac Toe with two levels of "AI" or with two human players. https://repl.it/repls/StandardOrnateSystemcall
import random
random.seed('ticTacToeKata')
mode = False
player1Turn = True
moves = [[' ' for y in range(3)] for x in range(3)]
AI_EASY = 1
AI_JOSHUA = 2
AI_NONE = 3
@nathanburgess
nathanburgess / kata_28SEP2018.js
Created September 28, 2018 16:31
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a li…
const calculateTake = (input) => {
let odds = [], evens = []
input.forEach((e, i) => {
if (i % 2 === 0)
evens.push(e)
else
odds.push(e)
})
odds = odds.reduce((i, x) => {
@nathanburgess
nathanburgess / kata_magicsquare_21SEP18.py
Last active September 21, 2018 17:06
A magic square is an NxN square grid of numbers such that all rows, columns, and diagonals all add up the the exact same sum, the magic constant. Magic constant is defined as N(N^2+1)/2
def generate(n):
# Make a 1D list of n^2 0s
square = [0 for _ in range(n * n)]
# Starting position, next position will be (col - 1, row + 1), and so forth
col = int(n / 2)
row = n - 1
value = 1
while value <= n * n:
@nathanburgess
nathanburgess / kata_07SEP2018.js
Last active September 15, 2021 14:31
Two kangaroos are on a number line and will jump in the positive direction. Figure out at which position will they run into each other, if a position exists. Program takes 4 integers as input: kangaroo 1s position and jump distance followed by kangaroo 2s position and distance.
/**
* Calculate the least common multiple of two numbers up to the power of 15
*
* @param a
* @param b
* @param pwr
* @returns {number}
*/
const lcm = (a, b, pwr = 15) => {
let as = [], bs = []
<?php
$input = " 56 65 74 100 99 68 86 180 90 ";
// Clean up the input and drop any blank values
// and assign the new weights to each key
$input = explode(' ', $input);
foreach ($input as $key => $value)
if (empty($value)) unset($input[$key]);
else $input[$key] = [
@nathanburgess
nathanburgess / serve.sh
Created April 25, 2018 17:17
A simple script for creating serving sites through nginx
#!/usr/bin/env bash
mkdir /etc/nginx/ssl 2>/dev/null
PATH_SSL="/etc/nginx/ssl"
PATH_CNF="${PATH_SSL}/${1}.cnf"
PATH_KEY="${PATH_SSL}/${1}.key"
PATH_CRT="${PATH_SSL}/${1}.crt"
# Only generate a certificate if there isn't one already there.
if [ ! -f $PATH_CNF ] || [ ! -f $PATH_KEY ] || [ ! -f $PATH_CRT ]
@nathanburgess
nathanburgess / Vagrantfile
Last active April 25, 2018 17:18
Vagrantfile Example
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "nathanburgess/thegreatvalley"
config.vm.box_check_update = true
# When I have multiple machines, the network IP hints at the ports
# IP ends with 140, and so 40 is the basis of the ports
config.vm.network :private_network, ip: "192.168.100.140"
# I use a high port range to reduce conflict chance, so the first port is going to be 10040