tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
10
Task/Reverse-a-string/0815/reverse-a-string-1.0815
Normal file
10
Task/Reverse-a-string/0815/reverse-a-string-1.0815
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
}:r: Start reader loop.
|
||||
!~>& Push a character to the "stack".
|
||||
<:a:=- Stop reading on newline.
|
||||
^:r:
|
||||
@> Rotate the newline to the end and enqueue a sentinel 0.
|
||||
{~ Dequeue and rotate the first character into place.
|
||||
}:p:
|
||||
${~ Print the current character until it's 0.
|
||||
^:p:
|
||||
#:r: Read again.
|
||||
3
Task/Reverse-a-string/0815/reverse-a-string-2.0815
Normal file
3
Task/Reverse-a-string/0815/reverse-a-string-2.0815
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
echo -e "foo\nbar" | 0815 rev.0
|
||||
oof
|
||||
rab
|
||||
3
Task/Reverse-a-string/0DESCRIPTION
Normal file
3
Task/Reverse-a-string/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Take a string and reverse it. For example, "asdf" becomes "fdsa".
|
||||
|
||||
For extra credit, preserve Unicode combining characters. For example, "as⃝df̅" becomes "f̅ds⃝a", not "̅fd⃝sa".
|
||||
2
Task/Reverse-a-string/1META.yaml
Normal file
2
Task/Reverse-a-string/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: String manipulation
|
||||
1
Task/Reverse-a-string/ACL2/reverse-a-string.acl2
Normal file
1
Task/Reverse-a-string/ACL2/reverse-a-string.acl2
Normal file
|
|
@ -0,0 +1 @@
|
|||
(reverse "hello")
|
||||
13
Task/Reverse-a-string/ALGOL-68/reverse-a-string-1.alg
Normal file
13
Task/Reverse-a-string/ALGOL-68/reverse-a-string-1.alg
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
PROC reverse = (REF STRING s)VOID:
|
||||
FOR i TO UPB s OVER 2 DO
|
||||
CHAR c = s[i];
|
||||
s[i] := s[UPB s - i + 1];
|
||||
s[UPB s - i + 1] := c
|
||||
OD;
|
||||
|
||||
main:
|
||||
(
|
||||
STRING text := "Was it a cat I saw";
|
||||
reverse(text);
|
||||
print((text, new line))
|
||||
)
|
||||
2
Task/Reverse-a-string/ALGOL-68/reverse-a-string-2.alg
Normal file
2
Task/Reverse-a-string/ALGOL-68/reverse-a-string-2.alg
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
⌽'asdf'
|
||||
fdsa
|
||||
10
Task/Reverse-a-string/AWK/reverse-a-string-1.awk
Normal file
10
Task/Reverse-a-string/AWK/reverse-a-string-1.awk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
function reverse(s)
|
||||
{
|
||||
p = ""
|
||||
for(i=length(s); i > 0; i--) { p = p substr(s, i, 1) }
|
||||
return p
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print reverse("edoCattesoR")
|
||||
}
|
||||
9
Task/Reverse-a-string/AWK/reverse-a-string-2.awk
Normal file
9
Task/Reverse-a-string/AWK/reverse-a-string-2.awk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function reverse(s ,l)
|
||||
{
|
||||
l = length(s)
|
||||
return l < 2 ? s:( substr(s,l,1) reverse(substr(s,1,l-1)) )
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
print reverse("edoCattesoR")
|
||||
}
|
||||
12
Task/Reverse-a-string/ActionScript/reverse-a-string.as
Normal file
12
Task/Reverse-a-string/ActionScript/reverse-a-string.as
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function reverseString(string:String):String
|
||||
{
|
||||
var reversed:String = new String();
|
||||
for(var i:int = string.length -1; i >= 0; i--)
|
||||
reversed += string.charAt(i);
|
||||
return reversed;
|
||||
}
|
||||
|
||||
function reverseStringCQAlternative(string:String):String
|
||||
{
|
||||
return string.split('').reverse().join('');
|
||||
}
|
||||
14
Task/Reverse-a-string/Ada/reverse-a-string.ada
Normal file
14
Task/Reverse-a-string/Ada/reverse-a-string.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Reverse_String is
|
||||
function Reverse_It (Item : String) return String is
|
||||
Result : String (Item'Range);
|
||||
begin
|
||||
for I in Item'range loop
|
||||
Result (Result'Last - I + Item'First) := Item (I);
|
||||
end loop;
|
||||
return Result;
|
||||
end Reverse_It;
|
||||
begin
|
||||
Put_Line (Reverse_It (Get_Line));
|
||||
end Reverse_String;
|
||||
7
Task/Reverse-a-string/Agda2/reverse-a-string.agda2
Normal file
7
Task/Reverse-a-string/Agda2/reverse-a-string.agda2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module reverse_string where
|
||||
|
||||
open import Data.String
|
||||
open import Data.List
|
||||
|
||||
reverse_string : String → String
|
||||
reverse_string s = fromList (reverse (toList s))
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
get reverse_string("as⃝df̅")
|
||||
|
||||
on reverse_string(str)
|
||||
set old_delim to (get AppleScript's text item delimiters)
|
||||
set AppleScript's text item delimiters to ""
|
||||
|
||||
set temp to (reverse of text items of str)
|
||||
set temp to (text items of temp) as Unicode text
|
||||
|
||||
set AppleScript's text item delimiters to old_delim
|
||||
return temp
|
||||
end reverse_string
|
||||
8
Task/Reverse-a-string/AutoHotkey/reverse-a-string-1.ahk
Normal file
8
Task/Reverse-a-string/AutoHotkey/reverse-a-string-1.ahk
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
MsgBox % reverse("asdf")
|
||||
|
||||
reverse(string)
|
||||
{
|
||||
Loop, Parse, string
|
||||
reversed := A_LoopField . reversed
|
||||
Return reversed
|
||||
}
|
||||
19
Task/Reverse-a-string/AutoHotkey/reverse-a-string-2.ahk
Normal file
19
Task/Reverse-a-string/AutoHotkey/reverse-a-string-2.ahk
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Reverse(String){ ; credit to Rseding91
|
||||
If (A_IsUnicode){
|
||||
SLen := StrLen(String) * 2
|
||||
VarSetCapacity(RString,SLen)
|
||||
|
||||
Loop,Parse,String
|
||||
NumPut(Asc(A_LoopField),RString,SLen-(A_Index * 2),"UShort")
|
||||
} Else {
|
||||
SLen := StrLen(String)
|
||||
VarSetCapacity(RString,SLen)
|
||||
|
||||
Loop,Parse,String
|
||||
NumPut(Asc(A_LoopField),RString,SLen-A_Index,"UChar")
|
||||
}
|
||||
|
||||
VarSetCapacity(RString,-1)
|
||||
|
||||
Return RString
|
||||
}
|
||||
12
Task/Reverse-a-string/AutoIt/reverse-a-string.autoit
Normal file
12
Task/Reverse-a-string/AutoIt/reverse-a-string.autoit
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#AutoIt Version: 3.2.10.0
|
||||
$mystring="asdf"
|
||||
$reverse_string = ""
|
||||
$string_length = StringLen($mystring)
|
||||
|
||||
For $i = 1 to $string_length
|
||||
$last_n_chrs = StringRight($mystring, $i)
|
||||
$nth_chr = StringTrimRight($last_n_chrs, $i-1)
|
||||
$reverse_string= $reverse_string & $nth_chr
|
||||
Next
|
||||
|
||||
MsgBox(0, "Reversed string is:", $reverse_string)
|
||||
7
Task/Reverse-a-string/BASIC/reverse-a-string.basic
Normal file
7
Task/Reverse-a-string/BASIC/reverse-a-string.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function reverse$(a$)
|
||||
b$ = ""
|
||||
for i = 1 to len(a$)
|
||||
b$ = mid$(a$, i, 1) + b$
|
||||
next i
|
||||
reverse$ = b$
|
||||
end function
|
||||
9
Task/Reverse-a-string/BBC-BASIC/reverse-a-string.bbc
Normal file
9
Task/Reverse-a-string/BBC-BASIC/reverse-a-string.bbc
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
PRINT FNreverse("The five boxing wizards jump quickly")
|
||||
END
|
||||
|
||||
DEF FNreverse(A$)
|
||||
LOCAL B$, C%
|
||||
FOR C% = LEN(A$) TO 1 STEP -1
|
||||
B$ += MID$(A$,C%,1)
|
||||
NEXT
|
||||
= B$
|
||||
1
Task/Reverse-a-string/Babel/reverse-a-string.pb
Normal file
1
Task/Reverse-a-string/Babel/reverse-a-string.pb
Normal file
|
|
@ -0,0 +1 @@
|
|||
strrev: { str2ar ar2ls reverse ls2lf ar2str }
|
||||
17
Task/Reverse-a-string/Batch-File/reverse-a-string.bat
Normal file
17
Task/Reverse-a-string/Batch-File/reverse-a-string.bat
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
call :reverse %1 res
|
||||
echo %res%
|
||||
goto :eof
|
||||
|
||||
:reverse
|
||||
set str=%~1
|
||||
set cnt=0
|
||||
:loop
|
||||
if "%str%" equ "" (
|
||||
goto :eof
|
||||
)
|
||||
set chr=!str:~0,1!
|
||||
set str=%str:~1%
|
||||
set %2=%chr%!%2!
|
||||
goto loop
|
||||
14
Task/Reverse-a-string/Befunge/reverse-a-string.bf
Normal file
14
Task/Reverse-a-string/Befunge/reverse-a-string.bf
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
v The string to reverse. The row to copy to.
|
||||
| | The actual copying happens here.
|
||||
| | | Increment column to write to.
|
||||
| | | | Store column #.
|
||||
v v v v v
|
||||
> "reverse me" 3 10p >10g 4 p 10g1+ 10pv
|
||||
^ ^ |: <
|
||||
First column --| | @ ^
|
||||
to write to. | ^ Get the address
|
||||
All calls to 10 | to copy the next
|
||||
involve saving or | character to.
|
||||
reading the End when stack is empty or
|
||||
column to write explicit zero is reached.
|
||||
to.
|
||||
15
Task/Reverse-a-string/Bracmat/reverse-a-string.bracmat
Normal file
15
Task/Reverse-a-string/Bracmat/reverse-a-string.bracmat
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
( reverse
|
||||
= L x
|
||||
. :?L
|
||||
& @( !arg
|
||||
: ?
|
||||
( %?x
|
||||
& utf$!x
|
||||
& !x !L:?L
|
||||
& ~`
|
||||
)
|
||||
?
|
||||
)
|
||||
| str$!L
|
||||
)
|
||||
& out$reverse$Ελληνικά
|
||||
1
Task/Reverse-a-string/Brainf---/reverse-a-string-1.bf
Normal file
1
Task/Reverse-a-string/Brainf---/reverse-a-string-1.bf
Normal file
|
|
@ -0,0 +1 @@
|
|||
[-]>,+[->,+]<[.<]
|
||||
5
Task/Reverse-a-string/Brainf---/reverse-a-string-2.bf
Normal file
5
Task/Reverse-a-string/Brainf---/reverse-a-string-2.bf
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
,----- ----- [+++++ +++++ > , ----- -----] If a newline is hit counter will be zero and input loop ends
|
||||
<[.<] run all chars backwards and print them
|
||||
|
||||
just because it looks good we print CRLF
|
||||
+++++ +++++ +++ . --- .
|
||||
1
Task/Reverse-a-string/Brat/reverse-a-string.brat
Normal file
1
Task/Reverse-a-string/Brat/reverse-a-string.brat
Normal file
|
|
@ -0,0 +1 @@
|
|||
p "olleh".reverse #Prints "hello"
|
||||
1
Task/Reverse-a-string/Burlesque/reverse-a-string.blq
Normal file
1
Task/Reverse-a-string/Burlesque/reverse-a-string.blq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"Hello, world!"<-
|
||||
12
Task/Reverse-a-string/C++/reverse-a-string.cpp
Normal file
12
Task/Reverse-a-string/C++/reverse-a-string.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string s;
|
||||
std::getline(std::cin, s);
|
||||
std::reverse(s.begin(), s.end()); // modifies s
|
||||
std::cout << s << std::endl;
|
||||
return 0;
|
||||
}
|
||||
67
Task/Reverse-a-string/C/reverse-a-string-1.c
Normal file
67
Task/Reverse-a-string/C/reverse-a-string-1.c
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <wchar.h>
|
||||
|
||||
const char *sa = "abcdef";
|
||||
const char *su = "as⃝df̅"; /* Should be in your native locale encoding. Mine is UTF-8 */
|
||||
|
||||
int is_comb(wchar_t c)
|
||||
{
|
||||
if (c >= 0x300 && c <= 0x36f) return 1;
|
||||
if (c >= 0x1dc0 && c <= 0x1dff) return 1;
|
||||
if (c >= 0x20d0 && c <= 0x20ff) return 1;
|
||||
if (c >= 0xfe20 && c <= 0xfe2f) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
wchar_t* mb_to_wchar(const char *s)
|
||||
{
|
||||
wchar_t *u;
|
||||
size_t len = mbstowcs(0, s, 0) + 1;
|
||||
if (!len) return 0;
|
||||
|
||||
u = malloc(sizeof(wchar_t) * len);
|
||||
mbstowcs(u, s, len);
|
||||
return u;
|
||||
}
|
||||
|
||||
wchar_t* ws_reverse(const wchar_t* u)
|
||||
{
|
||||
size_t len, i, j;
|
||||
wchar_t *out;
|
||||
for (len = 0; u[len]; len++);
|
||||
out = malloc(sizeof(wchar_t) * (len + 1));
|
||||
out[len] = 0;
|
||||
j = 0;
|
||||
while (len) {
|
||||
for (i = len - 1; i && is_comb(u[i]); i--);
|
||||
wcsncpy(out + j, u + i, len - i);
|
||||
j += len - i;
|
||||
len = i;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
char *mb_reverse(const char *in)
|
||||
{
|
||||
size_t len;
|
||||
char *out;
|
||||
wchar_t *u = mb_to_wchar(in);
|
||||
wchar_t *r = ws_reverse(u);
|
||||
len = wcstombs(0, r, 0) + 1;
|
||||
out = malloc(len);
|
||||
wcstombs(out, r, len);
|
||||
free(u);
|
||||
free(r);
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
printf("%s => %s\n", sa, mb_reverse(sa));
|
||||
printf("%s => %s\n", su, mb_reverse(su));
|
||||
return 0;
|
||||
}
|
||||
13
Task/Reverse-a-string/C/reverse-a-string-2.c
Normal file
13
Task/Reverse-a-string/C/reverse-a-string-2.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <glib.h>
|
||||
gchar *srev (const gchar *s) {
|
||||
if (g_utf8_validate(s,-1,NULL)) {
|
||||
return g_utf8_strreverse (s,-1);
|
||||
} }
|
||||
// main
|
||||
int main (void) {
|
||||
const gchar *t="asdf";
|
||||
const gchar *u="as⃝df̅";
|
||||
printf ("%s\n",srev(t));
|
||||
printf ("%s\n",srev(u));
|
||||
return 0;
|
||||
}
|
||||
1
Task/Reverse-a-string/COBOL/reverse-a-string.cobol
Normal file
1
Task/Reverse-a-string/COBOL/reverse-a-string.cobol
Normal file
|
|
@ -0,0 +1 @@
|
|||
FUNCTION REVERSE-STRING('QWERTY')
|
||||
1
Task/Reverse-a-string/Clojure/reverse-a-string-1.clj
Normal file
1
Task/Reverse-a-string/Clojure/reverse-a-string-1.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(defn str-reverse [s] (apply str (reverse s)))
|
||||
1
Task/Reverse-a-string/Clojure/reverse-a-string-2.clj
Normal file
1
Task/Reverse-a-string/Clojure/reverse-a-string-2.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(apply str (interpose " " (reverse (.split "the quick brown fox" " "))))
|
||||
21
Task/Reverse-a-string/Clojure/reverse-a-string-3.clj
Normal file
21
Task/Reverse-a-string/Clojure/reverse-a-string-3.clj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(defn combining? [c]
|
||||
(let [type (Character/getType c)]
|
||||
;; currently hardcoded to the types taken from the sample string
|
||||
(or (= type 6) (= type 7))))
|
||||
|
||||
(defn group
|
||||
"Group normal characters with their combining characters"
|
||||
[chars]
|
||||
(cond (empty? chars) chars
|
||||
(empty? (next chars)) (list chars)
|
||||
:else
|
||||
(let [dres (group (next chars))]
|
||||
(cond (combining? (second chars)) (cons (cons (first chars)
|
||||
(first dres))
|
||||
(rest dres))
|
||||
:else (cons (list (first chars)) dres)))))
|
||||
|
||||
(defn str-reverse
|
||||
"Unicode-safe string reverse"
|
||||
[s]
|
||||
(apply str (apply concat (reverse (group s)))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
"qwerty".split("").reverse().join ""
|
||||
2
Task/Reverse-a-string/ColdFusion/reverse-a-string.cfm
Normal file
2
Task/Reverse-a-string/ColdFusion/reverse-a-string.cfm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<cfset myString = "asdf" />
|
||||
<cfset myString = reverse( myString ) />
|
||||
1
Task/Reverse-a-string/Common-Lisp/reverse-a-string.lisp
Normal file
1
Task/Reverse-a-string/Common-Lisp/reverse-a-string.lisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(reverse my-string)
|
||||
15
Task/Reverse-a-string/D/reverse-a-string.d
Normal file
15
Task/Reverse-a-string/D/reverse-a-string.d
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import std.stdio, std.range, std.conv;
|
||||
|
||||
void main() {
|
||||
string s1 = "hello"; // UTF-8
|
||||
string s1r = text(retro("hello"));
|
||||
assert(s1r == "olleh");
|
||||
|
||||
wstring s2 = "hello"w; // UTF-16
|
||||
wstring s2r = wtext(retro("hello"));
|
||||
assert(s2r == "olleh");
|
||||
|
||||
dstring s3 = "hello"d; // UTF-32
|
||||
dstring s3r = dtext(retro("hello"));
|
||||
assert(s3r == "olleh");
|
||||
}
|
||||
11
Task/Reverse-a-string/Dart/reverse-a-string.dart
Normal file
11
Task/Reverse-a-string/Dart/reverse-a-string.dart
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
String reverse(String s) {
|
||||
StringBuffer sb=new StringBuffer();
|
||||
for(int i=s.length-1;i>=0;i--) {
|
||||
sb.add(s[i]);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
main() {
|
||||
print(reverse('a string.'));
|
||||
}
|
||||
7
Task/Reverse-a-string/Delphi/reverse-a-string-1.delphi
Normal file
7
Task/Reverse-a-string/Delphi/reverse-a-string-1.delphi
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function ReverseString(const InString: string): string;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := Length(InString) downto 1 do
|
||||
Result := Result + InString[i];
|
||||
end;
|
||||
1
Task/Reverse-a-string/Delphi/reverse-a-string-2.delphi
Normal file
1
Task/Reverse-a-string/Delphi/reverse-a-string-2.delphi
Normal file
|
|
@ -0,0 +1 @@
|
|||
StrUtils.ReverseString
|
||||
4
Task/Reverse-a-string/E/reverse-a-string.e
Normal file
4
Task/Reverse-a-string/E/reverse-a-string.e
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pragma.enable("accumulator")
|
||||
def reverse(string) {
|
||||
return accum "" for i in (0..!(string.size())).descending() { _ + string[i] }
|
||||
}
|
||||
7
Task/Reverse-a-string/EGL/reverse-a-string.egl
Normal file
7
Task/Reverse-a-string/EGL/reverse-a-string.egl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function reverse( str string ) returns( string )
|
||||
result string;
|
||||
for ( i int from StrLib.characterLen( str ) to 1 decrement by 1 )
|
||||
result ::= str[i:i];
|
||||
end
|
||||
return( result );
|
||||
end
|
||||
15
Task/Reverse-a-string/Eiffel/reverse-a-string.e
Normal file
15
Task/Reverse-a-string/Eiffel/reverse-a-string.e
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
class
|
||||
APPLICATION
|
||||
create
|
||||
make
|
||||
feature
|
||||
make
|
||||
-- Demonstrate string reversal.
|
||||
do
|
||||
my_string := "Hello World!"
|
||||
my_string.mirror
|
||||
print (my_string)
|
||||
end
|
||||
my_string: STRING
|
||||
-- Used for reversal
|
||||
end
|
||||
1
Task/Reverse-a-string/Emacs-Lisp/reverse-a-string.l
Normal file
1
Task/Reverse-a-string/Emacs-Lisp/reverse-a-string.l
Normal file
|
|
@ -0,0 +1 @@
|
|||
(concat (reverse (append "Hello World" nil)))
|
||||
2
Task/Reverse-a-string/Erlang/reverse-a-string-1.erl
Normal file
2
Task/Reverse-a-string/Erlang/reverse-a-string-1.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
1> lists:reverse("reverse!").
|
||||
"!esrever"
|
||||
4
Task/Reverse-a-string/Erlang/reverse-a-string-2.erl
Normal file
4
Task/Reverse-a-string/Erlang/reverse-a-string-2.erl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
reverse(Bin) ->
|
||||
Size = size(Bin)*8,
|
||||
<<T:Size/integer-little>> = Bin,
|
||||
<<T:Size/integer-big>>.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
>function strrev (s) := chartostr(fliplr(strtochar(s)))
|
||||
>strrev("This is a test!")
|
||||
!tset a si sihT
|
||||
2
Task/Reverse-a-string/Euphoria/reverse-a-string.euphoria
Normal file
2
Task/Reverse-a-string/Euphoria/reverse-a-string.euphoria
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
include std/sequence.e
|
||||
printf(1, "%s\n", {reverse("abcdef") })
|
||||
8
Task/Reverse-a-string/FBSL/reverse-a-string-1.fbsl
Normal file
8
Task/Reverse-a-string/FBSL/reverse-a-string-1.fbsl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Function StrRev1(ByVal $p1)
|
||||
dim $b = ""
|
||||
repeat len(p1)
|
||||
b = b & right(p1,1)
|
||||
p1 = left(p1,len(p1)-1)
|
||||
end repeat
|
||||
return b
|
||||
End Function
|
||||
8
Task/Reverse-a-string/FBSL/reverse-a-string-2.fbsl
Normal file
8
Task/Reverse-a-string/FBSL/reverse-a-string-2.fbsl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Function StrRev2(ByVal $p1)
|
||||
dim $b = ""
|
||||
dim %i
|
||||
for i = len(p1) downto 1
|
||||
b = b & mid(p1,i,1)
|
||||
next
|
||||
return b
|
||||
End Function
|
||||
7
Task/Reverse-a-string/FBSL/reverse-a-string-3.fbsl
Normal file
7
Task/Reverse-a-string/FBSL/reverse-a-string-3.fbsl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Function StrRev3( $s )
|
||||
FOR DIM x = 1 TO LEN(s) \ 2
|
||||
PEEK(@s + LEN - x, $1)
|
||||
POKE(@s + LEN - x, s{x})(@s + x - 1, PEEK)
|
||||
NEXT
|
||||
RETURN s
|
||||
end function
|
||||
20
Task/Reverse-a-string/FBSL/reverse-a-string-4.fbsl
Normal file
20
Task/Reverse-a-string/FBSL/reverse-a-string-4.fbsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
DynC StringRev($theString) As String
|
||||
void rev(char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
char *HEAD = str;
|
||||
char *TAIL = str + len - 1;
|
||||
char temp;
|
||||
int i;
|
||||
for ( i = 0; i <= len / 2; i++, HEAD++, TAIL--) {
|
||||
temp = *HEAD;
|
||||
*HEAD = *TAIL;
|
||||
*TAIL = temp;
|
||||
}
|
||||
}
|
||||
char *main(char* theString)
|
||||
{
|
||||
rev(theString);
|
||||
return theString;
|
||||
}
|
||||
End DynC
|
||||
1
Task/Reverse-a-string/Factor/reverse-a-string-1.factor
Normal file
1
Task/Reverse-a-string/Factor/reverse-a-string-1.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
"hello" reverse
|
||||
1
Task/Reverse-a-string/Factor/reverse-a-string-2.factor
Normal file
1
Task/Reverse-a-string/Factor/reverse-a-string-2.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
"as⃝df̅" string-reverse "f̅ds⃝a" = .
|
||||
1
Task/Reverse-a-string/Fancy/reverse-a-string.fancy
Normal file
1
Task/Reverse-a-string/Fancy/reverse-a-string.fancy
Normal file
|
|
@ -0,0 +1 @@
|
|||
"hello world!" reverse
|
||||
9
Task/Reverse-a-string/Forth/reverse-a-string.fth
Normal file
9
Task/Reverse-a-string/Forth/reverse-a-string.fth
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
: exchange ( a1 a2 -- )
|
||||
2dup c@ swap c@ rot c! swap c! ;
|
||||
: reverse ( c-addr u -- )
|
||||
1- bounds begin 2dup > while
|
||||
2dup exchange
|
||||
-1 /string
|
||||
repeat 2drop ;
|
||||
|
||||
s" testing" 2dup reverse type \ gnitset
|
||||
16
Task/Reverse-a-string/Fortran/reverse-a-string-1.f
Normal file
16
Task/Reverse-a-string/Fortran/reverse-a-string-1.f
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
PROGRAM Example
|
||||
|
||||
CHARACTER(80) :: str = "This is a string"
|
||||
CHARACTER :: temp
|
||||
INTEGER :: i, length
|
||||
|
||||
WRITE (*,*) str
|
||||
length = LEN_TRIM(str) ! Ignores trailing blanks. Use LEN(str) to reverse those as well
|
||||
DO i = 1, length/2
|
||||
temp = str(i:i)
|
||||
str(i:i) = str(length+1-i:length+1-i)
|
||||
str(length+1-i:length+1-i) = temp
|
||||
END DO
|
||||
WRITE(*,*) str
|
||||
|
||||
END PROGRAM Example
|
||||
25
Task/Reverse-a-string/Fortran/reverse-a-string-2.f
Normal file
25
Task/Reverse-a-string/Fortran/reverse-a-string-2.f
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
program reverse_string
|
||||
|
||||
implicit none
|
||||
character (*), parameter :: string = 'no devil lived on'
|
||||
|
||||
write (*, '(a)') string
|
||||
write (*, '(a)') reverse (string)
|
||||
|
||||
contains
|
||||
|
||||
recursive function reverse (string) result (res)
|
||||
|
||||
implicit none
|
||||
character (*), intent (in) :: string
|
||||
character (len (string)) :: res
|
||||
|
||||
if (len (string) == 0) then
|
||||
res = ''
|
||||
else
|
||||
res = string (len (string) :) // reverse (string (: len (string) - 1))
|
||||
end if
|
||||
|
||||
end function reverse
|
||||
|
||||
end program reverse_string
|
||||
1
Task/Reverse-a-string/Frink/reverse-a-string.frink
Normal file
1
Task/Reverse-a-string/Frink/reverse-a-string.frink
Normal file
|
|
@ -0,0 +1 @@
|
|||
println[reverse["abcdef"]]
|
||||
2
Task/Reverse-a-string/GAP/reverse-a-string.gap
Normal file
2
Task/Reverse-a-string/GAP/reverse-a-string.gap
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Reversed("abcdef");
|
||||
# "fedcba"
|
||||
1
Task/Reverse-a-string/Gema/reverse-a-string-1.gema
Normal file
1
Task/Reverse-a-string/Gema/reverse-a-string-1.gema
Normal file
|
|
@ -0,0 +1 @@
|
|||
\L<U>=@reverse{$1}
|
||||
1
Task/Reverse-a-string/Gema/reverse-a-string-2.gema
Normal file
1
Task/Reverse-a-string/Gema/reverse-a-string-2.gema
Normal file
|
|
@ -0,0 +1 @@
|
|||
\L<U1><U>=@{$2}$1
|
||||
76
Task/Reverse-a-string/Go/reverse-a-string.go
Normal file
76
Task/Reverse-a-string/Go/reverse-a-string.go
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// no encoding
|
||||
func reverseBytes(s string) string {
|
||||
r := make([]byte, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
r[i] = s[len(s)-1-i]
|
||||
}
|
||||
return string(r)
|
||||
}
|
||||
|
||||
// reverseCodePoints interprets its argument as UTF-8 and ignores bytes
|
||||
// that do not form valid UTF-8. return value is UTF-8.
|
||||
func reverseCodePoints(s string) string {
|
||||
r := make([]rune, len(s))
|
||||
start := len(s)
|
||||
for _, c := range s {
|
||||
// quietly skip invalid UTF-8
|
||||
if c != utf8.RuneError {
|
||||
start--
|
||||
r[start] = c
|
||||
}
|
||||
}
|
||||
return string(r[start:])
|
||||
}
|
||||
|
||||
// reversePreservingCombiningCharacters interprets its argument as UTF-8
|
||||
// and ignores bytes that do not form valid UTF-8. return value is UTF-8.
|
||||
func reversePreservingCombiningCharacters(s string) string {
|
||||
if s == "" {
|
||||
return ""
|
||||
}
|
||||
p := []rune(s)
|
||||
r := make([]rune, len(p))
|
||||
start := len(r)
|
||||
for i := 0; i < len(p); {
|
||||
// quietly skip invalid UTF-8
|
||||
if p[i] == utf8.RuneError {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
j := i + 1
|
||||
for j < len(p) && (unicode.Is(unicode.Mn, p[j]) ||
|
||||
unicode.Is(unicode.Me, p[j]) || unicode.Is(unicode.Mc, p[j])) {
|
||||
j++
|
||||
}
|
||||
for k := j - 1; k >= i; k-- {
|
||||
start--
|
||||
r[start] = p[k]
|
||||
}
|
||||
i = j
|
||||
}
|
||||
return (string(r[start:]))
|
||||
}
|
||||
|
||||
func main() {
|
||||
test("asdf")
|
||||
test("as⃝df̅")
|
||||
}
|
||||
|
||||
func test(s string) {
|
||||
fmt.Println("\noriginal: ", []byte(s), s)
|
||||
r := reverseBytes(s)
|
||||
fmt.Println("reversed bytes:", []byte(r), r)
|
||||
fmt.Println("original code points:", []rune(s), s)
|
||||
r = reverseCodePoints(s)
|
||||
fmt.Println("reversed code points:", []rune(r), r)
|
||||
r = reversePreservingCombiningCharacters(s)
|
||||
fmt.Println("combining characters:", []rune(r), r)
|
||||
}
|
||||
1
Task/Reverse-a-string/Groovy/reverse-a-string.groovy
Normal file
1
Task/Reverse-a-string/Groovy/reverse-a-string.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
println "Able was I, 'ere I saw Elba.".reverse()
|
||||
1
Task/Reverse-a-string/Haskell/reverse-a-string-1.hs
Normal file
1
Task/Reverse-a-string/Haskell/reverse-a-string-1.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
reverse = foldl (flip (:)) []
|
||||
3
Task/Reverse-a-string/Haskell/reverse-a-string-2.hs
Normal file
3
Task/Reverse-a-string/Haskell/reverse-a-string-2.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import Data.Char (isMark)
|
||||
import Data.List (groupBy)
|
||||
myReverse = concat . reverse . groupBy (const isMark)
|
||||
10
Task/Reverse-a-string/HicEst/reverse-a-string.hicest
Normal file
10
Task/Reverse-a-string/HicEst/reverse-a-string.hicest
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
CHARACTER string = "Hello World", tmp
|
||||
|
||||
L = LEN( string )
|
||||
DO i = 1, L/2
|
||||
tmp = string(i)
|
||||
string(i) = string(L-i+1)
|
||||
string(L-i+1) = tmp
|
||||
ENDDO
|
||||
|
||||
WRITE(Messagebox, Name) string
|
||||
4
Task/Reverse-a-string/Icon/reverse-a-string.icon
Normal file
4
Task/Reverse-a-string/Icon/reverse-a-string.icon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
procedure main(arglist)
|
||||
s := \arglist[1] | "asdf"
|
||||
write(s," <-> ", reverse(s)) # reverse is built-in
|
||||
end
|
||||
1
Task/Reverse-a-string/Io/reverse-a-string.io
Normal file
1
Task/Reverse-a-string/Io/reverse-a-string.io
Normal file
|
|
@ -0,0 +1 @@
|
|||
"asdf" reverse
|
||||
2
Task/Reverse-a-string/J/reverse-a-string-1.j
Normal file
2
Task/Reverse-a-string/J/reverse-a-string-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|.'asdf'
|
||||
fdsa
|
||||
2
Task/Reverse-a-string/J/reverse-a-string-2.j
Normal file
2
Task/Reverse-a-string/J/reverse-a-string-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ranges=.16b02ff 16b036f, 16b1dbf 16b1dff, 16b20cf 16b20ff, 16bfe1f 16bfe2f
|
||||
iscombining=. 2 | ranges&I.
|
||||
1
Task/Reverse-a-string/J/reverse-a-string-3.j
Normal file
1
Task/Reverse-a-string/J/reverse-a-string-3.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
split=. (<;.1~ -.@iscombining) :. ;
|
||||
2
Task/Reverse-a-string/J/reverse-a-string-4.j
Normal file
2
Task/Reverse-a-string/J/reverse-a-string-4.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
|.&.split&.(3 u: 7&u:) 'as⃝df̅'
|
||||
f̅ds⃝a
|
||||
3
Task/Reverse-a-string/Java/reverse-a-string-1.java
Normal file
3
Task/Reverse-a-string/Java/reverse-a-string-1.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public static String reverseString(String s) {
|
||||
return new StringBuffer(s).reverse().toString();
|
||||
}
|
||||
3
Task/Reverse-a-string/Java/reverse-a-string-2.java
Normal file
3
Task/Reverse-a-string/Java/reverse-a-string-2.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
public static String reverseString(String s) {
|
||||
return new StringBuilder(s).reverse().toString();
|
||||
}
|
||||
3
Task/Reverse-a-string/JavaScript/reverse-a-string.js
Normal file
3
Task/Reverse-a-string/JavaScript/reverse-a-string.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var a = "cat".split("");
|
||||
a.reverse();
|
||||
print(a.join("")); // tac
|
||||
2
Task/Reverse-a-string/Julia/reverse-a-string.julia
Normal file
2
Task/Reverse-a-string/Julia/reverse-a-string.julia
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
julia> reverse("hey")
|
||||
"yeh"
|
||||
2
Task/Reverse-a-string/Lang5/reverse-a-string.lang5
Normal file
2
Task/Reverse-a-string/Lang5/reverse-a-string.lang5
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
: flip "" split reverse "" join ;
|
||||
"qwer asdf" flip .
|
||||
11
Task/Reverse-a-string/Liberty-BASIC/reverse-a-string.liberty
Normal file
11
Task/Reverse-a-string/Liberty-BASIC/reverse-a-string.liberty
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
input$ ="abcdefgABCDEFG012345"
|
||||
print input$
|
||||
print ReversedStr$( input$)
|
||||
|
||||
end
|
||||
|
||||
function ReversedStr$(in$)
|
||||
for i =len(in$) to 1 step -1
|
||||
ReversedStr$ =ReversedStr$ +mid$( in$, i, 1)
|
||||
next i
|
||||
end function
|
||||
1
Task/Reverse-a-string/Logo/reverse-a-string.logo
Normal file
1
Task/Reverse-a-string/Logo/reverse-a-string.logo
Normal file
|
|
@ -0,0 +1 @@
|
|||
print reverse "cat ; tac
|
||||
1
Task/Reverse-a-string/Lua/reverse-a-string.lua
Normal file
1
Task/Reverse-a-string/Lua/reverse-a-string.lua
Normal file
|
|
@ -0,0 +1 @@
|
|||
theString = theString:reverse()
|
||||
1
Task/Reverse-a-string/M4/reverse-a-string.m4
Normal file
1
Task/Reverse-a-string/M4/reverse-a-string.m4
Normal file
|
|
@ -0,0 +1 @@
|
|||
define(`invert',`ifelse(len(`$1'),0,,`invert(substr(`$1',1))'`'substr(`$1',0,1))')
|
||||
6
Task/Reverse-a-string/MATLAB/reverse-a-string.m
Normal file
6
Task/Reverse-a-string/MATLAB/reverse-a-string.m
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
>> fliplr(['She told me that she spoke English and I said great. '...
|
||||
'Grabbed her hand out the club and I said let''s skate.'])
|
||||
|
||||
ans =
|
||||
|
||||
.etaks s'tel dias I dna bulc eht tuo dnah reh debbarG .taerg dias I dna hsilgnE ekops ehs taht em dlot ehS
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
fn reverseString s =
|
||||
(
|
||||
local reversed = ""
|
||||
for i in s.count to 1 by -1 do reversed += s[i]
|
||||
reversed
|
||||
)
|
||||
6
Task/Reverse-a-string/MUMPS/reverse-a-string.mumps
Normal file
6
Task/Reverse-a-string/MUMPS/reverse-a-string.mumps
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
REVERSE
|
||||
;Take in a string and reverse it using the built in function $REVERSE
|
||||
NEW S
|
||||
READ:30 "Enter a string: ",S
|
||||
WRITE !,$REVERSE(S)
|
||||
QUIT
|
||||
2
Task/Reverse-a-string/Maple/reverse-a-string.maple
Normal file
2
Task/Reverse-a-string/Maple/reverse-a-string.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> StringTools:-Reverse( "foo" );
|
||||
"oof"
|
||||
1
Task/Reverse-a-string/Mathematica/reverse-a-string.math
Normal file
1
Task/Reverse-a-string/Mathematica/reverse-a-string.math
Normal file
|
|
@ -0,0 +1 @@
|
|||
StringReverse["asdf"]
|
||||
3
Task/Reverse-a-string/Maxima/reverse-a-string.maxima
Normal file
3
Task/Reverse-a-string/Maxima/reverse-a-string.maxima
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
sreverse("abcdef"); /* "fedcba" */
|
||||
|
||||
sreverse("rats live on no evil star"); /* not a bug :o) */
|
||||
5
Task/Reverse-a-string/Mirah/reverse-a-string.mirah
Normal file
5
Task/Reverse-a-string/Mirah/reverse-a-string.mirah
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def reverse(s:string)
|
||||
StringBuilder.new(s).reverse
|
||||
end
|
||||
|
||||
puts reverse('reversed')
|
||||
16
Task/Reverse-a-string/Modula-3/reverse-a-string.mod3
Normal file
16
Task/Reverse-a-string/Modula-3/reverse-a-string.mod3
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
MODULE Reverse EXPORTS Main;
|
||||
|
||||
IMPORT IO, Text;
|
||||
|
||||
PROCEDURE String(item: TEXT): TEXT =
|
||||
VAR result: TEXT := "";
|
||||
BEGIN
|
||||
FOR i := Text.Length(item) - 1 TO 0 BY - 1 DO
|
||||
result := Text.Cat(result, Text.FromChar(Text.GetChar(item, i)));
|
||||
END;
|
||||
RETURN result;
|
||||
END String;
|
||||
|
||||
BEGIN
|
||||
IO.Put(String("Foobarbaz") & "\n");
|
||||
END Reverse.
|
||||
23
Task/Reverse-a-string/Nemerle/reverse-a-string-1.nemerle
Normal file
23
Task/Reverse-a-string/Nemerle/reverse-a-string-1.nemerle
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Forms;
|
||||
using System.Console;
|
||||
using Nemerle.Utility.NString;
|
||||
|
||||
module StrReverse
|
||||
{
|
||||
UReverse(text : string) : string
|
||||
{
|
||||
mutable output = [];
|
||||
def elements = StringInfo.GetTextElementEnumerator(text);
|
||||
while (elements.MoveNext())
|
||||
output ::= elements.GetTextElement().ToString();
|
||||
Concat("", output.Reverse());
|
||||
}
|
||||
|
||||
Main() : void
|
||||
{
|
||||
def test = "as⃝df̅";
|
||||
MessageBox.Show($"$test --> $(UReverse(test))"); //for whatever reason my console didn't display Unicode properly, but a MessageBox worked
|
||||
}
|
||||
}
|
||||
7
Task/Reverse-a-string/Nemerle/reverse-a-string-2.nemerle
Normal file
7
Task/Reverse-a-string/Nemerle/reverse-a-string-2.nemerle
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Reverse(text : string) : string
|
||||
{
|
||||
mutable output = [];
|
||||
foreach (c in text.ToCharArray())
|
||||
output ::= c.ToString();
|
||||
Concat("", output)
|
||||
}
|
||||
11
Task/Reverse-a-string/NetRexx/reverse-a-string.netrexx
Normal file
11
Task/Reverse-a-string/NetRexx/reverse-a-string.netrexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* NetRexx */
|
||||
|
||||
options replace format comments java crossref savelog symbols nobinary
|
||||
|
||||
reverseThis = 'asdf'
|
||||
sihTesrever = reverseThis.reverse
|
||||
|
||||
say reverseThis
|
||||
say sihTesrever
|
||||
|
||||
return
|
||||
1
Task/Reverse-a-string/NewLISP/reverse-a-string.newlisp
Normal file
1
Task/Reverse-a-string/NewLISP/reverse-a-string.newlisp
Normal file
|
|
@ -0,0 +1 @@
|
|||
(reverse "!dlroW olleH")
|
||||
2
Task/Reverse-a-string/Nial/reverse-a-string.nial
Normal file
2
Task/Reverse-a-string/Nial/reverse-a-string.nial
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
reverse 'asdf'
|
||||
=fdsa
|
||||
9
Task/Reverse-a-string/Nimrod/reverse-a-string.nimrod
Normal file
9
Task/Reverse-a-string/Nimrod/reverse-a-string.nimrod
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
var
|
||||
str1 = "Reverse This!"
|
||||
|
||||
proc reverse(s: string): string =
|
||||
result = ""
|
||||
for i in countdown(high(str1), 0):
|
||||
result.add str1[i]
|
||||
|
||||
echo "Original string: ", str1, "\nReversed: ", reverse(str1)
|
||||
9
Task/Reverse-a-string/OCaml/reverse-a-string-1.ocaml
Normal file
9
Task/Reverse-a-string/OCaml/reverse-a-string-1.ocaml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let rev_string str =
|
||||
let len = String.length str in
|
||||
let res = String.create len in
|
||||
let last = len - 1 in
|
||||
for i = 0 to last do
|
||||
let j = last - i in
|
||||
res.[i] <- str.[j];
|
||||
done;
|
||||
(res)
|
||||
8
Task/Reverse-a-string/OCaml/reverse-a-string-2.ocaml
Normal file
8
Task/Reverse-a-string/OCaml/reverse-a-string-2.ocaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
let rev_string str =
|
||||
let last = String.length str - 1 in
|
||||
for i = 0 to last / 2 do
|
||||
let j = last - i in
|
||||
let c = str.[i] in
|
||||
str.[i] <- str.[j];
|
||||
str.[j] <- c;
|
||||
done
|
||||
4
Task/Reverse-a-string/OCaml/reverse-a-string-3.ocaml
Normal file
4
Task/Reverse-a-string/OCaml/reverse-a-string-3.ocaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let rec revs strin list index =
|
||||
if List.length list = String.length strin
|
||||
then String.concat "" list
|
||||
else revs strin ((String.sub strin index 1)::list) (index+1)
|
||||
1
Task/Reverse-a-string/Objeck/reverse-a-string.objeck
Normal file
1
Task/Reverse-a-string/Objeck/reverse-a-string.objeck
Normal file
|
|
@ -0,0 +1 @@
|
|||
result := "asdf"->Reverse();
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue