Skip to content

Instantly share code, notes, and snippets.

View rvandervort's full-sized avatar

Roger Vandervort rvandervort

  • Seeking my next opportunity.
  • Pittsburgh, PA USA
View GitHub Profile
DATA: lv_test TYPE STRING.
@rvandervort
rvandervort / zipToTuples.scala
Created July 5, 2016 19:23
Scala -- given two maps with identical keys, return a map that contains the keys and tuple of values from both maps
type TheMap: Map[String, String]
// a and b really should have the same keys
// If not, entries from b will be lost.
def zipToTuples(a: TheMap, b: TheMap) =
(a.keys zip (a.values zip b.values)).toMap
@rvandervort
rvandervort / sbtmkdirs.sh
Last active August 29, 2015 14:27 — forked from alvinj/sbtmkdirs.sh
A shell script to create an SBT project directory structure
#!/bin/bash
#------------------------------------------------------------------------------
# Name: sbtmkdirs
# Purpose: Create an SBT project directory structure with a few simple options.
# Author: Alvin Alexander, http://alvinalexander.com
# Info: http://alvinalexander.com/sbtmkdirs
# License: Creative Commons Attribution-ShareAlike 2.5 Generic
# http://creativecommons.org/licenses/by-sa/2.5/
#------------------------------------------------------------------------------
@rvandervort
rvandervort / 008.scala
Created January 26, 2015 00:10
008.scala
// Answer is supposed to be : 23514624000
object Eight {
val sampleData = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729
@rvandervort
rvandervort / 48.go
Created September 1, 2014 22:47
Project Euler : 48
package main
import "math"
import "fmt"
func ret(base float64) float64 {
if base == 1 {
return 1
} else {
return ret(base - 1) + math.Pow(base, base)
@rvandervort
rvandervort / 8-puzzle.rb
Created April 1, 2013 11:50
8-puzzle solver with flexible node selection
require 'priority_queue'
require 'set'
=begin
- solve the 8 puzzle
Basically, we have to treat each "State" as a node in the graph.
Add each 'move we can make' from the current state into the frontier
but only if we haven't visited it yet.
@rvandervort
rvandervort / simple_graph_bfs.rb
Created March 15, 2013 02:10
simple bfs in ruby
class Graph
def initialize
@nodes = {}
@edges = {}
end
def add_node(key, node)
@nodes[key] = node
@edges[key] = {}
@rvandervort
rvandervort / counting_inversions.py
Last active December 12, 2015 02:08
Divide and conquer algorithm for counting array inversions
def sort_and_count(array):
if len(array) <= 1:
return 0, array
mid = len(array) / 2
left_array = array[0:mid]
right_array = array[mid:len(array)]
left_result = sort_and_count(left_array)
@rvandervort
rvandervort / index.html
Created January 16, 2013 20:28
10 x 10 battleship board in canvas
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="opponent_board" width="800" height="800"></canvas>
<script type="text/javascript">
var canvas = document.getElementById('opponent_board');
var context = canvas.getContext("2d");
@rvandervort
rvandervort / gist:3517648
Created August 29, 2012 19:32
Palindrome checker in ruby
class String
def palindrome?
is_p = true
ch = self.gsub(/ /,"").chars.to_a
compares = ch.length / 2
back_index = ch.length - 1
compares.times do |i|