-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodulo26.html
More file actions
109 lines (106 loc) · 2.17 KB
/
modulo26.html
File metadata and controls
109 lines (106 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<script>
function doSomething()
{
const denominator=document.getElementById("denominator").value;
const decimal=1/denominator;
const modulo=document.getElementById("modulo").value;
let frac=0;
let more=""
if(!(modulo===""))
{
frac=mod26((modulo*1));
}
else
{
more=" denominator:"+denominator+" decimal:"+decimal+" ";
frac=mod26(decimal);
}
let output=document.getElementById("output");
output.innerHTML="mod26:"+frac;
}
function mod26(number,denominator=1)
{
if(denominator===1)
{
if(Number.isInteger(number))
{
if(number>=0)
{
console.log("normal modulo of "+number+" is "+number%26);
// return (number-(Math.floor(number/-26)*26));
return number%26;
}
else
{
console.log("negative conversion of "+number+" is "+(number+(Math.ceil(number/26)*26)));
// return (number+((Math.floor(number/-26)+1)*26));
return (number+(Math.ceil(number/-26)*26));
}
}
else
{
const n=naive(number)
if(!Number.isInteger(n))
{
console.log(number+" has no modulo 26");
return;
}
console.log("converting decimal "+number+" to 1/"+n);
return mod26(1,n);
}
}
else
{
const smaller=mod26(denominator);
let val=0;
switch(smaller)
{
case 25: val=25; break;
case 23: val=17; break;
case 21: val=5; break;
case 19: val=11; break;
case 17: val=23; break;
case 15: val=7; break;
case 11: val=19; break;
case 9: val=3; break;
case 7: val=15; break;
case 5: val=21; break;
case 3: val=9; break;
case 1: val=1; break;
default:
console.log("1/"+smaller+" has no modulo 26")
return;
}
console.log("modulo 26 of 1/"+smaller+" is "+val);
return val;
}
}
function naive(decimal)
{
let denominator=1;
if(decimal>0)
{
for(let x=1;x<(25*26);x++)
{
if((1/x)===decimal){return x;break;}
}
}
else
{
for(let x=-1;x>(-25*26);x--)
{
if((1/x)===decimal){return x;break;}
}
}
}
</script>
</head>
<body>
1/<input id="denominator" value="1"><br>
<input id="modulo">
<button onclick="doSomething()">process</button>
<div id="output"></div>
</body>
</html>