{{ message }}

Instantly share code, notes, and snippets.

# Peter Ferenczy ggPeti

Last active Feb 20, 2018
View keybase.md

### Keybase proof

I hereby claim:

• I am ggpeti on github.
• I am ggpeti (https://keybase.io/ggpeti) on keybase.
• I have a public key ASDfM5n7IbSbHEjogUBecO6zn9XUa7BNebgxgnq5NvynvQo

To claim this, I am signing this object:

Created Oct 16, 2016
View rule.rb
 #!/usr/bin/env ruby # Wolfram cellular automaton simulator # Usage: ./rule.rb [|100] rule = 7.downto(0).map { |x| x.to_s(2).rjust(3, ?0).chars.map(&:to_i) }.zip(ARGV.shift.to_i.to_s(2).rjust(8, ?0).chars.map(&:to_i)).to_h steps = ARGV.shift&.to_i || 100 row = [0] * steps + [1] + [0] * steps steps.times { puts(row.map { |c| c == 0 ? ' ' : "\u2588" }.join)
Created Nov 17, 2013
A linear time solution for the ArrayHopper problem.
View array_hopper.rb
 numbers = File.read(ARGV.first).split.map &:to_i best_path = [0] loop do current_pos = best_path.last max_hop = numbers[current_pos] candidates = (1..max_hop).map { |hop| current_pos + hop } if candidates.empty? best_path = ["failure"]
Last active Dec 26, 2015
Procedural Ruby solution for the Spiral task
View spiral.rb
 def spiral(h, w, r, c) spiral = [] step_counts = (1..Float::INFINITY).lazy.flat_map { |n| [n, n] } directions = [:up, :left, :down, :right].cycle while spiral.length < h * w spiral << (r - 1) * w + c if r.between?(1, h) && c.between?(1, w) if (current_step_count ||= 0).zero?
Created Jun 17, 2013
Hash extension with key and value mapper methods.
View hash.rb
 class Hash def map_keys Hash[self.map { |key, value| [yield(key), value] }] end def map_keys! keys.each { |key| self[yield(key)] = delete key }
Last active Aug 29, 2015
My KOHCTPYKTOP solutions
View Level 3 - AND, OR
 eNrtmVFygzAMRLGWn5yhV+h/z9L7X6SpMbXAkmpCQmi69jDM5GnBA/FawuP7+Hb5 TJePNA63dAoppJBCCimk8EChbBHKT09PEsptwtQrTKoP2+74cv+cnM6J3zIFYB77 aW7jcP1hGk896fvXKOjIJkRQm4cntch8tmK+aW+EMGBXwBVkFgQUtX+PAwLkv/Py Hn3euIami4hmwopDy5T38RQgegArniNEX6IEzKNGNY2j/M702S4jJiUlJcUDKU7/ NGiVpKSkJ6VxPkyrJCUlPVXeCFmV6EstQppLaPHzRr+CnwvwU+SctEpSUtIOqwwo YoqgxC5fSlmAk5KSvkghHGSVIZWYrtNGnVX+uQJ8/47S9Cyg1x5zVYK7KolPf93d IyUl7aIIzNCnEtMmKW09x9oB18V/vcAD97jvYpX2sZ9aeb/1IhCuSliuPswNSEnv WoAbk3QrBTZqFylSneHHOFLbvgCEdsjC
Created Feb 1, 2015
My KOHCTPYKTOP solutions
View asdf
 eNrtmVFygzAMRLGWn5yhV+h/z9L7X6SpMbXAkmpCQmi69jDM5GnBA/FawuP7+Hb5 TJePNA63dAoppJBCCimk8EChbBHKT09PEsptwtQrTKoP2+74cv+cnM6J3zIFYB77 aW7jcP1hGk896fvXKOjIJkRQm4cntch8tmK+aW+EMGBXwBVkFgQUtX+PAwLkv/Py Hn3euIami4hmwopDy5T38RQgegArniNEX6IEzKNGNY2j/M702S4jJiUlJcUDKU7/ NGiVpKSkJ6VxPkyrJCUlPVXeCFmV6EstQppLaPHzRr+CnwvwU+SctEpSUtIOqwwo YoqgxC5fSlmAk5KSvkghHGSVIZWYrtNGnVX+uQJ8/47S9Cyg1x5zVYK7KolPf93d IyUl7aIIzNCnEtMmKW09x9oB18V/vcAD97jvYpX2sZ9aeb/1IhCuSliuPswNSEnv WoAbk3QrBTZqFylSneHHOFLbvgCEdsjC
Created Dec 19, 2014
IDEA highlight bug p-o-c
View crusher.scala
 object unapplier { def unapply(x: Int) = Some((x, x)) } val tupleTaker = (_: (Int, Int)) => () 1 match { case unapplier(tuple) => tupleTaker(tuple) }
Created Sep 3, 2014
Arrow-like proc handling in Ruby
View ext.rb
 class Object def itself self end %i[> >> * &].each { |method| define_method(method) { |*args| to_proc.send method, *args } } end
Created Jun 17, 2014
View string_balanced
 class String def balanced? gsub! /\(\)|\[\]|\{\}/, '' while \$~ empty? end end