Skip to content

Instantly share code, notes, and snippets.

View chipbell4's full-sized avatar
๐Ÿ‘Š
KAMPUTORS!

Chip Bell chipbell4

๐Ÿ‘Š
KAMPUTORS!
View GitHub Profile
@chipbell4
chipbell4 / ds.js
Created October 1, 2015 18:52
Diamond Square Algorithm Implementation
var toAsciiGrayscale = function(luminence) {
var chars = " .:-=+*#%@";
var index = Math.floor((1 - luminence) * 0.99 * chars.length);
return chars[index];
};
var printBitmap = function(bitmap) {
return bitmap.map(function(row) {
return row.map(toAsciiGrayscale).join('');
}).join('\n');
@chipbell4
chipbell4 / Notes.md
Created September 29, 2015 20:32
JS Intro Notes

Brief History (when it came it out, background)

  • 1995
  • Brenden Eich, 2 weeks etc.

Basic Constructs

  • Open Node
  • Try Basic Math (1 + 2, etc);
  • Show strings
  • Variable assignment
  • Calling methods on variables
  • Array declaration (note that you can put anything there)
@chipbell4
chipbell4 / collatz.py
Created September 29, 2015 13:00
Runs "backwards" through the Collatz algorithm, printing the numbers that appear at each step.
def potential_parents(x):
S = { 2*x }
if (x - 1) % 3 is 0:
S.add( (x-1) // 3)
return S
def grid_print(elements):
output = ''
for i in range(200):
if i in elements:
@chipbell4
chipbell4 / chuck.py
Created September 29, 2015 04:59
Chuck Norris Encoding Solution
# Calculates the run length of a sequence in string starting at startIndex
def run_length(string, startIndex):
offset = 1
while startIndex + offset < len(string) and string[startIndex + offset] == string[startIndex]:
offset += 1
return offset
def encode_binary(binary):
offset = 0
encoded = ''
@chipbell4
chipbell4 / t9.js
Created September 25, 2015 16:31
A calculator for finding the time to type a t9 text message
var keyMap = {
2: 'abc',
3: 'def',
4: 'ghi',
5: 'jkl',
6: 'mno',
7: 'pqrs',
8: 'tuv',
9: 'wxyz',
0: ' '
@chipbell4
chipbell4 / heat_detector.py
Created September 25, 2015 03:39
Heat Detector Codingame Solution
import sys
from math import floor as F, ceil as C
w, h = [int(i) for i in input().split()]
n = int(input()) # maximum number of turns before game over.
x0, y0 = [int(i) for i in input().split()]
xMin = 0
xMax = w - 1
@chipbell4
chipbell4 / trie.py
Last active September 24, 2015 14:20
An Example Trie Implementation for the Phone Number Problem
def insertIntoTrie(trie, word):
if len(word) is 0:
return trie
if word[0] not in trie:
trie[word[0]] = { }
trie[word[0]] = insertIntoTrie(trie[word[0]], word[1:])
return trie
var toothSvg = function(position, radius) {
radius = radius || 10;
return '<circle fill="black" r="' + radius + '" cx="' + position.x + '" cy="' + position.y + '" />';
};
var bite = function(biteCenter, biteAngle) {
var biteRadius = 20;
var biteAngleOffset = 40;
// convert to radius
@chipbell4
chipbell4 / template
Created March 24, 2015 00:58
Template
#!/bin/bash
# Templates a file with a given properties file
template () {
# $1 is the template file
# $2 is the properties file
# first, we convert the properties into a list of SED replacements. This regex is awful, but essentially does this:
# A line like name=chip becomes a sed command s/${name}/chip/g for replacing "variables" with a particular value
touch sed_commands.txt
@chipbell4
chipbell4 / digit.py
Created November 17, 2014 01:19
My Extra Digit Solution
def insertions(two_digit, one_digit):
two_digit_str = str(two_digit)
one_digit_str = str(one_digit)
# yield all permutations, so it "feels" like an iterable
yield one_digit_str + two_digit_str
yield two_digit_str[0] + one_digit_str + two_digit_str[1]
yield two_digit_str + one_digit_str
def printOneSolution(solution):