Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
#!/usr/bin/awk -f # equiv.awk -- print equivalence class of a word under Lewis Carroll's # word ladder game. (What words in a particular lexicon are reachable # from a given starting word?) # usage: equiv.awk word [lexicon [lexicon2...]] # If lexicon is not specified, it will be read from standard input. function add(word, i, letter){ if (state[word] > seen) return; print word; state[word]++; for (i=1; i<=length(word); i++) { for (letter in alphabet){ a = alphabet[letter]; new = substr(word, 1, i-1) a substr(word, i+1); if (state[new] == seen) { add(new); } } } state[word]++; } BEGIN { letters = "abcdefghijklmnopqrstuvwxyz"; split(letters, alphabet, ""); startword = tolower(ARGV[1]); equivlen = length(startword); ARGV[1] = ""; seen = 1; reached = 2; done = 3; } (length($1) == equivlen) { state[tolower($1)] = seen }; END { # This version forces the start word to appear in the lexicon, by adding # it if it is not found. state[startword] = seen; add(startword); # This version ignores the start word entirely if it does not already # appear in the lexicon. # if (state[startword] == seen) add(startword); }