June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -4,7 +4,7 @@ A [[wp:semordnilap|semordnilap]] is a word (or phrase) that spells a different w
|
|||
Example: ''lager'' and ''regal''
|
||||
<br><br>
|
||||
;Task
|
||||
Using only words from the [http://www.puzzlers.org/pub/wordlists/unixdict.txt unixdict], report the total number of unique semordnilap pairs, and print 5 examples. (Note that lager/regal and regal/lager should be counted as one unique pair.)
|
||||
Using only words from <u>[http://www.puzzlers.org/pub/wordlists/unixdict.txt this list]</u>, report the total number of unique semordnilap pairs, and print 5 examples. (Note that lager/regal and regal/lager should be counted as one unique pair.)
|
||||
<br><br>
|
||||
;Related tasks
|
||||
* [[Palindrome_detection|Palindrome detection]]
|
||||
|
|
|
|||
|
|
@ -1,28 +1,21 @@
|
|||
integer p;
|
||||
record r;
|
||||
file f;
|
||||
text s;
|
||||
text s, t;
|
||||
|
||||
f_affix(f, "unixdict.txt");
|
||||
|
||||
while (f_line(f, s) != -1) {
|
||||
r[s] = 0;
|
||||
}
|
||||
f.affix("unixdict.txt");
|
||||
|
||||
p = 0;
|
||||
|
||||
for (s in r) {
|
||||
text t;
|
||||
|
||||
t = b_string(b_reverse(b_draft(s)));
|
||||
if (s > t) {
|
||||
if (r_key(r, t)) {
|
||||
p += 1;
|
||||
if (p <= 5) {
|
||||
o_(s, " ", t, "\n");
|
||||
}
|
||||
while (f.line(s) != -1) {
|
||||
if (r_o_integer(z, r, t = b_reverse(s))) {
|
||||
p += 1;
|
||||
if (p <= 5) {
|
||||
o_(s, " ", t, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
r[s] = 0;
|
||||
}
|
||||
|
||||
o_form("Semordnilap pairs: ~\n", p);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
import qualified Data.Set as S
|
||||
|
||||
semordnilaps = snd . foldl f (S.empty,[]) where
|
||||
f (s,w) x | S.member (reverse x) s = (s, x:w)
|
||||
| otherwise = (S.insert x s, w)
|
||||
semordnilaps
|
||||
:: (Ord a, Foldable t)
|
||||
=> t [a] -> [[a]]
|
||||
semordnilaps =
|
||||
let f x (s, w)
|
||||
| S.member (reverse x) s = (s, x : w)
|
||||
| otherwise = (S.insert x s, w)
|
||||
in snd . foldr f (S.empty, [])
|
||||
|
||||
main=do s <- readFile "unixdict.txt"
|
||||
let l = semordnilaps (lines s)
|
||||
print $ length l
|
||||
mapM_ print $ map (\x->(x, reverse x)) $ take 5 l
|
||||
main :: IO ()
|
||||
main = do
|
||||
s <- readFile "unixdict.txt"
|
||||
let l = semordnilaps (lines s)
|
||||
print $ length l
|
||||
mapM_ (print . ((,) <*> reverse)) $ take 5 l
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
// version 1.2.0
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val words = File("/usr/share/dict/words").readLines().toSet()
|
||||
val words = File("unixdict.txt").readLines().toSet()
|
||||
val pairs = words.map { Pair(it, it.reversed()) }
|
||||
.filter { it.first < it.second && it.second in words } // avoid dupes+palindromes, find matches
|
||||
println("Found ${pairs.size} semordnilap pairs")
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ module StrSet = Set.Make(String)
|
|||
|
||||
let str_rev s =
|
||||
let len = String.length s in
|
||||
let r = String.create len in
|
||||
let r = Bytes.create len in
|
||||
for i = 0 to len - 1 do
|
||||
r.[i] <- s.[len - 1 - i]
|
||||
Bytes.set r i s.[len - 1 - i]
|
||||
done;
|
||||
(r)
|
||||
Bytes.to_string r
|
||||
|
||||
let input_line_opt ic =
|
||||
try Some (input_line ic)
|
||||
|
|
|
|||
5
Task/Semordnilap/Octave/semordnilap.octave
Normal file
5
Task/Semordnilap/Octave/semordnilap.octave
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a = strsplit(fileread("unixdict.txt"), "\n");
|
||||
a = intersect(a, cellfun(@fliplr, a, "UniformOutput", false));
|
||||
a = a(arrayfun(@(i) ismember(fliplr(a{i}), a(i+1:length(a))), 1:length(a)));
|
||||
length(a)
|
||||
arrayfun(@(i) printf("%s %s\n", a{i}, fliplr(a{i})), 1:5)
|
||||
|
|
@ -1,17 +1,27 @@
|
|||
load "stdlib.ring"
|
||||
aList = file2list("C:\Ring\unixdict.txt")
|
||||
for m = 1 to 10
|
||||
nr = random(len(aList)-1) + 1
|
||||
bool = semordnilap(aList[nr])
|
||||
see aList[nr] + nl
|
||||
if bool = 0 see "is palindrome" + nl + nl
|
||||
else see "is semordnilap" + nl + nl ok
|
||||
next
|
||||
# Project : Semordnilap
|
||||
# Date : 2018/04/18
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
func semordnilap aString
|
||||
bString = ""
|
||||
for i=len(aString) to 1 step -1
|
||||
bString = bString + aString[i]
|
||||
next
|
||||
see aString
|
||||
if aString = bString return 0 else return 1 ok
|
||||
load "stdlib.ring"
|
||||
nr = 0
|
||||
num = 0
|
||||
aList = file2list("C:\Ring\CalmoSoft\unixdict.txt")
|
||||
for n = 1 to len(aList)
|
||||
bool = semordnilap(aList[n])
|
||||
if (bool > 0 and nr > n)
|
||||
num = num + 1
|
||||
if num % 31 = 0
|
||||
see aList[n] + " " + aList[nr] + nl
|
||||
ok
|
||||
ok
|
||||
next
|
||||
see "Total number of unique pairs = " + num + nl
|
||||
|
||||
func semordnilap(aString)
|
||||
bString = ""
|
||||
for i=len(aString) to 1 step -1
|
||||
bString = bString + aString[i]
|
||||
next
|
||||
nr = find(aList,bString)
|
||||
return nr
|
||||
|
|
|
|||
18
Task/Semordnilap/Stata/semordnilap.stata
Normal file
18
Task/Semordnilap/Stata/semordnilap.stata
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
set seed 17760704
|
||||
import delimited http://www.puzzlers.org/pub/wordlists/unixdict.txt, clear
|
||||
save temp, replace
|
||||
replace v1=strreverse(v1)
|
||||
merge 1:1 v1 using temp, nogen keep(3)
|
||||
drop if v1>=strreverse(v1)
|
||||
count
|
||||
158
|
||||
sample 5, count
|
||||
gen v2=strreverse(v1)
|
||||
list, noheader noobs
|
||||
+-------------+
|
||||
| evil live |
|
||||
| pat tap |
|
||||
| at ta |
|
||||
| nit tin |
|
||||
| ku uk |
|
||||
+-------------+
|
||||
Loading…
Add table
Add a link
Reference in a new issue