Last active
December 15, 2015 08:39
-
-
Save Crysknife007/5232235 to your computer and use it in GitHub Desktop.
Pi Mem. A Memorization aid for the first 500 digits of pi implemented with javascript.
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<META NAME="DESCRIPTION" CONTENT="Pi Mem. A Memorization aid for the first 500 digits of pi implemented with javascript. Complete with configurable dificulty levels, current digit counter, and next digit tips."> | |
<META NAME="KEYWORDS" CONTENT="pi,memorization,500,aid,pi mem,spike snell,spike"> | |
<title>Pi Mem - Memorize the first 500 digits</title> | |
<STYLE TYPE="text/css"> | |
body { | |
height: 100%; | |
margin-left: 0px%; | |
margin-top: 10%; | |
margin-right: 0px; | |
margin-bottom: 0px; | |
} | |
.text { | |
font-size:200% | |
} | |
#piField { | |
overflow: auto; | |
background-color: black; | |
border-color: lightblue; | |
border: 1px solid; | |
font-family: arial; | |
font-weight: bold; | |
font-size: 14pt; | |
color: lightblue; | |
background-image: url(pi.gif); | |
background-position: center center; | |
background-repeat: no-repeat; | |
resize: none; | |
} | |
#count { | |
overflow: auto; | |
background-color: black; | |
border-color: lightblue; | |
border: 0px; | |
font-family: arial; | |
font-weight: bold; | |
font-size: 14pt; | |
color: lightblue; | |
resize: none; | |
} | |
#status { | |
overflow: auto; | |
background-color: black; | |
border-color: lightblue; | |
border: 0px solid; | |
font-family: arial; | |
font-weight: bold; | |
font-size: 14pt; | |
color: lightblue; | |
resize: none; | |
} | |
#error { | |
overflow: auto; | |
background-color: black; | |
border-color: lightblue; | |
border: 0px; | |
font-family: arial; | |
font-weight: bold; | |
font-size: 14pt; | |
color: lightblue; | |
resize: none; | |
} | |
</STYLE> | |
<script language="javascript"> | |
<!-- | |
// The first 500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3,0,1,1,9,4,9,1,2]; | |
// A function to check the last digit of pi and see if it agrees with pi | |
function checkPi() { | |
// Set a pattern for number and grab the pi text field | |
var number = /[0-9]$/; | |
var piField = document.pi.piField.value; | |
var enteredWrong = false; | |
// Get the length of the piField | |
var piFieldLength = piField.length; | |
// If the user didn't enter a number | |
if ( number.test(piField.slice(-1)) != true ) { | |
enteredWrong = true; | |
document.pi.error.value = "Enter only numbers please."; | |
document.pi.piField.value = piField.slice(0,-1); | |
} | |
// If the user entered the wrong number | |
if (pi[piFieldLength-1] != piField.slice(-1) && piField.slice(-1) != "" && number.test(piField.slice(-1)) == true) { | |
enteredWrong = true; | |
document.pi.error.value = ""; | |
document.pi.piField.value = piField.slice(0,-1); | |
document.pi.status.value = "The next digits were: " + pi[piFieldLength-1] + pi[piFieldLength] + pi[piFieldLength+1] + pi[piFieldLength+2]; | |
} | |
// If the user entered the right number | |
if (pi[piFieldLength-1] == piField.slice(-1) && piField.slice(-1) != "") { | |
document.pi.status.value = ""; | |
} | |
// If the user entered a number | |
if (number.test(piField.slice(-1)) == true) { | |
document.pi.error.value = ""; | |
} | |
// Check to make sure the entire pi field is valid starting with the leftmost entry | |
var current = 0; | |
while (pi[current] == piField.charAt(current) && piField.charAt(current) != "") { | |
current++; | |
} | |
// Set the pi field to the last largest correct value of pi | |
// Erase more than one of the last digits entered if a 5, 10, 15, 20, or 25 back option is selected | |
var back = 1; | |
// Get the chosen radio button and set | |
chosen = ""; | |
len = document.pi.back.length; | |
for (var j = 0; j < len; j++) { | |
if (document.pi.back[j].checked) { | |
chosen = document.pi.back[j].value; | |
} | |
} | |
if (chosen == "") { | |
// set the radio button with javascript | |
back = 1; | |
} | |
else { | |
back = chosen - 1; | |
} | |
// If the user entered a wrong value set him back the right number of places | |
if ( enteredWrong ) { | |
if ( current < back ) { | |
document.pi.piField.value = ""; | |
document.pi.count.value = "0"; | |
} | |
else { | |
document.pi.piField.value = piField.slice(0,current-back); | |
document.pi.count.value = current-back; | |
} | |
} | |
else { | |
document.pi.piField.value = piField.slice(0,current); | |
// Display the current digit count of pi in the pi field | |
document.pi.count.value = current; | |
} | |
} | |
--> | |
</script> | |
</head> | |
<body bgcolor="#000000" onLoad="document.pi.piField.value = ''; document.pi.error.value = ' And put pi in the box.'; document.pi.status.value = ' Select a difficulty level.'; document.pi.count.value = '0';"> | |
<center> | |
<form action="#" name="pi"> | |
<table border="0" cellspacing="0" cellpadding="0" width="40%"> | |
<tr> | |
<td align="right" valign="top"> | |
<label class="text"><font color="lightblue" face="Arial">3.</label><br><br><br><br> | |
00 <br><input type="radio" name="back" value="1" onClick="document.pi.piField.focus();" checked> <br> | |
01 <br><input type="radio" name="back" value="2" onClick="document.pi.piField.focus();"> <br> | |
05 <br><input type="radio" name="back" value="6" onClick="document.pi.piField.focus();"> <br> | |
10 <br><input type="radio" name="back" value="11" onClick="document.pi.piField.focus();"> <br> | |
15 <br><input type="radio" name="back" value="16" onClick="document.pi.piField.focus();"> <br> | |
20 <br><input type="radio" name="back" value="21" onClick="document.pi.piField.focus();"> <br> | |
25 <br><input type="radio" name="back" value="26" onClick="document.pi.piField.focus();"> <br></font> | |
</td> | |
<td colspan="1" align="center" valign="middle"> | |
<textarea valign="middle" rows="20" cols="50" name="piField" id="piField" onKeyUp="checkPi()"></textarea> | |
</td> | |
</tr> | |
</table> | |
<table border="0" cellspacing="0" cellpadding="0" width="40%"> | |
<tr> | |
<td rowspan="2"> | |
<font color="black">Spike Snell</font> | |
</td> | |
<td align="left" colspan="1"> | |
<textarea valign="middle" rows="1" cols="3" name="count" id="count" readonly="readonly"></textarea> | |
</td> | |
<td align="right" colspan="2"> | |
<textarea valign="middle" rows="1" cols="28" name="status" id="status" readonly="readonly"></textarea> | |
</td> | |
</tr> | |
<tr> | |
<td align="right" colspan="3" valign="top"> | |
<textarea valign="middle" rows="1" cols="33" name="error" id="error" readonly="readonly"></textarea> | |
</td> | |
</tr> | |
</table> | |
</form> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment