--nextPart1430604.daV680bTed
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit

Here is one of my (more) obfuscated implementations.  It's built
around 'define_method', too, but defines a method for each cell in the
data-array, representing the command in that cell.  It seems to work with
some of the examples from the Befunge-page, but it's pretty slow.



--nextPart1430604.daV680bTed
Content-Type: application/x-ruby; name="befunge3.rb"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="befunge3.rb"

IyEvdXNyL2Jpbi9lbnYgcnVieQoKIyBTaWduYWxzIHRoZSBlbmQgb2YgdGhlIHByb2dyYW0uCmNs
YXNzIEVuZFByb2dyYW0gPCBFeGNlcHRpb24KZW5kCgojIEVycm9yOiBJbnZhbGlkIEJlZnVuZ2Ut
Y29kZQpjbGFzcyBJbnZhbGlkQ29kZUVycm9yIDwgRXhjZXB0aW9uCmVuZAoKIyBUaGlzIGNsYXNz
IGNvbnRhaW5zIHNvbWUgY29tbW9uIG1ldGhvZHMgZm9yIGRlYWxpbmcgd2l0aCB0aGUgc3RhY2sK
IyBhbmQgdGhlIGNvZGUtYXJlYS4gIEZvciBlYWNoIGNlbGwsIGEgbmV3IG1ldGhvZCBpcyBkZWZp
bmVkCiMgb24tdGhlLWZseSByZXByZXNlbnRpbmcgdGhlIGNvbW1hbmQgYW5kIHRoZSBjaGFyYWN0
ZXIgaW4gdGhhdCBjZWxsLgpjbGFzcyBQcm9ncmFtCgogICAgIyBUaGlzIHRhYmxlIGNvbnRhaW5z
IHRoZSBjb2RlIHRoYXQgc2hvdWxkIGJlIGV4ZWN1dGVkIGZvciBlYWNoIGNlbGwuCiAgICAjIGZp
cnN0IHRoZSBwdXNoIGNvbW1hbmRzCiAgICBUQUJMRSA9IEhhc2hbKigwLi45KS5tYXB7fGl8IFtp
LnRvX3NbMF0sICJwdXNoICN7aX0iXX0uZmxhdHRlbl0KICAgICMgdGhlIGNvbnRyb2wgY29tbWFu
ZHMKICAgIFRBQkxFLnVwZGF0ZSh7CiAgICAgICAgPz4gPT4gJ0BkaXIgPSA6ZWFzdCcsCiAgICAg
ICAgPzwgPT4gJ0BkaXIgPSA6d2VzdCcsCiAgICAgICAgP14gPT4gJ0BkaXIgPSA6bm9ydGgnLAog
ICAgICAgID92ID0+ICdAZGlyID0gOnNvdXRoJywKICAgICAgICA/fCA9PiAnQGRpciA9IChwb3Ag
PT0gMCA/IDpzb3V0aCA6IDpub3J0aCknLAogICAgICAgID9fID0+ICdAZGlyID0gKHBvcCA9PSAw
ID8gOmVhc3QgOiA6d2VzdCknLAogICAgICAgID8/ID0+ICdAZGlyID0gWzp3ZXN0LDplYXN0LDpu
b3J0aCw6c291dGhdW3JhbmQoNCldJywKICAgICAgICA/IyA9PiAnc2VuZChAZGlyKScsCiAgICAg
ICAgPyEgPT4gJ3B1c2gocG9wID09IDAgPyAxIDogMCknLAogICAgICAgID9gID0+ICdwdXNoKHBv
cCA8IHBvcCA/IDEgOiAwKScsCiAgICAgICAgPzogPT4gJ3B1c2godG9wKScsCiAgICAgICAgP1xc
PT4gJ3kseD1wb3AscG9wOyBwdXNoIHk7IHB1c2ggeCcsCiAgICAgICAgPyQgPT4gJ3BvcCcsCiAg
ICAgICAgPy4gPT4gJ3ByaW50ICIje3BvcH0gIicsCiAgICAgICAgPywgPT4gJ3ByaW50IHBvcC5j
aHInLAogICAgICAgID9nID0+ICdwdXNoIGdldF9hdChwb3AscG9wKScsCiAgICAgICAgP3AgPT4g
J3NldF9hdChwb3AscG9wLHBvcCknLAogICAgICAgID8mID0+ICdwdXNoIFNURElOLmdldHMudG9f
aScsICMgdGhpcyBpcyBub3QgdGhlIHNhbWUgYXMgc2NhbmYgaW4gQwogICAgICAgID9+ID0+ICdw
dXNoIFNURElOLmdldGMnLAogICAgICAgID9AID0+ICdyYWlzZSBFbmRQcm9ncmFtJywKICAgICAg
ICA/IiA9PiAnQHN0cmluZ19tb2RlID0gIUBzdHJpbmdfbW9kZScsCiAgICAgICAgP1wgPT4gJycK
ICAgIH0pCiAgICAjIHRoZSBhcml0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Ag
IGZvciByb3cgaW4gMC4uLkByb3dkaW0KICAgICAgICAgICAgZm9yIGNvbCBpbiAwLi4uQGNvbGRp
bQogICAgICAgICAgICAgICAgc2V0X2F0KCByb3csIGNvbCwgbGluZXNbcm93XVtjb2xdICkKICAg
ICAgICAgICAgZW5kCiAgICAgICAgZW5kCiAgICBlbmQKCiAgICAjIEV4ZWN1dGVzIHRoZSBwcm9n
cmFtLiAgVGhpcyBtZWFucyB0aGUgbWV0aG9kIGNvcnJlc3BvbmRpbmcgdG8KICAgICMgdGhlIGN1
cnJlbnQgY2VsbCBpcyBjYWxsZWQgdW50aWwgdGhlIHByb2dyYW0gZW5kcy4KICAgIGRlZiBydW4K
ICAgICAgICBAcm93ID0gMAogICAgICAgIEBjb2wgPSAwCiAgICAgICAgQGRpciA9IDplYXN0CiAg
ICAgICAgQHN0YWNrID0gW10KICAgICAgICBAc3RyaW5nX21vZGUgPSBmYWxzZQogICAgICAgIAog
ICAgICAgIGxvb3AgZG8KICAgICAgICAgICAgY21kID0gc2VuZCggImNlbGxfI3tAcm93fV8je0Bj
b2x9IiwgOmdldCApCiAgICAgICAgICAgIAogICAgICAgICAgICAjcHV0cyAiUEMgI3tbQHJvdyxA
Y29sXS5pbnNwZWN0fSAje2NtZC5jaHJ9IgogICAgICAgICAgICAKICAgICAgICAgICAgc2VuZCgg
ImNlbGxfI3tAcm93fV8je0Bjb2x9IiwgOmV4ZWMgKQoKICAgICAgICAgICAgI3B1dHMgIlN0YWNr
OiAje0BzdGFjay5pbnNwZWN0fSIKICAgICAgICAgICAgCiAgICAgICAgICAgIHNlbmQoIEBkaXIg
KQogICAgICAgIGVuZAogICAgcmVzY3VlIEVuZFByb2dyYW0KICAgIGVuZAoKICAgICMgcHVzaCBh
biBlbGVtZW50IG9udG8gdGhlIHN0YWNrCiAgICBkZWYgcHVzaCggeCApCiAgICAgICAgQHN0YWNr
IDw8IHgudG9faQogICAgZW5kCgogICAgIyBwb3AgdGhlIHRvcC1tb3N0IGVs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GNvZGUgPSBUQUJMRVtjaF0gfHwgInJhaXNlIEludmFsaWRD
b2RlRXJyb3IiIAogICAgICAgIG5hbWUgPSAiY2VsbF8je3Jvd31fI3tjb2x9IgogICAgICAgIAog
ICAgICAgIGNsYXNzIDw8IHNlbGYKICAgICAgICAgICAgc2VsZgogICAgICAgIGVuZC5jbGFzc19l
dmFsIGRvCiAgICAgICAgICAgIGRlZmluZV9tZXRob2QobmFtZSkgZG8gfHR5cGV8CiAgICAgICAg
ICAgICAgICBpZiB0eXBlID09IDpnZXQKICAgICAgICAgICAgICAgICAgICBjaAogICAgICAgICAg
ICAgICAgZWxzaWYgQHN0cmluZ19tb2RlICYmIGNoICE9ID8iCiAgICAgICAgICAgICAgICAgICAg
cHVzaChjaCkKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICBpbnN0YW5j
ZV9ldmFsKGNvZGUpCiAgICAgICAgICAgICAgICBlbmQKICAgICAgICAgICAgZW5kCiAgICAgICAg
ZW5kCiAgICBlbmQKCiAgICAjIHJldHVybnMgdGhlIGNoYXJhY3RlciBvZiBjZWxsIChyb3csY29s
KS4KICAgIGRlZiBnZXRfYXQocm93LCBjb2wpCiAgICAgICAgc2VuZCggImNlbGxfI3tyb3d9XyN7
Y29sfSIsIDpnZXQgKQogICAgZW5kCgplbmQKCmlmIF9fRklMRV9fID09ICQwCiAgICBwID0gUHJv
Z3JhbS5uZXcKICAgIAogICAgZm5hbWUgPSBBUkdWLnNoaWZ0CiAgICBpZiBmbmFtZQogICAgICAg
IHAuY29kZSA9IEZpbGUucmVhZChmbmFtZSkKICAgIGVsc2UKICAgICAgICBwLmNvZGUgPSBTVERJ
Ti5yZWFkCiAgICBlbmQKCiAgICBwLnJ1bgogICAgcHV0cyAiIgplbmQK

--nextPart1430604.daV680bTed--