function gcd(a, b) { if (b === 0) return a; else return gcd(b, a % b); } function inverse_mod(n, m) { var inv1 = 1, inv2 = 0, tmp; while (m) { tmp = inv1; inv1 = inv2; inv2 = tmp - inv2 * (n / m | 0); tmp = n; n = m; m = tmp % m; } return inv1; } function shortest_str(arr) { var min = 0; for (var i = 1; i < arr.length; i++) if (arr[i].length < arr[min].length) min = i; return min; } var map = [], plus_map = [""], minus_map = [""], iter = true, repeat = 2, start; for (var i = 1; i < 256; i++) { plus_map[i] = plus_map[i - 1] + "+"; minus_map[i] = minus_map[i - 1] + "-"; } for (var x = 0; x < 256; x++) { map[x] = []; for (var y = 0; y < 256; y++) { var delta = y - x; if (delta > 128) delta -= 256; if (delta < -128) delta += 256; if (delta >= 0) map[x][y] = plus_map[delta]; else map[x][y] = minus_map[-delta]; } } function generate(str) { var last = 0, len = str.length, char_map, result = "", memory = [0], index = 0; for (var i = 0; i < len; i++) { var chr = str.charCodeAt(i) & 255, options = [ ">" + map[0][chr], map[last][chr], ], shortest; shortest = shortest_str(options); result += options[shortest] + "."; last = chr; } return result; } export default { generate };