Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Created March 16, 2014 14:41
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 zakuroishikuro/9584222 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/9584222 to your computer and use it in GitHub Desktop.
AAの構造を数値として保存して遊ぶ
module AAUtils
def get_chars(aa)
aa.chars.uniq.sort.join
end
def to_num(aa, chars)
aa.tr(chars, "0-9a-z").to_i(chars.size)
end
def to_aa(num, chars)
num.to_s(chars.size).tr("0-9a-z", chars)
end
end
require_relative 'aautils.rb'
include AAUtils
aa = <<AA
@@@@ @ @ @@@@ @ @
@ @ @ @ @ @ @ @
@@@@ @ @ @@@@ @@@
@ @ @ @ @ @ @
@ @ @@@ @@@@ @
AA
chars = get_chars(aa)
#=> "\n @"
num = to_num(aa, chars)
#=> 105473034664962489775046190356208086050182701341217319175540905
puts aa = to_aa(num, chars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment