Changeable words: Difference between revisions

Line 874:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq># Emit a stream of words "greater than" the input word that differ by just one character.
<lang jq>
def changeable_to($dict; $alphas):
# $alphas is an array of the characters that can be substituted.
# Emit a stream of words "greater than" the input word that differ by just one character.
def changeable_to($dict; $alphas):
. as $w
| range(0;length) as $i
| (.[$i:$i+1]|explode[]) as $j
| [range(97$j+1;123) | [.] | implode] as $alphas # 122 is "z"
| .[:$i] + $alphas[] + .[$i+1:]
| select($w < . and $dict[.]);
INDEX( inputs; . )
| . as $dict
| keys_unsorted[] # or keys[] for gojq
| [range(97;123) | [.] | implode] as $alphas
| keys[] # keys_unsorted[]
| select(length>11)
| . as $w
| [changeable_to($dict; $alphas)] | unique[] # avoid redundancy
| "\($w) <=> \(.)"</lang>
</lang>
Invocation: jq -n -rR -f changeable-words.jq unixdict.txt
{{out}}
Line 922 ⟶ 920:
upperclassman <=> upperclassmen
</pre>
 
 
=={{header|Julia}}==
2,496

edits