Skip to content

Instantly share code, notes, and snippets.

// original (ew)
class Person(val name: String, val department: String)
var people = Array(new Person(“Jones”, “Marketing”), new Person(“Smith”, “Engineering”))
var engineer: Person = null
var index = 0
while (index < people.length) {
if (people(index).department == “Engineering”) engineer = people(index) index = index + 1
}
println(engineer.name + “ is an engineer”)
@polyglotpiglet
polyglotpiglet / Dijkstra.scala
Last active January 27, 2016 19:35
Dijkstra in scala
object Dijkstra extends App {
val graph = buildExampleGraph()
shortestPath(Node[String]("car"), Node[String]("tat"), graph)
shortestPath(Node[String]("cat"), Node[String]("tar"), graph)
case class Node[T](value: T)
class Graph[T] {
private val edges = new mutable.HashMap[Node[T], Seq[Node[T]]]()
private var nodes = Seq[Node[T]]()
val input = Array(1,2,3,4,3,4,1,2,3,4,6,2)
println(evaluate(input))
def evaluate(arr: Array[Int]): Int = {
val p = peaks(arr)
var i = arr.length
while (i > 0) {
if (arr.length % i == 0
&& canSplit(arr.length, p , arr.length/i)) {
@polyglotpiglet
polyglotpiglet / Rotation.scala
Created February 25, 2016 12:51
Matrix rotation
object Rotation extends App {
val matrix = Array(Array(1,2), Array(3,4), Array(5,6))
print(matrix)
print(transpose(matrix))
print(rotate90(matrix))
print(rotateMinus90(matrix))
def transpose(matrix: Array[Array[Int]]): Array[Array[Int]] = {
[polyglotpiglet/home-office-setup]
checkout = git clone 'git@github-personal:polyglotpiglet/home-office-setup.git' 'home-office-setup'
[.config/vcsh/repo.d/vim.git]
checkout = vcsh clone 'git@github-personal:polyglotpiglet/vim.git' 'vim'
[.config/vcsh/repo.d/bashrc.git]
checkout = vcsh clone 'git@github-personal:polyglotpiglet/bashrc.git' 'bashrc'
[.config/vcsh/repo.d/git.git]
public static void main(String... args) {
int count = 0;
for (int i =0; i <1000; i++) {
long startTime = System.nanoTime();
for (int j = 0; j < 1000; j ++) {
count += j;
}
import matplotlib.pyplot as plt
ys = []
with open('output.txt') as fp:
content = fp.readlines()
for line in content:
ys.append(int(line.strip()))
public static void main(String... args) {
String curveBall = null;
int count = 0;
for (int i =0; i <1000; i++) {
long startTime = System.nanoTime();
for (int j = 0; j < 1000; j ++) {
count += j;
public static void main(String... args) throws IOException {
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("/Users/alexbate/out.txt"))));
int count = 0;
for (int i =0; i <2000; i++) {
long startTime = System.nanoTime();
for (int j = 0; j < 1000; j ++) {
count += j;
}
public static void main(String... args) {
int[] data = new int[100_000];
Random random = new Random();
for (int i = 0; i< 100_000; i++) {
data[i] = random.nextInt();
}
int max = Integer.MIN_VALUE;
for (int x : data) {
max = Math.max(max, x);