```--nextPart1462683.XyMqu45Hlp
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit

Hi,

This post has not much to do with a solution of the current QUIZ, but some
ideas about extensions to the QUIZ, so feel free to stop reading (and sorry
for bothering you).

My current solution looks almost the same as the others, so it's not so
interesting.  But the QUIZ inspired me to another funny problem: Try to
generate Befunge-code automatically:

An easy observation is, that one can split up Befunge-code into some linear
pieces.  Each piece of code is then connected to up to two following pieces
(by a '|' or '_', I don't look at random-jumps here).  So the problem is
the following: given some linear pieces of codes and knowing their
connections, write a program that arranges those pieces in the 80x25 (or
whatever) lattice and add the right commands to realize the required
connections.  For example, assume a program that reads to variables and
prints the greater one.  The linear pieces are:

&:01p&:11p`     ... INPUT X,Y and TEST
01g.@           ... PRINT X
11g.@           ... PRINT Y

so you have 3 pieces, and two connection (one from the first to second and
one from the first to the third, depending on the topmost value on the
stack).

A very simple approach is to put each piece in one line, leave some lines
empty and use that empty lines to connect the pieces.  My implementation of
this approach is attached to this message.  The example above would
generate the following code (without the '#'):
###################
#v            > v #
#> &:01p&:11p`|>  #
#             >  v#
#                 #
#  01g.@        > #
#                 #
#                 #
#  11g.@         >#
###################

The attached program includes the euclidian algorithm as a second example,
i.e. the program generates a Befunge-program that reads two numbers and
computes the gcd.

I can imagine two interesting tasks:

1. write some simple high-level-language that can be compiled to linear
pieces of code with the correct connections.  Together with my example one
could create a language-to-Befunge compiler (i.e. using Befunge
as 'assembly').  The language should support conditionals (IF, THEN, ELSE)
and loops (WHILE), and perhaps, if you're really good, subroutines (the
latter would be more challenging, I think).

2. write better arrangements of the code-pieces.  In my implementation much
space is wasted.  Remember, linear pieces do not need to be in one line,
the may contain turns or jumps or whatever.  So one can ask
a. how to generate very compact code
b. how to generate code with a visually nice layout (think of a program
computing Pi whose code looks like a Pi :))
c. ...

These are just a view thoughts about extensions to the nice QUIZ.

Bye,
Frank

--nextPart1462683.XyMqu45Hlp
Content-Type: application/x-ruby; name="befc.rb"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="befc.rb"

IyEvdXNyL2Jpbi9lbnYgcnVieQoKIyBHZW5lcmF0ZXMgdGhlIGNvZGUgdG8gc2V0IG9yIGdldCB0
aGUgdmFsdWUgb2YgYSB2YXJpYWJsZXMgc3RvcmVkIGF0CiMgcG9zaXRpb24geCx5LiBUaGUgdmFy
aWFibGVzIG1heSBiZSA4IG9yIDE2LUJpdC4KIyBUaGlzIGNvZGUgZG9lcyBub3Qgd29yayB3ZWxs
IHdpdGggbmVnYXRpdmUgMTYtQml0IG51bWJlcnMuIApjbGFzcyBWYXJpYWJsZQoKICAgIGRlZiBp
bml0aWFsaXplKCB4LCB5LCBzaXplID0gMSApCiAgICAgICAgQHggPSB4CiAgICAgICAgQHkgPSB5
CiAgICAgICAgQHNpemUgPSBzaXplCiAgICAgICAgcmFpc2UgIlVuc3VwcG9ydGVkIHZhcmlhYmxl
IHNpemU6ICN7QHNpemV9IiBpZiBzaXplICE9IDEgJiYgc2l6ZSAhPSAyCiAgICBlbmQKCiAgICAj
IGdlbmVyYXRlcyB0aGUgY29kZSB0byBnZXQgdGhlIHZhcmlhYmxlJ3MgdmFsdWUgb250byB0aGUg
c3RhY2suCiAgICBkZWYgZ2V0CiAgICAgICAgY2FzZSBAc2l6ZQogICAgICAgIHdoZW4gMQogICAg
ICAgICAgICAiI3tAeH0je0B5fWciCiAgICAgICAgd2hlbiAyCiAgICAgICAgICAgICI4ODQqKjo6
I3tAeH0je0B5fWcrXFwlXFwje0B4KzF9I3tAeX1nXFwqKyIKICAgICAgICBlbmQKICAgIGVuZAoK
ICAgICMgZ2VuZXJhdGVzIHRoZSBjb2RlIHRvIHNldCB0aGUgdmFyaWFibGUncyB2YWx1ZSB0byB0
aGUgc3RhY2sncyB0b3AuCiAgICBkZWYgc2V0CiAgICAgICAgY2FzZSBAc2l6ZQogICAgICAgIHdo
ZW4gMQogICAgICAgICAgICAiI3tAeH0je0B5fXAiCiAgICAgICAgd2hlbiAyCiAgICAgICAgIC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ICAgICAgICAgICAgIGVsc2lmIGYu
Y29ubmVjdF90cnVlCiAgICAgICAgICAgICAgICAgICAgP14KICAgICAgICAgICAgICAgIGVsc2lm
IGYuY29ubmVjdF9mYWxzZQogICAgICAgICAgICAgICAgICAgID92CiAgICAgICAgICAgICAgICBl
bHNlCiAgICAgICAgICAgICAgICAgICAgP0AKICAgICAgICAgICAgICAgIGVuZAoKICAgICAgICAg
ICAgaWYgZi5jb25uZWN0X3RydWUKICAgICAgICAgICAgICAgIGRhdGFbeS0xXVt4XSA9ID8+CiAg
ICAgICAgICAgICAgICBkYXRhW3ktMV1beGRpcnN0YXJ0ICsgaW5kZXhfb2YoIGYuY29ubmVjdF90
cnVlICldID0gInYiCiAgICAgICAgICAgIGVuZAogICAgICAgICAgICAgICAgICAgIAogICAgICAg
ICAgICBpZiBmLmNvbm5lY3RfZmFsc2UKICAgICAgICAgICAgICAgIGRhdGFbeSsxXVt4XSA9ID8+
CiAgICAgICAgICAgICAgICBkYXRhW3krMV1beGRpcnN0YXJ0ICsgaW5kZXhfb2YoIGYuY29ubmVj
dF9mYWxzZSApXSA9ICJ2IgogICAgICAgICAgICBlbmQKICAgICAgICBlbmQKCiAgICAgICAgIyBy
ZWRpcmVjdCB0byB0aGUgZmlyc3QgZnJhZ21lbnQKICAgICAgICBkYXRhWzBdWzBdID0gP3YKICAg
ICAgICBkYXRhW3lvZmYgKyAxXVswXSA9ID8+CgogICAgICAgIGRhdGEuam9pbigiXG4iKQogICAg
ZW5kCgoKICAgIGRlZiBpbmRleF9vZiggZnJhZ21lbnQgKQogICAgICAgIEBmcmFnbWVudHMuaW5k
ZXgoIGZyYWdtZW50ICkKICAgIGVuZAoKZW5kCgojIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMj
IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKIyBFWEFNUExFOiBtYXgoeCx5KSAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA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