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
module Mat | |
module_function def ch(input, &block) | |
matcher = Matcher.new | |
matcher.instance_exec(&block) | |
matcher.match(input) | |
end | |
module_function def cher(&block) | |
matcher = Matcher.new | |
matcher.instance_exec(&block) |
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
# a transversal is an array of Int32. | |
# | |
# utilities | |
# print a square | |
def p(s, depth = 0) | |
indent = " " * depth | |
s.each do |line| |
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
POSSIBLE_MOVES = [[3,4,5], [5,4,3], | |
[6,7,8], [8,7,6], | |
[7,8,9], [9,8,7], | |
[10,11,12], [12,11,10], | |
[11,12,13], [13,12,11], | |
[12,13,14], [14,13,12], | |
[0,1,3], [4,1,0], | |
[1,3,6], [6,3,1], | |
[3,6,10], [10,6,3], | |
[2,4,7], [7,4,2], |
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
$ time crystal build --release triangle_peg.cr && ./triangle_peg | |
real 0m1.518s | |
user 0m1.497s | |
sys 0m0.040s | |
Solutions for Board[011111111111111] | |
Solutions for Board[101111111111111] | |
Solutions for Board[111011111111111] | |
Solutions for Board[111101111111111] | |
Benchmark: 2.860000 0.040000 2.900000 ( 2.267569) |
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 "http/client" | |
require "json" | |
class StarWars | |
BASE_URI = "http://swapi.co/api" | |
def self.get(uri) | |
new.get(uri) | |
end |