Skip to content

Commit

Permalink
renamed ret to num for clarity; converted for loop to possibly more i…
Browse files Browse the repository at this point in the history
…diomatic foreach
  • Loading branch information
smholloway committed Aug 12, 2012
1 parent c9fadd3 commit 6d7850e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions scala/col2num.scala
Expand Up @@ -7,11 +7,11 @@
* col2num("aaa") -> 703
*/
def col2num(str: String): Int = {
var ret = 0
var num = 0
var index = 0
for (c <- str.toUpperCase.reverse) {
ret = ret + ((c - 'A' + 1) * scala.math.pow(26, index).toInt)
str.toUpperCase.reverse.foreach { c =>
num = num + ((c - 'A' + 1) * scala.math.pow(26, index).toInt)
index += 1
}
ret
num
}

0 comments on commit 6d7850e

Please sign in to comment.