![](themes/Helius/images/top_left.gif) |
|
![](themes/Helius/images/top_right.gif) |
![](themes/Helius/forums/images/logo1.gif) |
|
![](themes/Helius/forums/images/logo2.gif) |
IT Security and Insecurity Portal |
|
![](themes/Helius/forums/images/top_left.gif) |
Algorithms |
![](themes/Helius/forums/images/top_right.gif) |
Posted: Fri Sep 24, 2004 7:55 pm |
|
|
ic3 |
Regular user |
![Regular user Regular user](modules/Forums/images/ranks/rang2.gif)
![](https://www.waraxe.us/images/blank.gif) |
|
Joined: Jul 18, 2004 |
Posts: 14 |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/post_corner.gif) |
|
|
_________________
![](http://icecold42.port5.com/ice.jpg) |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/top_left.gif) |
|
![](themes/Helius/forums/images/top_right.gif) |
Posted: Sat Sep 25, 2004 5:26 pm |
|
|
ic3 |
Regular user |
![Regular user Regular user](modules/Forums/images/ranks/rang2.gif)
![](https://www.waraxe.us/images/blank.gif) |
|
Joined: Jul 18, 2004 |
Posts: 14 |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/post_corner.gif) |
|
i have made this in javascript to try and help me solve it - but its not 100% working can u help me with it?
Code: | <script>
var size =3;
var start =1;
var step =1;
var row =1;
var col = (size + 1) / 2;
var count = 1;
var number = start;
while (count > size * size)
{
var ans=new Array("row","col");
ans = number;
number = number + step;
count = count + 1;
var newrow = row - 1;
if (newrow < 1)
{
newrow = size;
}
var newcol = col - 1;
if (newcol < 1)
{
newcol = size;
}
if (array(newrow,newcol) != array("",""))
{
newrow = row + 1;
newcol = col;
}
if (newrow > size)
{
newrow = 1;
}
row = newrow
col = newcol
document.write("newrow:" + newrow + "<br>");
document.write("newcol:" + newcol + "<br>");
document.write("ans[0] + ans[1]:" + ans[0] + ans[1] + "<br>");
document.write("ans[1] + ans[0]:" + ans[1] + ans[0] + "<br>");
document.write("ans[1] + ans[1]:" + ans[1] + ans[1] + "<br>");
}
document.write("size:" + size + "<br>");
document.write("start:" + start + "<br>");
document.write("step:" + step + "<br>");
document.write("row:" + row + "<br>");
document.write("col:" + col + "<br>");
document.write("count:" + count + "<br>");
document.write("number:" + number + "<br>");
</script> |
|
|
_________________
![](http://icecold42.port5.com/ice.jpg) |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/top_left.gif) |
|
![](themes/Helius/forums/images/top_right.gif) |
Posted: Sun Sep 26, 2004 5:12 pm |
|
|
ic3 |
Regular user |
![Regular user Regular user](modules/Forums/images/ranks/rang2.gif)
![](https://www.waraxe.us/images/blank.gif) |
|
Joined: Jul 18, 2004 |
Posts: 14 |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/post_corner.gif) |
|
ok i finished it:
Code: | <html>
<title>Task 2 Algorithm</title>
<body>
<form name=value>
size: <input type="text" name="size" value="0" size=1 maxlength=1>
start: <input type="text" name="start" value="0" size=1 maxlength=1>
step: <input type="text" name="step" value="0" size=1 maxlength=1>
<input type="button" value="Submit" onclick="wholething()"/></form>
<script language=javascript>
function wholething()
{
size = parseInt(document.value.size.value);
start = parseInt(document.value.start.value);
step = parseInt(document.value.step.value);
populate(size,start,step)
}
function doHeadings()
{
var headings = new Array("Size","Start","Step","Row","Col","Count","Number","Array(1,1)","Array(1,2)","Array(1,3)","Array(2,1)","Array(2,2)","Array(2,3)","Array(3,1)","Array(3,2)","Array(3,3)","NewRow","NewCol");
for (i=0; i<headings.length; i++)
{
document.write("<td width=44><b>" + headings[i] + "</b></td>");
}
document.write("</tr>")
}
function createTable()
{
document.write("<table width=792 border=1 bordercolor=black CELLSPACING=0, CELLPADDING=1><tr>");
}
function closeTable()
{
document.write("</table><br><br>")
}
function createArray(first,second)
{
answer=new Array(first);
for (i=0; i <first ; i++)
{
answer[i]=new Array(second);
}
return answer;
}
function doResults()
{
document.write("<tr>");
document.write("<td align=center>" + size + "</td>");
document.write("<td align=center>" + start + "</td>");
document.write("<td align=center>" + step + "</td>");
document.write("<td align=center>" + row + "</td>");
document.write("<td align=center>" + col + "</td>");
document.write("<td align=center>" + count + "</td>");
document.write("<td align=center>" + number + "</td>")
document.write("<td align=center>" + Empty(answer[0][0]) + "</td>");
document.write("<td align=center>" + Empty(answer[0][1])+ "</td>");
document.write("<td align=center>" + Empty(answer[0][2])+ "</td>");
document.write("<td align=center>" + Empty(answer[1][0])+ "</td>");
document.write("<td align=center>" + Empty(answer[1][1])+ "</td>");
document.write("<td align=center>" + Empty(answer[1][2])+ "</td>");
document.write("<td align=center>" + Empty(answer[2][0])+ "</td>");
document.write("<td align=center>" + Empty(answer[2][1])+ "</td>");
document.write("<td align=center>" + Empty(answer[2][2])+ "</td>");
document.write("<td align=center>" + newrow + "</td>");
document.write("<td align=center>" + newcol + "</td>");
document.write("</tr>");
}
function Empty(element)
{
if (element == undefined)
{
return "empty";
}
else return element;
}
function displayResults(results)
{
document.write("<table width=" + results.length * 80 + " border=1 bordercolor=black CELLSPACING=0, CELLPADDING=1><tr>");
document.write("<td width=44></td>");
for (i=0; i<results.length; i++)
{
document.write("<td width=80 align=center><b>" + (i+1) + "</b></td>");
}
document.write("</tr>");
for (i=0; i<results.length; i++)
{
document.write("<tr><td align=center><b>" + (i+1) + "</b></td>");
for (j=0; j<results.length; j++)
{
document.write("<td align=center>" + Empty(results[i][j]) + "</td>");
}
document.write("</tr>");
}
closeTable();
}
function populate(size,start,step)
{
row = 1;
col = (size + 1)/2;
count = 1;
number = start;
answer = createArray(size,size);
createTable();
doHeadings();
do
{
answer[row-1][col-1]=number;
number=number+step;
count++;
newrow = row-1;
if (newrow<1)
{
newrow = size;
}
newcol = col-1;
if (newcol<1)
{
newcol = size;
}
if (answer[newrow-1][newcol-1] != undefined)
{
newrow = row+1;
newcol = col;
if (newrow > size)
{
newrow=1;
}
}
row = newrow;
col = newcol;
doResults();
}
while (count <= Math.pow(size,2))
closeTable();
document.write("<br><br>")
displayResults(answer);
}
</script> |
|
|
_________________
![](http://icecold42.port5.com/ice.jpg) |
|
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/top_left.gif) |
|
![](themes/Helius/forums/images/top_right.gif) |
Posted: Fri Nov 12, 2004 1:01 am |
|
|
OkIDaN |
Regular user |
![Regular user Regular user](modules/Forums/images/ranks/rang2.gif)
![](https://www.waraxe.us/images/blank.gif) |
|
Joined: Nov 12, 2004 |
Posts: 6 |
Location: Azerbaijan |
|
|
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/spacer.gif) |
![](themes/Helius/forums/images/post_corner.gif) |
|
Heh, nice trilogy. Consider this post as the Null byte. |
|
|
|
|
www.waraxe.us Forum Index -> General discussion
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
All times are GMT
Page 1 of 1
|
|
|
Powered by phpBB © 2001-2008 phpBB Group
|
|
|
|
|