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 simple translate from a string to integer. | |
# A minus before all numbers will be consider to be a negative number. | |
def atoi(str) | |
return str if !str.is_a? String | |
fixed_str = fix(str) | |
result = 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
class Chromosome | |
attr_accessor :bit_string, :fitness | |
def initialize length, bit_string = nil | |
@length = length | |
if bit_string.nil? | |
generate_random length | |
else | |
@bit_string = bit_string |
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
#!/bin/sh | |
gem search --no-vers | parallel -j0 -I$ 'curl -O `curl https://rubygems.org/api/v1/gems/$.json | jq -r .gem_uri`' |
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
class Weazel | |
CHARS = [*'A'..'Z', ' '] | |
def initialize target | |
@target = target | |
@best = Array.new(28) { CHARS.sample }.join | |
end | |
def call | |
0.upto Float::INFINITY do |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
class Integer | |
def collatz_chain_size | |
n = self | |
chain = [] | |
until n == 1 | |
chain << n | |
n.even? ? n /= 2 : n = n * 3 + 1 | |
end | |
[chain.size, chain.first] | |
end |
NewerOlder