Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created May 15, 2010 23:23
Show Gist options
  • Save sirupsen/402498 to your computer and use it in GitHub Desktop.
Save sirupsen/402498 to your computer and use it in GitHub Desktop.
Implementation of the "BrainDamage" language.
# 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