Jeph Jacques's comics discussion forums

  • 05 Dec 2021, 00:38
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: A programming challenge (j/k)  (Read 1612 times)

pwhodges

  • Admin emeritus
  • Awakened
  • *
  • Offline Offline
  • Posts: 16,934
  • I'll only say this once...
    • My home page
A programming challenge (j/k)
« on: 07 Jan 2014, 14:58 »

Malbolge is a programming language designed to be impossible to write a program in.  It failed in this aim, because after a mere two years, someone managed to produce a meaningful program (not manually, even then); it took seven years, however, before a "99 bottles of beer" program was managed (and it's not actually a loop, but just lists the output required). 

The Malbolge machine is ternary, just to get you started, and: "Malbolge figures out which instruction to execute by taking the value at [c], adding the value of c to it, and taking the remainder when this is divided by 94", where c is the instruction pointer, [c] being the location pointed to.  Also: "After each instruction is executed, the guilty instruction gets encrypted (see below) so that it won't do the same thing next time" - which makes writing loops tricky!

Here are two "Hello World!" programs written in Malbolge:

Code: [Select]
('&%:9]!~}|z2Vxwv-,POqponl$Hjig%[email protected]@>}=<M:9wv6WsU2T|nm-,jcL(I&%$#"
`CB]V?Tx<uVtT`[email protected]?]!~|4XzyTT43Qsqq(Lnmkj"Fhg${[email protected]>

Code: [Select]
(=<`#9]~6ZY32Vx/4Rs+0No-&Jk)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc
A more detailed description.  I am not suggesting that anyone really tries to write a program in this, nor even tries to work out how one of those programs works!

(This post could just as well have gone in the pointless thread, but it's technical nature belongs here.)
« Last Edit: 07 Jan 2014, 15:11 by pwhodges »
Logged
"Being human, having your health; that's what's important."  (from: Magical Shopping Arcade Abenobashi )
"As long as we're all living, and as long as we're all having fun, that should do it, right?"  (from: The Eccentric Family )

cesium133

  • Preventing third impact
  • *****
  • Offline Offline
  • Posts: 6,062
  • Has a fucked-up browser history
    • Cesium Comics
Re: A programming challenge (j/k)
« Reply #1 on: 07 Jan 2014, 15:01 »

Thinking of esoteric programming languages, somewhere on my hard drive I have a Shakespeare program that sets up a subroutine call system. The return address is stored by telling an act number to Hamlet and a scene number to Horatio.
Logged
The nerdy comic I update sometimes: Cesium Comics

Unofficial character tag thingy for QC

snalin

  • Vulcan 3-D Chess Master
  • *****
  • Offline Offline
  • Posts: 3,567
  • You may Baste me
Re: A programming challenge (j/k)
« Reply #2 on: 08 Jan 2014, 04:02 »

I wrote an interpreter for Befunge for a compiler course this last semestre. It's a lot less complicated than many others, but it's still really, really hard to write code that does something sensible for it. 99 bottles should not be too hard, gcd would be much worse.
Logged
I am a cowboy / on a steel horse I ride
I am wanted / Dead or alive

ankhtahr

  • GET ON THE NIGHT TRAIN
  • *****
  • Offline Offline
  • Posts: 2,689
  • A hacker spathe night owl
Re: A programming challenge (j/k)
« Reply #3 on: 08 Jan 2014, 05:33 »

For some reason I really enjoy Brainfuck.

But yeah, the SPL is pretty awesome too.
Logged
Quote from: Terry Pratchett
He had the look of a lawn mower just after the grass had organised a workers' collective.

snalin

  • Vulcan 3-D Chess Master
  • *****
  • Offline Offline
  • Posts: 3,567
  • You may Baste me
Re: A programming challenge (j/k)
« Reply #4 on: 08 Jan 2014, 05:40 »

Okay, dammit, I made a gcd for befunge. You can see how it works on the brilliant playground (not made by me, just to be clear) here. Just paste the code into the box, select "input code and reset", and then "run". You'll be prompted to enter two numbers, and the output should be their greatest common divisor.

Code: [Select]
>" regetni tsrif tupni">:v     < storage cell       v,_ $&  v input on line 1,2
                       ^,_ &0" regetni dnoces tupni">:^

>                               v                           <
^ \ g 0 * 5 6 % p 0 * 5 6 : <
                            | : < algorithm on lines 4,5,6,7
    @.,,,,,,,, "output: " $ <

The playground shows you what the stack is at any time, and what symbol the program pointer is at. It's a pretty cool feature, and debugging the stuff without something like that is a nightmare.
Logged
I am a cowboy / on a steel horse I ride
I am wanted / Dead or alive

Edguy

  • Psychopath in a hockey mask
  • ****
  • Offline Offline
  • Posts: 637
  • Takin' care of business!
    • My facebook page
Re: A programming challenge (j/k)
« Reply #5 on: 08 Jan 2014, 08:57 »



#Goes away to play LoL, read webcomics or work on my engineering studies.*
Logged
I dunno..
Pages: [1]   Go Up