Last active
December 26, 2015 04:39
-
-
Save elegantcoder/7095440 to your computer and use it in GitHub Desktop.
Synap apply
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log = (input) -> | |
Math.log(input) / Math.log(26) | |
getColName = (input) -> | |
temp = input | |
char = '' | |
result = '' | |
# temp -= temp / temp^power | |
# console.log power | |
i = 3 | |
power = Math.floor(log(temp)) | |
loop | |
n = Math.pow(26, power) # 제곱수 | |
k = Math.floor(temp/n) # 계수 | |
temp -= k*n # 나머지 | |
# console.log input, temp, power, k, n | |
# XXX => 진법 계산이랑 똑같잖아 ㅁ니어ㅏㄹㅁ니어란ㅁ이ㅏㅓㄹ | |
break unless power-- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAlphaName1(input) { | |
var ret = ''; | |
var div = input; | |
var table = [''] // 0 index 채움 | |
for(var i = 0; i < 26; i++) { | |
table.push(String.fromCharCode(i+65)) | |
} | |
while (div > 0) { | |
mod = div%26 | |
div = parseInt(div/26) | |
if (mod === 0) { | |
div-- | |
mod = 26 | |
} | |
ret = table[mod]+ret | |
} | |
return ret; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAlphaName3(input) { | |
//input--; //0-based index | |
var i = 0; | |
var base26 = input.toString(26); | |
var len = base26.length; | |
var column = ''; | |
var code = 0; | |
for(i = 0; i < len; i++) { | |
code = parseInt(base26[i], 10) + 65 | |
column += String.fromCharCode(code) | |
} | |
return column; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment