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
2
Task/String-length/Apex/string-length.apex
Normal file
2
Task/String-length/Apex/string-length.apex
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
String myString = 'abcd';
|
||||
System.debug('Size of String', myString.length());
|
||||
2
Task/String-length/Axe/string-length.axe
Normal file
2
Task/String-length/Axe/string-length.axe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"HELLO, WORLD"→Str1
|
||||
Disp length(Str1)▶Dec,i
|
||||
23
Task/String-length/FreeBASIC/string-length.freebasic
Normal file
23
Task/String-length/FreeBASIC/string-length.freebasic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Dim s As String = "moose" '' variable length ascii string
|
||||
Dim f As String * 5 = "moose" '' fixed length ascii string (in practice a zero byte is appended)
|
||||
Dim z As ZString * 6 = "moose" '' fixed length zero terminated ascii string
|
||||
Dim w As WString * 6 = "møøse" '' fixed length zero terminated unicode string
|
||||
|
||||
' Variable length strings have a descriptor consisting of 3 Integers (12 bytes on 32 bit, 24 bytes on 64 bit systems)
|
||||
' In order, the descriptor contains the address of the data, the memory currently used and the memory allocated
|
||||
|
||||
' In Windows, WString uses UCS-2 encoding (i.e. 2 bytes per character, surrogates are not supported)
|
||||
' In Linux, WString uses UCS-4 encoding (i.e. 4 bytes per character)
|
||||
|
||||
' The Len function always returns the length of the string in characters
|
||||
' The SizeOf function returns the bytes used (by the descriptor in the case of variable length strings)
|
||||
|
||||
Print "s : " ; s, "Character Length : "; Len(s), "Byte Length : "; Len(s); " (data)"
|
||||
Print "s : " ; s, "Character Length : "; Len(s), "Byte Length : "; SizeOf(s); " (descriptor)"
|
||||
Print "f : " ; f, "Character Length : "; Len(s), "Byte Length : "; SizeOf(f)
|
||||
Print "z : " ; z, "Character Length : "; Len(s), "Byte Length : "; SizeOf(z)
|
||||
Print "w : " ; w, "Character Length : "; Len(s), "Byte Length : "; SizeOf(w)
|
||||
Print
|
||||
Sleep
|
||||
8
Task/String-length/LFE/string-length-1.lfe
Normal file
8
Task/String-length/LFE/string-length-1.lfe
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(length "ASCII text")
|
||||
10
|
||||
(length "𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱")
|
||||
12
|
||||
> (set encoded (binary ("𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱" utf8)))
|
||||
#B(240 157 148 152 240 157 148 171 240 157 ...)
|
||||
> (length (unicode:characters_to_list encoded 'utf8))
|
||||
12
|
||||
12
Task/String-length/LFE/string-length-2.lfe
Normal file
12
Task/String-length/LFE/string-length-2.lfe
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
> (set encoded (binary ("𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱" utf8)))
|
||||
#B(240 157 148 152 240 157 148 171 240 157 ...)
|
||||
> (byte_size encoded)
|
||||
45
|
||||
> (set bytes (binary ("𝔘𝔫𝔦𝔠𝔬𝔡𝔢 𝔗𝔢𝒙𝔱")))
|
||||
#B(24 43 38 32 44 33 34 32 23 34 153 49)
|
||||
> (byte_size bytes)
|
||||
12
|
||||
> (set encoded (binary ("ASCII text" utf8)))
|
||||
#B(65 83 67 73 73 32 116 101 120 116)
|
||||
> (byte_size encoded)
|
||||
10
|
||||
3
Task/String-length/Lasso/string-length-1.lasso
Normal file
3
Task/String-length/Lasso/string-length-1.lasso
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
'Hello, world!'->size // 13
|
||||
'møøse'->size // 5
|
||||
'𝔘𝔫𝔦𝔠𝔬𝔡𝔢'->size // 7
|
||||
3
Task/String-length/Lasso/string-length-2.lasso
Normal file
3
Task/String-length/Lasso/string-length-2.lasso
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
'Hello, world!'->asBytes->size // 13
|
||||
'møøse'->asBytes->size // 7
|
||||
'𝔘𝔫𝔦𝔠𝔬𝔡𝔢'->asBytes->size // 28
|
||||
3
Task/String-length/Lingo/string-length-1.lingo
Normal file
3
Task/String-length/Lingo/string-length-1.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
utf8Str = "Hello world äöü"
|
||||
put utf8Str.length
|
||||
-- 15
|
||||
3
Task/String-length/Lingo/string-length-2.lingo
Normal file
3
Task/String-length/Lingo/string-length-2.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
utf8Str = "Hello world äöü"
|
||||
put bytearray(utf8Str).length
|
||||
-- 18
|
||||
4
Task/String-length/Nim/string-length-1.nim
Normal file
4
Task/String-length/Nim/string-length-1.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has byte length: ", len(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 17
|
||||
6
Task/String-length/Nim/string-length-2.nim
Normal file
6
Task/String-length/Nim/string-length-2.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import unicode
|
||||
|
||||
var s: string = "Hello, world! ☺"
|
||||
echo '"',s, '"'," has unicode char length: ", runeLen(s)
|
||||
|
||||
# -> "Hello, world! ☺" has unicode char length: 15
|
||||
2
Task/String-length/Phix/string-length.phix
Normal file
2
Task/String-length/Phix/string-length.phix
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
constant s = "𝔘𝔫𝔦𝔠𝔬𝔡𝔢"
|
||||
?length(s)
|
||||
3
Task/String-length/Potion/string-length.potion
Normal file
3
Task/String-length/Potion/string-length.potion
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
"møøse" length print
|
||||
"𝔘𝔫𝔦𝔠𝔬𝔡𝔢" length print
|
||||
"J̲o̲s̲é̲" length print
|
||||
3
Task/String-length/Ring/string-length.ring
Normal file
3
Task/String-length/Ring/string-length.ring
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
aString = "Welcome to the Ring Programming Language"
|
||||
aStringSize = len(aString)
|
||||
see "Character lenghts : " + aStringSize
|
||||
1
Task/String-length/Sidef/string-length-1.sidef
Normal file
1
Task/String-length/Sidef/string-length-1.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
var str = "J\x{332}o\x{332}s\x{332}e\x{301}\x{332}";
|
||||
1
Task/String-length/Sidef/string-length-2.sidef
Normal file
1
Task/String-length/Sidef/string-length-2.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
say str.bytes.len; #=> 14
|
||||
1
Task/String-length/Sidef/string-length-3.sidef
Normal file
1
Task/String-length/Sidef/string-length-3.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
say str.encode('UTF-16').bytes.len; #=> 20
|
||||
1
Task/String-length/Sidef/string-length-4.sidef
Normal file
1
Task/String-length/Sidef/string-length-4.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
say str.chars.len; #=> 9
|
||||
1
Task/String-length/Sidef/string-length-5.sidef
Normal file
1
Task/String-length/Sidef/string-length-5.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
say str.graphs.len; #=> 4
|
||||
2
Task/String-length/Sparkling/string-length.sparkling
Normal file
2
Task/String-length/Sparkling/string-length.sparkling
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
spn:1> sizeof "Hello, wørld!"
|
||||
= 14
|
||||
1
Task/String-length/Swift/string-length-1.swift
Normal file
1
Task/String-length/Swift/string-length-1.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCharacters = "møøse".characters.count // 5
|
||||
1
Task/String-length/Swift/string-length-10.swift
Normal file
1
Task/String-length/Swift/string-length-10.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF16 = "møøse".utf16.count * 2 // 10
|
||||
1
Task/String-length/Swift/string-length-11.swift
Normal file
1
Task/String-length/Swift/string-length-11.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF16 = count("møøse".utf16) * 2 // 10
|
||||
1
Task/String-length/Swift/string-length-12.swift
Normal file
1
Task/String-length/Swift/string-length-12.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF16 = countElements("møøse".utf16) * 2 // 10
|
||||
1
Task/String-length/Swift/string-length-2.swift
Normal file
1
Task/String-length/Swift/string-length-2.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCharacters = count("møøse") // 5
|
||||
1
Task/String-length/Swift/string-length-3.swift
Normal file
1
Task/String-length/Swift/string-length-3.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCharacters = countElements("møøse") // 5
|
||||
1
Task/String-length/Swift/string-length-4.swift
Normal file
1
Task/String-length/Swift/string-length-4.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCodePoints = "møøse".unicodeScalars.count // 5
|
||||
1
Task/String-length/Swift/string-length-5.swift
Normal file
1
Task/String-length/Swift/string-length-5.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCodePoints = count("møøse".unicodeScalars) // 5
|
||||
1
Task/String-length/Swift/string-length-6.swift
Normal file
1
Task/String-length/Swift/string-length-6.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfCodePoints = countElements("møøse".unicodeScalars) // 5
|
||||
1
Task/String-length/Swift/string-length-7.swift
Normal file
1
Task/String-length/Swift/string-length-7.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF8 = "møøse".utf8.count // 7
|
||||
1
Task/String-length/Swift/string-length-8.swift
Normal file
1
Task/String-length/Swift/string-length-8.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF8 = count("møøse".utf8) // 7
|
||||
1
Task/String-length/Swift/string-length-9.swift
Normal file
1
Task/String-length/Swift/string-length-9.swift
Normal file
|
|
@ -0,0 +1 @@
|
|||
let numberOfBytesUTF8 = countElements("møøse".utf8) // 7
|
||||
3
Task/String-length/Wren/string-length-1.wren
Normal file
3
Task/String-length/Wren/string-length-1.wren
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
System.print("møøse".bytes.count)
|
||||
System.print("𝔘𝔫𝔦𝔠𝔬𝔡𝔢".bytes.count)
|
||||
System.print("J̲o̲s̲é̲".bytes.count)
|
||||
3
Task/String-length/Wren/string-length-2.wren
Normal file
3
Task/String-length/Wren/string-length-2.wren
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
System.print("møøse".count)
|
||||
System.print("𝔘𝔫𝔦𝔠𝔬𝔡𝔢".count)
|
||||
System.print("J̲o̲s̲é̲".count)
|
||||
5
Task/String-length/jq/string-length-1.jq
Normal file
5
Task/String-length/jq/string-length-1.jq
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$ cat String_length.jq
|
||||
def describe:
|
||||
"length of \(.) is \(length)";
|
||||
|
||||
("J̲o̲s̲é̲", "𝔘𝔫𝔦𝔠𝔬𝔡𝔢") | describe
|
||||
3
Task/String-length/jq/string-length-2.jq
Normal file
3
Task/String-length/jq/string-length-2.jq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$ jq -n -f String_length.jq
|
||||
"length of J̲o̲s̲é̲ is 8"
|
||||
"length of 𝔘𝔫𝔦𝔠𝔬𝔡𝔢 is 7"
|
||||
Loading…
Add table
Add a link
Reference in a new issue