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
defmodule AdventOfCode.Day02 do | |
@loss 0 | |
@draw 3 | |
@win 6 | |
@rock 1 | |
@paper 2 | |
@scisors 3 |
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
def cons(x,y) | |
->(m){ m.call(x, y) } | |
end | |
def car(z) | |
z.call( ->(p, q) {p} ) | |
end | |
def cdr(z) | |
z.call( ->(p, q) {q} ) |
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
require 'redis' | |
r = Redis.new | |
nodes = r.keys "zw_node:*" | |
nodes.each do |node| | |
name = r.hget node, "nodeName" | |
value = r.hget node, "v_Basic" | |
puts "Node: #{name} has value: #{value}" | |
end |
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
def neighborhood | |
n = [] | |
[-1,0,1].each {|y_adj| | |
[-1,0,1].each {|x_adj| | |
n << [@x + x_adj, @y + y_adj] | |
} | |
} | |
n.delete_at(4) | |
n |
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
require 'ostruct' | |
class Article < OpenStruct | |
def initialize(hash=nil, &blk) | |
super(hash) | |
instance_eval &blk if blk | |
end | |
def method_missing(method, *args) | |
super "#{method}=".to_sym, args |
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
def parse(name) | |
results = [] | |
tokens = name.split(/(\[[^\]]*\])/).reject{|s| s.empty? } | |
permutations = 2**tokens.count{|s| s.start_with?("[") } | |
permutations.times do |permutation| | |
result = "" | |
opt_count = 1 | |
tokens.each do |word| | |
if word.start_with?("[") | |
if (opt_count & permutation) > 0 |
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
require 'java' | |
require 'jmatharray.jar' | |
id = org.math.array.LinearAlgebra.identity(4) | |
ruby_arr = [[0.25, 0.25, 0.25, 0.25], | |
[0.25, 0.25, 0.25, 0.25], | |
[0.25, 0.25, 0.25, 0.25], | |
[0.25, 0.25, 0.25, 0.25]] |
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
(defn build [size operation] | |
(if (== size 1) (list (eval operation)) | |
(concat (list (eval operation)) (build (dec size) operation)) | |
) | |
) | |
(println (build 25 '(int (rand 2048)))) | |
(println (build 2 '(int (rand 20)))) |
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
private ArrayList<Integer> d = new ArrayList<Integer>(); | |
@Test | |
public void testSort() { | |
this.d.add(5); | |
this.d.add(10); | |
this.d.add(1); | |
Collections.sort(this.d); // -> I'm getting a type mismatch here | |
assertEquals(1, this.d.get(0).intValue()); | |
assertEquals(5, this.d.get(1).intValue()); |