Created
May 15, 2010 23:23
-
-
Save sirupsen/402498 to your computer and use it in GitHub Desktop.
Implementation of the "BrainDamage" language.
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
# Implementation of TheLinx's BrainDamage in Ruby | |
# => http://gist.github.com/402454 | |
# | |
class BrainDamage < Array | |
SPACE = 32 | |
NEWLINE = 10 | |
def run(file) | |
file = get_file_content(file) | |
i = 0 | |
file.each_byte do |char| | |
case char | |
when SPACE then i += 1 | |
when NEWLINE then push i and i = 0 | |
end | |
end | |
pack("C*") # Teehee, ascii stuwfz | |
end | |
def get_file_content(file) | |
raise RuntimeError, "No input file specified" unless file | |
return File.read(file) if File.exist?(file) | |
raise RuntimeError, "File #{file} does not exist on the filesystem." | |
end | |
end | |
puts BrainDamage.new.run(ARGV[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment