fork download
  1. require 'minitest/autorun'
  2.  
  3. F=->s{v=->s{(0...s.size).map{|i|(i+1)*(s[i].ord-64)}.inject :+}
  4. r="#{s} DOES NOT BALANCE"
  5. (0...s.size).map{|i|b,a=s[0...i],s[i+1..-1]
  6. v[b.reverse]==v[a]&&r=b+" #{s[i]} "+a}
  7. r}
  8.  
  9. describe F do
  10. def test_cases
  11. assert_equal 'S T EAD', F['STEAD']
  12. assert_equal 'CONSUBST A NTIATION', F['CONSUBSTANTIATION']
  13. assert_equal 'WRO N GHEADED', F['WRONGHEADED']
  14. assert_equal 'UNINTELL I GIBILITY', F['UNINTELLIGIBILITY']
  15. assert_equal 'SUPERGLUE DOES NOT BALANCE', F['SUPERGLUE']
  16. end
  17. end
Success #stdin #stdout 0.06s 8528KB
stdin
Standard input is empty
stdout
Run options: --seed 7872

# Running tests:

.

Finished tests in 0.001664s, 600.9312 tests/s, 3004.6560 assertions/s.

1 tests, 5 assertions, 0 failures, 0 errors, 0 skips