Guest User

Untitled

a guest
Feb 17th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. $ sh soundex.sh fissbux
  2. ./fizzbuzz
  3. ./fizzbuzz.c
  4. ./fizzbuzz2
  5. ./fizzbuzz2.c
  6.  
  7. $ sh soundex.sh sharlok
  8. ./HackerRank/Algorithms/02-Implementation/17-sherlock_and_squares.c
  9.  
  10. $ sh soundex.sh sundek
  11. ./soundex.sh
  12. ./soundex.sed
  13.  
  14. #!/bin/sh
  15.  
  16. soundex=$( printf '%sn' "$1" | tr 'a-z' 'A-Z' | sed -f soundex.sed )
  17.  
  18. find . -exec sh -c '[ "$( printf '%sn' "${1##*/}" | tr 'a-z' 'A-Z' | sed -f soundex.sed )" = "$0" ]' "$soundex" {} ';' -print
  19.  
  20. s/[^[:alpha:]]//g
  21. h
  22. s/^(.).*$/1/
  23. x
  24. y/bfpvBFPV/11111111/
  25. y/cgjkqsxzCGJKQSXZ/2222222222222222/
  26. y/dtDT/3333/
  27. y/lL/44/
  28. y/mnMN/5555/
  29. y/rR/66/
  30. s/([1-6])[hwHW]1/1/g
  31. s/([1-6])11*/1/g
  32. s/[aeiouyhwAEIOUYHW]/!/g
  33. s/^.//
  34. H
  35. x
  36. s/n//
  37. s/!//g
  38. s/^(....).*$/1/
  39. s/^(...)$/10/
  40. s/^(..)$/100/
  41. s/^(.)$/1000/
  42.  
  43. # Remove non-alphabetic characters
  44. s/[^[:alpha:]]//g
  45.  
  46. # STEP 1 (part 1: retain first character)
  47.  
  48. # Save whole line in hold-space
  49. h
  50.  
  51. # Delete everything but the first character and swap with hold-space
  52. s/^(.).*$/1/
  53. x
  54.  
  55. # The hold-space now contains only the first character
  56.  
  57. # STEP 2
  58.  
  59. y/bfpvBFPV/11111111/
  60. y/cgjkqsxzCGJKQSXZ/2222222222222222/
  61. y/dtDT/3333/
  62. y/lL/44/
  63. y/mnMN/5555/
  64. y/rR/66/
  65.  
  66. # STEP 3
  67.  
  68. s/([1-6])[hwHW]1/1/g
  69. s/([1-6])11*/1/g
  70.  
  71. # STEP 1 (part 2: remove vowels etc.)
  72.  
  73. # We don't actually remove them but "mask" them with "!"
  74. # This avoids accidentally deleting the first character later
  75. s/[aeiouyhwAEIOUYHW]/!/g
  76.  
  77. # Replace first character with the one saved in the hold-space
  78.  
  79. # Delete first character
  80. s/^.//
  81.  
  82. # Append pattern-space to hold-space and swap
  83. H
  84. x
  85.  
  86. # Remove newline inserted by "H" above and all "!" (old vowels etc.)
  87. s/n//
  88. s/!//g
  89.  
  90. # STEP 4
  91.  
  92. s/^(....).*$/1/
  93. s/^(...)$/10/
  94. s/^(..)$/100/
  95. s/^(.)$/1000/
Add Comment
Please, Sign In to add comment