Skip to content

Instantly share code, notes, and snippets.

@scotttam
Created February 10, 2012 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scotttam/1785473 to your computer and use it in GitHub Desktop.
Save scotttam/1785473 to your computer and use it in GitHub Desktop.
Reverse split a big number
def log(what, str, offset=0)
len = str.length
puts sprintf("| %-25s | %30s | (%-2s) |", what, str << " "*offset, len)
puts "_____________________________________________________________________"
end
def doit(match, buffer_size)
sl = match.slice(-14, 14)
log "14 of first 16", sl, buffer_size
sl = match.slice(-15, 15)
log "15 of first 16", sl, buffer_size
sl = match.slice(-16, 16)
log "16 of first 16", sl, buffer_size
end
original = "12345678901234567890123456"
log "Original", original
copy = original.dup
copy.length
for i in 0..copy.length - 16
sl = copy.slice((-16 + -i), 16)
doit(sl, i)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment