As a joke, I (with the help of Tari) made an esoteric programming language called Merthese. Here's the spec:
Quote:
Merthese is an esoteric programming language written by Merthsoft. It has 5 instructions:
m - Prints "merth"
e - Prints a new line (defined as new line for the environment)
r - Prints a space
t - Prints a random-length string of random letters where letters are [a-z], and the length of the string is between [0, 13.4)
h - Seeks to the character after the next "h" character
All other characters are ignored. The program terminates when input ends.
Edit by Tanner: Added the Merthing @ Kerm rules
Quote:
k - Print accum. char
e - accum++
r - Reset accum
m - Print accum. num
I also decided to make an interpreter, called Merthterpreter, in C# (of course). Here's the code:
Code: using System;
using System.Text;
namespace Merthterpreter {
class Merthterpreter {
static bool hFlag = false;
static Random rand = new Random();
static void Main(string[] args) {
foreach (String s in args) {
foreach (char c in s) {
Merthterpret(c);
}
}
}
private static void Merthterpret(char c) {
if (hFlag && c != 'h') {
return;
}
switch (c) {
case 'm':
Console.Write("merth");
break;
case 'e':
Console.WriteLine();
break;
case 'r':
Console.Write(" ");
break;
case 't':
int len = (int)(rand.NextDouble() * 13.4);
StringBuilder s = new StringBuilder(len);
for (int i = 0; i < len; i++) {
s.Append((char)(rand.Next((int)'a', (int)'z' + 1)));
}
Console.Write(s.ToString());
break;
case 'h':
hFlag = !hFlag;
break;
}
}
}
}
I clearly could've easily made this one function, but then I wouldn't've gotten to use call Merthterpret. Here's a download link:
http://merthsoft.com/Merthterpreter.exe
And here's some sample output:
Code: Merthterpreter.exe merthsoft is the coolest guy in the whole entire world.
merth
ms
jrswvltxukzbgis
dhkystskhow
Haha very nice.
Hmm I got something different for your test
http://www.pastie.org/2111931
That's because it's a nondeterministic language:
Quote:
t - Prints a random-length string of random letters where letters are [a-z], and the length of the string is between [0, 13.4)
Code: Merthterpreter.exe Merthhhhhh
z
Weregoose wrote:
Code: Merthterpreter.exe Merthhhhhh
z
Looks good to me.
Can't test this, so it might be wrong. The specs for this "kerm" extension are:
Code: k - print accum. char
e - accum++
r - reset accum
m - print accum. num
Since "merth" takes up most of "kerm", it just chooses a random option at each letter that collides.
Code: using System;
using System.Text;
namespace Merthterpreter {
class Merthterpreter {
static bool hFlag = false;
static Random rand = new Random();
static char accum = '\0';
static void Main(string[] args) {
foreach (String s in args) {
foreach (char c in s) {
Merthterpret(c);
}
}
}
private static void Merthterpret(char c) {
if (hFlag && c != 'h') {
return;
}
switch (c) {
case 'm':
if (rand.NextInt() % 2)
Console.Write("merth");
else
Console.Write(((int)accum).ToString());
break;
case 'e':
if (rand.NextInt() % 2)
Console.WriteLine();
else
accum++;
break;
case 'r':
if (rand.NextInt() % 2)
Console.Write(" ");
else
accum = 0;
break;
case 't':
int len = (int)(rand.NextDouble() * 13.4);
StringBuilder s = new StringBuilder(len);
for (int i = 0; i < len; i++) {
s.Append((char)(rand.Next((int)'a', (int)'z' + 1)));
}
Console.Write(s.ToString());
break;
case 'h':
hFlag = !hFlag;
break;
case 'k':
Console.Write(accum);
break;
}
}
}
}
Looks ok. NextInt() isn't a thing, and integers aren't booleans in C#. Here's it fixed to compile, at least:
Code: using System;
using System.Text;
namespace Merthterpreter {
class Merthterpreter {
static bool hFlag = false;
static Random rand = new Random();
static char accum = '\0';
static void Main(string[] args) {
foreach (String s in args) {
foreach (char c in s) {
Merthterpret(c);
}
}
}
private static void Merthterpret(char c) {
if (hFlag && c != 'h') {
return;
}
switch (c) {
case 'm':
if (rand.Next() % 2 == 0)
Console.Write("merth");
else
Console.Write(((int)accum).ToString());
break;
case 'e':
if (rand.Next() % 2 == 0)
Console.WriteLine();
else
accum++;
break;
case 'r':
if (rand.Next() % 2 == 0)
Console.Write(" ");
else
accum = '\0';
break;
case 't':
int len = (int)(rand.NextDouble() * 13.4);
StringBuilder s = new StringBuilder(len);
for (int i = 0; i < len; i++) {
s.Append((char)(rand.Next((int)'a', (int)'z' + 1)));
}
Console.Write(s.ToString());
break;
case 'h':
hFlag = !hFlag;
break;
case 'k':
Console.Write(accum);
break;
}
}
}
}
And here's a sample run:
Quote:
Merthterpreter.exe merthsoft is the coolest guy in the whole entire world.
0xpbpsbo
efplpd
nqrvca
Requested:
Code: PROGRAM:MERTHESE
Input Str1
"?→Str2
For(X,1,length(Str1
sub(Str1,X,1→Str3
If Str3="M
Str2+"MERTH→Str2
If Str3="E
Then
Disp sub(Str2+" ",2,length(Str2
"?→Str2
End
If Str3="R
Str2+" →Str2
If Str3="T
Then
For(A,0,int(rand13.4)-1
Str2+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",randInt(1,26),1→Str2
End
End
If Str3="H
inString(Str1+"H","H",X+1→X
End
sub(Str2+" ",2,length(Str2
If you'd rather use Ans as your input, get rid of ":Input Str1" and put ":Ans→Str1" there instead.
Haha, looks good, Weregoose. This is kind of and extension too, since it uses capital letters
Haha, this is superb. Have you found the Hello, World seed yet, Merth?
Strictly speaking, there is no "Hello, World" seed, but I'm looking for the "hello world" seed. I'm up to 38000 out of 2,147,483,647... Here's some new code, btw:
Code: using System;
using System.Text;
namespace Merthterpreter {
class Merthterpreter {
static bool hFlag = false;
static Random rand = new Random();
static char accum = '\0';
static void Main(string[] args) {
bool kermFlag = false;
int start = 0;
if (args[0] == "-k") {
kermFlag = true;
start++;
}
if (args[start] == "-s") {
int seed;
if (int.TryParse(args[start + 1], out seed) && seed > 0) {
rand = new Random(seed);
start += 2;
}
}
for (int i = start; i < args.Length; i++) {
foreach (char c in args[i]) {
if (!kermFlag) {
Merthterpret(c);
} else {
MerthingAtKermterpret(c);
}
}
}
}
private static void Merthterpret(char c) {
if (hFlag && c != 'h') {
return;
}
switch (c) {
case 'm':
Console.Write("merth");
break;
case 'e':
Console.WriteLine();
break;
case 'r':
Console.Write(" ");
break;
case 't':
int len = (int)(rand.NextDouble() * 13.4);
StringBuilder s = new StringBuilder(len);
for (int i = 0; i < len; i++) {
s.Append((char)(rand.Next((int)'a', (int)'z' + 1)));
}
Console.Write(s.ToString());
break;
case 'h':
hFlag = !hFlag;
break;
}
}
private static void MerthingAtKermterpret(char c) {
if (hFlag && c != 'h') {
return;
}
switch (c) {
case 'm':
if (rand.Next() % 2 == 0)
Console.Write("merth");
else
Console.Write(((int)accum).ToString());
break;
case 'e':
if (rand.Next() % 2 == 0)
Console.WriteLine();
else
accum++;
break;
case 'r':
if (rand.Next() % 2 == 0)
Console.Write(" ");
else
accum = '\0';
break;
case 't':
int len = (int)(rand.NextDouble() * 13.4);
StringBuilder s = new StringBuilder(len);
for (int i = 0; i < len; i++) {
s.Append((char)(rand.Next((int)'a', (int)'z' + 1)));
}
Console.Write(s.ToString());
break;
case 'h':
hFlag = !hFlag;
break;
case 'k':
Console.Write(accum);
break;
}
}
}
}
You can set it to Merthing @ Kerm mode (Tanner's extension) by doing Merthterpreter.exe -k, and you can set the seed by doing -s seed. So:
Merthterpreter.exe -k -s 1
Sets it into Kerm mode with a seed of one, and:
Merthterpreter.exe -s 1
Just gives it a seed of 1.
With the Merthing @ Kerm extension, it is possible to get "Hello, World". You'd have to get very lucky with the extra "Kerm" letters, but it would be possible.
I'll find the seed for that one next.
Python implementation. Reads a program from standard input and prints it on standard out.
Code: #!/usr/bin/env python
import random
from sys import stdin, stdout
r = random.Random()
c = ' '
while len(c) > 0:
s = ""
if c == 'm':
s = "merth"
elif c == 'e':
s = '\n'
elif c == 'r':
s = ' '
elif c == 't':
# Random string between 0 and 13.4 chars
l = r.randint(0, int(13.4))
while len(s) < l:
s += r.choice("abcdefghijklmnopqrstuvwxyz")
elif c == 'h':
# Skip to next 'h'
c = ' '
while c != 'h' and len(c) > 0:
c = stdin.read(1)
stdout.write(s)
c = stdin.read(1)
Example usage:
Code: $ echo "merth" | python merth.py
merth
ootkt
I would find it trivial to write the shell script to wrap that program and find the seeds on Linux, but how are you doing it on Windows? Did you modify the program to iterate over possible seeds instead of doing batch scripting for the sake of simplicity?
Alright, so now we've got a C# implementation, a TI-BASIC implementation, and a Python (3.1?) implementation. Let's get more! Someone make the z80 implementation!
KermMartian wrote:
I would find it trivial to write the shell script to wrap that program and find the seeds on Linux, but how are you doing it on Windows? Did you modify the program to iterate over possible seeds instead of doing batch scripting for the sake of simplicity?
Python. And it's running on Linux now so I could run it in a screen session.
My Python version should work under any version of Python, so we can say 3.1 if it makes you happy.
I'm working on a version in Haskell now.
Ok then... I was bored and made a Racket implementation.
Code:
#lang racket
(define (merthterpreter program)
(foldl mertherpret #f (string->list program))
(void))
(define ft (hash
#\m (λ (sf) (display "merth") sf)
#\e (λ (sf) (newline) sf)
#\r (λ (sf) (display " ") sf)
#\t (λ (sf) (display (random-string 14)) sf)
#\h (λ (sf) (not sf))
)
)
(define (mertherpret instruction skip)
(or (and (not (equal? instruction #\h)) skip)
(apply (hash-ref ft instruction) (list skip))))
(define (random-string max)
(list->string (build-list (random max) (λ (c) (integer->char (+ (random 26) 97))))))
(if (> (vector-length (current-command-line-arguments)) 0)
(merthterpreter (vector-ref (current-command-line-arguments) 0))
(merthterpreter (symbol->string (read))))
Note: not a Lisp/Racket expert.
Here is one in Common Lisp (Doesn't have the Merthing @ Kerm extension yet) 30 lines:
Code: (defmacro cond-string= (&rest rest)
(do ((i 1 (1+ i))
(answer (list 'cond))
(cur (elt rest 0) (elt rest i)))
((= i (length rest)) answer)
(setf answer (append answer (list (list (list 'not (list 'eql 'nil (list 'string= 'cur (first (first cur)))))
(do ((j 1 (1+ j))
(answerj ()))
((= j (length cur)) answerj)
(setf answerj (append answerj (elt cur j))))))))))
(defun merthterpreter (input &optional (kerm 0))
(do ((i 1 (1+ i))
(cur (elt input 0) (elt input i))
(hflag nil))
((= i (length input)) (format t "~%"))
(if hflag
(when (string= cur "h")
(setf hflag (not hflag)))
(cond-string= (("m")
(format t "merth"))
(("e")
(format t "~%"))
(("r")
(format t " "))
(("t")
(dotimes (random 13.4)
(format t "~a" (code-char (+ (random 26) 97)))))
(("h")
(setf hflag (not hflag)))))))
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
»
Go to Registration page
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