Talk:Alphaprint
Mini interpreter
var code = prompt("Code?");
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var i = 0;
var result = "";
while (i < code.length) {
if (code.substr(i, 1) === alphabet.substr(i % 26, 1)) {
}
else if (code.substr(i, 1) === alphabet.substr(i % 26, 1).toUpperCase()) {
result += String.fromCharCode(i % 256);
}
else {
alert("Non-valid program: the characters doesn't follow the alphabetical order");
break;
}
i += 1;
}
if (i == code.length) {
alert(result);
}
--Rerednaw (talk) 23:19, 31 January 2020 (UTC)
So recently, the author put an example of a "Hello, World!" program and an interpreter. The little problem is that my code in JS was based on the example code that was supposed to print "!".
There was already a problem, since "!" isn't the 33rd ASCII character but is the 34th one (because "!" has the value 33 and the value 0 is used for the NUL character in ASCII), so the real example should be:
abcdefghijklmnopqrstuvwxyzabcdefgH
I should have asked the creator about that, but I was focused on the example, so my priority was that the example gives the right result.
So I modified this code, replacing (i - 1) % 256 by i % 256. Also, before anyone asks, the first "if" is there in the case you want to modify the code to print something if there's no error.--Rerednaw (talk) 13:03, 31 March 2020 (UTC)
- "!" is the 33rd ASCII character. NUL is the 0th ASCII character.
Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ord("!"), ord("\0")
(33, 0)
>>>
- User:PythonshellDebugwindow (talk) 14:38, 7 November 2020 (UTC)
Interpreter in Python
code = "abcdefghijklmnopqrstuvwxyzabcdefG" alphabet = "abcdefghijklmnopqrstuvwxyz" alphabet += alphabet * (len(code) // 26) assert(code.lower() in alphabet) # Error when it isn't valid for i,v in enumerate(code): if v.isupper(): print(chr((i + 1) % 256), end = "")
In Io
code := "abcdefghijklmnopqrstuvwxyzabcdefG"
alphabet := "abcdefghijklmnopqrstuvwxyz"
alphabet = \
list (
alphabet,
alphabet repeated((code size / 26) floor)
) join
if(alphabet containsSeq(code asLowercase), 0, exit)
code asList map(i,v,if(v isUppercase,(i+1)asCharacter print))
----(this comment by A at 12:34, 1 January 2016 UTC; please sign your comments with ~~~~) 05:30, 19 March 2020 (UTC)