Server IP : 85.214.239.14 / Your IP : 3.21.247.221 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/self/root/usr/share/doc/gawk/examples/prog/ |
Upload File : |
# anagram.awk --- An implementation of the anagram-finding algorithm # from Jon Bentley's "Programming Pearls," 2nd edition. # Addison Wesley, 2000, ISBN 0-201-65788-0. # Column 2, Problem C, section 2.8, pp 18-20. # # This program requires gawk 4.0 or newer. # Required gawk-specific features: # - True multidimensional arrays # - split() with "" as separator splits out individual characters # - asort() and asorti() functions # # See https://savannah.gnu.org/projects/gawk. # # Arnold Robbins # arnold@skeeve.com # Public Domain # January, 2011 /'s$/ { next } # Skip possessives { key = word2key($1) # Build signature data[key][$1] = $1 # Store word with signature } # word2key --- split word apart into letters, sort, and join back together function word2key(word, a, i, n, result) { n = split(word, a, "") asort(a) for (i = 1; i <= n; i++) result = result a[i] return result } END { sort = "sort" for (key in data) { # Sort words with same key nwords = asorti(data[key], words) if (nwords == 1) continue # And print. Minor glitch: trailing space at end of each line for (j = 1; j <= nwords; j++) printf("%s ", words[j]) | sort print "" | sort } close(sort) }