Created
September 30, 2018 07:32
-
-
Save keithrbennett/ef3a3f194fb57e436bebedda4daafb69 to your computer and use it in GitHub Desktop.
Illustrates using built-in Ruby counter to present numbers as upper case strings including 'A' - 'Z'.
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
2.5.1 :022 > def fmt(n); n.to_s(26).chars.map { |c| (c.ord + 16).chr }.join; end | |
=> :fmt | |
2.5.1 :023 > def val(s); s.chars.map { |c| (c.ord - 16).chr }.join.to_i(26); end | |
=> :val | |
2.5.1 :024 > n = (26 * 26) + (2 * 26) + 3 # 'ABC' | |
=> 731 | |
2.5.1 :025 > fmt n | |
=> "ABC" | |
2.5.1 :026 > val 'ABC' | |
=> 731 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment