Skip to content

Instantly share code, notes, and snippets.

@thomasbrus
thomasbrus / pattern_match_example.rb
Last active January 10, 2020 14:45
Pattern match example (Ruby 2.7)
require 'pry'
class Category
def initialize(attributes)
@id, @name = *attributes.values_at(:id, :name)
end
def valid?
errors.empty?
end
@thomasbrus
thomasbrus / ann.txt
Created October 15, 2014 18:50
Predictions of Scrabble game outcomes
=== Run information ===
Scheme:weka.classifiers.functions.MultilayerPerceptron -L 0.3 -M 0.2 -N 500 -V 0 -S 0 -E 20 -H a
Relation: scrabble-game-states
Instances: 7273
Attributes: 8
number_of_plays
first_player_current_score
second_player_current_score
current_score_difference
@thomasbrus
thomasbrus / knn.txt
Created September 30, 2014 17:20
Predictions of Scrabble game outcomes
=== Run information ===
Scheme:weka.classifiers.lazy.IBk -K 350 -W 0 -F -A "weka.core.neighboursearch.LinearNNSearch -A \"weka.core.ManhattanDistance -R first-last\""
Relation: scrabble-game-states
Instances: 7273
Attributes: 8
number_of_plays
first_player_current_score
second_player_current_score
current_score_difference
@thomasbrus
thomasbrus / least_median_of_squares.txt
Last active August 29, 2015 14:07
Predictions of final scores in Scrabble
=== Run information ===
Scheme:weka.classifiers.functions.LeastMedSq -S 4 -G 0
Relation: scrabble-game-states
Instances: 7273
Attributes: 6
number_of_moves
first_player_current_score
second_player_current_score
first_player_average_score
@thomasbrus
thomasbrus / masgn_test.rb
Last active August 29, 2015 14:01
Multiple assignment with splat operator
arr1 = [1, 2, 3, 4]
arr2 = [1, 2, 3, 4]
*a, b, c = *arr1
puts [a, b, c].inspect # => [[1, 2], 3, 4]
puts arr1.inspect # => [1, 2]
d, *e, f = *arr2
@thomasbrus
thomasbrus / cipher.txt
Last active August 29, 2015 13:57
Semi-automatic Vigenère cipher decrypter.
xsjztliyjvphmamicnwlriemsotjpsgcdtensyyllyydjwlxicnidtjonjqjvpsxnfidfvnntsjvdgedjhzsxsjppyxpwwzkevjchtvonxtxednqaqiqtvxtjatpjfpamemjxthwfgwenxfymzsxsjztliyjvphmamicmedgipsvpnrgjrejhxfrjymxjwemixjxsthhfwzwmrnrlqpjiidhvtgiogcrnsgfrmfxtxxlgiwfwznrsnwqnjejiykmqycemvpjfztowfgtkvliiwxmrlmzaeygeenweffpqedtlzbigjvemidhlprihfwwfxpwqtxeeyvtgyejhetfwfmdjhpamrjrpwitsxsjrtsiejiyylnjrezvjfronwytahnhpqcvsshsedylpamrjrpwinntsjvemmdhmamicnwhjpwprzbrmjglzwpbltqitymdjeddxzzrojvdyeyieyimxuppriyymetjejrlutpfvdysmjktsrpwwetfpzrmwilpemqiemmdjecsionxemiojwnwmaymzspphltkjcjmyiinmmqkvlgppkvpsgskscylpzrmwilpemqinntsjvntrdjufjreqcxfrjuizuppmegjxcnioystrtwjqpsxzgjfxglymzsscjrnwcaymzswnmixjwemeefvpjwdjrenewqcgnkpsicjgtulpwwzspjyssfzpylprfctopsxsjwewiylxsgisnroylpamrjrpwinntsjvwnopfpwuswdewullgiengnntsjvdnwtywlgmwnxjysdycxniqwibziyhclsewdwtxjcjufjrndeyfpjxmdnwemiawenymnjsqiinwcaymylexjwdfkpgcntyyymylxsjjcjufjrndsqhmamicyiiyppyxpwwlshpvylymylmeysemiwjxejvqwibziyhczkrzwqlqxpcxqtvtswefrnjmqusnhycwiorsdymyfgtulpwxpcxhmsdjtwfmyyiiymdnrpskwnwstr
$.each @items, (index, item) =>
listItem.click => alert(item)
(ns hypergraph.core
"A clojure library for dealing with undirected (hyper)graphs."
(:gen-class)
(:use (clojure set)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrecord Graph [vertices edges])
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def max-marbles (memoize (fn [board x y i j]
(let [tile-marbles (nth (nth board x) y)]
(cond
(and (= x i) (= y j)) tile-marbles
(= x i) (+ tile-marbles (max-marbles board x (inc y) i j))
(= y j) (+ tile-marbles (max-marbles board (inc x) y i j))
:else (+ tile-marbles (max
(max-marbles board x (inc y) i j)
(max-marbles board (inc x) y i j))))))))
boolean canRemoveEdge(HashMap<Node, List<Node>> adjacencyList, node1, node2) {
// Verwijder edge vw
adjacencyList.get(node1).remove(node2);
adjacencyList.get(node2).remove(node1);
List<Node> reachableNodes = getReachableNodes(adjacencyList, [], node1);
return reachableNodes.contains(node2);
}