Although this challenge looks simple it’s not very easy to be implemented.
We got only 15 solutions during the weekend: 7 Pythons, 3 C, 2 bash, 1 C#, 1 AWK, 1 Java.
The solutions are uploaded at GitHub and waiting you to see them 🙂 https://github.com/OLIMEX/WPC/tree/master/ISSUE-12
Jun 10, 2013 @ 21:48:24
No C++ this time :O
Jun 11, 2013 @ 14:29:10
Hi,
I have checked some of the codes, see below the result.
I have learned much from the two bash-versions:-)
Has someone tested the solutions written in C?
sol#2 Dylan,Python
go -> ‘got’, ‘o’ not found
tone -> ‘toe’, ‘tones’ not found
sol#3 Marek Vasut, Bash
her -> “hear” not found
say -> “stay” not found
I think the line with ‘sed’ must be corrected:
echo “$word” | sed “s/\([[:alnum:]]\{$i\}\)\(.\)\(.*$\)/\1[[:alnum:]]\3\n\1\3\n\1[[:alnum:]]\2\3/” ;
sol#5 Michael Zucchi, Bash
I think it is correct, one of my favourites.
sol#10 st0le, Python
go -> ‘got’, ‘o’ not found
her -> “hear” not found
Sorry, if I was wrong.
Jun 12, 2013 @ 10:28:19
C solution 8 seems to work (apart from including punctuation). Interesting solution.
The C solution 14 doesn’t work fully:
input word : bob
bob : box
bob : box
bob : box
end of file
should be box,boy,sob
I couldn’t get solution 15 to compile with gcc, it’s not C fwiw.
Jun 12, 2013 @ 12:16:46
I’ve started to study the Levenshtein distance:-)
Jun 12, 2013 @ 14:57:12
For solution 14 , If using any editor , you may to replace “.” “,” “!” … with space in file alice.txt . Now the program working with any symbol , for example ( # , a . ! : ) are symbols and are parts of word . Space is delimiter .
Jun 11, 2013 @ 16:13:44
Classic fencepost error on got/tones (xrange(l) instead of xrange(s) makes it work). Impatience.
Laziness to blame for ‘toe’ (‘toe.’ can be found).
But ‘o’ is not in my list (Similar words to ‘o’ are: I to of on or no a So so A Do do go * oh O V No X p Go 😉 Hubris?
Jun 11, 2013 @ 16:50:15
Hi,
As for similar words to ‘go’ , I think the difference, the missing ‘o’, comes from using case sensitiveness or not.
Jun 11, 2013 @ 18:35:25
solution 12:
$ ./wpc12.awk -v s=”go” alice_in_wonderland.txt
go
[1] no
[1] got
[1] do
[1] so
[1] to
Jun 12, 2013 @ 11:03:22
The text file for solution#12 in github is a truncated one.
?
Jun 12, 2013 @ 12:34:41
then use file from solution#6 intead
some additional changes
@@ -7,7 +7,7 @@
BEGIN {
IGNORECASE=1
– RS=”[^a-z]”
+ RS=”[^a-z’]”
SUBSEP=”@”
if (s==””) s=”Alice”
@@ -16,7 +16,7 @@
# distance between s and t
# http://pl.wikipedia.org/wiki/Odleg%C5%82o%C5%9B%C4%87_Levenshteina
-function lev(s,t, ls,lt,i,j,d,cost,del,ins,chg,tmp) {
+function lev(s,t, s_a,t_a,l_s,l_t,i,j,d,cost,del,ins,chg,tmp) {
split(s,s_a,””); l_s=length(s)
split(t,t_a,””); l_t=length(t)
@@ -43,7 +43,7 @@
}
{
– d=lev(s,$0)
+ d=lev(s,gensub(/[‘]/,””,”g”,$0))
cnt[d]+=1
distance[d,cnt[d]]=$0
}