Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am chastell on github.
  • I am chastell (https://keybase.io/chastell) on keybase.
  • I have a public key whose fingerprint is B36D 8E7B DC48 18B8 6569 E98C 8BF9 827D D128 F14A

To claim this, I am signing this object:

@chastell
chastell / unindent.rb
Last active June 14, 2016 17:24 — forked from avdi/unindent.rb
TEXT = <<EOF
See, the interesting thing about this text
is that while it seems like the first line defines an indent
it's actually the last line which has the smallest indent
there are also some blank lines
both with and without extra spaces in them
and it just goes on and on
#!/usr/bin/env ruby
# encoding: UTF-8
require 'iconv'
blocks = <<end
░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░ ░░ ░░░ ░░░ ░░░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░░░ ░░░ ░░░ ░░░ ░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░ ░░░
█▀█ █▀█ █▀▀ █▀█ █▀▀ █▀▀ █▀▀ █░█ █ ░█ █░█ █░░ █▀█▀█ █▀█ █▀█ █▀█ █▀█ █▀█ █▀▀ ▀█▀ █░█ █░█ █░█░█ ▀░▀ █░█ ▀▀█ ░ █▀█ ▀█░ ▀▀█ ▀▀█ █░█ █▀▀ █▀▀ ▀▀█ █▀█ █▀█
█▀█ █▀█ █░░ █░█ █▀▀ █▀▀ █░█ █▀█ █ ░█ ██░ █░░ █░█░█ █░█ █░█ █▀▀ ▀▀█ ██▀ ▀▀█ ░█░ █░█ █░█ █░█░█ ░▀░ ▀▀█ █▀▀ ░ █░█ ░█░ █▀▀ ▀▀█ ▀▀█ ▀▀█ █▀█ ░░█ █▀█ ▀▀█
▀░▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ▀░░ ▀▀▀ ▀░▀ ▀ ▀▀ ▀░▀ ▀▀▀ ▀░▀░▀ ▀░▀ ▀▀▀ ▀░░ ░░▀ ▀░▀ ▀▀▀ ░▀░ ▀▀▀ ░▀░ ▀▀▀▀▀ ▀░▀ ░▀▀ ▀▀▀ ░ ▀▀▀ ▀▀▀ ▀▀▀ ▀▀▀ ░░▀ ▀▀▀ ▀▀▀ ░░▀ ▀▀▀ ▀▀▀

Pressman

General Information

Pressman is a two-player game played with sixteen black and sixteen white stones on a square, eight by eight board. Each player controls all of the stones of a single colour, and they take alternating turns to move their stones; the goal

class Hash
def to_html
[
'<ul>',
map { |k, v| ["<li><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></li>"] },
'</ul>'
].join
end
end
require 'benchmark'
require './integer'
require 'prime'
Benchmark.bmbm do |bench|
bench.report 'simple:' do
(2..100_000).each { |i| i.simple_prime? }
end
bench.report 'clever:' do
(2..100_000).each { |i| i.clever_prime? }
require 'ostruct'
require 'delegate'
os = OpenStruct.new
sd = SimpleDelegator.new os
os.foo # => nil
os.bar = :baz # => :baz
sd.qux # => NoMethodError
# Form all the arithmetic expressions that consist of the digits one
# through nine, in order, with a plus-sign, a times-sign, or a null
# character interpolated between each pair of digits; for instance,
# 12+34*56+7*89 is a valid expression that evaluates to 2539. What
# number is the most frequent result of evaluating all possible
# arithmetic expressions formed as described above? How many times
# does it occur? What are the expressions that evaluate to that result?
digits = ('1'..'9').to_a
opers = ['', '+', '*']
require 'benchmark'
require './integer'
require 'prime'
Benchmark.bmbm do |bench|
bench.report 'simple:' do
(2..100_000).each { |i| i.simple_prime? }
end
bench.report 'stdlib:' do
(2..100_000).each { |i| i.prime? }
words = Hash.new 0
Dir.glob("#{ARGV.first}/**/*").reject { |file| File.directory? file }.each do |file|
File.read(file).scan(/\w+/).each { |word| words[word] += 1 }
end
File.open('counts-descreasing-ruby', 'w') do |file|
file << words.sort_by { |word, count| count }.reverse.map { |word, count| "#{word}\t#{count}" }.join("\n")
end