September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
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 ) ]
|
||||
;
|
||||
Loading…
Add table
Add a link
Reference in a new issue