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
17
Task/Rep-string/EchoLisp/rep-string-1.echolisp
Normal file
17
Task/Rep-string/EchoLisp/rep-string-1.echolisp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
(lib 'list) ;; list-rotate
|
||||
|
||||
;; a list is a rep-list if equal? to itself after a rotation of lam units
|
||||
;; lam <= list length / 2
|
||||
;; truncate to a multiple of lam before rotating
|
||||
;; try cycles in decreasing lam order (longest wins)
|
||||
|
||||
(define (cyclic? cyclic)
|
||||
(define len (length cyclic))
|
||||
(define trunc null)
|
||||
|
||||
(if (> len 1)
|
||||
(for ((lam (in-range (quotient len 2) 0 -1)))
|
||||
(set! trunc (take cyclic (- len (modulo len lam))))
|
||||
#:break (equal? trunc (list-rotate trunc lam)) => (list->string (take cyclic lam))
|
||||
'no-rep )
|
||||
'too-short-no-rep))
|
||||
20
Task/Rep-string/EchoLisp/rep-string-2.echolisp
Normal file
20
Task/Rep-string/EchoLisp/rep-string-2.echolisp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(define strings '["1001110011" "1110111011" "0010010010" "1010101010"
|
||||
"1111111111" "0100101101" "0100100" "101" "11" "00" "1"])
|
||||
|
||||
(define (task strings)
|
||||
(for-each (lambda (s)
|
||||
(writeln s (cyclic? (string->list s)))) strings))
|
||||
|
||||
(task strings)
|
||||
|
||||
"1001110011" "10011"
|
||||
"1110111011" "1110"
|
||||
"0010010010" "001"
|
||||
"1010101010" "1010"
|
||||
"1111111111" "11111"
|
||||
"0100101101" no-rep
|
||||
"0100100" "010"
|
||||
"101" no-rep
|
||||
"11" "1"
|
||||
"00" "0"
|
||||
"1" too-short-no-rep
|
||||
13
Task/Rep-string/LFE/rep-string-1.lfe
Normal file
13
Task/Rep-string/LFE/rep-string-1.lfe
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
(defun get-reps (text)
|
||||
(lists:filtermap
|
||||
(lambda (x)
|
||||
(case (get-rep text (lists:split x text))
|
||||
('() 'false)
|
||||
(x `#(true ,x))))
|
||||
(lists:seq 1 (div (length text) 2))))
|
||||
|
||||
(defun get-rep
|
||||
((text `#(,head ,tail))
|
||||
(case (string:str text tail)
|
||||
(1 head)
|
||||
(_ '()))))
|
||||
10
Task/Rep-string/LFE/rep-string-2.lfe
Normal file
10
Task/Rep-string/LFE/rep-string-2.lfe
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(defun report
|
||||
((`#(,text ()))
|
||||
(io:format "~p has no repeating characters.~n" `(,text)))
|
||||
((`#(,text (,head . ,_)))
|
||||
(io:format "~p repeats ~p every ~p character(s).~n" `(,text ,head ,(length head))))
|
||||
((data)
|
||||
(lists:map
|
||||
#'report/1
|
||||
(lists:zip data (lists:map #'get-reps/1 data)))
|
||||
'ok))
|
||||
22
Task/Rep-string/NGS/rep-string.ngs
Normal file
22
Task/Rep-string/NGS/rep-string.ngs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
tests = [
|
||||
'1001110011'
|
||||
'1110111011'
|
||||
'0010010010'
|
||||
'1010101010'
|
||||
'1111111111'
|
||||
'0100101101'
|
||||
'0100100'
|
||||
'101'
|
||||
'11'
|
||||
'00'
|
||||
'1'
|
||||
]
|
||||
|
||||
F is_repeated(s:Str) (s.len()/2..0).first(F(x) s.starts_with(s[x..null]))
|
||||
|
||||
{
|
||||
tests.each(F(test) {
|
||||
local r = is_repeated(test)
|
||||
echo("${test} ${if r "has repetition of length ${r} (i.e. ${test[0..r]})" "is not a rep-string"}")
|
||||
})
|
||||
}
|
||||
22
Task/Rep-string/Nim/rep-string.nim
Normal file
22
Task/Rep-string/Nim/rep-string.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import strutils
|
||||
|
||||
proc isRepeated(text): int =
|
||||
for x in countdown(text.len div 2, 0):
|
||||
if text.startsWith(text[x..text.high]): return x
|
||||
|
||||
const matchstr = """1001110011
|
||||
1110111011
|
||||
0010010010
|
||||
1010101010
|
||||
1111111111
|
||||
0100101101
|
||||
0100100
|
||||
101
|
||||
11
|
||||
00
|
||||
1"""
|
||||
|
||||
for line in matchstr.split():
|
||||
let ln = isRepeated(line)
|
||||
echo "'", line, "' has a repetition length of ", ln, " i.e ",
|
||||
(if ln > 0: "'" & line[0 .. <ln] & "'" else: "*not* a rep-string")
|
||||
6
Task/Rep-string/Oforth/rep-string.oforth
Normal file
6
Task/Rep-string/Oforth/rep-string.oforth
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
: repString(s)
|
||||
| sz i |
|
||||
s size dup ->sz 2 / 1 -1 step: i [
|
||||
s left(sz i - ) s right(sz i -) == ifTrue: [ s left(i) return ]
|
||||
]
|
||||
null ;
|
||||
15
Task/Rep-string/Sidef/rep-string.sidef
Normal file
15
Task/Rep-string/Sidef/rep-string.sidef
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var arr = <1001110011 1110111011
|
||||
0010010010 1010101010
|
||||
1111111111 0100101101
|
||||
0100100 101 11 00 1>;
|
||||
|
||||
arr.each { |n|
|
||||
if (var m = /^(.+)\1+(.*$)(?(?{ substr($1, 0, length $2) eq $2 })|(?!))/.match(n)) {
|
||||
var i = m[0].len;
|
||||
say (n.substr(0, i),
|
||||
n.substr(i, i).tr('01', '𝟘𝟙'),
|
||||
n.substr(i*2));
|
||||
} else {
|
||||
say "#{n} (no repeat)";
|
||||
}
|
||||
}
|
||||
20
Task/Rep-string/jq/rep-string-1.jq
Normal file
20
Task/Rep-string/jq/rep-string-1.jq
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def is_rep_string:
|
||||
# if self is a rep-string then return [n, prefix]
|
||||
# where n is the number of full occurrences of prefix
|
||||
def _check(prefix; n; sofar):
|
||||
length as $length
|
||||
| if length <= (sofar|length) then [n, prefix]
|
||||
else (sofar+prefix) as $sofar
|
||||
| if startswith($sofar) then _check(prefix; n+1; $sofar)
|
||||
elif ($sofar|length) > $length and
|
||||
startswith($sofar[0:$length]) then [n, prefix]
|
||||
else [0, prefix]
|
||||
end
|
||||
end
|
||||
;
|
||||
|
||||
[range (1; length/2 + 1) as $i
|
||||
| .[0:$i] as $prefix
|
||||
| _check($prefix; 1; $prefix)
|
||||
| select( .[0] > 1 ) ]
|
||||
;
|
||||
17
Task/Rep-string/jq/rep-string-2.jq
Normal file
17
Task/Rep-string/jq/rep-string-2.jq
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
def test:
|
||||
(
|
||||
"1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1"
|
||||
) | { (.) : is_rep_string }
|
||||
;
|
||||
|
||||
test
|
||||
12
Task/Rep-string/jq/rep-string-3.jq
Normal file
12
Task/Rep-string/jq/rep-string-3.jq
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
$ jq -n -c -f rep-string.jq
|
||||
{"1001110011":[[2,"10011"]]}
|
||||
{"1110111011":[[2,"1110"]]}
|
||||
{"0010010010":[[3,"001"]]}
|
||||
{"1010101010":[[5,"10"],[2,"1010"]]}
|
||||
{"1111111111":[[10,"1"],[5,"11"],[3,"111"],[2,"1111"],[2,"11111"]]}
|
||||
{"0100101101":[]}
|
||||
{"0100100":[[2,"010"]]}
|
||||
{"101":[]}
|
||||
{"11":[[2,"1"]]}
|
||||
{"00":[[2,"0"]]}
|
||||
{"1":[]}
|
||||
Loading…
Add table
Add a link
Reference in a new issue