Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
113
Task/Balanced-ternary/Glagol/balanced-ternary.glagol
Normal file
113
Task/Balanced-ternary/Glagol/balanced-ternary.glagol
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
PROGRAM Setun+;
|
||||
USES
|
||||
Parameter IS "...\Departments\Exchange\"
|
||||
Text IS "...\Departments\Numbers\"
|
||||
Output IS "...\Departments\Exchange\";
|
||||
|
||||
VAR
|
||||
AF: RANGE 10 IS SIGN;
|
||||
mfpos: INT;
|
||||
number: INT;
|
||||
memory ACCESS TO STRUCT
|
||||
cell: RANGE 20 IS INT;
|
||||
size: UZKEL;
|
||||
negative: BOOL
|
||||
END;
|
||||
|
||||
PROC Create.Memory;
|
||||
BEGIN
|
||||
CREATE(memory);
|
||||
memory.size := 0;
|
||||
memory.negative := FALSE
|
||||
END Create.Memory;
|
||||
|
||||
PROC Add.Memory(that: INT)
|
||||
BEGIN
|
||||
memory.cells[memory.size] := that;
|
||||
ZOOM(memory.size)
|
||||
END Add.Memory;
|
||||
|
||||
PROC Invert.Memory;
|
||||
VAR
|
||||
zchsl: INT;
|
||||
account: INT;
|
||||
BEGIN
|
||||
FOR cq := 0 TO memory.size DIVIDE 2 - 1 DO
|
||||
zchsl := memory.cells[cq];
|
||||
memory.cells[cq] := memory.cells[memory.size-size-1];
|
||||
memory.cells[memory.size-MF-1] := zchsl
|
||||
END
|
||||
END Invert.Memory;
|
||||
|
||||
PROC Withdraw.Memory;
|
||||
VAR
|
||||
account: INT;
|
||||
BEGIN
|
||||
FOR cq := 0 TO memory.size-1 DO
|
||||
IF memory.cells[cq] < 0 THEN
|
||||
Output.Append("-")
|
||||
ANDIF memory.cells[cq] > 0 THEN
|
||||
Output.Append("+")
|
||||
ELSE Output.Append("0") END
|
||||
END
|
||||
END Withdraw.Memory;
|
||||
|
||||
PROC Remove.Memory;
|
||||
BEGIN
|
||||
memory := Empty
|
||||
END Remove.Memory;
|
||||
|
||||
PROC Translate(number: INT)
|
||||
VAR
|
||||
about: INT;
|
||||
s: BOOL;
|
||||
PROC B.Memory(that: INT)
|
||||
BEGIN
|
||||
IF memory.negative THEN
|
||||
IF that < 0 THEN Add.Memory(1)
|
||||
ANDIF that > 0 THEN Add.Memory(1)
|
||||
ELSE Add.Memory(0) END
|
||||
ELSE
|
||||
Add.Memory(that)
|
||||
END
|
||||
END B.Memory;
|
||||
BEGIN
|
||||
IF number < 0 THEN memory.negative := TRUE END;
|
||||
number := UNIT(number)
|
||||
s := FALSE;
|
||||
WHILE number > 0 DO
|
||||
about := number BALANCE 3;
|
||||
number := number DIVIDE 3;
|
||||
IF s THEN
|
||||
IF about = 2 THEN B.Memory(0) ANDIF about = 1 THEN B.Memory(1) ELSE B.Memory(1) s := FALSE END
|
||||
ELSE
|
||||
IF about = 2 THEN B.Memory(-1) s := TRUE ELSE B.Memory(a) END
|
||||
END
|
||||
END;
|
||||
IF s THEN B.Memory(1) END;
|
||||
Invert.Memory;
|
||||
Withdraw.Memory(TRUE)
|
||||
END Translate;
|
||||
|
||||
PROC InNumber(): INT;
|
||||
VAR
|
||||
MF, MN: INT;
|
||||
result: INT;
|
||||
BEGIN
|
||||
result := 0
|
||||
pl := 1;
|
||||
FOR cq := 0 TO memory.size-1 DO
|
||||
ZOOM(result, memory.Cells[memory.size-cq-1] * mn);
|
||||
pl := pl * 3
|
||||
END;
|
||||
RETURN result;
|
||||
END InNumber;
|
||||
|
||||
BEGIN
|
||||
Parameter.Text(1, AF); mfpos := 0;
|
||||
number := Text.Whole(AF, mfpos);
|
||||
Create.Memory;
|
||||
Translate(number);
|
||||
Output.ChTarget(" = %d.", InNumber(), 0, 0, 0);
|
||||
Remove.Memory
|
||||
END Setun.
|
||||
Loading…
Add table
Add a link
Reference in a new issue