Created
February 10, 2012 02:03
-
-
Save scotttam/1785473 to your computer and use it in GitHub Desktop.
Reverse split a big number
This file contains hidden or 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
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