This file contains hidden or 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
| 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}" |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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`) |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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) => { |
This file contains hidden or 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
| 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: |
This file contains hidden or 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
| /** | |
| * 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 = [] |
This file contains hidden or 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
| <?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] = [ |
This file contains hidden or 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/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 ] |
This file contains hidden or 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
| # -*- 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 |
NewerOlder