Jump to content

Word wheel: Difference between revisions

1,069 bytes added ,  3 years ago
Add Factor
(Add Factor)
Line 132:
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2020-07-03}}
<lang factor>USING: assocs assocs.extras combinators.short-circuit grouping
io.encodings.ascii io.files kernel math math.statistics
prettyprint sequences sets sorting ;
 
! Only consider words longer than two letters and words that
! contain elt.
: pare ( elt seq -- new-seq )
[ [ member? ] keep length 2 > and ] with filter ;
 
: words ( input-str path -- words )
[ [ midpoint@ ] keep nth ] [ ascii file-lines pare ] bi* ;
 
: ?<= ( m n/f -- ? ) dup f = [ nip ] [ <= ] if ;
 
! Can we make sequence 1 with the elements in sequence 2?
: can-make? ( seq1 seq2 -- ? )
[ histogram ] bi@ [ swapd at ?<= ] curry assoc-all? ;
 
: solve ( input-str path -- seq )
[ words ] keepd [ can-make? ] curry filter ;
 
"ndeokgelw" "unixdict.txt" solve [ length ] sort-with .</lang>
{{out}}
<pre style="height:20ex">
{
"eke"
"elk"
"keg"
"ken"
"wok"
"keel"
"keen"
"keno"
"knee"
"knew"
"know"
"kong"
"leek"
"week"
"woke"
"kneel"
"knowledge"
}
</pre>
 
=={{header|Julia}}==
1,827

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.