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
15
Task/Substring/Apex/substring.apex
Normal file
15
Task/Substring/Apex/substring.apex
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
String x = 'testing123';
|
||||
//Test1: testing123
|
||||
System.debug('Test1: ' + x.substring(0,x.length()));
|
||||
//Test2: esting123
|
||||
System.debug('Test2: ' + x.substring(1,x.length()));
|
||||
//Test3: testing123
|
||||
System.debug('Test3: ' + x.substring(0));
|
||||
//Test4: 3
|
||||
System.debug('Test4: ' + x.substring(x.length()-1));
|
||||
//Test5:
|
||||
System.debug('Test5: ' + x.substring(1,1));
|
||||
//Test 6: testing123
|
||||
System.debug('Test6: ' + x.substring(x.indexOf('testing')));
|
||||
//Test7: e
|
||||
System.debug('Test7: ' + x.substring(1,2));
|
||||
19
Task/Substring/Axe/substring.axe
Normal file
19
Task/Substring/Axe/substring.axe
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Lbl SUB1
|
||||
0→{r₁+r₂+r₃}
|
||||
r₁+r₂
|
||||
Return
|
||||
|
||||
Lbl SUB2
|
||||
r₁+r₂
|
||||
Return
|
||||
|
||||
Lbl SUB3
|
||||
0→{r₁+length(r₁)-1}
|
||||
r₁
|
||||
Return
|
||||
|
||||
Lbl SUB4
|
||||
inData(r₂,r₁)-1→I
|
||||
0→{r₁+I+r₃}
|
||||
r₁+I
|
||||
Return
|
||||
32
Task/Substring/ECL/substring.ecl
Normal file
32
Task/Substring/ECL/substring.ecl
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* In this task display a substring:
|
||||
|
||||
1. starting from n characters in and of m length;
|
||||
2. starting from n characters in, up to the end of the string;
|
||||
3. whole string minus last character;
|
||||
4. starting from a known character within the string and of m length;
|
||||
5. starting from a known substring within the string and of m length.
|
||||
*/
|
||||
|
||||
IMPORT STD; //imports a standard string library
|
||||
|
||||
TheString := 'abcdefghij';
|
||||
CharIn := 3; //n
|
||||
StrLength := 4; //m
|
||||
KnownChar := 'f';
|
||||
KnownSub := 'def';
|
||||
FindKnownChar := STD.Str.Find(TheString, KnownChar,1);
|
||||
FindKnownSub := STD.Str.Find(TheString, KnownSub,1);
|
||||
|
||||
OUTPUT(TheString[Charin..CharIn+StrLength-1]); //task1
|
||||
OUTPUT(TheString[Charin..]); //task2
|
||||
OUTPUT(TheString[1..LENGTH(TheString)-1]); //task3
|
||||
OUTPUT(TheString[FindKnownChar..FindKnownChar+StrLength-1]);//task4
|
||||
OUTPUT(TheString[FindKnownSub..FindKnownSub+StrLength-1]); //task5
|
||||
|
||||
/* OUTPUTS:
|
||||
defg
|
||||
cdefghij
|
||||
abcdefghi
|
||||
fghi
|
||||
defg
|
||||
*/
|
||||
13
Task/Substring/Eero/substring.eero
Normal file
13
Task/Substring/Eero/substring.eero
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main()
|
||||
autoreleasepool
|
||||
str := 'abcdefgh'
|
||||
n := 2
|
||||
m := 3
|
||||
Log( '%@', str[0 .. str.length-1] ) // abcdefgh
|
||||
Log( '%@', str[n .. m] ) // cd
|
||||
Log( '%@', str[n .. str.length-1] ) // cdefgh
|
||||
Log( '%@', str.substringFromIndex: n ) // cdefgh
|
||||
Log( '%@', str[(str.rangeOfString:'b').location .. m] ) // bcd
|
||||
return 0
|
||||
12
Task/Substring/FreeBASIC/substring.freebasic
Normal file
12
Task/Substring/FreeBASIC/substring.freebasic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim s As String = "123456789"
|
||||
Dim As Integer n = 3, m = 4
|
||||
Print Mid(s, n, m)
|
||||
Print Mid(s, n)
|
||||
Print Left(s, Len(s) - 1)
|
||||
'start from "5" say
|
||||
Print Mid(s, Instr(s, "5"), m)
|
||||
' start from "12" say
|
||||
Print Mid(s, Instr(s, "12"), m)
|
||||
Sleep
|
||||
18
Task/Substring/LFE/substring.lfe
Normal file
18
Task/Substring/LFE/substring.lfe
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
> (set n 3)
|
||||
3
|
||||
> (set m 5)
|
||||
5
|
||||
> (string:sub_string "abcdefghijklm" n)
|
||||
"cdefghijklm"
|
||||
> (string:sub_string "abcdefghijklm" n (+ n m -1))
|
||||
"cdefg"
|
||||
> (string:sub_string "abcdefghijklm" 1 (- (length "abcdefghijklm") 1))
|
||||
"abcdefghijkl"
|
||||
> (set char-index (string:chr "abcdefghijklm" #\e))
|
||||
5
|
||||
> (string:sub_string "abcdefghijklm" char-index (+ char-index m -1))
|
||||
"efghi"
|
||||
> (set start-str (string:str "abcdefghijklm" "efg"))
|
||||
5
|
||||
> (string:sub_string "abcdefghijklm" start-str (+ start-str m -1))
|
||||
"efghi"
|
||||
16
Task/Substring/Lasso/substring.lasso
Normal file
16
Task/Substring/Lasso/substring.lasso
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
local(str = 'The quick grey rhino jumped over the lazy green fox.')
|
||||
|
||||
//starting from n characters in and of m length;
|
||||
#str->substring(16,5) //rhino
|
||||
|
||||
//starting from n characters in, up to the end of the string
|
||||
#str->substring(16) //rhino jumped over the lazy green fox.
|
||||
|
||||
//whole string minus last character
|
||||
#str->substring(1,#str->size - 1) //The quick grey rhino jumped over the lazy green fox
|
||||
|
||||
//starting from a known character within the string and of m length;
|
||||
#str->substring(#str->find('g'),10) //grey rhino
|
||||
|
||||
//starting from a known substring within the string and of m length
|
||||
#str->substring(#str->find('rhino'),12) //rhino jumped
|
||||
30
Task/Substring/Lingo/substring.lingo
Normal file
30
Task/Substring/Lingo/substring.lingo
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
str = "The quick brown fox jumps over the lazy dog"
|
||||
|
||||
-- starting from n characters in and of m length
|
||||
n = 5
|
||||
m = 11
|
||||
put str.char[n..n+m-1]
|
||||
-- "quick brown"
|
||||
|
||||
-- starting from n characters in, up to the end of the string
|
||||
n = 11
|
||||
put str.char[n..str.length]
|
||||
-- "brown fox jumps over the lazy dog"
|
||||
|
||||
-- whole string minus last character
|
||||
put str.char[1..str.length-1]
|
||||
-- "The quick brown fox jumps over the lazy do"
|
||||
|
||||
-- starting from a known character within the string and of m length
|
||||
c = "x"
|
||||
m = 7
|
||||
pos = offset(c, str)
|
||||
put str.char[pos..pos+m-1]
|
||||
-- "x jumps"
|
||||
|
||||
-- starting from a known substring within the string and of m length
|
||||
sub = "fox"
|
||||
m = 9
|
||||
pos = offset(sub, str)
|
||||
put str.char[pos..pos+m-1]
|
||||
-- "fox jumps"
|
||||
6
Task/Substring/LiveCode/substring.livecode
Normal file
6
Task/Substring/LiveCode/substring.livecode
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
put "pple" into x
|
||||
answer char 2 to char 5 of x // n = 2, m=5
|
||||
answer char 2 to len(x) of x // n = 2, m = len(x), can also use -1
|
||||
answer char 1 to -2 of x // n = 1, m = 1 less than length of string
|
||||
answer char offset("p",x) to -1 of x // known char "p" to end of string
|
||||
answer char offset("pl",x) to -1 of x // known "pl" to end of string
|
||||
26
Task/Substring/Nim/substring.nim
Normal file
26
Task/Substring/Nim/substring.nim
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import strutils
|
||||
|
||||
let
|
||||
s = "abcdefgh"
|
||||
n = 2
|
||||
m = 3
|
||||
c = 'd'
|
||||
cs = "cd"
|
||||
var i = 0
|
||||
|
||||
# starting from n=2 characters in and m=3 in length
|
||||
echo s[n-1 .. n+m-2]
|
||||
|
||||
# starting from n characters in, up to the end of the string
|
||||
echo s[n-1 .. s.high]
|
||||
|
||||
# whole string minus last character:
|
||||
echo s[0 .. <s.high]
|
||||
|
||||
# starting from a known character c='d'within the string and of m length
|
||||
i = s.find(c)
|
||||
echo s[i .. <i+m]
|
||||
|
||||
# starting from a known substring cs="cd" within the string and of m length
|
||||
i = s.find(cs)
|
||||
echo s[i .. <i+m]
|
||||
6
Task/Substring/Oforth/substring.oforth
Normal file
6
Task/Substring/Oforth/substring.oforth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
: substrings(s, n, m)
|
||||
s sub(n, m) println
|
||||
s right(s size n - 1 +) println
|
||||
s left(s size 1 - ) println
|
||||
s sub(s indexOf('d'), m) println
|
||||
s sub(s indexOfAll("de"), m) println ;
|
||||
29
Task/Substring/Phix/substring-1.phix
Normal file
29
Task/Substring/Phix/substring-1.phix
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
--(1) starting from n characters in and of m length;
|
||||
--(2) starting from n characters in, up to the end of the string;
|
||||
--(3) whole string minus last character;
|
||||
--(4) starting from a known character within the string and of m length;
|
||||
--(5) starting from a known substring within the string and of m length.
|
||||
|
||||
constant sentence = "the last thing the man said was the",
|
||||
n = 10, m = 5
|
||||
integer k, l
|
||||
l = n+m-1
|
||||
if l<=length(sentence) then
|
||||
?sentence[n..l] -- (1)
|
||||
end if
|
||||
if n<=length(sentence) then
|
||||
?sentence[n..-1] -- (2) or [n..$]
|
||||
end if
|
||||
if length(sentence)>0 then
|
||||
?sentence[1..-2] -- (3) or [1..$-1]
|
||||
end if
|
||||
k = find('m',sentence)
|
||||
l = k+m-1
|
||||
if l<=length(sentence) then
|
||||
?sentence[k..l] -- (4)
|
||||
end if
|
||||
k = match("aid",sentence)
|
||||
l = k+m-1
|
||||
if l<=length(sentence) then
|
||||
?sentence[k..l] -- (5)
|
||||
end if
|
||||
5
Task/Substring/Phix/substring-2.phix
Normal file
5
Task/Substring/Phix/substring-2.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
?sentence[n..n+m-1]
|
||||
?sentence[n..-1]
|
||||
?sentence[1..-2]
|
||||
?(sentence[find('m',sentence)..$])[1..m]
|
||||
?(sentence[match("aid",sentence)..$])[1..m]
|
||||
12
Task/Substring/Ring/substring.ring
Normal file
12
Task/Substring/Ring/substring.ring
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
cStr = "a":"h" # 'abcdefgh'
|
||||
n = 3 m = 3
|
||||
# starting from n characters in and of m length
|
||||
See substr(cStr,n, m) + nl #=> cde
|
||||
# starting from n characters in, up to the end of the string
|
||||
See substr(cStr,n) + nl #=> cdefgh
|
||||
# whole string minus last character
|
||||
See substr(cstr,1,len(cStr)-1) + nl #=> abcdefg
|
||||
# starting from a known character within the string and of m length
|
||||
See substr(cStr,substr(cStr,"e"),m) +nl #=> efg
|
||||
# starting from a known substring within the string and of m length
|
||||
See substr(cStr,substr(cStr,"de"),m) +nl #=> def
|
||||
8
Task/Substring/Sidef/substring.sidef
Normal file
8
Task/Substring/Sidef/substring.sidef
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
var str = 'abcdefgh';
|
||||
var n = 2;
|
||||
var m = 3;
|
||||
say str.substr(n, m); #=> cde
|
||||
say str.substr(n); #=> cdefgh
|
||||
say str.substr(0, -1); #=> abcdefg
|
||||
say str.substr(str.index('d'), m); #=> def
|
||||
say str.substr(str.index('de'), m); #=> def
|
||||
57
Task/Substring/Swift/substring.swift
Normal file
57
Task/Substring/Swift/substring.swift
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
let string = "Hello, Swift language"
|
||||
let (n, m) = (5, 4)
|
||||
|
||||
// Starting from `n` characters in and of `m` length.
|
||||
do {
|
||||
let start = string.startIndex.advancedBy(n)
|
||||
let end = start.advancedBy(m)
|
||||
// Pure-Swift (standard library only):
|
||||
_ = string[start..<end]
|
||||
// With Apple's Foundation framework extensions:
|
||||
string.substringWithRange(start..<end)
|
||||
}
|
||||
|
||||
// Starting from `n` characters in, up to the end of the string.
|
||||
do {
|
||||
// Pure-Swift (standard library only):
|
||||
_ = String(
|
||||
string.characters.suffix(string.characters.count - n)
|
||||
)
|
||||
// With Apple's Foundation framework extensions:
|
||||
_ = string.substringFromIndex(string.startIndex.advancedBy(n))
|
||||
}
|
||||
|
||||
// Whole string minus last character.
|
||||
do {
|
||||
// Pure-Swift (standard library only):
|
||||
_ = String(
|
||||
string.characters.prefix(
|
||||
string.characters.count.predecessor()
|
||||
)
|
||||
)
|
||||
// With Apple's Foundation framework extensions:
|
||||
_ = string.substringToIndex(string.endIndex.predecessor())
|
||||
}
|
||||
|
||||
// Starting from a known character within the string and of `m` length.
|
||||
do {
|
||||
// Pure-Swift (standard library only):
|
||||
let character = Character("l")
|
||||
guard let characterIndex = string.characters.indexOf(character) else {
|
||||
fatalError("Index of '\(character)' character not found.")
|
||||
}
|
||||
let endIndex = characterIndex.advancedBy(m)
|
||||
_ = string[characterIndex..<endIndex]
|
||||
}
|
||||
|
||||
// Starting from a known substring within the string and of `m` length.
|
||||
do {
|
||||
// With Apple's Foundation framework extensions:
|
||||
let substring = "Swift"
|
||||
guard let range = string.rangeOfString(substring) else {
|
||||
fatalError("Range of substring \(substring) not found")
|
||||
}
|
||||
let start = range.startIndex
|
||||
let end = start.advancedBy(m)
|
||||
string[start..<end]
|
||||
}
|
||||
22
Task/Substring/Wart/substring.wart
Normal file
22
Task/Substring/Wart/substring.wart
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
s <- "abcdefgh"
|
||||
s.0
|
||||
=> "a"
|
||||
|
||||
# starting from n characters in and of m length;
|
||||
def (substr s start len)
|
||||
(s start start+len)
|
||||
(substr s 3 2)
|
||||
=> "de"
|
||||
|
||||
# starting from n characters in, up to the end of the string
|
||||
(s 3 nil)
|
||||
=> "defgh"
|
||||
|
||||
# whole string minus last character;
|
||||
(s 3 -1)
|
||||
=> "defg"
|
||||
|
||||
# starting from a known character within the string and of <tt>m</tt> length;
|
||||
# starting from a known substring within the string and of <tt>m</tt> length.
|
||||
let start (pos s pat)
|
||||
(s start start+m)
|
||||
1
Task/Substring/jq/substring-1.jq
Normal file
1
Task/Substring/jq/substring-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def s: "一二三四五六七八九十";
|
||||
1
Task/Substring/jq/substring-2.jq
Normal file
1
Task/Substring/jq/substring-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def ix(s): explode | index(s|explode);
|
||||
20
Task/Substring/jq/substring-3.jq
Normal file
20
Task/Substring/jq/substring-3.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# starting from n characters in and of m length: .[n+1: n+m+1]
|
||||
"s[1:2] => \( s[1:2] )",
|
||||
|
||||
# starting from n characters in, up to the end of the string: .[n+1:]
|
||||
"s[9:] => \( s[9:] )",
|
||||
|
||||
# whole string minus last character: .[0:length-1]
|
||||
"s|.[0:length-1] => \(s | .[0:length-1] )",
|
||||
|
||||
# starting from a known character within the string and of m length:
|
||||
# jq 1.4: ix(c) as $i | .[ $i: $i + m]
|
||||
# jq>1.4: match(c).offset as $i | .[ $i: $i + m]
|
||||
"s | ix(\"五\") as $i | .[$i: $i + 1] => \(s | ix("五") as $i | .[$i: $i + 1] )",
|
||||
|
||||
|
||||
# starting from a known substring within the string and of m length:
|
||||
# jq 1.4: ix(sub) as $i | .[ $i: $i + m]
|
||||
# jq>1.4: match(sub).offset as $i | .[ $i: $i + m]
|
||||
"s | ix(\"五六\") as $i | .[$i: $i + 2] => " +
|
||||
"\( s | ix("五六") as $i | .[$i: $i + 2] )"
|
||||
6
Task/Substring/jq/substring-4.jq
Normal file
6
Task/Substring/jq/substring-4.jq
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$ jq -M -n -r -f Substring.jq
|
||||
s[1:2] => 二
|
||||
s[9:] => 十
|
||||
s|.[0:length-1] => 一二三四五六七八九
|
||||
s | ix("五") as $i | .[$i: $i + 1] => 五
|
||||
s | ix("五六") as $i | .[$i: $i + 2] => 五六
|
||||
Loading…
Add table
Add a link
Reference in a new issue