Teacup rim text: Difference between revisions

m
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Minor tidy)
 
(5 intermediate revisions by one other user not shown)
Line 1,802:
 
5 circular words were found.
</pre>
 
=={{header|Ruby}}==
"woordenlijst.txt" is a Dutch wordlist. It has 413125 words > 2 chars and takes about two minutes.
<syntaxhighlight lang="ruby">lists = ["unixdict.txt", "wordlist.10000", "woordenlijst.txt"]
 
lists.each do |list|
words = open(list).readlines( chomp: true).reject{|w| w.size < 3 }
grouped_by_size = words.group_by(&:size)
tea_words = words.filter_map do |word|
chars = word.chars
next unless chars.none?{|c| c < chars.first }
next if chars.uniq.size == 1
rotations = word.size.times.map {|i| chars.rotate(i).join }
rotations if rotations.all?{|rot| grouped_by_size[rot.size].include? rot }
end
puts "", list + ":"
tea_words.uniq(&:to_set).each{|ar| puts ar.join(", ") }
end
</syntaxhighlight>
{{out}}
<pre>
unixdict.txt:
apt, pta, tap
arc, rca, car
ate, tea, eat
 
wordlist.10000:
aim, ima, mai
arc, rca, car
asp, spa, pas
ate, tea, eat
ips, psi, sip
 
woordenlijst.txt:
ast, sta, tas
een, ene, nee
eer, ere, ree
</pre>
 
Line 1,954 ⟶ 1,992:
{{libheader|Wren-str}}
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./str" for Str
import "./sort" for Find
 
var readWords = Fn.new { |fileName|
9,479

edits