Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Best-shuffle/Jq/best-shuffle-1.jq
Normal file
34
Task/Best-shuffle/Jq/best-shuffle-1.jq
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
def count(s): reduce s as $i (0;.+1);
|
||||
|
||||
def swap($i;$j):
|
||||
.[$i] as $x | .[$i] = .[$j] | .[$j] = $x;
|
||||
|
||||
# Input: an array
|
||||
# Output: a best shuffle
|
||||
def bestShuffleArray:
|
||||
. as $s
|
||||
| reduce range(0; length) as $i (.;
|
||||
. as $t
|
||||
| (first(range(0; length)
|
||||
| select( $i != . and
|
||||
$t[$i] != $s[.] and
|
||||
$s[$i] != $t[.] and
|
||||
$t[$i] != $t[.])) as $j
|
||||
| swap($i;$j))
|
||||
// $t # fallback
|
||||
);
|
||||
|
||||
# Award 1 for every spot which changed:
|
||||
def score($base):
|
||||
. as $in
|
||||
| count( range(0;length)
|
||||
| select($base[.] != $in[.]) );
|
||||
|
||||
# Input: a string
|
||||
# Output: INPUT, BESTSHUFFLE, (NUMBER)
|
||||
def bestShuffle:
|
||||
. as $in
|
||||
| explode
|
||||
| . as $s
|
||||
| bestShuffleArray
|
||||
| "\($in), \(implode), (\( length - score($s) ))" ;
|
||||
2
Task/Best-shuffle/Jq/best-shuffle-2.jq
Normal file
2
Task/Best-shuffle/Jq/best-shuffle-2.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"abracadabra", "seesaw", "elk", "grrrrrr", "up", "a", "antidisestablishmentarianism"
|
||||
| bestShuffle
|
||||
Loading…
Add table
Add a link
Reference in a new issue