Last active
August 29, 2015 14:08
-
-
Save mix3/0930494368764a41360e to your computer and use it in GitHub Desktop.
組み合わせを整数で設定出来る様にしたときの、整数が何に該当するか確認出来るようにするためのGAS
This file contains 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 mylookup(arg, range, val, blk) { | |
if (!blk) { | |
blk = " "; | |
} | |
var max = range[int(range.length-1)][0] * 2; | |
if (max <= arg) { | |
return "range over"; | |
} | |
var ret = []; | |
var key = 1; | |
var quot = int(arg / 2); | |
var cose = arg % 2; | |
while (1) { | |
if (0 < cose) { | |
ret.push(vlookup(key, range, val)); | |
} else { | |
ret.push(blk) | |
} | |
if (quot <= 0) { | |
return ret.join(" "); | |
} | |
key = int(key * 2); | |
cose = quot % 2; | |
quot = int(quot / 2); | |
} | |
} | |
function vlookup(arg, range, val) { | |
for (var r in range) { | |
if (arg == range[r][0]) { | |
return range[r][val-1]; | |
} | |
} | |
} | |
function int(arg) { | |
return Math.floor(arg); | |
} | |
function main() { | |
for (var key = 1; key <= 128; key++) { | |
Logger.log(Utilities.formatString("%3d", key)+": "+mylookup(key, [ | |
[ 1,,"月"], | |
[ 2,,"火"], | |
[ 4,,"水"], | |
[ 8,,"木"], | |
[16,,"金"], | |
[32,,"土"], | |
[64,,"日"], | |
], 3)); | |
} | |
} |
Author
mix3
commented
Oct 31, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment