flat assembler
Message board for the users of flat assembler.

flat assembler > Heap > Esoteric Programming Challenges!

Goto page Previous  1, 2, 3 ... , 10, 11, 12  Next
Author
Thread Post new topic Reply to topic
Pinecone_



Joined: 28 Apr 2008
Posts: 180
rugxulo wrote:
Lame idea: name your Befunge knockoff "SeaSponge".
Reminds me too much of sponge bob square pants Razz I'm thinking winfunge or winfungus or something similar because i also plan on letting it call the windows api. Still need to think of an easy way to handle that with single character instructions as much as possible... and i dont really want to just add funge to win or something because there's quite a few differences in the languages so far... but then it is clearly based on funge langues so i dont want to loose it entirely... here's what i've written of the planned specifications so far...
Code:
should be a way to distinguish between a console mode script and a GUI script.. haven't figured out how i'm going to do that yet.

uppercase letters and digits are registers.
the following registers have special meaning:
    X = the instruction pointer's current X position
    Y = the instruction pointer's current Y position
    S = the number of items currently on the stack... read only
    R = random number... read only
    0 through 9 are read only and hold their value. eg register 3 holds value 3.

Note: commands can be mapped or remapped to other commands or registers but the default registers (A-Z 0-9) cannot be remapped.
writing to a read only register is effectively the same as executing $

When executed, a register (or command mapped to a register) pushes it's value.

any value < 255 and > 0 other than registers can be a command (see r command) if it is not mapped as a command it performs no operation.

> sets execution direction to the right
< sets execution direction to the left
v sets execution direction downward
^ sets execution direction upwards
] rotates execution direction 90 degrees to the right
[ rotates execution direction 90 degrees to the left
+ push(pop+pop)
- push(pop-pop)
* push(pop*pop)
/ push(pop/pop)
% push remainder of (pop/pop)
` push 1 if(pop > pop) else push 0
! push 1 if(pop = 0) else push 0
@ terminate program
# trampoline - same as befunge
$ pop value off stack and disregard it
& if console mode ask user for number and push it (shows it on screen as they enter it)
~ if console mode ask user for a single character and push it (does not print it to screen)
. if console mode pop value off stack and output as an integer
, if console mode pop value off stack and output as ascii character
" sets stringmode - same as befunge.
' pushes the value of the next cell to the stack. e.g. 'A will push value 65 to the stack.
: duplicate value on top of stack
{ rotate top 3 values on stack left... pop x then y then z... push y then z then x
} rotate top 3 values on stack right... pop x then y then z.. push z then x then y
\ swap top 2 values on the stack.
i pushes an integer value to the stack. e.g. i370 will push the value 370 to the stack. register remapping should not effect this command - it requires characters 0-9.
= sets register values.. reigster is defined as next instruction. sets it to a value poped off the stack. e.g. i350=A will set register A to 350.. and B=A will set register A to the value of register B.
r remaps commands... pops x then y... remaps command x to y e.g. "xr"r remaps command r to x. if x and y are both commands their mapping is switched.
g pop x then y, then push value at location x,y
p pop x then y then v, put value v at location x,y
| vertical if.. pop value off stack.. if it's 1 go down, otherwise go up
_ horizontal if.. pop value off stack.. if it's 1 go right, otherwise go left
; start comment mode: every character is moved over but ignored until another ; is met.


execution plane is limited in size to the maximum dimensions used in loaded file in each direction.
eg if a file is loaded with  32 lines in it and the longest line is 56 characters long the execution plane will be 56 across by 32 down
if execution goes over the boundries it is wrapped back to the starting size.    


Yay 11'th page in this thread Smile
Post 15 Sep 2009, 10:15
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Man, I'm completely stuck trying to do challenge 7 in brainfuck... I can't figure out how to read a number and convert it to a number that i can do multiplication with...
Post 17 Sep 2009, 04:20
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
Read in a character, check if in number range. If not, check if enter was pressed, and continue to end if it was. If it was number, subtract 48 then add it to a number buffer and multiply that by 10. When enter has been pressed you multiply the buffer by 2 and, umm....hmmm...how would you do remainders in brainfuck? Ok, I'm stumped too.

_________________
----> * <---- My star, won HERE
Post 17 Sep 2009, 04:40
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
I've got all that theory... but i dont know how to do the if part to check if they hit enter...

and to do remainders, repeatedly divide until only a remainder is left

Edit: I've got the if part now.. just have to convert it back to ascii and print it in reverse.

Edit#2: Hmmmm..... dividing...... I'm stuck again Razz The only thing i can think of will give me an infinite loop if it's not a multiple of 10... and there goes my "repeated divide until only a remainder is left" idea Razz

Edit#3: Well here's what I've got so far. not optimised at all, just trying to get it working... maybe someone can work off it...
Code:
+                              Increase to allow to enter loop
[                              Enter loop
  ->,                            Reset re loop variable (Cell 0) and read input to cell 1
  ----- -----                    Subtract 10 from cell 1
  [                              If Cell 1 != 0 (aka the user did not enter return)
    >[>+<-]>[<++++++++++>-]<<      Multiply current value by 10
    <++++[>----------<-]>++        Subtract 38 from read character
    [>+<-]                         add read value to current value
    <+>                            Set loop variable to loop again
  ]                              End IF
  <                              Go back to loop variable
]                              If Loop variable is set: loop to read another character

>>[<++>-]<                     Multiply the value that was read by 2    
Notes:
  • will not work with values > 127 because brainfuck data cells are only 1 byte in size....added that note to challenge description
  • will enter infinite loop if EOF or CR is given instead of LF (unless LF is provided later, in which case the number will be read wrong)
  • does not check if a character is a number.. assumes it is
  • Negative numbers will not work


Comments removed:
Code:
+[->,----------[>[>+<-]>[<++++++++++>-]<<<++++[>----------<-]>++[>+<-]<+>]<],>>[<++>-]<    


Edit#4: added comments to that code

Edit#5: To sum up the problem: We need to divide x by 10 using only addition and subtraction operators in a loop which can only check if something equals zero as a condition...
Post 17 Sep 2009, 04:49
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
Alright, finally back in town, so I can play again (more comfortable on my own cpu).

Okay, it's not one of the challenges, but I thought it was interesting, so I hacked together DUAL.C:

Code:
char a[]="v";int b=43;char c[]="<";int d=33;char e[]="v";int f=30;int ppp;
   void main() {
        printf(
     "Hello, world!"
        );
   }
/*  > ,,,,,,,,,,,,, @    */
    


Last edited by rugxulo on 23 Sep 2009, 21:47; edited 1 time in total
Post 20 Sep 2009, 21:50
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
rugxulo wrote:
Also Ryan Kusnery's tiny BEFI.COM DOS interpreter fails unless you remove the first comment line (EDIT: chokes on "=") and put 0 at the end of the next line.


As we all know, Pinecone_'s (EDIT: old/original) interpreter only runs under Windows (and uses MSVCRT), so my DOS bias decided to look for various other DOS-compatible interpreters. The one mentioned above is very small (1280 bytes unpacked) and seems to work, but it was TASM. I spent a few hours looking over it, and it seems I now know why I had such trouble converting it to FASM (basically some tricky stuff: self-modifying code, TASM-specific opcode needed, "befungecode:" needed to be specifically aligned, etc). Long story short, I've finished, and ironically now the damn original link is broken, so all the more reason to post it here. Very Happy

P.S. Feel free to tweak it further, esp. for smaller size. I'll probably mess with it later to do so, but for now it's good enough (reached my goal of < 1024 bytes, even if I had to use aPACK to do it).

Quote:

- now 1023 bytes (aPACK'd)
- cleaned up code, now easy to convert to NASM/YASM
- finally fixed (?) stack underflow won't-pop-0 bug
- fixed "interpreter" reserved word clash (FASM 1.69.05)
- converted to FASM, deleted buggy '=' check, added fopen fail check/exit


EDIT: Seems to crash DOSEMU 1.4.0 under XUbuntu x86-64 although DOSBox 0.73 on Vista (and also DOSEMU on 32-bit Linux) handles it fine.

FINAL EDIT: Deleted obsolete attachment, see post far below for newer (smaller) version.


Last edited by rugxulo on 23 Oct 2009, 07:11; edited 7 times in total
Post 23 Sep 2009, 21:46
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
Sorry, still no attempts by me at other challenges, maybe I should get crackin'. Laughing

Anyways, I found some Ruby Befunge interpreters (some briefly tested with DJGPP-compiled 1.8.7) and a cool example:

Code:
v > v"Enter year."0<       Computes the day of the week
>#,#:              ^       from the year, month and date.
  ^ _25*,$">",&0".htn"v    By Joshua Belsky (jjbelsky@yahoo.com)
v"Enter"<>v"Enter mo" <    February 4, 2000  (Runs under Befunge-93)
> >v>5*v ,:>25*,">",$&v                    
  ,:2  , ^_^v"date."0 <                     
  ^_^v <^" "<                               
v,">"<                                      
>$&93*6p93*7p72*93*7g-v                      > >v
v44-g*25*39p*25*39/*26<                        ,:
>*55**52*9*+7+*44*55**v                        ^_".yad",,,,25*,@
v26g7*39+1*2*53+g6*39/<                             
>*93*52*g*+2-*26*/+7%0v                     
v"at date falls on a "<                       
">  >v      >v    >v    >v    >v    >v    >v ^       <
h   ,: >:5`!|>:4`!|>:3`!|>:2`!|>:1`!|>:0`!|>0"nuS"   ^
T   ^_$^    >                               0"rutaS" ^
"                 >                         0"irF"   ^
>^                      >                   0"sruhT" ^
                              >             0"sendeW"^
                                    >       0"seuT"  ^
                                          > 0"noM"   ^
    
Post 27 Sep 2009, 01:50
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
BTW, http://shinh.skr.jp/obf/ has some really cool stuff, including:


  • polyglot quine in C, Ruby, Python, Perl, Brainf***
  • polyglot quine in C, Ruby, Python, Perl
  • polyglot hello in Perl / Ruby / Python / C++ / Brainf*** / Befunge
  • polyglot in Brainf*** & Whitespace & Befunge & ELF binary
  • polyglot in C & Brainf*** & Whitespace (also is C interpreter for Brainf*** and Whitespace !!)
  • Linux ELF Brainf*** compiler in sed
  • cal in Brainf***


And it even links to the famous (10th anniversary update, added Perl, fixed machine code for Win32) "polyglot in 8 languages":

  • COBOL (ANSI)
  • Pascal (ISO)
  • Fortran (ANSI, f77)
  • C (ANSI-ish)
  • PostScript
  • Linux/Unix shell script (bash, sh, csh)
  • x86 machine language (MS-DOS, Win32)
  • Perl (version 5)


Very Happy Laughing Cool
Post 28 Sep 2009, 22:29
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
Apparently ETA is a cool language too, so I took a gander at seeing if I could write something nifty. I like languages (even though I mostly suck at 'em), and the Esperanto saluton.eta was pretty funny, so I thought I'd "translate" the good ol' Pater Noster. Wink Okay, so it's pretty lame, and it sounds more like broken Old English or 1337 speak or whatever, but hey, it prints a string! (Better than nothing. Hey, I'm new to it all, heh.)

N.B. mtve's ETA interpreter in Befunge is very picky about which interpreters it works in (apparently none besides official!), just a friendly warning.

Code:
My nuw Abba of cluwd zkye
Nawz luv ur awzum nume
Nuw pluz ladaz your well du fur uz
Nudurlly all uz hope fur brud frum u
Und to furgive uddur dudz fur u
O God boo off zkury dudgum uvul frum uz
    


EDIT: I changed it to not use any numbers, esp. so I can post one that does (easier to read? harder??). Oh, and the "GNU telnet" is a way to officially end the program (not that it majorly matters).

Code:
My n3w Abba of cl0wd 5kye
N0w all l0v3 ur aw3z0m3 n4me
N0w pluz la73r alw4yz your well d0 f0r uz
N47ur4lly all uz hope f0r br34d fr0m y0u
4nd to f0rgive 0dd3r dud3z f0r y0u
O God boo7 off 5c4ry d4dgum 3v1l fr0m uz

(fr0m GNU telnet)
    


P.S. Wrote a silly to/from base7 converter in Ruby if anybody wants it. Wink


Last edited by rugxulo on 23 Oct 2009, 07:14; edited 1 time in total
Post 29 Sep 2009, 08:43
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
BTW, one of the fastest Brainf*** interpreters is allegedly BFF4 (written in C), if anyone's curious.
Post 04 Oct 2009, 14:34
View user's profile Send private message Visit poster's website Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
I've been a little inactive lately, because I was working on a rewrite for my befunge interpreter. I think it no longer has any bugs (although chess still does not work Sad)

I've also been working on a javascript befunge debugger because I was sick of mixing my interpreter with buggy beQunge to debug and thought a simple bugless debugger was needed Smile

My javascript befunge debugger can be found here.

It's not complete yet, mainly because I'm not sure how to solve two problems:
  • Copy + paste browser security issues - Firefox doesn't let javascript access the clipboard anymore. If anyone has suggestions for other methods I could use to load a script from the user, please discuss them here Smile

  • The stack view is horrible currently. I don't know why but when i put a new line (<br/>) between items it slowed the debugger down to an unacceptable level. Again please discuss any ideas you have for solutions.


I've not yet tested it in anything other than Firefox on Windows XP. I'm dreading the pain that ill be facing when I try to make it compatible with IE.

Any comments, suggestions, improvements, bug reports, bugfixes, etc are all welcomed Smile

Also note: I've tried to make the output section act as much like a real console as I can, but haven't tested it extensively yet.

Edit: It's not quite what I had planned, but i added a load button which shows a textarea to input a script to load.. still hoping for better sugestions Smile
Post 12 Oct 2009, 00:52
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
@Pinecone_

For the BR tag slow down use the PRE tag for your Stack and your replace(/,/g, '\n')

For Paste you can have a TEXTAREA for the user to paste into, then parse the text to your formatted grid.

For Copy you can use the DesignMode attribute. Here's a hack I found on google http://www.infogears.com/cgi-bin/infogears/javascript_clipboard_for_cut_copy_paste.html

You could also do a File Upload / Download and use an Open / Save instead of Copy / Paste. Although you'd need a back-end web language.

FireFox makes you jump through security hoops for clipboard access which is a good thing (just annoying for developers).
Post 13 Oct 2009, 18:17
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Great tips, thanks Smile

r22 wrote:
FireFox makes you jump through security hoops for clipboard access which is a good thing (just annoying for developers).
Makes me wonder what the point of having the security features is when there are just other ways around it.... even if they're a little annoying, it can still be done (or so that article says, haven't tried it yet) so what's the point in not allowing the "normal" methods?
Post 14 Oct 2009, 06:05
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
Okay, it's lame, but I wrote a few more dumb examples:

Code:
APATHY PREVAILS UNTIL NOOBS CONVERT DIGITS TO ETA LETTERS
IN SUSE 1S ( 0NE GNOME F0SS ) A V3RY UNTRUE HUT
NAH, SEX OFF GNU TELNET
UNPAY ALL PIEZ FOR UNPUT BEND GET
PUNTS W1SE OW NUT ELM UNGLUE 1T
GNATS EBB OR NUB TELL NY METZ
FUN WAY THE OF W1NTEL NETW0RK
N00BZ AT W1ND0WZ BE WOW GN0ME W4TER L1NEZ T0D0
NAP A BOX BE DO N0W 0R L4TER L1NK ME T0 A PATCH
    


Code:
digit to ETA converter

0h  1t  2a 3o  4i  5n  6s
104 116 97 111 105 110 115

>++++++++++[>++++++++++>++++++++++>++++++++++>++++++++++>++++++++++>
++++++++++>++++++++++<<<<<<<-]>++++>++++++++++++++++>--->+++++++++++>
+++++>++++++++++>+++++++++++++++<<<<<<<,-----------------------------
-------------------[>[-]<[->+<]>-]>.
    


Code:
char a[]="v";int b=43;char c[]="<";int d=33;char e[]="v";int f=30;int ppp;
   void main() {
        printf(
     "Is this string long enough for you??? Hi, Pinecone_!"
        ); }
/*  v       <
    > :!#@_,^  */
    


EDIT: Updated and fixed the "befi.com" interpreter (see below).


Last edited by rugxulo on 24 Oct 2009, 17:44; edited 2 times in total
Post 15 Oct 2009, 00:45
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
BTW, where is everyone? Too busy? Bah. (windwakr got a new cpu, I know. Guess he's busy recovering everything.)

I updated the BEFI.COM program again (though the original site is still down, wtf??). Nothing major, just some code cleanups, can assemble with NASM/YASM now too. And it's still a noticeable bit faster (and smaller, of course) than the C interpreter (although I don't claim it's 100% bug free, e.g. I doubt chess works, even non-GCC compiles of the C version don't handle chess, e.g. CC386 or OpenWatcom).

Also, I'm a little disappointed that Japheth hasn't responded to my HX bug query (re: Pinecone_'s new Win32 .EXE), but then again, he's always really busy with all his million projects (e.g. JWasm).

If ATV were around, I'd bet he could shrink it to < 1024 without needing aPACK (shouldn't be too hard, only 200 bytes or so, heh). I might take a closer look later on.

I also wonder if an Octasm source version would be smaller and easier to read (although my first attempt wasn't so great, but I'll try again later).
Post 20 Oct 2009, 06:56
View user's profile Send private message Visit poster's website Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
Location: Michigan, USA
I lost interest in befunge and brainfuck for now. I do this with everything.
Post 20 Oct 2009, 14:10
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
Well, that's okay, it's to be expected. Nobody keeps interest up all the time.

However, I did get EsCo to compile with DJGPP (after some trickery), which is cool since it supports seven different esolangs. Very Happy
Post 20 Oct 2009, 23:49
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
rugxulo wrote:

If ATV were around, I'd bet he could shrink it to < 1024 without needing aPACK (shouldn't be too hard, only 200 bytes or so, heh). I might take a closer look later on.

I also wonder if an Octasm source version would be smaller and easier to read (although my first attempt wasn't so great, but I'll try again later).


Haven't really done a "true" Octasm conversion yet (using its HLL-ish shortcuts), but it does assemble at least. My ideas (not necessarily realistic) are:


  • shrink to <= 1024 bytes without aPACK (1154 currently, 1004 packed)
  • alternate version: additionally convert to more Octasm-y syntax (multiple statements on one line etc., hopefully shorter or more readable)
  • add use of LFN-to-SFN func for more convenience


So that is, in order, very hard, medium, and easy difficulty. Laughing
Post 21 Oct 2009, 13:33
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
rugxulo wrote:

shrink to <= 1024 bytes without aPACK (1154 currently, 1004 packed)

... very hard


Worked on it some more, but I won't post it just yet (unless somebody requests it). Obviously haven't gotten to 1024 (is it even possible??), currently at 1102 bytes unpacked (using Octasm for fun). So that's good at least (but shaving 78 more bytes will be tough).

P.S. Two more lame Befunge examples: Cool

Code:
"?",&>"?",~v
           >:"+"-#v_$1+       v
     ^            >:"-"-#v_$1->:"  ",,.
                         >:"@"-#v_@
     ^                  $<      <
    


Not exactly the simple arithmetic calculator I envisioned, but it's funny at least. And it shows how different Befunge interpreters handle input quite differently.(Enter a number, then press "+" to add or "-" to subtract or "@" to quit.)

Code:
<v"Hello, world!"   ?<
     >               ?@
>>:!#^ #, #+ #1 #9_,
^"Saluton, mondo!"  <
    


Prints a random message (out of two) 1-? times. No hardcoded string lengths, \n automatically printed at end, easy to change strings.
Post 22 Oct 2009, 13:48
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2335
Location: Usono (aka, USA)
rugxulo wrote:

shrink to <= 1024 bytes without aPACK ... very hard


Okay, so I'm releasing BEFI_2D.ZIP now since I'd rather do that than keep everything in suspense. Currently 1077 bytes (or 1016 aPACK'd). I kept the previous source in there for comparison (and even the original TASM src + .COM [1280 bytes or 1082 aPACK'd !!] for ultra clarity). I may still work on it further, though. Cool Too bad nobody cares. Laughing

EDIT: Removed old attachment, added new one, see next page. Cool


Last edited by rugxulo on 24 Oct 2009, 17:46; edited 1 time in total
Post 23 Oct 2009, 07:09
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3 ... , 10, 11, 12  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.