Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,14 @@
(define (string-reverse string)
(list->string (reverse (string->list string))))
(define (task str)
(for-each writeln (list
(string-reverse str)
(string-join (map string-reverse (string-split str )))
(string-join (reverse (string-split str ))))))
(task "rosetta code phrase reversal")
"lasrever esarhp edoc attesor"
"attesor edoc esarhp lasrever"
"reversal phrase code rosetta"

View file

@ -0,0 +1,64 @@
' FB 1.05.0 Win64
Sub split (s As Const String, sepList As Const String, result() As String)
If s = "" OrElse sepList = "" Then
Redim result(0)
result(0) = s
Return
End If
Dim As Integer i, j, count = 0, empty = 0, length
Dim As Integer position(Len(s) + 1)
position(0) = 0
For i = 0 To len(s) - 1
For j = 0 to Len(sepList) - 1
If s[i] = sepList[j] Then
count += 1
position(count) = i + 1
End If
Next j
Next i
Redim result(count)
If count = 0 Then
result(0) = s
Return
End If
position(count + 1) = len(s) + 1
For i = 1 To count + 1
length = position(i) - position(i - 1) - 1
result(i - 1) = Mid(s, position(i - 1) + 1, length)
Next
End Sub
Function reverse(s As Const String) As String
If s = "" Then Return ""
Dim t As String = s
Dim length As Integer = Len(t)
For i As Integer = 0 to length\2 - 1
Swap t[i], t[length - 1 - i]
Next
Return t
End Function
Dim s As String = "rosetta code phrase reversal"
Dim a() As String
Dim sepList As String = " "
Print "Original string => "; s
Print "Reversed string => "; reverse(s)
Print "Reversed words => ";
split s, sepList, a()
For i As Integer = LBound(a) To UBound(a)
Print reverse(a(i)); " ";
Next
Print
Print "Reversed order => ";
For i As Integer = UBound(a) To LBound(a) Step -1
Print a(i); " ";
Next
Print : Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,3 @@
"rosetta code phrase reversal" reverse println
"rosetta code phrase reversal" words map(#reverse) unwords println
"rosetta code phrase reversal" words reverse unwords println

View file

@ -0,0 +1,8 @@
constant test="rosetta code phrase reversal"
?reverse(test)
sequence words = split(reverse(test))
for i=1 to length(words) do
words[i] = reverse(words[i])
end for
?join(words)
?join(reverse(words))

View file

@ -0,0 +1,9 @@
aString = "Welcome to the Ring Language"
bString = ""
see reverseString(aString)
func reverseString cString
for i= len(cString) to 1 step -1
bString = bString + cString[i]
next
return bString

View file

@ -0,0 +1,5 @@
var str = "rosetta code phrase reversal";
say str.reverse; # reversed string
say str.words.map{.reverse}.join(' '); # words reversed
say str.words.reverse.join(' '); # word order reversed

View file

@ -0,0 +1,8 @@
def reverse_string: explode | reverse | implode;
"rosetta code phrase reversal"
| split(" ") as $words
| "0. input: \(.)",
"1. string reversed: \(reverse_string)",
"2. each word reversed: \($words | map(reverse_string) | join(" "))",
"3. word-order reversed: \($words | reverse | join(" "))"