- Koch Snowflake
- Toothpick Pattern
- Ulam Warburton Cellular Automaton
- Hilbert's Curve
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
import java.io.*; | |
import java.util.*; | |
public class DigitFactorialChain { | |
public static int factorial(int n) { | |
switch (n) { | |
case 0: return 1; | |
case 1: return 1; | |
case 2: return 2; | |
case 3: return 6; |
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
import time | |
#### Works #### | |
start = time.time() | |
''' Moderate Puzzle ''' # Takes about 0.641 to solve | |
puzzel = '8..4.6..7......4...1....65.5.9.3.78.....7.....48.2.1.3.52....9...1......3..9.2..5' |
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
var data = { | |
"inbox": [ | |
{ | |
"id": 1, | |
"sender": "a@cs.com", | |
"subject": "sub 1", | |
"body": "body 1" | |
}, |
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
Program to find the nth term of fibonacci sequence where n is input between 2 and 9 (inclusive) | |
, input (number between 2 and 9) | |
>>++++++[-<++++++++>]<[-<->]< subtract 48 from the 1st cell (48 is the ASCII value of zero | |
we subtract inorder to convert from ASCII to integer) | |
-- subtract 2 from the 1st cell since first 2 terms of the | |
fibonacci series is 1 and 1 | |
>+>+ initialize the 2nd and the 3rd cells to 1 (the first 2 terms |
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
valid_commands = ['>', '<', '+', '-', '[', ']', ',', '.'] | |
clean = lambda raw_script: list(filter(lambda x: x in valid_commands, raw_script)) | |
def parse_square_brackets(script): | |
stack = [] | |
brackets_map = {} | |
for index, command in enumerate(script): | |
if command == '[': | |
stack.append(index) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Snake Pub Sub</title> | |
</head> | |
<body> | |
<canvas id="canvas" height="500" width="500"> |
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
function flatten(xs) { | |
var itr = xs; | |
while (true) { | |
var ys = []; | |
var allFlat = true; | |
itr.forEach(x => !(allFlat = (!Array.isArray(x) && allFlat)) ? (ys = ys.concat(x)) : ys.push(x)); | |
if (allFlat) return ys; | |
itr = ys; | |
} | |
} |
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
function flatten(xs) { | |
var ys = []; | |
var stack = [[0, xs]]; | |
while(stack.length > 0) { | |
var [index, arr] = stack.pop(); | |
while(index < arr.length) { | |
if (Array.isArray(arr[index])) { | |
stack.push([index+1, arr]); |
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
function ColorGenerator() { | |
let index = 0; | |
const colors = ["red", "green", "blue", "yellow", "black", "white"]; | |
const rand = (s, e) => Math.random() * (e - s + 1); | |
return { | |
generate: () => colors[index++ % colors.length], | |
generateRGB: () => `rgb(${rand(0, 255)}, ${1}, ${rand(0, 255)})` | |
}; |
OlderNewer