Skip to content

Instantly share code, notes, and snippets.

@simonszu
Created June 16, 2015 17:35
Show Gist options
  • Save simonszu/5750cc349f4412792daa to your computer and use it in GitHub Desktop.
Save simonszu/5750cc349f4412792daa to your computer and use it in GitHub Desktop.
Converts the numbers from 1 to 10k to german words, and sorts them alphabetically
#! /usr/bin/env ruby
# Encoding: utf-8
output = Array.new
10000.times do |zahl|
zahl = zahl+1
array = zahl.to_s.scan(/./)
string = ""
if array.length == 1
einer = array[0]
elsif array.length == 2
zehner = array[0]
einer = array[1]
elsif array.length == 3
hunderter = array[0]
zehner = array[1]
einer = array[2]
elsif array.length == 4
tausender = array[0]
hunderter = array[1]
zehner = array[2]
einer = array[3]
elsif array.length == 5
string = "zehntausend"
end
if string.eql? ""
unless tausender.nil?
case tausender
when "1"
string = string+"eintausend"
when "2"
string = string+"zweitausend"
when "3"
string = string+"dreitausend"
when "4"
string = string+"viertausend"
when "5"
string = string+"fünftausend"
when "6"
string = string+"sechstausend"
when "7"
string = string+"siebentausend"
when "8"
string = string+"achttausend"
when "9"
string = string+"neuntausend"
end
end
unless hunderter.nil?
case hunderter
when "1"
string = string+"einhundert"
when "2"
string = string+"zweihundert"
when "3"
string = string+"dreihundert"
when "4"
string = string+"vierhundert"
when "5"
string = string+"fünfhundert"
when "6"
string = string+"sechshundert"
when "7"
string = string+"siebenhundert"
when "8"
string = string+"achthundert"
when "9"
string = string+"neunhundert"
end
end
unless einer.nil?
if (!zehner.nil? && zehner == "1")
if einer.eql? "1"
string = string+"elf"
elsif einer.eql? "2"
string = string+"zwölf"
end
elsif (!zehner.nil? && einer == "1")
string = string+"ein"
else
case einer
when "1"
string = string+"eins"
when "2"
string = string+"zwei"
when "3"
string = string+"drei"
when "4"
string = string+"vier"
when "5"
string = string+"fünf"
when "6"
string = string+"sechs"
when "7"
string = string+"sieben"
when "8"
string = string+"acht"
when "9"
string = string+"neun"
end
end
end
unless zehner.nil?
if (!einer == "" && (einer == "1" || einer == "2") && zehner == "1")
string = string + ""
else
case zehner
when "1"
string = string+"zehn"
when "2"
string = string+"undzwanzig"
when "3"
string = string+"unddreißig"
when "4"
string = string+"undvierzig"
when "5"
string = string+"undfünfzig"
when "6"
string = string+"undsechzig"
when "7"
string = string+"undsiebzig"
when "8"
string = string+"undachtzig"
when "9"
string = string+"undneunzig"
end
end
end
end
output.push(string)
end
output.sort!
output.each do |word|
puts word
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment