This is how I check the CSC101- Zero Day Problem. I used Javascript because an important segment of the code is already done by someone else thankfully.
Examples to Use the Code
To check if a certain number in base 10 has the desired properties in a certain base, use testNum(base10number, whatbase). In the example below, the browser returns, passed because 252525 base 8 in base 10 is equal to 87381 which when multiplied by two equals base 10 174762 which is equal to the base 8 525252.
// Example:
testNum(174762,8);
// Return Value:
base[10]: 174762 base[8]: 525252 inv: 252525 inv[10]: 87381 inv[10] x 2: 174762 passed
To check if a certain range of base 10 numbers have the same properties. Use the testNums(floor, ciel, base, seek); function. Floor and ciel are the min and max base 10 numbers to test, base is the base which to convert this numbers to, and seek is the last character in the end of the number in which to seek the property on. In the example below, we test base 10 values from 0 to 174762, using base 8 and a seek of 2. The program will convert each base 10 number from 0 to 174762, then check if their base 8 counterpart has a last character of 2, if they do, then it puts 2 as the first character and shifts the rest to the right, making 5252 (base 8) in to 2525 (base 8). It then converts the new base 8 number in to base 10 which is 1365. After that it multiples 1365 (base 10) by 2 and finds out it's equal to 2730 which is the base 10 of 5252 (base 8). It means that both base 8 numbers 5252 and 525252 satisfy the Zero-Day problems required properties.
// Example:
testNums(0,174762,8,2);
// Return Value:
base[10]: 2730 base[8]: 5252 inv: 2525 inv[10]: 1365 inv[10] x 2: 2730
base[10]: 174762 base[8]: 525252 inv: 252525 inv[10]: 87381 inv[10] x 2: 174762
tested: 21782 passed: 2 failed: 21780 elements: 174762
In order to use the code, copy them to a text file and then put them in a single directory and make sure they have the appropriate names numbersystems.js and numbersystems.html respectively. In order to use the code, open the html file with your regular browser (should support Javascript).
numbersystems.js
// On our first day of CSC 101 class our teacher asked
// us to find a number that ends in 2. We then have
// to put two in the begining of the number then shift
// the rest of the characters to the right. For example
// 345642 wil become 234564 and 4562 will become
// 2456. We then have to check if this new number
// multiplied by two is equals to one. But sadly neither
// of my examples are. A lof of my classmates tried
// but I think it's hopeless. So I made a program to
// check this out and thankfully, I found some
// interesting things. First you have to know that
// from 0 to 10,000 in base ten, you cannot find
// the number we were finding. The closest number
// that you can get with this kind of property is at
// base 7 and 8. I wrote the program in Javascript
// because I don't have time to try it on C++. I need
// to do it quick. :D
function baseConverter (number,ob,nb) {
// Created 1997 by Brian Risk. http://brianrisk.com
number = number.toUpperCase();
var list = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var dec = 0;
for (var i = 0; i <= number.length; i++) {
dec += (list.indexOf(number.charAt(i))) * (Math.pow(ob , (number.length - i - 1)));
}
number = "";
var magnitude = Math.floor((Math.log(dec))/(Math.log(nb)));
for (var i = magnitude; i >= 0; i--) {
var amount = Math.floor(dec/Math.pow(nb,i));
number = number + list.charAt(amount);
dec -= amount*(Math.pow(nb,i));
}
return number;
}
function testNums(floor, ciel, base, seek){
var strSeek = new String(seek);
var strCurrNum = new String();
var intCurrNum = 0;
var intTested = 0;
var intPassed = 0;
var intFailed = 0;
var intStrNumOfTen = 0;
var intSeekTimesStrNumOfTen = 0;
for (var i = floor; i<=ciel; i++){
var strNum = new String(i);
strCurrNum = baseConverter(strNum ,10,base);
if ((strCurrNum[strCurrNum.length-1]==strSeek[0]) && (strCurrNum.length > 3)){
intTested++;
strNum = strCurrNum[strCurrNum.length-1] + strCurrNum.substring(0, strCurrNum.length-1);
intStrNumOfTen = parseInt(baseConverter(strNum,parseInt(base),10));
intSeekTimesStrNumOfTen = parseInt(strSeek[0]) * intStrNumOfTen;
if (intSeekTimesStrNumOfTen == i){
document.writeln("base[10]: " + i + " base[" + base + "]: " + strCurrNum + " inv: " + strNum + " inv[10]: " + intStrNumOfTen + " inv[10] x " + seek + ": " + intSeekTimesStrNumOfTen + "<br>");
intPassed++;
} else {
intFailed++;
//document.writeln("base[10]: " + i + " base[" + base + "]: " + strCurrNum + " inv: " + strNum + " inv[10]: " + intStrNumOfTen + " inv[10] x " + seek + ": " + intSeekTimesStrNumOfTen + "<br>");
}
}
}
document.writeln("tested: " + intTested + " passed: " + intPassed + " failed: " + intFailed + " elements: " + (ciel - floor) + "<br>");
}
function testNum(num, base){
var intStrNumOfTen = 0;
var intSeekTimesStrNumOfTen = 0;
var strCurrNum = new String(num);
var strSeek = new String(strCurrNum[strCurrNum.length-1]);
var strNum = new String(strCurrNum);
strCurrNum = baseConverter(strCurrNum ,10,base);
if ((strCurrNum[strCurrNum.length-1]==strSeek[0]) && (strCurrNum.length > 3))
{
strNum = strCurrNum[strCurrNum.length-1] + strCurrNum.substring(0, strCurrNum.length-1);
intStrNumOfTen = parseInt(baseConverter(strNum,parseInt(base),10));
intSeekTimesStrNumOfTen = parseInt(strSeek[0]) * intStrNumOfTen;
if (intSeekTimesStrNumOfTen == parseInt(num))
{
document.writeln("base[10]: " + num + " base[" + base + "]: " + strCurrNum + " inv: " + strNum + " inv[10]: " + intStrNumOfTen + " inv[10] x " + strSeek + ": " + intSeekTimesStrNumOfTen + " passed" + "<br>");
} else {
document.writeln("base[10]: " + num + " base[" + base + "]: " + strCurrNum + " inv: " + strNum + " inv[10]: " + intStrNumOfTen + " inv[10] x " + strSeek + ": " + intSeekTimesStrNumOfTen + " failed" + "<br>");
}
}
}
function testBaseRange(floor, ciel, minbase, maxbase)
{
for (var intCurrBase = minbase; intCurrBase<=maxbase; intCurrBase++)
{
testNums(floor,ciel,intCurrBase,2);
}
}
// Change this to the operation you want.
// And if you know JavaScript, improve upon.
testNums(0,174762,8,2);
numbersystems.html
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>Test</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<SCRIPT src="numbersystems.js" type=text/javascript></SCRIPT>
</HEAD>
</HTML>