September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,70 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* Constraints: input is in the form of (\+|-)?[0-9]+
* and without leading zero (0 itself can be as "0" or "+0", but not "-0");
* input pointer is realloc'able and may change;
* if input has leading + sign, return may or may not keep it.
* The constranits conform to sprintf("%+d") and this function's own output.
*/
char * incr(char *s)
{
int i, begin, tail, len;
int neg = (*s == '-');
char tgt = neg ? '0' : '9';
/* special case: "-1" */
if (!strcmp(s, "-1")) {
s[0] = '0', s[1] = '\0';
return s;
}
len = strlen(s);
begin = (*s == '-' || *s == '+') ? 1 : 0;
/* find out how many digits need to be changed */
for (tail = len - 1; tail >= begin && s[tail] == tgt; tail--);
if (tail < begin && !neg) {
/* special case: all 9s, string will grow */
if (!begin) s = realloc(s, len + 2);
s[0] = '1';
for (i = 1; i <= len - begin; i++) s[i] = '0';
s[len + 1] = '\0';
} else if (tail == begin && neg && s[1] == '1') {
/* special case: -1000..., so string will shrink */
for (i = 1; i < len - begin; i++) s[i] = '9';
s[len - 1] = '\0';
} else { /* normal case; change tail to all 0 or 9, change prev digit by 1*/
for (i = len - 1; i > tail; i--)
s[i] = neg ? '9' : '0';
s[tail] += neg ? -1 : 1;
}
return s;
}
void string_test(const char *s)
{
char *ret = malloc(strlen(s));
strcpy(ret, s);
printf("text: %s\n", ret);
printf(" ->: %s\n", ret = incr(ret));
free(ret);
}
int main()
{
string_test("+0");
string_test("-1");
string_test("-41");
string_test("+41");
string_test("999");
string_test("+999");
string_test("109999999999999999999999999999999999999999");
string_test("-100000000000000000000000000000000000000000000");
return 0;
}

View file

@ -1,16 +0,0 @@
text: +0
->: +1
text: -1
->: 0
text: -41
->: -40
text: +41
->: +42
text: 999
->: 1000
text: +999
->: 1000
text: 109999999999999999999999999999999999999999
->: 110000000000000000000000000000000000000000
text: -100000000000000000000000000000000000000000000
->: -99999999999999999999999999999999999999999999

View file

@ -0,0 +1,7 @@
Public Sub Main()
Dim vInput As Variant = "12345"
Inc vInput
Print vInput
End

View file

@ -0,0 +1 @@
(show . succ) (read "1234" :: Int)

View file

@ -0,0 +1 @@
(str (inc (int "123")))

View file

@ -0,0 +1 @@
(-> "123" (int) (inc) (str))

View file

@ -0,0 +1,4 @@
let s = '9999';
let splusplus = (+s+1)+""
console.log([splusplus, typeof splusplus]) // 10000,string

View file

@ -0,0 +1,14 @@
(() => {
'use strict';
// stringSucc :: Maybe String -> Maybe String
const stringSucc = s =>
isNaN(s) ? undefined : (Number(s) + 1).toString();
// show :: a -> String
const show = x => JSON.stringify(x, null, 2);
return show(
['2', '4', '8', '16', 'anomaly'].map(stringSucc)
);
})();

View file

@ -1,2 +0,0 @@
var s = "12345";
+s++

View file

@ -0,0 +1,18 @@
// version 1.0.5-2
/** overload ++ operator to increment a numeric string */
operator fun String.inc(): String =
try {
val num = this.toInt()
(num + 1).toString()
}
catch(e: NumberFormatException) {
this // return string unaltered
}
fun main(args: Array<String>) {
var ns = "12345"
println(++ns)
ns = "ghijk" // not numeric, so won't be changed by increment operator
println(++ns)
}

View file

@ -0,0 +1,3 @@
var %n = 12345
inc %n
echo -ag %n

View file

@ -0,0 +1,6 @@
\newcount\acounter
\def\stringinc#1{\acounter=#1\relax%
\advance\acounter by 1\relax%
\number\acounter}
The number 12345 is followed by \stringinc{12345}.
\bye

View file

@ -1,3 +0,0 @@
import String;
public str IncrNumStr(str s) = "<toInt(s) + 1>";

View file

@ -1,2 +0,0 @@
rascal>IncrNumStr("123")
str: "124"

View file

@ -0,0 +1,3 @@
import <Utilities/Conversion.sl>;
increment(input(1)) := intToString(stringToInt(input) + 1);

View file

@ -1 +0,0 @@
Int.toString (1 + valOf (Int.fromString "1234"))

View file

@ -0,0 +1,2 @@
fcn numStringPlusOne(s){1+s}
numStringPlusOne("123") //-->124