PDA

View Full Version : Mathematics reversing issue...

luckygirl
01-28-2006, 03:38 PM
date = new Date();
year = date.getYear();
for (i = 1; i<= year;i++)
{
}
{
window.location.href=year+".php";

Given the i<= year, i++ statement, I assume that add and year are the same, and that "i" is equal to add or year +1.

So should something like this work?

var year = 1;
var i = 2;
var final;
for (final = 1; final< 395425559298;final++)
{
document.write(year+"<br>")
document.write(i+"<br>")
year++
i++
}

I would test it, but I am on a slow pc right now. I'm scared that it might crash my computer.

BaldEagle
01-28-2006, 04:23 PM
If what you want to know is if what you wrote is equivalent to the prior code then the answer is no. Will it run, yes, even though it will take a long time. add += year + i as you stated is equiv to add = add + year + i.

So, in the upper code year = 2006, add = year (2006) and the loop for i goes from 1 to year(2006).

first iteration of add += year + i will make add = to 2006 + 2006 + 1 which is 4013. second pass through the loop will make add = 4013 + 2006 + 2 which is 6021. Each time add is updated to the new result of the addition.

In your example you are simply counting from 1 to a huge number by increments of 1.

BaldEagle

luckygirl
01-28-2006, 04:53 PM
<script>
var year = 2006;
var i = 1;
var final;
{
}
}
}
</script>

I have no idea how to write the script so that it parallels what you're saying.

;) thxy

SyKo
01-28-2006, 05:18 PM
var year = 2006;
var i = 1;
var final;
{
}
}

I have no idea how to write the script so that it parallels what you're saying.

;) thxy

You forgot a { after the function. Just letting ya know in case it didn't work and you weren't sure why.

^_^

luckygirl
01-28-2006, 05:26 PM
Is the code correct though? lol

Thanks for the tip. :D

BaldEagle
01-28-2006, 05:28 PM
var year = 2006;
var i = 1;
var final;
{
{
// change this
// to this
i++
}
// I rearranged this for clarity
else
{
}
}

BaldEagle

 using a loop as the original code does is probably more efficient

 One last thing, i didn't run this out to see if the value actually adds up the 395425559298, but if it doesn't your version will run forever. You can avoid that by changing it to

luckygirl
01-28-2006, 05:38 PM
<script>
var year = 2006;
var i = 1;
var final;
{
i++
}
else
{
}
}
</script>

The new code won't work either.

//Eagle My orignal way of looping I can't figure out how to make it equivilant to the first code posted. The mathematics are difficult for me to reverse.

BaldEagle
01-28-2006, 05:41 PM
<script>
var year = 2006;
var i = 1;
var final;
{
i++
}
else
{
}
}
</script>

my mistake. Move the addMe() to the if side and don't have an else

<script>
var year = 2006;
var i = 1;
var final;
{
i++
}
}
</script>

BaldEagle

luckygirl
01-28-2006, 05:53 PM
Lets start over. The new javascript is not going to bring up anything pertaining to the first javascript I posted.

date = new Date();
year = date.getYear();
for (i = 1; i<= year;i++)
{
}
{
window.location.href=year+".php";

I am looking to create a loop that will solve for year where the final add variable is equal to 395425559298 and add=add+year+i

BaldEagle
01-28-2006, 05:56 PM
You will need to change the if (add != ...) to if (add >= ...). I suspected this might be an issue. I come from a different background programming wise in which a stack is maintained to allow the called function to know where to return. I assume javascript works the same way. So if you have a function that calls itsself then the stack just keeps growing. As I stated earlier the looping method is the only real efficient way to do this.

BaldEagle

luckygirl
01-28-2006, 05:59 PM
I think that by posted my misinterpretation of your first reply, I threw us off course. My reply before this one should clarify. me hopes*

BaldEagle
01-28-2006, 06:20 PM
I am looking to create a loop that will solve for year where the final add variable is equal to 395425559298 and add=add+year+i

I apologize because I did misinperpret what you wanted. Let me see if I got it straight. Do you want to start with a number: 395425559298 and then determine what year it represents based on the reversal of the algorithm from the original code? Is this right?

BaldEagle

luckygirl
01-28-2006, 06:26 PM
Yes

hehe

ps - no apology necessary. I'm new with javascript and enjoy the opportunities to learn and help.

BaldEagle
01-28-2006, 07:11 PM
var year = 2006;
function findYear()
{
for (i = 1; i<= year;i++)
{
{
year = i;
break;
}
}
}

Not certain this is what you want. Didn't test it either. Also this will not find years in the future as I have started it from current year.

I have also made it that add does not have to be an exact match. You can modify to your liking.

Baldeagle

luckygirl
01-28-2006, 07:24 PM
Thanks// I'll work on it :D

BaldEagle
01-28-2006, 07:39 PM
Just out of curiousity what is this for? In the original code in order for add to be = to 395425559298 year will have to way in the future.

Just wondering what the point of it is.

BaldEagle

luckygirl
01-28-2006, 07:51 PM
For a futuristic website login. I need to make sure the year is correct. Each user has his or her own year value which is validated by this code

I figured out how to get an exact year in the future in a simple way, but the stack keeps overflowing. //without the mathematics

<script>
date = new Date();
year = 2006;
function yearget()
{
for (i = 1; i<= year;i++)
{
}
{
window.location.href=year+".php";
}
else
{
year++
yearget()
}
}
</script>

I'm assuming the error is generated because there are too many functions running at once. Is there a way to clear the function and still retain the variable amount for year from the previous function calls?

wow, what a day. Thanks for the help eagle. You're awesome.

BaldEagle
01-28-2006, 07:58 PM
You can look up recursion and see if there is a way to keep from exhausting the stack, but the bottom line is your year will have to be out in the million range in order for the algorithm to = that huge number. So I reckon I still don't really understand what you are doing.

BaldEagle

luckygirl
01-28-2006, 08:07 PM
I will send you a link when I get the login and other scripts to work. :D Thanks again!

BaldEagle
01-28-2006, 08:08 PM
For a futuristic website login. I need to make sure the year is correct. Each user has his or her own year value which is validated by this code

I figured out how to get an exact year in the future in a simple way, but the stack keeps overflowing. //without the mathematics

<script>
date = new Date();
year = 2006;
function yearget()
{
for (i = 1; i<= year;i++)
{
}
{
window.location.href=year+".php";
}
else
{
year++
yearget()
}
}
</script>

I'm assuming the error is generated because there are too many functions running at once. Is there a way to clear the function and still retain the variable amount for year from the previous function calls?

wow, what a day. Thanks for the help eagle. You're awesome.

Sometimes I am pretty dense. I think I get it now. Each user has a log in number (year) and the purpose of the code is to verify that the number they entered does not exceed the boundaries set up by the algorithm. Which as I stated before would be a number range from 1 to somewhere around a million. Then there are .php pages whith that persons year as the page name (1.php, 27.php and so forth). Correct so far? If this is what you re looking for then I think I can help you, if not then I'm totally lost and will have to defer to someone else.

BaldEagle

luckygirl
01-28-2006, 08:13 PM
Yes, each user has a separate year. :D

Something similar. I just need to be able to generate a year from random add variables. That's why I'm reversing the script.

BaldEagle
01-28-2006, 08:17 PM
<script>
year = document.getElementById("sometextinputbox").value;
// or
year = "<%=querystringinfo%>"
function yearget()
{
for (i = 1; i<= year;i++)
{
}
{
window.location.href=whereveryouneedtosendthem;
}
else
{
window.location.href=year+".php";
}
}
</script>

I hope this is what you want because I hate to have you not get your answer or fix and I am running out of ideas (personal problem on my part). I'm certain there is a solution. The only thing that this doesn't address is someone trying to login with an arbitrary number that doesn't fail the algorithm only to find there is no page by that number.

BaldEagle

BaldEagle
01-28-2006, 08:19 PM
The other code I gave you (couple, three posts back) will reverse the algorithm and should work, but you can't really find the year you can only verify it is within a range.

BaldEagle

luckygirl
01-28-2006, 08:21 PM
The problem is, I have a script that generates a (somewhat) random code as the final add value. How can I check it to make sure I write to the right php/perl pages?

I'm not mathematical genious, so I have no idea how to reverse the algorithm to find the year.

BaldEagle
01-28-2006, 08:49 PM
Perhaps you could just eliminate the algorithm (add value) all together and just use a random number that is generated when a user registers. If you make the random number range big enough you will rarely get duplicates. Then when you do get dupes just call random number gen again. Just a thought.

I really think I should defer this to someone more experienced than me. Although it is a good excercise I fear that I may lead you way out on a limb.

I am not certain posting more code would help either especially if it is php code as I am not fluent in php.

Sorry and good luck,

BaldEagle