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,45 @@
function pairwiseAnagrams X
if the optionkey is down then breakpoint
put the long seconds into T
put empty into itemsSoFar
repeat for each item W in X
put word 1 to -1 of W into W
if D[W] = 1 then next repeat
put 1 into D[W]
repeat for each item W2 in itemsSoFar
put W,W2 & cr after WPairs[sortChars(W & W2,true)]
end repeat
put W & comma after itemsSoFar
end repeat
repeat for each key K in WPairs
put empty into pairsSoFar
repeat for each line L in WPairs[K]
repeat for each line L2 in pairsSoFar
if item 1 of L is among the items of L2 or item 2 of L is among the items of L2 then next repeat
put L && "and" && L2 & cr after R
end repeat
put L & cr after pairsSoFar
end repeat
end repeat
put the long seconds - T
return char 1 to -2 of R
end pairwiseAnagrams
function sortChars X,lettersOnly
get charsToItems(X,lettersOnly)
sort items of it
return itemsToChars(it)
end sortChars
 
function charsToItems X,lettersOnly
repeat for each char C in X
if lettersOnly and C is not in "abcdefghijklmnopqrstuvwxyz" then next repeat
put C & comma after R
end repeat
return char 1 to -2 of R
end charsToItems
 
function itemsToChars X
replace comma with empty in X
return X
end itemsToChars

View file

@ -0,0 +1,40 @@
# Input: a string
# Output: an array, being the exploded form of the normalized input
def normalize:
explode
| map(if . >= 97 then (. - 97) elif . >= 65 then (. - 65) else empty end);
# Input: an array of strings
# Output: a dictionary with key:value pairs: normalizedString:string
def dictionary:
reduce .[] as $s ( {}; . + { ($s|normalize|implode): $s });
# Input: an array of strings (e.g. state names)
# Output: a stream of solutions
def solve:
# Given a pair of normalized state names as lists of integers:
def nletters: map(length) | add;
# input [[s1,s2], [t2,t2]]
def solved:
( .[0] | add | sort) == (.[1] | add | sort);
unique
| length as $l
| dictionary as $dictionary
| ($dictionary | keys | map(explode)) as $states
| reduce ( range(0; $l) as $s1
| range($s1+1; $l) as $s2
| range($s1+1; $l) as $t1
| select($s2 != $t1)
| range($t1+1; $l) as $t2
| select($s2 != $t2)
| [[$states[$s1], $states[$s2]], [$states[$t1], $states[$t2]]] ) as $quad
([];
if ($quad[0] | nletters) == ($quad[1] | nletters)
and ($quad | solved)
then . + [$quad | map( map( $dictionary[ implode ] ))]
else .
end)
| .[];

View file

@ -0,0 +1,20 @@
def States: [
"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado",
"Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey",
"New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina",
"South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming"
];
def task:
"Real state names:",
(States | solve),
"",
"States together with fictional state names:",
(States + ["New Kory", "Wen Kory", "York New", "Kory New", "New Kory"] | solve) ;
task

View file

@ -0,0 +1,21 @@
$ jq -c -n -r -f State_name_puzzle.jq
Real state names:
[["North Carolina","South Dakota"],["North Dakota","South Carolina"]]
States together with fictional state names:
[["Kory New","New Kory"],["New York","Wen Kory"]]
[["Kory New","New Kory"],["New York","York New"]]
[["Kory New","New Kory"],["Wen Kory","York New"]]
[["Kory New","New York"],["New Kory","Wen Kory"]]
[["Kory New","New York"],["New Kory","York New"]]
[["Kory New","New York"],["Wen Kory","York New"]]
[["Kory New","Wen Kory"],["New Kory","New York"]]
[["Kory New","Wen Kory"],["New Kory","York New"]]
[["Kory New","Wen Kory"],["New York","York New"]]
[["Kory New","York New"],["New Kory","New York"]]
[["Kory New","York New"],["New Kory","Wen Kory"]]
[["Kory New","York New"],["New York","Wen Kory"]]
[["New Kory","New York"],["Wen Kory","York New"]]
[["New Kory","Wen Kory"],["New York","York New"]]
[["New Kory","York New"],["New York","Wen Kory"]]
[["North Carolina","South Dakota"],["North Dakota","South Carolina"]]