Arithmetic
Arithmetic is an esolang invented by User:None1, which is based on arithmetic exams.
Syntax
==Begin Exam X==
begins an exam, X must be the number of the exam, for example, the first exam must starts with ==Begin Exam 1==.
==End Exam X==
matches the ==Begin Exam X== command, the X must be the same as the X in its matching command.
X. A+B=? (y points)
defines a problem in the exam. A and B must be positive decimal integers. X must be the number of the problem
X. A
defines a choice of a problem. The first choice of a problem must be A. xxx, The second choice must be B. xxx, in which xxx is a positive decimal integer, etc. (Space between . and the number is MANDATORY). Each problem must have only one correct choice.
Answer: X
defines the answer of a problem. If the answer is correct, the points of the problem will be earned.
Execution
Each time one exam ends, Arithmetic prints the total points earned in that exam modulo 256 as an ASCII character. Arithmetic has no input.
Example Programs
Nope. interpreter
==Begin Exam 1== 1. 1+1=? (78 points) A. 2 Answer: A ==End Exam 1== ==Begin Exam 2== 1. 1+1=? (111 points) A. 2 Answer: A ==End Exam 2== ==Begin Exam 3== 1. 1+1=? (112 points) A. 2 Answer: A ==End Exam 3== ==Begin Exam 4== 1. 1+1=? (101 points) A. 2 Answer: A ==End Exam 4== ==Begin Exam 5== 1. 1+1=? (46 points) A. 2 Answer: A ==End Exam 5==
Hello World
==Begin Exam 1== 1. 1+1=? (72 points) A. 2 Answer: A ==End Exam 1== ==Begin Exam 2== 1. 1+1=? (101 points) A. 2 Answer: A ==End Exam 2== ==Begin Exam 3== 1. 1+1=? (108 points) A. 2 Answer: A ==End Exam 3== ==Begin Exam 4== 1. 1+1=? (108 points) A. 2 Answer: A ==End Exam 4== ==Begin Exam 5== 1. 1+1=? (111 points) A. 2 Answer: A ==End Exam 5== ==Begin Exam 6== 1. 1+1=? (32 points) A. 2 Answer: A ==End Exam 6== ==Begin Exam 7== 1. 1+1=? (87 points) A. 2 Answer: A ==End Exam 7== ==Begin Exam 8== 1. 1+1=? (111 points) A. 2 Answer: A ==End Exam 8== ==Begin Exam 9== 1. 1+1=? (114 points) A. 2 Answer: A ==End Exam 9== ==Begin Exam 10== 1. 1+1=? (108 points) A. 2 Answer: A ==End Exam 10== ==Begin Exam 11== 1. 1+1=? (100 points) A. 2 Answer: A ==End Exam 11== ==Begin Exam 12== 1. 1+1=? (33 points) A. 2 Answer: A ==End Exam 12==
Interpreter
Written in JavaScript. Problems can have up to 26 choices (one for each uppercase letter).
function interpret(a){const e=a.split`\n`;let o="",st=x=p=c=P=C=+o,r,v;for(const n of e){if((!++C)||n==[])continue;if(st==0&&n=="==Begin Exam "+ ++x+"=="&&++st&&!(v={},p=c=P=+!v))continue;if(st==1&&(m=n.match(/^([0-9]+). ([0-9]+)\+([0-9]+)=\? \(([0-9]+) points\)$/))&&+m[2]&&+m[3]&&++p==m[1]&&++st&&!(v={},c=+!v)&&(r=m.slice(2,5)))continue;if(st==2&&c<26&&(m=n.match(new RegExp("^("+String.fromCharCode(++c+64)+")\. ([0-9]+)$")))&&+m[2]&&(!(Object.values(v).indexOf(m[2])>-1&&m[2]==+r[0]+ +r[1]))&&(v[m[1]]=m[2]))continue;if(st==2&&(m=n.match(/^Answer: ([A-Z])$/))&&m[1].charCodeAt(0)-64<c&&v[m[1]]==+r[0]+ +r[1]&&(P+=(+r[2])%256)&&--st)continue;if(st==2&&(m=n.match(/^Answer: ([A-Z])$/))&&m[1].charCodeAt(0)-64<c&&--st)continue;if(st==1&&n=="==End Exam "+x+"=="&&1+--st&&(o+=String.fromCharCode(P%256)))continue;throw new Error("Invalid syntax on line "+C);}if(st)throw new Error("Unexpected end of input");console.log(o);}
Well, that interpreter uses regular expressions, making it very unreadable, so I , User:None1, am trying to make an interpreter in C++ using sscanf instead of regular expressions.