Pascal, 158 B
The implementation‑defined set of char
values must correspond to ASCII and the ordinal value of the built‑inimplementation‑defined constant maxChar
must be greater than or equal to 255.
program P(input,output);var C:char;A:0‥255;begin
A≔0;while not EOF do begin
read(C);if C='−' then write(chr(A));A≔(A+ord(C='+')−ord(C='−'))mod 256 end end.
−3 B: If you have a processor supporting “Extended Pascal” as defined by ISO standard 10206, you may write a zero‑width string:
program P(input,output);var C:char;A:0‥255;begin
A≔0;while not EOF do begin
read(C);write(chr(A):ord(C='−'));A≔(A+ord(C='+')−ord(C='−'))mod 256 end end.
Users of the FreePascal Compiler need to insert a {$modeSwitch ISOMod+}
compiler directive.
This ensures an ISO‑compliant definition of the mod
operator, in particular in case of negative dividends the result is still non‑negative (Euclidean‑like definition of mod
).