Skip to content

Instantly share code, notes, and snippets.

@nasser
Created December 5, 2013 21:05
Show Gist options
  • Save nasser/7813877 to your computer and use it in GitHub Desktop.
Save nasser/7813877 to your computer and use it in GitHub Desktop.
Prints out numbers who's value is the same as the length of their spelled out form in a given language.
require 'json'
require 'open-uri'
require 'numbers_in_words'
require 'numbers_in_words/duck_punch'
class Numeric
def to_words language
if language == 'en'
self.in_words
else
url = "http://translate.google.com/translate_a/t?client=t&tl=#{language}&hl=en&ie=UTF-8&oe=UTF-8&uptl=#{language}&alttl=en&q=#{URI.escape(self.in_words)}"
json = open(url).read.gsub /,+/, "," # wtf google
JSON.parse(json).first.first.first
end
end
end
language = ARGV.first
100.times { |i| words = i.to_words language; puts words if words.length == i }
@nasser
Copy link
Author

nasser commented Dec 5, 2013

$ gem install numbers_in_words
$ ruby towords.rb en
four
$ ruby towords.rb es
cinco
$ ruby towords.rb hr
tri

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment