论坛帮助 |
社区圈子 |
日历事件 |
2022-10-29, 10:59 | #1 | ||
|
|||
java爱好者
等级: 六袋长老
|
https://blog.csdn.net/jialan75/artic...ails/127583607 下面是JavaScript部分 代码:
RULE = { '2x1 4': '4 1 2 3', '2x2 8': '1* 8* 4 5 7* 2* 6 3', '2x2 4': '1* 4* 2 3', '2x3 12': '1* 12* 4 9 5* 8* 11* 2* 10 3 7* 6*', '4x1 8': '4 5 8 1 2 7 6 3', '4x1 4': '2 3 4 1', '4x2 16': '1* 16* 13* 4* 8 9 12 5 3* 14* 15* 2* 6 11 10 7', '4x2 8': '1* 8* 7* 2* 4 5 6 3', '4x2 4': '2 3 4 1 2 3 4 1', '2x4 16': '1* 16* 4 13 5* 12* 8 9 15* 2* 14 3 11* 6* 10 7', '2x4 8': '1* 8* 4 5 3* 6* 2 7', '2x4 4': '1* 4* 1* 4* 2 3 2 3', '4x3 12': '7* 6* 5* 8* 10 3 4 9 11* 2* 1* 12*', '4x4 32': '13* 20* 21* 12* 4 29 28 5 1* 32* 25* 8* 16 17 24 9 11* 22* 19* 14* 6 27 30 3 7* 26* 31* 2* 10 23 18 15', '4x4 16': '5* 12* 9* 8* 4 13 16 1 3* 14* 15* 2* 6 11 10 7', '4x4 8': '1* 8* 5* 4* 1* 8* 5* 4* 2 7 6 3 2 7 6 3', '4x4 4': '1* 4* 1* 4* 1* 4* 1* 4* 2 3 2 3 2 3 2 3' } function saddleStitch(col, row, page_count) { temp_page_count = page_count _list = [] //拼数 spell = col * row * 2 //余数 remainder = page_count % spell if (spell == 12 && remainder != 0) return if (spell == 24 && spell % 12 != 0) return if (remainder != 0 && spell != 24) { if (spell == 4 || spell == 8 || spell == 16 || spell == 32) { if (remainder == 4 || remainder == 8) { _list.push(remainder) } else if (remainder == 12) { _list.push(4) _list.push(8) } else if (remainder == 16) { _list.push(16) } else if (remainder == 20) { _list.push(4) _list.push(16) } else if (remainder == 24) { _list.push(8) _list.push(16) } else if (remainder == 28) { _list.push(4) _list.push(8) _list.push(16) } else { return } } else { return } page_count -= remainder } if (spell == 24) { for (var i = 0; i < parseInt(page_count / (col * row)); i++) _list.push(row * col) } else { for (var i = 0; i < parseInt(page_count / (col * row * 2)); i++) _list.push(row * col * 2) } list_result = [] start = 0 for (var i = 0; i < _list.length; i++) { len = _list[i] / 2 before_start = parseInt(start + 1) before_end = parseInt(start + len) before = before_start + '-' + before_end after_start = parseInt(temp_page_count - start - len + 1) after_end = parseInt(temp_page_count - start) after = after_start + "-" + after_end start += len key = col + "x" + row + " " + _list[i] print_model = _list[i] == spell ? '正反' : '自翻' key_rule = i + "-" + print_model + "-" + col + "x" + row + " " + _list[i] + ' ' + before + " " + after s = RULE[key] if (s == undefined) return value = '' for (var j = 0; j < s.split(' ').length; j++) { item = s.split(' ')[j] page = parseInt(item.replace("*", '')) xx = item.indexOf("*") == -1 ? '' : '*' if (page > len) { value += parseInt(after_end - len * 2 + page) + xx + '>' } else { value += parseInt(before_start - 1 + page) + xx + '>' } } list_result.push(key_rule + ' ' + value) } return list_result } function getRule(col, row, page_count) { list_result = saddleStitch(col, row, page_count); if (list_result != undefined && list_result.length > 0) { value = '' for (var i = 0; i < list_result.length; i++) { item = list_result[i]; arr = item.split(/ |x|-/); value += arr[arr.length - 1].replace(/>/g, " ") } return value } } col = 2 row = 2 page_count = 44 list_result = saddleStitch(col, row, page_count) alert(list_result) rule = getRule(col, row, page_count) alert(rule) |
||
右列会员因为此帖价值甚高向 jialan75 表示感谢: |
zcl119 (2023-05-15)
|