September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,8 +1,4 @@
|
|||
10 REM STRING SLICING EXAMPLE
|
||||
20 LET S$="KNIGHTS"
|
||||
30 REM WITH FIRST CHARACTER REMOVED:
|
||||
40 PRINT S$(2 TO )
|
||||
50 REM WITH LAST CHARACTER REMOVED:
|
||||
60 PRINT S$( TO LEN S$-1)
|
||||
70 REM WITH BOTH REMOVED:
|
||||
80 PRINT S$(2 TO LEN S$-1)
|
||||
100 LET S$="Knights"
|
||||
110 PRINT S$(2:)
|
||||
120 PRINT S$(:LEN(S$)-1)
|
||||
130 PRINT S$(2:LEN(S$)-1)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
10 REM STRING SLICING EXAMPLE
|
||||
20 LET S$="KNIGHTS"
|
||||
30 REM WITH FIRST CHARACTER REMOVED:
|
||||
40 PRINT S$(2 TO )
|
||||
50 REM WITH LAST CHARACTER REMOVED:
|
||||
60 PRINT S$( TO LEN S$-1)
|
||||
70 REM WITH BOTH REMOVED:
|
||||
80 PRINT S$(2 TO LEN S$-1)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
identification division.
|
||||
program-id. toptail.
|
||||
|
||||
data division.
|
||||
working-storage section.
|
||||
01 data-field.
|
||||
05 value "[this is a test]".
|
||||
|
||||
procedure division.
|
||||
sample-main.
|
||||
display data-field
|
||||
*> Using reference modification, which is (start-position:length)
|
||||
display data-field(2:)
|
||||
display data-field(1:length of data-field - 1)
|
||||
display data-field(2:length of data-field - 2)
|
||||
goback.
|
||||
end program toptail.
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
program =
|
||||
[
|
||||
var testString := "test".
|
||||
public program()
|
||||
{
|
||||
var testString := "test";
|
||||
|
||||
console printLine(testString Substring(1)).
|
||||
console printLine(testString Substring(0, testString length - 1)).
|
||||
console printLine(testString Substring(1, testString length - 2)).
|
||||
].
|
||||
console.printLine(testString.Substring(1));
|
||||
console.printLine(testString.Substring(0, testString.Length - 1));
|
||||
console.printLine(testString.Substring(1, testString.Length - 2))
|
||||
}
|
||||
|
|
|
|||
11
Task/Substring-Top-and-tail/Neko/substring-top-and-tail.neko
Normal file
11
Task/Substring-Top-and-tail/Neko/substring-top-and-tail.neko
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
Subtring/Top-Tail in Neko
|
||||
*/
|
||||
|
||||
var data = "[this is a test]"
|
||||
var len = $ssize(data)
|
||||
|
||||
$print(data, "\n")
|
||||
$print($ssub(data, 1, len - 1), "\n")
|
||||
$print($ssub(data, 0, len - 1), "\n")
|
||||
$print($ssub(data, 1, len - 2), "\n")
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
from functools import (reduce)
|
||||
|
||||
|
||||
def main():
|
||||
for xs in transpose(
|
||||
(chunksOf(3)(
|
||||
ap([tail, init, compose(init)(tail)])(
|
||||
['knights', 'socks', 'brooms']
|
||||
)
|
||||
))
|
||||
):
|
||||
print(xs)
|
||||
|
||||
|
||||
# GENERIC -------------------------------------------------
|
||||
|
||||
# tail :: [a] -> [a]
|
||||
def tail(xs):
|
||||
return xs[1:]
|
||||
|
||||
|
||||
# init::[a] - > [a]
|
||||
def init(xs):
|
||||
return xs[:-1]
|
||||
|
||||
|
||||
# ap (<*>) :: [(a -> b)] -> [a] -> [b]
|
||||
def ap(fs):
|
||||
return lambda xs: reduce(
|
||||
lambda a, f: a + reduce(
|
||||
lambda a, x: a + [f(x)], xs, []
|
||||
), fs, []
|
||||
)
|
||||
|
||||
|
||||
# chunksOf :: Int -> [a] -> [[a]]
|
||||
def chunksOf(n):
|
||||
return lambda xs: reduce(
|
||||
lambda a, i: a + [xs[i:n + i]],
|
||||
range(0, len(xs), n), []
|
||||
) if 0 < n else []
|
||||
|
||||
|
||||
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
|
||||
def compose(g):
|
||||
return lambda f: lambda x: g(f(x))
|
||||
|
||||
|
||||
# transpose :: [[a]] -> [[a]]
|
||||
def transpose(xs):
|
||||
return list(map(list, zip(*xs)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
str='abcdefg'
|
||||
echo "${str#?}" # Remove first char
|
||||
echo "${str%?}" # Remove last char
|
||||
|
|
@ -0,0 +1 @@
|
|||
echo ${${str#?}%?} # Remove first & last chars
|
||||
|
|
@ -0,0 +1 @@
|
|||
echo "${s:1:${#s}-2}"
|
||||
|
|
@ -0,0 +1 @@
|
|||
tmp=${s#?}; tmp=${tmp%?}; echo "$tmp"
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
#!/bin/zsh
|
||||
str='abcdefg'
|
||||
echo ${str#?} # Remove first char
|
||||
echo ${str%?} # Remove last char
|
||||
echo ${${str#?}%?} # Remove first & last chars
|
||||
Loading…
Add table
Add a link
Reference in a new issue