langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
|
|
@ -0,0 +1,2 @@
|
|||
mutable str = "12345";
|
||||
str = $"$(Int32.Parse(str)+1)";
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/* NetRexx */
|
||||
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
numbers = '12345'
|
||||
say numbers
|
||||
numbers = numbers + 1
|
||||
say numbers
|
||||
|
||||
return
|
||||
|
|
@ -0,0 +1 @@
|
|||
string_of_int (succ (int_of_string "1234"))
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
MODULE addstr;
|
||||
|
||||
IMPORT Out, Strings;
|
||||
|
||||
VAR str1, str2 : ARRAY 9 OF CHAR;
|
||||
num, pos : INTEGER;
|
||||
carry : BOOLEAN;
|
||||
ch : CHAR;
|
||||
|
||||
BEGIN
|
||||
str1 := "9999";
|
||||
Out.Char ('"'); Out.String (str1); Out.String ('" + 1 = ');
|
||||
num := Strings.Length (str1) - 1;
|
||||
pos := num;
|
||||
IF str1 [0] = '9' THEN INC (pos) END;
|
||||
str2 [pos + 1] := 0X;
|
||||
carry := TRUE;
|
||||
REPEAT
|
||||
ch := str1 [num];
|
||||
IF carry THEN
|
||||
ch := CHR (ORD (ch) + 1)
|
||||
END;
|
||||
IF ch > '9' THEN
|
||||
carry := TRUE;
|
||||
ch := '0'
|
||||
ELSE
|
||||
carry := FALSE
|
||||
END;
|
||||
str2 [pos] := ch;
|
||||
DEC (num);
|
||||
DEC (pos)
|
||||
UNTIL num < 0;
|
||||
IF carry THEN str2 [0] := '1' END;
|
||||
Out.String (str2);
|
||||
Out.Ln
|
||||
END addstr.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
s := "12345";
|
||||
i := int->ToInt(s) + 1;
|
||||
s := i->ToString();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
NSString *s = @"12345";
|
||||
int i = [s intValue] + 1;
|
||||
s = [NSString stringWithFormat:@"%i", i]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
nstring = "123";
|
||||
nstring = sprintf("%d", str2num(nstring) + 1);
|
||||
disp(nstring);
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
DEFINE VARIABLE cc AS CHARACTER INITIAL "12345".
|
||||
|
||||
MESSAGE
|
||||
INTEGER( cc ) + 1
|
||||
VIEW-AS ALERT-BOX.
|
||||
|
|
@ -0,0 +1 @@
|
|||
{Int.toString {String.toInt "12345"} + 1}
|
||||
|
|
@ -0,0 +1 @@
|
|||
foo(s)=Str(eval(s)+1);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
declare s picture '999999999';
|
||||
s = '123456789';
|
||||
s = s + 1;
|
||||
put skip list (s);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my $s = "12345";
|
||||
$s++;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
string number = "0";
|
||||
number = (string)((int)number+1);
|
||||
Result: "1"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
lvars s = '123456789012123456789999999999';
|
||||
(strnumber(s) + 1) >< '' -> s;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$s = "12345"
|
||||
$t = [string] ([int] $s + 1)
|
||||
|
|
@ -0,0 +1 @@
|
|||
$t = [string] (1 + $s)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
string$="12345"
|
||||
string$=Str(Val(string$)+1)
|
||||
Debug string$
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
REBOL [
|
||||
Title: "Increment Numerical String"
|
||||
Author: oofoe
|
||||
Date: 2009-12-23
|
||||
URL: http://rosettacode.org/wiki/Increment_numerical_string
|
||||
]
|
||||
|
||||
; Note the use of unusual characters in function name. Also note that
|
||||
; because REBOL collects terms from right to left, I convert the
|
||||
; string argument (s) to integer first, then add that result to one.
|
||||
|
||||
s++: func [s][to-string 1 + to-integer s]
|
||||
|
||||
; Examples. Because the 'print' word actually evaluates the block
|
||||
; (it's effectively a 'reduce' that gets printed space separated),
|
||||
; it's possible for me to assign the test string to 'x' and have it
|
||||
; printed as a side effect. At the end, 'x' is available to submit to
|
||||
; the 's++' function. I 'mold' the return value of s++ to make it
|
||||
; obvious that it's still a string.
|
||||
|
||||
print [x: "-99" "plus one equals" mold s++ x]
|
||||
print [x: "42" "plus one equals" mold s++ x]
|
||||
print [x: "12345" "plus one equals" mold s++ x]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import String;
|
||||
|
||||
public str IncrNumStr(str s) = "<toInt(s) + 1>";
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
rascal>IncrNumStr("123")
|
||||
str: "124"
|
||||
|
|
@ -0,0 +1 @@
|
|||
"123" toNumber 1+ toString
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
string$ = "12345"
|
||||
numeric = val(string$)
|
||||
numeric = numeric + 1
|
||||
string$ = str$(numeric)
|
||||
print string$
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
output = trim(input) + 1
|
||||
output = "123" + 1
|
||||
end
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
s/^.*$/&:/
|
||||
:bubble
|
||||
s/^:/1/
|
||||
/.:/ {
|
||||
h
|
||||
s/^.*\(.\):.*$/\1/
|
||||
y/0123456789/123456789:/
|
||||
s/:/:0/
|
||||
G
|
||||
s/\(.*\)\n\(.*\).:\(.*\)$/\2\1\3/
|
||||
b bubble
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var string: s is "12345";
|
||||
|
||||
s := str(succ(integer parse s));
|
||||
|
|
@ -0,0 +1 @@
|
|||
((Integer readFrom: '123') + 1) printString
|
||||
|
|
@ -0,0 +1 @@
|
|||
Int.toString (1 + valOf (Int.fromString "1234"))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
:"1"→Str1
|
||||
:expr(Str1)+1→A
|
||||
:{0,1}→L₁
|
||||
:{0,A}→L₂
|
||||
:LinReg(ax+b) Y₁
|
||||
:Equ►String(Y₁,Str1)
|
||||
:sub(Str1,1,length(Str1)-3)→Str1
|
||||
|
|
@ -0,0 +1 @@
|
|||
string(expr(str)+1)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
$$ MODE TUSCRIPT
|
||||
teststring="0'1'-1'12345'10000000'-10000000"
|
||||
LOOP/CLEAR n=teststring
|
||||
n=n+1
|
||||
PRINT n
|
||||
ENDLOOP
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
@(do (defun inc-num-str (str-in)
|
||||
(let ((len (length str-in))
|
||||
(str (copy-str str-in)))
|
||||
(for ((i (- len 1)))
|
||||
((>= i 0) `1@str`)
|
||||
((dec i))
|
||||
(if (<= (inc [str i]) #\9)
|
||||
(return str)
|
||||
(set [str i] #\0))))))
|
||||
@(bind a @(inc-num-str "9999"))
|
||||
@(bind b @(inc-num-str "1234"))
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
@(deffilter incdig ("0" "1") ("1" "2") ("2" "3") ("3" "4") ("4" "5")
|
||||
("5" "6") ("6" "7") ("7" "8") ("8" "9"))
|
||||
@(define increment (num out))
|
||||
@ (local prefix dig junk)
|
||||
@ (next :string num)
|
||||
@ (cases)
|
||||
9
|
||||
@ (bind out "10")
|
||||
@ (or)
|
||||
@*{prefix}@{dig /[0-8]/}
|
||||
@ (bind out `@prefix@{dig :filter incdig}`)
|
||||
@ (or)
|
||||
@*{prefix}9
|
||||
@ (bind out `@{prefix :filter (:fun increment)}0`)
|
||||
@ (or)
|
||||
@junk
|
||||
@ (throw error `bad input: @junk`)
|
||||
@ (end)
|
||||
@(end)
|
||||
@in
|
||||
@(increment in out)
|
||||
|
|
@ -0,0 +1 @@
|
|||
" 100" >number drop 1 + >string
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# All variables are strings within the shell
|
||||
# Although num look like a number, it is in fact a numerical string
|
||||
num=5
|
||||
num=`expr $num + 1` # Increment the number
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
num=5
|
||||
let num=num+1 # Increment the number
|
||||
let "num = num + 1" # Increment again. (We can use spaces inside quotes)
|
||||
((num = num + 1)) # This time we use doublebrackets
|
||||
let num+=1 # This time we use +=
|
||||
let "num += 1"
|
||||
((num += 1))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
integer num=5 # Declare an integer...
|
||||
num=$num+1 # ...then increment without the let keyword.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
@ num = 5
|
||||
@ num += 1
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#import nat
|
||||
|
||||
instring = ~&h+ %nP+ successor+ %np@iNC # convert, do the math, convert back
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#cast %sL
|
||||
|
||||
tests = instring* <'22435','4','125','77','325'>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Public Function incr(astring As String) As String
|
||||
'simple function to increment a number string
|
||||
incr = CStr(CLng(astring) + 1)
|
||||
End Function
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
Public Function Lincr(astring As String) As String
|
||||
'increment a number string, of whatever length
|
||||
'calls function "increment" or "decrement"
|
||||
Dim result As String
|
||||
|
||||
'see if it is a negative number
|
||||
If left$(astring, 1) = "-" Then
|
||||
'negative x: decrease |x| by 1, then add "-"
|
||||
'(except if the result is zero)
|
||||
result = decrement(Mid$(astring, 2))
|
||||
If result <> "0" Then result = "-" & result
|
||||
Else
|
||||
'0 or positive x: increase x by 1
|
||||
If left$(astring, 1) = "+" Then 'allow a + before the number
|
||||
result = increment(Mid$(astring, 2))
|
||||
Else
|
||||
result = increment(astring)
|
||||
End If
|
||||
End If
|
||||
Lincr = result
|
||||
End Function
|
||||
|
||||
Public Function increment(astring) As String
|
||||
Dim result As String
|
||||
'increment a string representing a positive number
|
||||
'does not work with negative numbers
|
||||
carry = 1
|
||||
L = Len(astring)
|
||||
result = ""
|
||||
For j = L To 1 Step -1
|
||||
digit = Val(Mid$(astring, j, 1)) + carry
|
||||
If digit > 9 Then
|
||||
digit = digit - 10
|
||||
carry = 1
|
||||
Else
|
||||
carry = 0
|
||||
End If
|
||||
result = CStr(digit) & result
|
||||
Next
|
||||
If carry = 1 Then result = CStr(carry) & result
|
||||
increment = result
|
||||
End Function
|
||||
|
||||
Public Function decrement(astring) As String
|
||||
Dim result As String
|
||||
'decrement a string representing a positive number
|
||||
'does not work with zero or negative numbers
|
||||
borrow = 1
|
||||
L = Len(astring)
|
||||
result = ""
|
||||
For j = L To 1 Step -1
|
||||
digit = Val(Mid$(astring, j, 1)) - borrow
|
||||
If digit < 0 Then
|
||||
digit = digit + 10
|
||||
borrow = 1
|
||||
Else
|
||||
borrow = 0
|
||||
End If
|
||||
result = CStr(digit) & result
|
||||
Next
|
||||
'remove leading zero, if necessary
|
||||
If (Len(result) > 1) And (left$(result, 1) = "0") Then result = Mid$(result, 2)
|
||||
decrement = result
|
||||
End Function
|
||||
|
|
@ -0,0 +1 @@
|
|||
itoa(atoi(10)+1, 10)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
EOL
|
||||
do {
|
||||
if (At_BOL) {
|
||||
Ins_Char('1') // add new digit
|
||||
Break
|
||||
}
|
||||
Char(-1)
|
||||
#1 = Cur_Char+1 // digit
|
||||
#2 = 0 // carry bit
|
||||
if (#1 > '9') {
|
||||
#1 = '0'
|
||||
#2 = 1
|
||||
}
|
||||
Ins_Char(#1, OVERWRITE)
|
||||
Char(-1)
|
||||
} while (#2) // repeat until no carry
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Dim s As String = "123"
|
||||
|
||||
s = CStr(CInt("123") + 1)
|
||||
' or
|
||||
s = (CInt("123") + 1).ToString
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
string 0; \use zero-terminated string convention
|
||||
code Text=12;
|
||||
|
||||
func StrLen(A); \Return number of characters in an ASCIIZ string
|
||||
char A;
|
||||
int I;
|
||||
for I:= 0 to -1>>1-1 do
|
||||
if A(I) = 0 then return I;
|
||||
|
||||
proc IncStr(S); \Increment a numeric string
|
||||
char S;
|
||||
int I;
|
||||
[for I:= StrLen(S)-1 downto 0 do
|
||||
[S(I):= S(I)+1;
|
||||
if S(I) > ^9 then S(I):= S(I)-10 else return;
|
||||
];
|
||||
];
|
||||
|
||||
char Str;
|
||||
[Str:= "0123999999999"; \MSD first (big endian)
|
||||
IncStr(Str); IncStr(Str);
|
||||
Text(0, Str);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue