Skip to content

Instantly share code, notes, and snippets.

@robpe
robpe / shortest_path_jumps.rb
Created September 5, 2017 16:17
Shortest path in grid with tunnels and jumps
def neighbours(grid, pos)
x, y = pos
[[x-1, y], [x+1, y], [x, y-1], [x, y+1]].select do |i, j|
i > 0 && i < grid.first.size && j > 0 && j < grid.size && grid[j][i] == 0
end
end
def jump_neighbours(grid, pos)
x, y = pos
width, height = grid.first.size, grid.size
@robpe
robpe / proxy.go
Last active August 29, 2015 14:18 — forked from montanaflynn/proxy.go
package main
import (
"log"
"net/http"
"net/http/httputil"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
/* https://github.com/fay-jai/coderbyte */
function ArrayAdditionI(arr) {
var arr = arr.sort(function(a, b) { return a-b; })
max = arr.pop(),
sums = [];
(function smash(sum, arr) {
if(arr.length == 0 || sum > max ) return;
sums.push(sum)
for(var i in arr) {
@robpe
robpe / permutations.js
Last active December 19, 2015 15:48
array permutations
function ipslice(arr, l) {
var arr = arr.slice()
arr.splice(l, 1)
return arr
}
var permutations = function(arr) {
if(!arr.length) return [arr]
var perm = []
for(var i in arr) {
@robpe
robpe / goto.rb
Created July 1, 2013 16:46
Ruby goto (PoC)
module Kernel
require 'singleton'
require 'continuation'
class Env < Hash
include Singleton
def initialize
super
@robpe
robpe / sum.js
Last active December 19, 2015 00:59
short recursive sum()
function sum(a) {
return (a[0] != undefined)+0 && a[0] + sum(a.slice(1, a.length))
}