Teacup rim text: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 1,802: | Line 1,802: | ||
5 circular words were found. |
5 circular words were found. |
||
</pre> |
|||
=={{header|Ruby}}== |
|||
"woordenlijst.txt" is a Dutch wordlist. |
|||
<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) } |
|||
rotations.map(&:join) if rotations.all?{|rot| grouped_by_size[rot.size].include? rot.join } |
|||
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> |
</pre> |
||