Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
# Using built-in functions
|
||||
Incr := s -> String(Int(s) + 1);
|
||||
|
||||
# Implementing addition
|
||||
# (but here 9...9 + 1 = 0...0 since the string length is fixed)
|
||||
Increment := function(s)
|
||||
local c, n, carry, digits;
|
||||
digits := "0123456789";
|
||||
n := Length(s);
|
||||
carry := true;
|
||||
while n > 0 and carry do
|
||||
c := Position(digits, s[n]) - 1;
|
||||
if carry then
|
||||
c := c + 1;
|
||||
fi;
|
||||
if c > 9 then
|
||||
carry := true;
|
||||
c := c - 10;
|
||||
else
|
||||
carry := false;
|
||||
fi;
|
||||
s[n] := digits[c + 1];
|
||||
n := n - 1;
|
||||
od;
|
||||
end;
|
||||
|
||||
s := "2399";
|
||||
Increment(s);
|
||||
s;
|
||||
# "2400"
|
||||
Loading…
Add table
Add a link
Reference in a new issue