Skip to content

Instantly share code, notes, and snippets.

View melwyn95's full-sized avatar
🐫
OCaml

Melwyn Saldanha melwyn95

🐫
OCaml
View GitHub Profile
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;
@melwyn95
melwyn95 / sudoku.py
Last active September 29, 2019 23:30
Sudoku Solver
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'
@melwyn95
melwyn95 / data.js
Created June 20, 2017 01:38
gmail clone
var data = {
"inbox": [
{
"id": 1,
"sender": "a@cs.com",
"subject": "sub 1",
"body": "body 1"
},
@melwyn95
melwyn95 / fibo.bf
Last active August 26, 2019 00:04
fibo.bf
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
@melwyn95
melwyn95 / bf_interpreter.py
Created August 27, 2019 15:47
BrainFuck Interpreter in Python
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)
@melwyn95
melwyn95 / _list.md
Last active September 12, 2020 03:09
Fractals and Automatons
  1. Koch Snowflake
  2. Toothpick Pattern
  3. Ulam Warburton Cellular Automaton
  4. Hilbert's Curve
@melwyn95
melwyn95 / index.html
Last active March 8, 2020 15:10
Snake Pub Sub
<!DOCTYPE html>
<html>
<head>
<title>Snake Pub Sub</title>
</head>
<body>
<canvas id="canvas" height="500" width="500">
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;
}
}
@melwyn95
melwyn95 / flatten.js
Last active March 28, 2020 18:07
Array Flattening (Iterative Version)
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]);
@melwyn95
melwyn95 / App.js
Created May 5, 2020 12:03
Recursive Squares + Random color generator
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)})`
};