Created
March 16, 2014 14:41
-
-
Save zakuroishikuro/9584222 to your computer and use it in GitHub Desktop.
AAの構造を数値として保存して遊ぶ
This file contains 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
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 |
This file contains 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
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