fork(1) download
  1.  
  2. F=
  3. ->d{o=[]
  4. c={}
  5. d=d.sort_by{|w|[w.size,w]}.map{|w|w=w.upcase.gsub /[^A-Z]/,''
  6. c[w]=l=1
  7. w.size.times{|i|p,x,s=w[0...i],w[i],w[i+1..-1]
  8. c[p+s]&&l!=x&&o<<p+"(#{w[i]})"+s
  9. l=x}}
  10. o}
  11.  
  12.  
  13. require 'minitest/autorun'
  14.  
  15. describe F do
  16. def test_case_1
  17. assert_equal [
  18. 'CA(R)T',
  19. '(C)ODE',
  20. 'I(N)PLAY',
  21. 'VER(S)IFY'],
  22. F[[
  23. 'cat',
  24. 'cart',
  25. 'code',
  26. 'golf',
  27. 'ode',
  28. 'verify',
  29. 'versify',
  30. 'in-play',
  31. 'IpLay']]
  32. end
  33.  
  34. def test_case_2
  35. assert_equal [
  36. 'MA(R)',
  37. 'MA(T)',
  38. 'MA(R)T',
  39. 'MAR(T)'],
  40. F[[
  41. 'mart',
  42. 'mar',
  43. 'mat',
  44. 'ma']]
  45. end
  46.  
  47. def test_case_3
  48. assert_equal [
  49. 'SCRA(P)PED'],
  50. F[[
  51. 'scrapped',
  52. 'scraped']]
  53. end
  54. end
  55.  
Success #stdin #stdout 0.1s 10648KB
stdin
Standard input is empty
stdout
Run options: --seed 56114

# Running tests:

...

Finished tests in 0.001217s, 2465.3374 tests/s, 2465.3374 assertions/s.

3 tests, 3 assertions, 0 failures, 0 errors, 0 skips