Skip to content

Instantly share code, notes, and snippets.

View radarek's full-sized avatar

Radosław Bułat radarek

View GitHub Profile

Solution (code golf) to the "Coat of Many Colours" challenge

Challenge: Coat of Many Colours

Note Do not copy the solver code directly fron the website. It contains binary data (unprintable characters), thus copying and pasting will probably corrupt data. Use generator (see belo) or download solver to the disk and then run.

Usage

Generating solver:

require 'benchmark'
N = 1_000_000
def dowork
N.times do
a = "1"
end
end
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
sudo apt-get update
sudo apt-get install sublime-text
class Hello {
public static String helloString = "Hello World!";
public static void main(String[] args) {
System.out.println(helloString);
foo();
}
public static void foo() {
System.out.println("Foo called");
@radarek
radarek / how_many_nodes.rb
Created December 29, 2015 14:33
Veryfing "Table 1—Number of additional T_NODE objects created by an iterator" from "Ruby Performance Optimization" book
def count_nodes(label)
before = ObjectSpace.count_objects
yield
after = ObjectSpace.count_objects
puts " #{label} created T_NODE: %d" % (after[:T_NODE] - before[:T_NODE])
end
class MyClass
include Enumerable
defmodule ExUnit.Lets do
defmacro __using__([]) do
quote do
import ExUnit.Lets
end
end
defmacro let(name, expr) do
if match?([do: _], expr) do
expr = expr[:do]
@radarek
radarek / solver_spec.rb
Created July 4, 2014 16:51
[spoj] JLITOSL 1310. Liczba na słowo - specs
require "spec_helper"
describe Solver do
let(:solver) { subject }
describe "#number_to_words" do
it "converts given number to its words representation" do
expect(solver.number_to_words(0)).to eq "zero"
expect(solver.number_to_words(1)).to eq "jeden"
expect(solver.number_to_words(2)).to eq "dwa"
class Bob
def hey(message)
if empty?(message)
"Fine. Be that way!"
elsif yelling?(message)
"Woah, chill out!"
elsif question?(message)
"Sure."
else
"Whatever."