September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
1
Task/Repeat-a-string/Aime/repeat-a-string.aime
Normal file
1
Task/Repeat-a-string/Aime/repeat-a-string.aime
Normal file
|
|
@ -0,0 +1 @@
|
|||
call_n(5, o_text, "ha");
|
||||
|
|
@ -1,17 +1,20 @@
|
|||
on run
|
||||
nreps("ha", 50000)
|
||||
end run
|
||||
replicate(5000, "ha")
|
||||
|
||||
-- Repetition by 'Egyptian multiplication' -
|
||||
-- progressively doubling a list, appending
|
||||
-- stages of doubling to an accumulator where needed for
|
||||
-- binary assembly of a target length.
|
||||
|
||||
-- String -> Int -> String
|
||||
on nreps(s, n)
|
||||
set o to ""
|
||||
if n < 1 then return o
|
||||
-- replicate :: Int -> String -> String
|
||||
on replicate(n, s)
|
||||
set out to ""
|
||||
if n < 1 then return out
|
||||
set dbl to s
|
||||
|
||||
repeat while (n > 1)
|
||||
if (n mod 2) > 0 then set o to o & s
|
||||
if (n mod 2) > 0 then set out to out & dbl
|
||||
set n to (n div 2)
|
||||
set s to (s & s)
|
||||
set dbl to (dbl & dbl)
|
||||
end repeat
|
||||
return o & s
|
||||
end nreps
|
||||
return out & dbl
|
||||
end replicate
|
||||
|
|
|
|||
3
Task/Repeat-a-string/Beeswax/repeat-a-string.beeswax
Normal file
3
Task/Repeat-a-string/Beeswax/repeat-a-string.beeswax
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
p <
|
||||
p0~1<}~< d@<
|
||||
_VT@1~>yg~9PKd@M'd;
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
#import system.
|
||||
#import system'routines.
|
||||
#import extensions.
|
||||
import system'routines.
|
||||
import extensions.
|
||||
|
||||
#symbol program =
|
||||
program =
|
||||
[
|
||||
#var s := 0 repeat &till:5 &each: n [ "ha" ] summarize:(String new) literal.
|
||||
var s := 0 till:5 repeat(:n)( "ha" ); summarize(String new); literal.
|
||||
].
|
||||
|
|
|
|||
5
Task/Repeat-a-string/Gambas/repeat-a-string.gambas
Normal file
5
Task/Repeat-a-string/Gambas/repeat-a-string.gambas
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Public Sub Main()
|
||||
|
||||
Print String$(5, "ha")
|
||||
|
||||
End
|
||||
9
Task/Repeat-a-string/Haskell/repeat-a-string-6.hs
Normal file
9
Task/Repeat-a-string/Haskell/repeat-a-string-6.hs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
repString :: String -> Int -> String
|
||||
repString s n =
|
||||
let rep x = xs
|
||||
where
|
||||
xs = mappend x xs
|
||||
in take (n * length s) (rep s)
|
||||
|
||||
main :: IO ()
|
||||
main = print $ repString "ha" 5
|
||||
25
Task/Repeat-a-string/Haskell/repeat-a-string-7.hs
Normal file
25
Task/Repeat-a-string/Haskell/repeat-a-string-7.hs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import Data.Tuple (swap)
|
||||
import Data.List (unfoldr)
|
||||
import Control.Monad (join)
|
||||
|
||||
-- BY RHIND PAPYRUS 'EGYPTIAN' OR 'ETHIOPIAN' MULTIPLICATION ------------------
|
||||
repString :: Int -> String -> String
|
||||
repString n s =
|
||||
foldr
|
||||
(\(d, x) a ->
|
||||
if d > 0 -- Is this power of 2 needed for the binary recomposition ?
|
||||
then mappend a x
|
||||
else a)
|
||||
mempty $
|
||||
zip
|
||||
(unfoldr
|
||||
(\h ->
|
||||
if h > 0
|
||||
then Just $ swap (quotRem h 2) -- Binary decomposition of n
|
||||
else Nothing)
|
||||
n)
|
||||
(iterate (join mappend) s) -- Iterative duplication ( mappend to self )
|
||||
|
||||
-- TEST -----------------------------------------------------------------------
|
||||
main :: IO ()
|
||||
main = print $ repString 500 "ha"
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
public static String repeat(String str, int times){
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for(int i = 0;i < times;i++) ret.append(str);
|
||||
return ret.toString();
|
||||
public static String repeat(String str, int times) {
|
||||
StringBuilder sb = new StringBuilder(str.length() * times);
|
||||
for (int i = 0; i < times; i++)
|
||||
sb.append(str);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println(repeat("ha", 5));
|
||||
public static void main(String[] args) {
|
||||
System.out.println(repeat("ha", 5));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
public static String repeat(String str, int times){
|
||||
public static String repeat(String str, int times) {
|
||||
return new String(new char[times]).replace("\0", str);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
function nreps(s, n) {
|
||||
var o = '';
|
||||
if (n < 1) return o;
|
||||
while (n > 1) {
|
||||
if (n & 1) o += s;
|
||||
n >>= 1;
|
||||
s += s;
|
||||
}
|
||||
return o + s;
|
||||
}
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
nreps('ha', 50000);
|
||||
// replicate :: Int -> String -> String
|
||||
const replicate = (n, s) => {
|
||||
let v = [s],
|
||||
o = [];
|
||||
if (n < 1) return o;
|
||||
while (n > 1) {
|
||||
if (n & 1) o = o + v;
|
||||
n >>= 1;
|
||||
v = v + v;
|
||||
}
|
||||
return o.concat(v);
|
||||
};
|
||||
|
||||
|
||||
return replicate(5000, "ha")
|
||||
})();
|
||||
|
|
|
|||
27
Task/Repeat-a-string/JavaScript/repeat-a-string-4.js
Normal file
27
Task/Repeat-a-string/JavaScript/repeat-a-string-4.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// repeat :: Int -> String -> String
|
||||
const repeat = (n, s) =>
|
||||
concat(replicate(n, s));
|
||||
|
||||
|
||||
// GENERIC FUNCTIONS ------------------------------------------------------
|
||||
|
||||
// concat :: [[a]] -> [a] | [String] -> String
|
||||
const concat = xs =>
|
||||
xs.length > 0 ? (() => {
|
||||
const unit = typeof xs[0] === 'string' ? '' : [];
|
||||
return unit.concat.apply(unit, xs);
|
||||
})() : [];
|
||||
|
||||
// replicate :: Int -> a -> [a]
|
||||
const replicate = (n, x) =>
|
||||
Array.from({
|
||||
length: n
|
||||
}, () => x);
|
||||
|
||||
|
||||
// TEST -------------------------------------------------------------------
|
||||
return repeat(5, 'ha');
|
||||
})();
|
||||
3
Task/Repeat-a-string/Kotlin/repeat-a-string-2.kotlin
Normal file
3
Task/Repeat-a-string/Kotlin/repeat-a-string-2.kotlin
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
operator fun String.times(n: Int) = this.repeat(n)
|
||||
|
||||
fun main(args: Array<String>) = println("ha" * 5)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
import strutils
|
||||
repeatStr(5, "ha")
|
||||
1
Task/Repeat-a-string/Pure/repeat-a-string-2.pure
Normal file
1
Task/Repeat-a-string/Pure/repeat-a-string-2.pure
Normal file
|
|
@ -0,0 +1 @@
|
|||
str_repeat n::int s::string = string $ take n $ cycle (s:[]);
|
||||
|
|
@ -1 +0,0 @@
|
|||
(make-string 5 #\*) => "*****"
|
||||
|
|
@ -1 +0,0 @@
|
|||
"ha" * 5 # ==> "hahahahaha"
|
||||
|
|
@ -1 +0,0 @@
|
|||
5 * "ha" # TypeError: String can't be coerced into Fixnum
|
||||
1
Task/Repeat-a-string/Rust/repeat-a-string-2.rust
Normal file
1
Task/Repeat-a-string/Rust/repeat-a-string-2.rust
Normal file
|
|
@ -0,0 +1 @@
|
|||
"ha".repeat(5); // ==> "hahahahaha"
|
||||
2
Task/Repeat-a-string/Sed/repeat-a-string.sed
Normal file
2
Task/Repeat-a-string/Sed/repeat-a-string.sed
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ echo ha | sed 's/.*/&&&&&/'
|
||||
hahahahaha
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
10 LET S$="HA"
|
||||
20 LET N=5
|
||||
30 GOSUB 60
|
||||
40 PRINT T$
|
||||
50 STOP
|
||||
60 LET T$=""
|
||||
70 FOR I=1 TO N
|
||||
80 LET T$=T$+S$
|
||||
90 NEXT I
|
||||
100 RETURN
|
||||
4
Task/Repeat-a-string/Stata/repeat-a-string.stata
Normal file
4
Task/Repeat-a-string/Stata/repeat-a-string.stata
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
. scalar a="ha"
|
||||
. scalar b=a*5
|
||||
. display b
|
||||
hahahahaha
|
||||
1
Task/Repeat-a-string/Zkl/repeat-a-string.zkl
Normal file
1
Task/Repeat-a-string/Zkl/repeat-a-string.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
"ha" * 5 # --> "hahahahaha"
|
||||
Loading…
Add table
Add a link
Reference in a new issue