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
1
Task/Reverse-a-string/8th/reverse-a-string.8th
Normal file
1
Task/Reverse-a-string/8th/reverse-a-string.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
"abc" s:rev
|
||||
3
Task/Reverse-a-string/Apex/reverse-a-string-1.apex
Normal file
3
Task/Reverse-a-string/Apex/reverse-a-string-1.apex
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
String str = 'Hello World!';
|
||||
str = str.reverse();
|
||||
system.debug(str);
|
||||
2
Task/Reverse-a-string/Apex/reverse-a-string-2.apex
Normal file
2
Task/Reverse-a-string/Apex/reverse-a-string-2.apex
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
⌽'asdf'
|
||||
fdsa
|
||||
15
Task/Reverse-a-string/ERRE/reverse-a-string.erre
Normal file
15
Task/Reverse-a-string/ERRE/reverse-a-string.erre
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
PROGRAM REVERSE_STRING
|
||||
|
||||
PROCEDURE REVERSE(A$->R$)
|
||||
LOCAL I%
|
||||
R$=""
|
||||
FOR I=1 TO LEN(A$) DO
|
||||
R$=MID$(A$,I,1)+R$
|
||||
END FOR
|
||||
END PROCEDURE
|
||||
|
||||
BEGIN
|
||||
A$="THE FIVE BOXING WIZARDS JUMP QUICKLY"
|
||||
REVERSE(A$->R$)
|
||||
PRINT(R$)
|
||||
END PROGRAM
|
||||
7
Task/Reverse-a-string/EchoLisp/reverse-a-string.echolisp
Normal file
7
Task/Reverse-a-string/EchoLisp/reverse-a-string.echolisp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(define (string-reverse string)
|
||||
(list->string (reverse (string->list string))))
|
||||
|
||||
(string-reverse "ghij")
|
||||
→ jihg
|
||||
(string-reverse "un roc lamina l animal cornu")
|
||||
→ unroc lamina l animal cor nu
|
||||
39
Task/Reverse-a-string/Elm/reverse-a-string.elm
Normal file
39
Task/Reverse-a-string/Elm/reverse-a-string.elm
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
-- The import on the next line provides the reverse string
|
||||
-- functionality satisfying the rosettacode.org task description.
|
||||
import String exposing (reverse)
|
||||
|
||||
-- The rest is fairly boilerplate code demonstrating
|
||||
-- interactively that the reverse function works.
|
||||
import Html exposing (Html, Attribute, text, div, input)
|
||||
import Html.Attributes exposing (placeholder, value, style)
|
||||
import Html.Events exposing (on, targetValue)
|
||||
import Html.App exposing (beginnerProgram)
|
||||
|
||||
main = beginnerProgram { model = "", view = view, update = update }
|
||||
|
||||
update newStr oldStr = newStr
|
||||
|
||||
view : String -> Html String
|
||||
view forward =
|
||||
div []
|
||||
([ input
|
||||
[ placeholder "Enter a string to be reversed."
|
||||
, value forward
|
||||
, on "input" targetValue
|
||||
, myStyle
|
||||
]
|
||||
[]
|
||||
] ++
|
||||
[ let backward = reverse forward
|
||||
in div [ myStyle] [text backward]
|
||||
])
|
||||
|
||||
myStyle : Attribute msg
|
||||
myStyle =
|
||||
style
|
||||
[ ("width", "100%")
|
||||
, ("height", "20px")
|
||||
, ("padding", "5px 0 0 5px")
|
||||
, ("font-size", "1em")
|
||||
, ("text-align", "left")
|
||||
]
|
||||
44
Task/Reverse-a-string/Ezhil/reverse-a-string.ezhil
Normal file
44
Task/Reverse-a-string/Ezhil/reverse-a-string.ezhil
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
## இந்த நிரல் தரப்படும் சரம் ஒன்றைத் தலைகீழாகத் திருப்பி அச்சிடும்
|
||||
## உதாரணமாக "abc" என்ற சரம் தரப்பட்டால் அதனைத் திருப்பி "cba" என அச்சிடும்
|
||||
## "எழில்" மொழியின்மூலம் இரண்டு வகைகளில் இதனைச் செய்யலாம். இரண்டு உதாரணங்களும் இங்கே தரப்பட்டுள்ளன
|
||||
|
||||
நிரல்பாகம் திருப்புக (சரம்1)
|
||||
|
||||
## முதல் வகை
|
||||
|
||||
சரம்2 = ""
|
||||
|
||||
@( சரம்1 இல் இ) ஒவ்வொன்றாக
|
||||
சரம்2 = இ + சரம்2
|
||||
முடி
|
||||
|
||||
பின்கொடு சரம்2
|
||||
|
||||
முடி
|
||||
|
||||
நிரல்பாகம் மீண்டும்திருப்புக (சரம்1)
|
||||
|
||||
## இரண்டாம் வகை
|
||||
|
||||
சரநீளம் = len(சரம்1)
|
||||
|
||||
சரம்2 = ""
|
||||
|
||||
@(எண் = 0, எண் < சரநீளம், எண் = எண் + 1) ஆக
|
||||
|
||||
சரம்2 = எடு(சரம்1, எண்) + சரம்2
|
||||
|
||||
முடி
|
||||
|
||||
பின்கொடு சரம்2
|
||||
|
||||
முடி
|
||||
|
||||
|
||||
அ = உள்ளீடு("ஓர் எழுத்துச் சரத்தைத் தாருங்கள் ")
|
||||
|
||||
பதிப்பி "நீங்கள் தந்த எழுத்துச் சரம்" அ
|
||||
|
||||
பதிப்பி "அதனை முதல் வகையில் திருப்பியுள்ளோம்: " திருப்புக(அ)
|
||||
|
||||
பதிப்பி "வேறொரு வகையில் திருப்பியுள்ளோம்: " மீண்டும்திருப்புக(அ)
|
||||
14
Task/Reverse-a-string/FreeBASIC/reverse-a-string.freebasic
Normal file
14
Task/Reverse-a-string/FreeBASIC/reverse-a-string.freebasic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function ReverseString(s As Const String) As String
|
||||
If s = "" Then Return s
|
||||
Dim length As Integer = Len(s)
|
||||
Dim r As String = Space(length)
|
||||
For i As Integer = 0 To length - 1
|
||||
r[i] = s[length - 1 - i]
|
||||
Next
|
||||
Return r
|
||||
End Function
|
||||
|
||||
Dim s As String = "asdf"
|
||||
Print "'"; s; "' reversed is '"; ReverseString(s); "'"
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
dim as Str31 str
|
||||
dim as long i
|
||||
|
||||
str = "123456789abcdefghijk"
|
||||
|
||||
print str
|
||||
print
|
||||
|
||||
for i = str[0] to 1 step -1
|
||||
print mid$( str, i, 1 );
|
||||
next i
|
||||
10
Task/Reverse-a-string/GFA-Basic/reverse-a-string.gfa
Normal file
10
Task/Reverse-a-string/GFA-Basic/reverse-a-string.gfa
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
PRINT @reverse$("asdf")
|
||||
'
|
||||
FUNCTION reverse$(string$)
|
||||
LOCAL result$,i%
|
||||
result$=""
|
||||
FOR i%=1 TO LEN(string$)
|
||||
result$=MID$(string$,i%,1)+result$
|
||||
NEXT i%
|
||||
RETURN result$
|
||||
ENDFUNC
|
||||
9
Task/Reverse-a-string/Harbour/reverse-a-string.harbour
Normal file
9
Task/Reverse-a-string/Harbour/reverse-a-string.harbour
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
FUNCTION Reverse( sIn )
|
||||
|
||||
LOCAL cOut := "", i
|
||||
|
||||
FOR i := Len( sIn ) TO 1 STEP -1
|
||||
cOut += Substr( sIn, i, 1 )
|
||||
NEXT
|
||||
|
||||
RETURN cOut
|
||||
6
Task/Reverse-a-string/L++/reverse-a-string.lpp
Normal file
6
Task/Reverse-a-string/L++/reverse-a-string.lpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(include "string" "algorithm")
|
||||
(main
|
||||
(decl std::string s)
|
||||
(std::getline std::cin s)
|
||||
(std::reverse (s.begin) (s.end))
|
||||
(prn s))
|
||||
35
Task/Reverse-a-string/LC3-Assembly/reverse-a-string.lc3
Normal file
35
Task/Reverse-a-string/LC3-Assembly/reverse-a-string.lc3
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
.ORIG 0x3000
|
||||
|
||||
LEA R1,STRING
|
||||
LEA R2,GNIRTS
|
||||
LD R3,MINUS1
|
||||
NOT R5,R1
|
||||
ADD R5,R5,1
|
||||
|
||||
SCAN LDR R4,R1,0
|
||||
BRZ COPY
|
||||
ADD R1,R1,1
|
||||
BRNZP SCAN
|
||||
|
||||
COPY ADD R1,R1,R3
|
||||
ADD R4,R1,R5
|
||||
BRN COPIED
|
||||
LDR R4,R1,0
|
||||
STR R4,R2,0
|
||||
ADD R2,R2,1
|
||||
BRNZP COPY
|
||||
|
||||
COPIED AND R4,R4,0
|
||||
STR R4,R2,0
|
||||
|
||||
LEA R0,GNIRTS
|
||||
PUTS
|
||||
|
||||
HALT
|
||||
|
||||
MINUS1 .FILL 0xFFFF
|
||||
|
||||
STRING .STRINGZ "If thou beest he -- but O how fall'n! how chang'd"
|
||||
GNIRTS .BLKW 128
|
||||
|
||||
.END
|
||||
2
Task/Reverse-a-string/LFE/reverse-a-string-1.lfe
Normal file
2
Task/Reverse-a-string/LFE/reverse-a-string-1.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (lists:reverse "asdf")
|
||||
"fdsa"
|
||||
2
Task/Reverse-a-string/LFE/reverse-a-string-2.lfe
Normal file
2
Task/Reverse-a-string/LFE/reverse-a-string-2.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (set encoded (binary ("åäö ð" utf8)))
|
||||
#B(195 165 195 164 195 182 32 195 176)
|
||||
2
Task/Reverse-a-string/LFE/reverse-a-string-3.lfe
Normal file
2
Task/Reverse-a-string/LFE/reverse-a-string-3.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (io:format "~tp~n" (list encoded))
|
||||
<<"åäö ð"/utf8>>
|
||||
2
Task/Reverse-a-string/LFE/reverse-a-string-4.lfe
Normal file
2
Task/Reverse-a-string/LFE/reverse-a-string-4.lfe
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> (lists:reverse (unicode:characters_to_list encoded))
|
||||
"ð öäå"
|
||||
2
Task/Reverse-a-string/Lasso/reverse-a-string-1.lasso
Normal file
2
Task/Reverse-a-string/Lasso/reverse-a-string-1.lasso
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local(input) = 'asdf'
|
||||
#input->reverse
|
||||
4
Task/Reverse-a-string/Lasso/reverse-a-string-2.lasso
Normal file
4
Task/Reverse-a-string/Lasso/reverse-a-string-2.lasso
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
local(input = 'asdf', output = array)
|
||||
with i in #input->values
|
||||
do #output->insertFirst(#i)
|
||||
#output->join
|
||||
7
Task/Reverse-a-string/Lingo/reverse-a-string-1.lingo
Normal file
7
Task/Reverse-a-string/Lingo/reverse-a-string-1.lingo
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
on reverse (str)
|
||||
res = ""
|
||||
repeat with i = str.length down to 1
|
||||
put str.char[i] after res
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
8
Task/Reverse-a-string/Lingo/reverse-a-string-2.lingo
Normal file
8
Task/Reverse-a-string/Lingo/reverse-a-string-2.lingo
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
on reverseBytes (str)
|
||||
ba = byteArray(str)
|
||||
res = byteArray()
|
||||
repeat with i = ba.length down to 1
|
||||
res[res.length+1] = ba[i]
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
6
Task/Reverse-a-string/LiveCode/reverse-a-string.livecode
Normal file
6
Task/Reverse-a-string/LiveCode/reverse-a-string.livecode
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
function reverseString S
|
||||
repeat with i = length(S) down to 1
|
||||
put char i of S after R
|
||||
end repeat
|
||||
return R
|
||||
end reverseString
|
||||
39
Task/Reverse-a-string/Nim/reverse-a-string.nim
Normal file
39
Task/Reverse-a-string/Nim/reverse-a-string.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import unicode
|
||||
|
||||
proc reverse(s: var string) =
|
||||
for i in 0 .. s.high div 2:
|
||||
swap(s[i], s[s.high - i])
|
||||
|
||||
proc reversed(s: string): string =
|
||||
result = newString(s.len)
|
||||
for i,c in s:
|
||||
result[s.high - i] = c
|
||||
|
||||
proc uniReversed(s: string): string =
|
||||
result = newStringOfCap(s.len)
|
||||
var tmp: seq[Rune] = @[]
|
||||
for r in runes(s):
|
||||
tmp.add(r)
|
||||
for i in countdown(tmp.high, 0):
|
||||
result.add(toUtf8(tmp[i]))
|
||||
|
||||
proc isComb(r: Rune): bool =
|
||||
(r >=% Rune(0x300) and r <=% Rune(0x36f)) or
|
||||
(r >=% Rune(0x1dc0) and r <=% Rune(0x1dff)) or
|
||||
(r >=% Rune(0x20d0) and r <=% Rune(0x20ff)) or
|
||||
(r >=% Rune(0xfe20) and r <=% Rune(0xfe2f))
|
||||
|
||||
proc uniReversedPreserving(s: string): string =
|
||||
result = newStringOfCap(s.len)
|
||||
var tmp: seq[Rune] = @[]
|
||||
for r in runes(s):
|
||||
if isComb(r): tmp.insert(r, tmp.high)
|
||||
else: tmp.add(r)
|
||||
for i in countdown(tmp.high, 0):
|
||||
result.add(toUtf8(tmp[i]))
|
||||
|
||||
for str in ["Reverse This!", "as⃝df̅"]:
|
||||
echo "Original string: ", str
|
||||
echo "Reversed: ", reversed(str)
|
||||
echo "UniReversed: ", uniReversed(str)
|
||||
echo "UniReversedPreserving: ", uniReversedPreserving(str)
|
||||
1
Task/Reverse-a-string/Oforth/reverse-a-string.oforth
Normal file
1
Task/Reverse-a-string/Oforth/reverse-a-string.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
reverse
|
||||
1
Task/Reverse-a-string/Peloton/reverse-a-string-1.peloton
Normal file
1
Task/Reverse-a-string/Peloton/reverse-a-string-1.peloton
Normal file
|
|
@ -0,0 +1 @@
|
|||
<# 显示 指定 变量 反转顺序 字串>集装箱|猫坐在垫子</#>
|
||||
1
Task/Reverse-a-string/Peloton/reverse-a-string-2.peloton
Normal file
1
Task/Reverse-a-string/Peloton/reverse-a-string-2.peloton
Normal file
|
|
@ -0,0 +1 @@
|
|||
<# 보이십 할당하 변물건 열거꾸 문자그>컨테이너|고양이가 매트 위에 앉아</#>
|
||||
1
Task/Reverse-a-string/Peloton/reverse-a-string-3.peloton
Normal file
1
Task/Reverse-a-string/Peloton/reverse-a-string-3.peloton
Normal file
|
|
@ -0,0 +1 @@
|
|||
<@ SAYLETVARREVLIT>集装箱|猫坐在垫子</@>
|
||||
1
Task/Reverse-a-string/Phix/reverse-a-string-1.phix
Normal file
1
Task/Reverse-a-string/Phix/reverse-a-string-1.phix
Normal file
|
|
@ -0,0 +1 @@
|
|||
?reverse("asdf")
|
||||
19
Task/Reverse-a-string/Phix/reverse-a-string-2.phix
Normal file
19
Task/Reverse-a-string/Phix/reverse-a-string-2.phix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
function unicode_reverse(string utf8)
|
||||
sequence utf32 = utf8_to_utf32(utf8)
|
||||
integer ch
|
||||
-- the assumption is made that <char><comb1><comb2>
|
||||
-- and <char><comb2><comb1> etc would work the same.
|
||||
for i=1 to length(utf32) do
|
||||
ch = utf32[i]
|
||||
if (ch>=0x300 and ch<=0x36f)
|
||||
or (ch>=0x1dc0 and ch<=0x1dff)
|
||||
or (ch>=0x20d0 and ch<=0x20ff)
|
||||
or (ch>=0xfe20 and ch<=0xfe2f) then
|
||||
utf32[i] = utf32[i-1]
|
||||
utf32[i-1] = ch
|
||||
end if
|
||||
end for
|
||||
utf32 = reverse(utf32)
|
||||
utf8 = utf32_to_utf8(utf32)
|
||||
return utf8
|
||||
end function
|
||||
3
Task/Reverse-a-string/Ring/reverse-a-string.ring
Normal file
3
Task/Reverse-a-string/Ring/reverse-a-string.ring
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
cStr = "asdf" cStr2 = ""
|
||||
for x = len(cStr) to 1 step -1 cStr2 += cStr[x] next
|
||||
See cStr2 # fdsa
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import <Utilities/Sequence.sl>;
|
||||
|
||||
main(args(2)) := Sequence::reverse(args[1]);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
reverse<T> : T(1) -> T(1);
|
||||
reverse(list(1))[i] :=
|
||||
let
|
||||
range := - ((1 ... size(list)) - (size(list) + 1));
|
||||
in
|
||||
list[i] foreach i within range;
|
||||
2
Task/Reverse-a-string/Sidef/reverse-a-string.sidef
Normal file
2
Task/Reverse-a-string/Sidef/reverse-a-string.sidef
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"asdf".reverse; # fdsa
|
||||
"résumé niño".reverse; # oñin émusér
|
||||
5
Task/Reverse-a-string/Swift/reverse-a-string-1.swift
Normal file
5
Task/Reverse-a-string/Swift/reverse-a-string-1.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func reverseString(s: String) -> String {
|
||||
return String(s.characters.reverse())
|
||||
}
|
||||
print(reverseString("asdf"))
|
||||
print(reverseString("as⃝df̅"))
|
||||
5
Task/Reverse-a-string/Swift/reverse-a-string-2.swift
Normal file
5
Task/Reverse-a-string/Swift/reverse-a-string-2.swift
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
func reverseString(s: String) -> String {
|
||||
return String(reverse(s))
|
||||
}
|
||||
println(reverseString("asdf"))
|
||||
println(reverseString("as⃝df̅"))
|
||||
1
Task/Reverse-a-string/Wart/reverse-a-string.wart
Normal file
1
Task/Reverse-a-string/Wart/reverse-a-string.wart
Normal file
|
|
@ -0,0 +1 @@
|
|||
(rev "asdf")
|
||||
4
Task/Reverse-a-string/Wortel/reverse-a-string.wortel
Normal file
4
Task/Reverse-a-string/Wortel/reverse-a-string.wortel
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
; the @rev operator reverses strings and arrays
|
||||
@rev "abc" ; returns "cba"
|
||||
; or the same thing using a pointer expression
|
||||
!~r "abc"
|
||||
1
Task/Reverse-a-string/jq/reverse-a-string.jq
Normal file
1
Task/Reverse-a-string/jq/reverse-a-string.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
def reverse_string: explode | reverse | implode;
|
||||
Loading…
Add table
Add a link
Reference in a new issue