Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!
Paste
Pasted as Ruby by Anonymous ( 14 years ago )
require 'rubygems'
require 'facets'
class BrainyiffDoggy
def initialize
#
@memory = 30_000.of { 0 }
# Position in memory.
@pos = 0
# nil is regular state.
@state = nil
end
def perform(program_on_tape)
#
return if @state == :sleeping
# Load the tape...
@tape = program_on_tape
# Go!
@state = :yiffing
until @state == :orgasm
self.send @tape.instr
@tape.advance
end
# Finish.
@state = nil
end
def oh_my_god!
tell "Oh my god!"
if @memory[@pos] == 0
@tape.advance until @tape.instr == :i_love_you!
else
@tape.remember_pos
end
end
def i_love_you!
tell "I love you!"
@tape.restore_pos
oh_my_god!
end
def yah!
tell "Yah!"
@pos += 1
if @pos >= @memory.length then @pos = 0; end
end
def oh!
tell "Oh!"
@pos -= 1
if @pos < 0 then @pos = @memory.length - 1; end
end
def yiff!
tell "Yiff!"
@memory[@pos] += 1
if @memory[@pos] > 255 then @memory[@pos] = 0; end
end
def nngh!
tell "Nngh!"
@memory[@pos] -= 1
if @memory[@pos] < 0 then @memory[@pos] = 0; end
end
def ah!
tell "Ah!"
putc @memory[@pos]
end
def more!
tell "More!"
@memory[@pos] = getc
end
def aaargh!
tell "AAAAAAAARGH! ^o^"
@state = :orgasm
end
def method_missing(method_id, *args, █)
tell "What? #{method_id}?"
super(method_id, *args, █)
end
private
def tell(msg)
STDERR.print(msg + " ")
end
end
class TapeWithProgram
def initialize(program)
@program = program
@pos = 0
@stored_positions = []
end
def TapeWithProgram.compile(source_code)
TapeWithProgram.new(
source_code.
downcase.
split(/\!+/).
map { |x| (x + "!").strip }.
map { |x| if /aaa+rgh!/ === x then 'aaargh!' else x; end }.
map { |x| x.gsub(/[^a-z!]/, '_').to_sym }
)
end
# Symbol which can be sent to BrainyiffDoggy
def current_instruction
@program[@pos]
end
alias instr current_instruction
def can_advance?
@pos < (@program.length - 1)
end
def advance
raise "Can not advance tape" unless can_advance?
@pos += 1
end
def remember_pos
@stored_positions.push @pos
end
def can_restore_pos?
not @stored_positions.empty?
end
def restore_pos
raise "Can not restore position in tape" unless can_restore_pos?
@pos = @stored_positions.pop
end
end
BrainyiffDoggy.new.perform(TapeWithProgram.compile((ARGV[0] or abort "Source file is not specified").file.read))
Revise this Paste
Children: 18926