Skip to content

Instantly share code, notes, and snippets.

# O(n) Tombolizer
class Extractor
def initialize(range)
@range, @list = range, {}
end
def extract
time = Time.now.to_i
Array.new(@range).each_with_index.map {|e,i|
token = @list[rnd = (time % (@range - i)) + 1] || rnd
@list[rnd] = @list[@range - i] || @range - i
@sandropaganotti-zz
sandropaganotti-zz / quiz-fiddle-with-regular-expressions.rb
Created September 1, 2010 20:22
[QUIZ] Fiddle with regular expressions (#2)
#= part 1
reg =
/^
[\w!#\$%&'*+\/=?`{|}~^-]+ # 1 or more glyph of: underscore alphabetic letters and symbols choosed from !#\$%&'*+\/=?`{|}~^-
# followed by
(?:\. # a non-catching block wich has to begin with a dot followed by
[\w!#\$%&'*+\/=?`{|}~^-]+ # 1 or more gliyp of the same class of line 3.
)* # this block can apper 0 or more times.
@ # followed by an 'at' sign
<html>
<head>
<title>We love shadows! A dynamic light source example created with JavaScript and CSS3</title>
<meta name="description" content="An example created by Sandro Paganotti trying to reproduce a light source effect using Javascript and CSS3" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Josefin+Sans+Std+Light' rel='stylesheet' type='text/css'>
<style>
body{
background: #575757;
p"#{$*}".scan(/./).reverse.inject([0,0]){|(a,b),m|[a+((m=10**((l=("IVXLCDM"=~/#{m}/))/2)*(5**(l%2)))<b ?m*=-1:m),m]}[0]
@sandropaganotti-zz
sandropaganotti-zz / golf_programming_sono_pazzi_questi_romani.rb
Created November 20, 2009 21:47
Golf programming: Sono Pazzi Questi Romani
p (1...3999).map{|i|l="";"M1000DM900D500CD400C100XC90L50XL40X10IX9V5IV4I1".scan(/(\D+)(\d+)/).inject(i){|a,(n,k)|k=k.to_i;while(a>=k);a-=k;l<<n;end;a};l}