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,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))

View 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

View 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)
(_ '()))))

View 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))

View 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"}")
})
}

View 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")

View 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 ;

View 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)";
}
}

View 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 ) ]
;

View file

@ -0,0 +1,17 @@
def test:
(
"1001110011",
"1110111011",
"0010010010",
"1010101010",
"1111111111",
"0100101101",
"0100100",
"101",
"11",
"00",
"1"
) | { (.) : is_rep_string }
;
test

View 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":[]}