Guest User

Untitled

a guest
Aug 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. # -- coding: utf-8
  2.  
  3. require "rubygems"
  4. require "rspec"
  5.  
  6. describe do
  7. def to_num(chars)
  8. table = ("A".."Z").to_a
  9. chars = chars.split(//u)
  10. count = 1
  11. chars.reverse.inject(0){|r, c|
  12. r += (table.index(c)+1) * count
  13. count *= 26
  14. r
  15. }
  16. end
  17.  
  18. it "A == 1" do
  19. to_num("A").should == 1
  20. end
  21.  
  22. it "B == 2" do
  23. to_num("B").should == 2
  24. end
  25.  
  26. it "Z == 26" do
  27. to_num("Z").should == 26
  28. end
  29.  
  30. it "AA == 27" do
  31. to_num("AA").should == 27
  32. end
  33.  
  34. it "XFD == 16384" do
  35. to_num("XFD").should == 16384
  36. end
  37. end
Add Comment
Please, Sign In to add comment