September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,61 @@
|
|||
# Given any array, produce an array of [item, count] pairs for each run.
|
||||
def runs:
|
||||
reduce .[] as $item
|
||||
( [];
|
||||
if . == [] then [ [ $item, 1] ]
|
||||
else .[length-1] as $last
|
||||
| if $last[0] == $item
|
||||
then (.[0:length-1] + [ [$item, $last[1] + 1] ] )
|
||||
else . + [[$item, 1]]
|
||||
end
|
||||
end ) ;
|
||||
|
||||
# string to string
|
||||
def next_self_referential:
|
||||
def runs2integer: # input is an array as produced by runs,
|
||||
# i.e. an array of [count, n] pairs, where count is an int,
|
||||
# and n is an "exploded" digit
|
||||
reduce .[] as $pair
|
||||
(""; . + ($pair[1] | tostring) + ([$pair[0]]|implode) ) ;
|
||||
|
||||
explode | sort | reverse | runs | runs2integer;
|
||||
|
||||
# Given an integer as a string,
|
||||
# compute the entire sequence (of strings) to convergence:
|
||||
def sequence_of_self_referentials:
|
||||
def seq:
|
||||
. as $ary
|
||||
| (.[length-1] | next_self_referential) as $next
|
||||
| if ($ary|index($next)) then $ary
|
||||
else $ary + [$next] | seq
|
||||
end;
|
||||
[.] | seq;
|
||||
|
||||
def maximals(n):
|
||||
def interesting:
|
||||
tostring | (. == (explode | sort | reverse | implode));
|
||||
|
||||
reduce range(0;n) as $i
|
||||
([[], 0]; # maximalseeds, length
|
||||
if ($i | interesting) then
|
||||
($i|tostring|sequence_of_self_referentials|length) as $length
|
||||
| if .[1] == $length then [ .[0] + [$i], $length]
|
||||
elif .[1] < $length then [ [$i], $length]
|
||||
else .
|
||||
end
|
||||
else .
|
||||
end );
|
||||
|
||||
def task(n):
|
||||
maximals(n) as $answer
|
||||
| "The maximal length to convergence for seeds up to \(n) is \($answer[1]).",
|
||||
"The corresponding seeds are the allowed permutations",
|
||||
"of the representative number(s): \($answer[0][])",
|
||||
"For each representative seed, the self-referential sequence is as follows:",
|
||||
($answer[0][] | tostring
|
||||
| ("Representative: \(.)",
|
||||
"Self-referential sequence:",
|
||||
(sequence_of_self_referentials | map(tonumber))))
|
||||
;
|
||||
|
||||
task(1000000)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
$ jq -n -r -f Self_referential_sequence.jq
|
||||
The maximal length to convergence for seeds up to 1000000 is 21.
|
||||
The corresponding seeds are the allowed permutations
|
||||
of the representative number(s): 9900
|
||||
For each representative seed, the self-referential sequence is as follows:
|
||||
Representative: 9900
|
||||
Self-referential sequence:
|
||||
[
|
||||
9900,
|
||||
2920,
|
||||
192210,
|
||||
19222110,
|
||||
19323110,
|
||||
1923123110,
|
||||
1923224110,
|
||||
191413323110,
|
||||
191433125110,
|
||||
19151423125110,
|
||||
19251413226110,
|
||||
1916151413325110,
|
||||
1916251423127110,
|
||||
191716151413326100,
|
||||
191726151423128100,
|
||||
19181716151413326000,
|
||||
19182716151423128000,
|
||||
29181716151413330000,
|
||||
19281716151423230000,
|
||||
19281716151413430000,
|
||||
19182716152413230000
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue