[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Exhausting link pairs between nodes using math.rand in a uniform network.

JT

2/26/2016 12:51:00 PM

A short snippet to exhaust possible links.
Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.

If anyone can see why it does not run thru with correct math rand restrictions tell me.

Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.

<script type="text/javascript">
arr = new Array();nodes = 9; links = 4;
for(k = 0; k < nodes; k ++ )
{
arr[k] = { nroflinks : 0, nodelinks : "" };
}
createLinks();

function createLinks()
{
i = 0;
j = 0;
temp = new Array();

while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j = arr[i].nroflinks;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
//Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
aLink = Math.floor(Math.random() *nodes) ;
for(k = 0; k < temp.length; k ++ )
{
if(aLink == temp[k])
{
dublett = true; document.write("already in list " );

}
}

if(aLink == i){dublett=true;}
document.write(dublett,"New Link-->", aLink, "<br>");
if(dublett == false )
{
temp[j] = aLink;
arr[i].nodelinks += aLink + ",";
arr[aLink].nodelinks += i + ",";
document.write(i, "<--->", arr[i].nodelinks, "<br>");
arr[i].nroflinks ++ ;
arr[aLink].nroflinks ++ ;
j ++ ;
}
}
document.write("<P>" );
i++;
}
}
</script>
20 Answers

JT

2/26/2016 1:13:00 PM

0

Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> A short snippet to exhaust possible links.
> Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
>
> If anyone can see why it does not run thru with correct math rand restrictions tell me.
>
> Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
>
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nroflinks : 0, nodelinks : "" };
> }
> createLinks();
>
> function createLinks()
> {
> i = 0;
> j = 0;
> temp = new Array();
>
> while(i < nodes)
> {
> //This see so that links already generated accounted for if one link than j=0 and so on.
> j = arr[i].nroflinks;
> while(j < links)
> {
> dublett = false;
> //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> aLink = Math.floor(Math.random() *nodes) ;
> for(k = 0; k < temp.length; k ++ )
> {
> if(aLink == temp[k])
> {
> dublett = true; document.write("already in list " );
>
> }
> }
>
> if(aLink == i){dublett=true;}
> document.write(dublett,"New Link-->", aLink, "<br>");
> if(dublett == false )
> {
> temp[j] = aLink;
> arr[i].nodelinks += aLink + ",";
> arr[aLink].nodelinks += i + ",";
> document.write(i, "<--->", arr[i].nodelinks, "<br>");
> arr[i].nroflinks ++ ;
> arr[aLink].nroflinks ++ ;
> j ++ ;
> }
> }
> document.write("<P>" );
> i++;
> }
> }
> </script>

Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.

So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.

JT

2/26/2016 1:15:00 PM

0

Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > A short snippet to exhaust possible links.
> > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> >
> > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> >
> > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> >
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nroflinks : 0, nodelinks : "" };
> > }
> > createLinks();
> >
> > function createLinks()
> > {
> > i = 0;
> > j = 0;
> > temp = new Array();
> >
> > while(i < nodes)
> > {
> > //This see so that links already generated accounted for if one link than j=0 and so on.
> > j = arr[i].nroflinks;
> > while(j < links)
> > {
> > dublett = false;
> > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > aLink = Math.floor(Math.random() *nodes) ;
> > for(k = 0; k < temp.length; k ++ )
> > {
> > if(aLink == temp[k])
> > {
> > dublett = true; document.write("already in list " );
> >
> > }
> > }
> >
> > if(aLink == i){dublett=true;}
> > document.write(dublett,"New Link-->", aLink, "<br>");
> > if(dublett == false )
> > {
> > temp[j] = aLink;
> > arr[i].nodelinks += aLink + ",";
> > arr[aLink].nodelinks += i + ",";
> > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > arr[i].nroflinks ++ ;
> > arr[aLink].nroflinks ++ ;
> > j ++ ;
> > }
> > }
> > document.write("<P>" );
> > i++;
> > }
> > }
> > </script>
>
> Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
>
> So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.

I rephrase the question how do i make nodelinks an array rather than a string.

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nroflinks : 0, nodelinks : "" };
}

JT

2/26/2016 1:22:00 PM

0

Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > A short snippet to exhaust possible links.
> > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > >
> > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > >
> > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > >
> > > <script type="text/javascript">
> > > arr = new Array();nodes = 9; links = 4;
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > }
> > > createLinks();
> > >
> > > function createLinks()
> > > {
> > > i = 0;
> > > j = 0;
> > > temp = new Array();
> > >
> > > while(i < nodes)
> > > {
> > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > j = arr[i].nroflinks;
> > > while(j < links)
> > > {
> > > dublett = false;
> > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > aLink = Math.floor(Math.random() *nodes) ;
> > > for(k = 0; k < temp.length; k ++ )
> > > {
> > > if(aLink == temp[k])
> > > {
> > > dublett = true; document.write("already in list " );
> > >
> > > }
> > > }
> > >
> > > if(aLink == i){dublett=true;}
> > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > if(dublett == false )
> > > {
> > > temp[j] = aLink;
> > > arr[i].nodelinks += aLink + ",";
> > > arr[aLink].nodelinks += i + ",";
> > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > arr[i].nroflinks ++ ;
> > > arr[aLink].nroflinks ++ ;
> > > j ++ ;
> > > }
> > > }
> > > document.write("<P>" );
> > > i++;
> > > }
> > > }
> > > </script>
> >
> > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> >
> > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
>
> I rephrase the question how do i make nodelinks an array rather than a string.
>
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nroflinks : 0, nodelinks : "" };
> }

That simple?
for(k = 0; k < nodes; k ++ )
{
arr[k] = { nroflinks : 0, nodelinks : [] };
}

JT

2/26/2016 1:27:00 PM

0

Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > A short snippet to exhaust possible links.
> > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > >
> > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > >
> > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > >
> > > > <script type="text/javascript">
> > > > arr = new Array();nodes = 9; links = 4;
> > > > for(k = 0; k < nodes; k ++ )
> > > > {
> > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > }
> > > > createLinks();
> > > >
> > > > function createLinks()
> > > > {
> > > > i = 0;
> > > > j = 0;
> > > > temp = new Array();
> > > >
> > > > while(i < nodes)
> > > > {
> > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > j = arr[i].nroflinks;
> > > > while(j < links)
> > > > {
> > > > dublett = false;
> > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > for(k = 0; k < temp.length; k ++ )
> > > > {
> > > > if(aLink == temp[k])
> > > > {
> > > > dublett = true; document.write("already in list " );
> > > >
> > > > }
> > > > }
> > > >
> > > > if(aLink == i){dublett=true;}
> > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > if(dublett == false )
> > > > {
> > > > temp[j] = aLink;
> > > > arr[i].nodelinks += aLink + ",";
> > > > arr[aLink].nodelinks += i + ",";
> > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > arr[i].nroflinks ++ ;
> > > > arr[aLink].nroflinks ++ ;
> > > > j ++ ;
> > > > }
> > > > }
> > > > document.write("<P>" );
> > > > i++;
> > > > }
> > > > }
> > > > </script>
> > >
> > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > >
> > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> >
> > I rephrase the question how do i make nodelinks an array rather than a string.
> >
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nroflinks : 0, nodelinks : "" };
> > }
>
> That simple?
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nroflinks : 0, nodelinks : [] };
> }

But how do i refer to it?

if (arr[i].nodelinks[j]==aLink){ } ?

JT

2/26/2016 1:50:00 PM

0

Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > A short snippet to exhaust possible links.
> > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > >
> > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > >
> > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > >
> > > > > <script type="text/javascript">
> > > > > arr = new Array();nodes = 9; links = 4;
> > > > > for(k = 0; k < nodes; k ++ )
> > > > > {
> > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > }
> > > > > createLinks();
> > > > >
> > > > > function createLinks()
> > > > > {
> > > > > i = 0;
> > > > > j = 0;
> > > > > temp = new Array();
> > > > >
> > > > > while(i < nodes)
> > > > > {
> > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > j = arr[i].nroflinks;
> > > > > while(j < links)
> > > > > {
> > > > > dublett = false;
> > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > for(k = 0; k < temp.length; k ++ )
> > > > > {
> > > > > if(aLink == temp[k])
> > > > > {
> > > > > dublett = true; document.write("already in list " );
> > > > >
> > > > > }
> > > > > }
> > > > >
> > > > > if(aLink == i){dublett=true;}
> > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > if(dublett == false )
> > > > > {
> > > > > temp[j] = aLink;
> > > > > arr[i].nodelinks += aLink + ",";
> > > > > arr[aLink].nodelinks += i + ",";
> > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > arr[i].nroflinks ++ ;
> > > > > arr[aLink].nroflinks ++ ;
> > > > > j ++ ;
> > > > > }
> > > > > }
> > > > > document.write("<P>" );
> > > > > i++;
> > > > > }
> > > > > }
> > > > > </script>
> > > >
> > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > >
> > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > >
> > > I rephrase the question how do i make nodelinks an array rather than a string.
> > >
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > }
> >
> > That simple?
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nroflinks : 0, nodelinks : [] };
> > }
>
> But how do i refer to it?
>
> if (arr[i].nodelinks[j]==aLink){ } ?

But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.

I mean this to just append an array slot and it is so hard to understand????
So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.

Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.

arr[i].nodelinks[arr[i].nroflinks] = aLink;


<script type="text/javascript">
arr = new Array();nodes = 9; links = 4;

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nroflinks : 0, nodelinks : [] };
}

createLinks();

function createLinks()
{
i = 0;
j = 0;
temp = new Array();

while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j = arr[i].nroflinks;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
//Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
aLink = Math.floor(Math.random() *nodes) ;
for(k = 0; k < temp.length; k ++ )
{
if(aLink == temp[k])
{
dublett = true; document.write("already in list " );

}
}

if(aLink == i){dublett=true;}

if(dublett == false )
{
document.write(dublett,"New Link-->", aLink, "<br>");
temp[j] = aLink;
arr[i].nodelinks[arr[i].nroflinks] = aLink;
arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
document.write(i, "<--->", arr[i].nodelinks, "<br>");
arr[i].nroflinks ++ ;
arr[aLink].nroflinks ++ ;
j ++ ;
}
}
document.write("<P>" );
i++;
}
}
</script>

JT

2/26/2016 2:05:00 PM

0

Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > A short snippet to exhaust possible links.
> > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > >
> > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > >
> > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > >
> > > > > > <script type="text/javascript">
> > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > {
> > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > }
> > > > > > createLinks();
> > > > > >
> > > > > > function createLinks()
> > > > > > {
> > > > > > i = 0;
> > > > > > j = 0;
> > > > > > temp = new Array();
> > > > > >
> > > > > > while(i < nodes)
> > > > > > {
> > > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > j = arr[i].nroflinks;
> > > > > > while(j < links)
> > > > > > {
> > > > > > dublett = false;
> > > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > > for(k = 0; k < temp.length; k ++ )
> > > > > > {
> > > > > > if(aLink == temp[k])
> > > > > > {
> > > > > > dublett = true; document.write("already in list " );
> > > > > >
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > if(aLink == i){dublett=true;}
> > > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > if(dublett == false )
> > > > > > {
> > > > > > temp[j] = aLink;
> > > > > > arr[i].nodelinks += aLink + ",";
> > > > > > arr[aLink].nodelinks += i + ",";
> > > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > arr[i].nroflinks ++ ;
> > > > > > arr[aLink].nroflinks ++ ;
> > > > > > j ++ ;
> > > > > > }
> > > > > > }
> > > > > > document.write("<P>" );
> > > > > > i++;
> > > > > > }
> > > > > > }
> > > > > > </script>
> > > > >
> > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > >
> > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > >
> > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > >
> > > > for(k = 0; k < nodes; k ++ )
> > > > {
> > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > }
> > >
> > > That simple?
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > }
> >
> > But how do i refer to it?
> >
> > if (arr[i].nodelinks[j]==aLink){ } ?
>
> But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
>
> I mean this to just append an array slot and it is so hard to understand????
> So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
>
> Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
>
> arr[i].nodelinks[arr[i].nroflinks] = aLink;
>
>
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
>
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nroflinks : 0, nodelinks : [] };
> }
>
> createLinks();
>
> function createLinks()
> {
> i = 0;
> j = 0;
> temp = new Array();
>
> while(i < nodes)
> {
> //This see so that links already generated accounted for if one link than j=0 and so on.
> j = arr[i].nroflinks;
> while(j < links)
> {
> dublett = false;
> //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> aLink = Math.floor(Math.random() *nodes) ;
> for(k = 0; k < temp.length; k ++ )
> {
> if(aLink == temp[k])
> {
> dublett = true; document.write("already in list " );
>
> }
> }
>
> if(aLink == i){dublett=true;}
>
> if(dublett == false )
> {
> document.write(dublett,"New Link-->", aLink, "<br>");
> temp[j] = aLink;
> arr[i].nodelinks[arr[i].nroflinks] = aLink;
> arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> document.write(i, "<--->", arr[i].nodelinks, "<br>");
> arr[i].nroflinks ++ ;
> arr[aLink].nroflinks ++ ;
> j ++ ;
> }
> }
> document.write("<P>" );
> i++;
> }
> }
> </script>

but probably should use length...

JT

2/26/2016 3:31:00 PM

0

Den fredag 26 februari 2016 kl. 15:05:11 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > A short snippet to exhaust possible links.
> > > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > > >
> > > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > > >
> > > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > > >
> > > > > > > <script type="text/javascript">
> > > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > {
> > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > }
> > > > > > > createLinks();
> > > > > > >
> > > > > > > function createLinks()
> > > > > > > {
> > > > > > > i = 0;
> > > > > > > j = 0;
> > > > > > > temp = new Array();
> > > > > > >
> > > > > > > while(i < nodes)
> > > > > > > {
> > > > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > > j = arr[i].nroflinks;
> > > > > > > while(j < links)
> > > > > > > {
> > > > > > > dublett = false;
> > > > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > > > for(k = 0; k < temp.length; k ++ )
> > > > > > > {
> > > > > > > if(aLink == temp[k])
> > > > > > > {
> > > > > > > dublett = true; document.write("already in list " );
> > > > > > >
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > > if(aLink == i){dublett=true;}
> > > > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > > if(dublett == false )
> > > > > > > {
> > > > > > > temp[j] = aLink;
> > > > > > > arr[i].nodelinks += aLink + ",";
> > > > > > > arr[aLink].nodelinks += i + ",";
> > > > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > > arr[i].nroflinks ++ ;
> > > > > > > arr[aLink].nroflinks ++ ;
> > > > > > > j ++ ;
> > > > > > > }
> > > > > > > }
> > > > > > > document.write("<P>" );
> > > > > > > i++;
> > > > > > > }
> > > > > > > }
> > > > > > > </script>
> > > > > >
> > > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > > >
> > > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > > >
> > > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > > >
> > > > > for(k = 0; k < nodes; k ++ )
> > > > > {
> > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > }
> > > >
> > > > That simple?
> > > > for(k = 0; k < nodes; k ++ )
> > > > {
> > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > }
> > >
> > > But how do i refer to it?
> > >
> > > if (arr[i].nodelinks[j]==aLink){ } ?
> >
> > But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
> >
> > I mean this to just append an array slot and it is so hard to understand????
> > So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
> >
> > Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
> >
> > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> >
> >
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> >
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nroflinks : 0, nodelinks : [] };
> > }
> >
> > createLinks();
> >
> > function createLinks()
> > {
> > i = 0;
> > j = 0;
> > temp = new Array();
> >
> > while(i < nodes)
> > {
> > //This see so that links already generated accounted for if one link than j=0 and so on.
> > j = arr[i].nroflinks;
> > while(j < links)
> > {
> > dublett = false;
> > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > aLink = Math.floor(Math.random() *nodes) ;
> > for(k = 0; k < temp.length; k ++ )
> > {
> > if(aLink == temp[k])
> > {
> > dublett = true; document.write("already in list " );
> >
> > }
> > }
> >
> > if(aLink == i){dublett=true;}
> >
> > if(dublett == false )
> > {
> > document.write(dublett,"New Link-->", aLink, "<br>");
> > temp[j] = aLink;
> > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > arr[i].nroflinks ++ ;
> > arr[aLink].nroflinks ++ ;
> > j ++ ;
> > }
> > }
> > document.write("<P>" );
> > i++;
> > }
> > }
> > </script>
>
> but probably should use length...

Reconstruction almost there.

<script type="text/javascript">
arr = new Array();nodes = 9; links = 4;

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nodelinks : [] };
}

createLinks();

function createLinks()
{
i = 0;
j = 0;


while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j=arr[i].nodelinks.length;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
//Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
aLink = Math.floor(Math.random() *nodes) ;
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true; document.write("already in list " );
}
}

if(aLink == i){dublett=true;}
document.write(i,"...",dublett,"Link-->", aLink, "<br>");
if(dublett == false )
{
arr[i].nodelinks[arr.length] = aLink;
arr[aLink].nodelinks[arr.length] = i;
j ++ ;
}
}
document.write(arr[i].nodelinks, "<br>");
i++;
}
}
</script>

JT

2/26/2016 3:35:00 PM

0

Den fredag 26 februari 2016 kl. 16:30:53 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 15:05:11 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t....@gmail.com:
> > > > > > > > A short snippet to exhaust possible links.
> > > > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > > > >
> > > > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > > > >
> > > > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > > > >
> > > > > > > > <script type="text/javascript">
> > > > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > {
> > > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > > }
> > > > > > > > createLinks();
> > > > > > > >
> > > > > > > > function createLinks()
> > > > > > > > {
> > > > > > > > i = 0;
> > > > > > > > j = 0;
> > > > > > > > temp = new Array();
> > > > > > > >
> > > > > > > > while(i < nodes)
> > > > > > > > {
> > > > > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > > > j = arr[i].nroflinks;
> > > > > > > > while(j < links)
> > > > > > > > {
> > > > > > > > dublett = false;
> > > > > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > > > > for(k = 0; k < temp.length; k ++ )
> > > > > > > > {
> > > > > > > > if(aLink == temp[k])
> > > > > > > > {
> > > > > > > > dublett = true; document.write("already in list " );
> > > > > > > >
> > > > > > > > }
> > > > > > > > }
> > > > > > > >
> > > > > > > > if(aLink == i){dublett=true;}
> > > > > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > > > if(dublett == false )
> > > > > > > > {
> > > > > > > > temp[j] = aLink;
> > > > > > > > arr[i].nodelinks += aLink + ",";
> > > > > > > > arr[aLink].nodelinks += i + ",";
> > > > > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > > > arr[i].nroflinks ++ ;
> > > > > > > > arr[aLink].nroflinks ++ ;
> > > > > > > > j ++ ;
> > > > > > > > }
> > > > > > > > }
> > > > > > > > document.write("<P>" );
> > > > > > > > i++;
> > > > > > > > }
> > > > > > > > }
> > > > > > > > </script>
> > > > > > >
> > > > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > > > >
> > > > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > > > >
> > > > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > > > >
> > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > {
> > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > }
> > > > >
> > > > > That simple?
> > > > > for(k = 0; k < nodes; k ++ )
> > > > > {
> > > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > > }
> > > >
> > > > But how do i refer to it?
> > > >
> > > > if (arr[i].nodelinks[j]==aLink){ } ?
> > >
> > > But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
> > >
> > > I mean this to just append an array slot and it is so hard to understand????
> > > So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
> > >
> > > Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
> > >
> > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > >
> > >
> > > <script type="text/javascript">
> > > arr = new Array();nodes = 9; links = 4;
> > >
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > }
> > >
> > > createLinks();
> > >
> > > function createLinks()
> > > {
> > > i = 0;
> > > j = 0;
> > > temp = new Array();
> > >
> > > while(i < nodes)
> > > {
> > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > j = arr[i].nroflinks;
> > > while(j < links)
> > > {
> > > dublett = false;
> > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > aLink = Math.floor(Math.random() *nodes) ;
> > > for(k = 0; k < temp.length; k ++ )
> > > {
> > > if(aLink == temp[k])
> > > {
> > > dublett = true; document.write("already in list " );
> > >
> > > }
> > > }
> > >
> > > if(aLink == i){dublett=true;}
> > >
> > > if(dublett == false )
> > > {
> > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > temp[j] = aLink;
> > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > arr[i].nroflinks ++ ;
> > > arr[aLink].nroflinks ++ ;
> > > j ++ ;
> > > }
> > > }
> > > document.write("<P>" );
> > > i++;
> > > }
> > > }
> > > </script>
> >
> > but probably should use length...
>
> Reconstruction almost there.
>
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
>
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nodelinks : [] };
> }
>
> createLinks();
>
> function createLinks()
> {
> i = 0;
> j = 0;
>
>
> while(i < nodes)
> {
> //This see so that links already generated accounted for if one link than j=0 and so on.
> j=arr[i].nodelinks.length;
> while(j < links)
> {
> dublett = false;
> //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> aLink = Math.floor(Math.random() *nodes) ;
> for(k = 0; k < arr[i].nodelinks.length; k ++ )
> {
> if(aLink == arr[i].nodelinks[k])
> {
> dublett = true; document.write("already in list " );
> }
> }
>
> if(aLink == i){dublett=true;}
> document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> if(dublett == false )
> {
> arr[i].nodelinks[arr.length] = aLink;
> arr[aLink].nodelinks[arr.length] = i;
> j ++ ;
> }
> }
> document.write(arr[i].nodelinks, "<br>");
> i++;
> }
> }
> </script>

Did it?
<script type="text/javascript">
arr = new Array();nodes = 9; links = 4;

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nodelinks : [] };
}

createLinks();

function createLinks()
{
i = 0;
j = 0;


while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j=arr[i].nodelinks.length;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
//Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
aLink = Math.floor(Math.random() *nodes) ;
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true; document.write("already in list " );
}
}
if(aLink == i){dublett=true;}

document.write(i,"...",dublett,"Link-->", aLink, "<br>");
if(dublett == false )
{
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
j ++ ;
}
}
document.write(arr[i].nodelinks, "<br>");
i++;
}
}
</script>

JT

2/26/2016 3:42:00 PM

0

Den fredag 26 februari 2016 kl. 16:35:18 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 16:30:53 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 15:05:11 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t....@gmail.com:
> > > > > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > A short snippet to exhaust possible links.
> > > > > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > > > > >
> > > > > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > > > > >
> > > > > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > > > > >
> > > > > > > > > <script type="text/javascript">
> > > > > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > > {
> > > > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > > > }
> > > > > > > > > createLinks();
> > > > > > > > >
> > > > > > > > > function createLinks()
> > > > > > > > > {
> > > > > > > > > i = 0;
> > > > > > > > > j = 0;
> > > > > > > > > temp = new Array();
> > > > > > > > >
> > > > > > > > > while(i < nodes)
> > > > > > > > > {
> > > > > > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > > > > j = arr[i].nroflinks;
> > > > > > > > > while(j < links)
> > > > > > > > > {
> > > > > > > > > dublett = false;
> > > > > > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > > > > > for(k = 0; k < temp.length; k ++ )
> > > > > > > > > {
> > > > > > > > > if(aLink == temp[k])
> > > > > > > > > {
> > > > > > > > > dublett = true; document.write("already in list " );
> > > > > > > > >
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > if(aLink == i){dublett=true;}
> > > > > > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > > > > if(dublett == false )
> > > > > > > > > {
> > > > > > > > > temp[j] = aLink;
> > > > > > > > > arr[i].nodelinks += aLink + ",";
> > > > > > > > > arr[aLink].nodelinks += i + ",";
> > > > > > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > > > > arr[i].nroflinks ++ ;
> > > > > > > > > arr[aLink].nroflinks ++ ;
> > > > > > > > > j ++ ;
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > document.write("<P>" );
> > > > > > > > > i++;
> > > > > > > > > }
> > > > > > > > > }
> > > > > > > > > </script>
> > > > > > > >
> > > > > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > > > > >
> > > > > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > > > > >
> > > > > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > > > > >
> > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > {
> > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > }
> > > > > >
> > > > > > That simple?
> > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > {
> > > > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > > > }
> > > > >
> > > > > But how do i refer to it?
> > > > >
> > > > > if (arr[i].nodelinks[j]==aLink){ } ?
> > > >
> > > > But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
> > > >
> > > > I mean this to just append an array slot and it is so hard to understand????
> > > > So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
> > > >
> > > > Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
> > > >
> > > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > >
> > > >
> > > > <script type="text/javascript">
> > > > arr = new Array();nodes = 9; links = 4;
> > > >
> > > > for(k = 0; k < nodes; k ++ )
> > > > {
> > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > }
> > > >
> > > > createLinks();
> > > >
> > > > function createLinks()
> > > > {
> > > > i = 0;
> > > > j = 0;
> > > > temp = new Array();
> > > >
> > > > while(i < nodes)
> > > > {
> > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > j = arr[i].nroflinks;
> > > > while(j < links)
> > > > {
> > > > dublett = false;
> > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > for(k = 0; k < temp.length; k ++ )
> > > > {
> > > > if(aLink == temp[k])
> > > > {
> > > > dublett = true; document.write("already in list " );
> > > >
> > > > }
> > > > }
> > > >
> > > > if(aLink == i){dublett=true;}
> > > >
> > > > if(dublett == false )
> > > > {
> > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > temp[j] = aLink;
> > > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > > arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > arr[i].nroflinks ++ ;
> > > > arr[aLink].nroflinks ++ ;
> > > > j ++ ;
> > > > }
> > > > }
> > > > document.write("<P>" );
> > > > i++;
> > > > }
> > > > }
> > > > </script>
> > >
> > > but probably should use length...
> >
> > Reconstruction almost there.
> >
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> >
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nodelinks : [] };
> > }
> >
> > createLinks();
> >
> > function createLinks()
> > {
> > i = 0;
> > j = 0;
> >
> >
> > while(i < nodes)
> > {
> > //This see so that links already generated accounted for if one link than j=0 and so on.
> > j=arr[i].nodelinks.length;
> > while(j < links)
> > {
> > dublett = false;
> > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > aLink = Math.floor(Math.random() *nodes) ;
> > for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > {
> > if(aLink == arr[i].nodelinks[k])
> > {
> > dublett = true; document.write("already in list " );
> > }
> > }
> >
> > if(aLink == i){dublett=true;}
> > document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> > if(dublett == false )
> > {
> > arr[i].nodelinks[arr.length] = aLink;
> > arr[aLink].nodelinks[arr.length] = i;
> > j ++ ;
> > }
> > }
> > document.write(arr[i].nodelinks, "<br>");
> > i++;
> > }
> > }
> > </script>
>
> Did it?
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
>
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nodelinks : [] };
> }
>
> createLinks();
>
> function createLinks()
> {
> i = 0;
> j = 0;
>
>
> while(i < nodes)
> {
> //This see so that links already generated accounted for if one link than j=0 and so on.
> j=arr[i].nodelinks.length;
> while(j < links)
> {
> dublett = false;
> //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> aLink = Math.floor(Math.random() *nodes) ;
> for(k = 0; k < arr[i].nodelinks.length; k ++ )
> {
> if(aLink == arr[i].nodelinks[k])
> {
> dublett = true; document.write("already in list " );
> }
> }
> if(aLink == i){dublett=true;}
>
> document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> if(dublett == false )
> {
> arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> j ++ ;
> }
> }
> document.write(arr[i].nodelinks, "<br>");
> i++;
> }
> }
> </script>

Fixed the math.rand bug, now it will do many nodes and many link multiples.

<script type="text/javascript">
arr = new Array();nodes = 9; links = 4;

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nodelinks : [] };
}

createLinks();

function createLinks()
{
i = 0;
j = 0;


while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j=arr[i].nodelinks.length;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
if(i==0){aLink = Math.floor(Math.random() * (nodes - i)) + i;}
else {aLink = Math.floor(Math.random() *nodes);}
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true; document.write("already in list " );
}
}
if(aLink == i){dublett=true;}

document.write(i,"...",dublett,"Link-->", aLink, "<br>");
if(dublett == false )
{
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
j ++ ;
}
}
document.write(arr[i].nodelinks, "<br>");
i++;
}
}
</script>

JT

2/26/2016 3:59:00 PM

0

Den fredag 26 februari 2016 kl. 16:41:54 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 16:35:18 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 16:30:53 UTC+1 skrev jonas.t...@gmail.com:
> > > Den fredag 26 februari 2016 kl. 15:05:11 UTC+1 skrev jonas.t...@gmail..com:
> > > > Den fredag 26 februari 2016 kl. 14:49:52 UTC+1 skrev jonas.t...@gmail.com:
> > > > > Den fredag 26 februari 2016 kl. 14:27:20 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > Den fredag 26 februari 2016 kl. 14:22:16 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > Den fredag 26 februari 2016 kl. 14:15:08 UTC+1 skrev jonas.t....@gmail.com:
> > > > > > > > Den fredag 26 februari 2016 kl. 14:13:07 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > Den fredag 26 februari 2016 kl. 13:51:05 UTC+1 skrev jonas.t...@gmail.com:
> > > > > > > > > > A short snippet to exhaust possible links.
> > > > > > > > > > Solution is close so close i thought it was correct, but when i set to correct restriction upon the random, the loop never end, and my understanding of firefox debugger to shallow to track down the loop error.
> > > > > > > > > >
> > > > > > > > > > If anyone can see why it does not run thru with correct math rand restrictions tell me.
> > > > > > > > > >
> > > > > > > > > > Sometimes one really would love a Turbo pascal debugger, because with it one could follow code execution and detect values that loop.
> > > > > > > > > >
> > > > > > > > > > <script type="text/javascript">
> > > > > > > > > > arr = new Array();nodes = 9; links = 4;
> > > > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > > > {
> > > > > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > > > > }
> > > > > > > > > > createLinks();
> > > > > > > > > >
> > > > > > > > > > function createLinks()
> > > > > > > > > > {
> > > > > > > > > > i = 0;
> > > > > > > > > > j = 0;
> > > > > > > > > > temp = new Array();
> > > > > > > > > >
> > > > > > > > > > while(i < nodes)
> > > > > > > > > > {
> > > > > > > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > > > > > > j = arr[i].nroflinks;
> > > > > > > > > > while(j < links)
> > > > > > > > > > {
> > > > > > > > > > dublett = false;
> > > > > > > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > > > > > > //Why?? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > > > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > > > > > > for(k = 0; k < temp.length; k ++ )
> > > > > > > > > > {
> > > > > > > > > > if(aLink == temp[k])
> > > > > > > > > > {
> > > > > > > > > > dublett = true; document.write("already in list " );
> > > > > > > > > >
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > >
> > > > > > > > > > if(aLink == i){dublett=true;}
> > > > > > > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > > > > > > if(dublett == false )
> > > > > > > > > > {
> > > > > > > > > > temp[j] = aLink;
> > > > > > > > > > arr[i].nodelinks += aLink + ",";
> > > > > > > > > > arr[aLink].nodelinks += i + ",";
> > > > > > > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > > > > > > arr[i].nroflinks ++ ;
> > > > > > > > > > arr[aLink].nroflinks ++ ;
> > > > > > > > > > j ++ ;
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > > document.write("<P>" );
> > > > > > > > > > i++;
> > > > > > > > > > }
> > > > > > > > > > }
> > > > > > > > > > </script>
> > > > > > > > >
> > > > > > > > > Well spotted an error, i probably need something else than storing links than in the string nodelinks. Because the comparisson do not account for links already written to node.
> > > > > > > > >
> > > > > > > > > So rather than the string nodelinks temp arr should be nodelinks. But i have no idea how to declare an array within array.
> > > > > > > >
> > > > > > > > I rephrase the question how do i make nodelinks an array rather than a string.
> > > > > > > >
> > > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > > {
> > > > > > > > arr[k] = { nroflinks : 0, nodelinks : "" };
> > > > > > > > }
> > > > > > >
> > > > > > > That simple?
> > > > > > > for(k = 0; k < nodes; k ++ )
> > > > > > > {
> > > > > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > > > > }
> > > > > >
> > > > > > But how do i refer to it?
> > > > > >
> > > > > > if (arr[i].nodelinks[j]==aLink){ } ?
> > > > >
> > > > > But then you end up with something sick and convoluted, that is really hard to understand when you want to refer to an update an object. And personally i wonder why they simply did not go for multi dimensional arrays.
> > > > >
> > > > > I mean this to just append an array slot and it is so hard to understand????
> > > > > So we have an array with an attribute that nold nodelinks before i update it i want to check how many already storred. So i must refer to the same object once again? and see how many i already stored to move forward the array index of nodelinks to right position it just seem awkward.
> > > > >
> > > > > Could it not just assume that nroflinks has the same arr[i] if not otherwise specified? It making it friggin hard to read.
> > > > >
> > > > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > > >
> > > > >
> > > > > <script type="text/javascript">
> > > > > arr = new Array();nodes = 9; links = 4;
> > > > >
> > > > > for(k = 0; k < nodes; k ++ )
> > > > > {
> > > > > arr[k] = { nroflinks : 0, nodelinks : [] };
> > > > > }
> > > > >
> > > > > createLinks();
> > > > >
> > > > > function createLinks()
> > > > > {
> > > > > i = 0;
> > > > > j = 0;
> > > > > temp = new Array();
> > > > >
> > > > > while(i < nodes)
> > > > > {
> > > > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > > > j = arr[i].nroflinks;
> > > > > while(j < links)
> > > > > {
> > > > > dublett = false;
> > > > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > > > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > > > aLink = Math.floor(Math.random() *nodes) ;
> > > > > for(k = 0; k < temp.length; k ++ )
> > > > > {
> > > > > if(aLink == temp[k])
> > > > > {
> > > > > dublett = true; document.write("already in list " );
> > > > >
> > > > > }
> > > > > }
> > > > >
> > > > > if(aLink == i){dublett=true;}
> > > > >
> > > > > if(dublett == false )
> > > > > {
> > > > > document.write(dublett,"New Link-->", aLink, "<br>");
> > > > > temp[j] = aLink;
> > > > > arr[i].nodelinks[arr[i].nroflinks] = aLink;
> > > > > arr[aLink].nodelinks[arr{aLink].nroflinks] += i;
> > > > > document.write(i, "<--->", arr[i].nodelinks, "<br>");
> > > > > arr[i].nroflinks ++ ;
> > > > > arr[aLink].nroflinks ++ ;
> > > > > j ++ ;
> > > > > }
> > > > > }
> > > > > document.write("<P>" );
> > > > > i++;
> > > > > }
> > > > > }
> > > > > </script>
> > > >
> > > > but probably should use length...
> > >
> > > Reconstruction almost there.
> > >
> > > <script type="text/javascript">
> > > arr = new Array();nodes = 9; links = 4;
> > >
> > > for(k = 0; k < nodes; k ++ )
> > > {
> > > arr[k] = { nodelinks : [] };
> > > }
> > >
> > > createLinks();
> > >
> > > function createLinks()
> > > {
> > > i = 0;
> > > j = 0;
> > >
> > >
> > > while(i < nodes)
> > > {
> > > //This see so that links already generated accounted for if one link than j=0 and so on.
> > > j=arr[i].nodelinks.length;
> > > while(j < links)
> > > {
> > > dublett = false;
> > > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > > aLink = Math.floor(Math.random() *nodes) ;
> > > for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > > {
> > > if(aLink == arr[i].nodelinks[k])
> > > {
> > > dublett = true; document.write("already in list " );
> > > }
> > > }
> > >
> > > if(aLink == i){dublett=true;}
> > > document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> > > if(dublett == false )
> > > {
> > > arr[i].nodelinks[arr.length] = aLink;
> > > arr[aLink].nodelinks[arr.length] = i;
> > > j ++ ;
> > > }
> > > }
> > > document.write(arr[i].nodelinks, "<br>");
> > > i++;
> > > }
> > > }
> > > </script>
> >
> > Did it?
> > <script type="text/javascript">
> > arr = new Array();nodes = 9; links = 4;
> >
> > for(k = 0; k < nodes; k ++ )
> > {
> > arr[k] = { nodelinks : [] };
> > }
> >
> > createLinks();
> >
> > function createLinks()
> > {
> > i = 0;
> > j = 0;
> >
> >
> > while(i < nodes)
> > {
> > //This see so that links already generated accounted for if one link than j=0 and so on.
> > j=arr[i].nodelinks.length;
> > while(j < links)
> > {
> > dublett = false;
> > //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> > //Why not correct???? aLink = Math.floor(Math.random() * (nodes - i)) + i;
> > aLink = Math.floor(Math.random() *nodes) ;
> > for(k = 0; k < arr[i].nodelinks.length; k ++ )
> > {
> > if(aLink == arr[i].nodelinks[k])
> > {
> > dublett = true; document.write("already in list " );
> > }
> > }
> > if(aLink == i){dublett=true;}
> >
> > document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> > if(dublett == false )
> > {
> > arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> > arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> > j ++ ;
> > }
> > }
> > document.write(arr[i].nodelinks, "<br>");
> > i++;
> > }
> > }
> > </script>
>
> Fixed the math.rand bug, now it will do many nodes and many link multiples.
>
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
>
> for(k = 0; k < nodes; k ++ )
> {
> arr[k] = { nodelinks : [] };
> }
>
> createLinks();
>
> function createLinks()
> {
> i = 0;
> j = 0;
>
>
> while(i < nodes)
> {
> //This see so that links already generated accounted for if one link than j=0 and so on.
> j=arr[i].nodelinks.length;
> while(j < links)
> {
> dublett = false;
> //Only have to generate random values that is bigger than "i" because the below all links full/exhausted
> if(i==0){aLink = Math.floor(Math.random() * (nodes - i)) + i;}
> else {aLink = Math.floor(Math.random() *nodes);}
> for(k = 0; k < arr[i].nodelinks.length; k ++ )
> {
> if(aLink == arr[i].nodelinks[k])
> {
> dublett = true; document.write("already in list " );
> }
> }
> if(aLink == i){dublett=true;}
>
> document.write(i,"...",dublett,"Link-->", aLink, "<br>");
> if(dublett == false )
> {
> arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
> arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
> j ++ ;
> }
> }
> document.write(arr[i].nodelinks, "<br>");
> i++;
> }
> }
> </script>

oops rushed it.
<script type="text/javascript">
arr = new Array();nodes = 4; links = 3;

for(k = 0; k < nodes; k ++ )
{
arr[k] = { nodelinks : [] };
}

createLinks();

function createLinks()
{
i = 0;
j = 0;


while(i < nodes)
{
//This see so that links already generated accounted for if one link than j=0 and so on.
j=arr[i].nodelinks.length;
while(j < links)
{
dublett = false;
//Only have to generate random values that is bigger than "i" because the below all links full/exhausted
if(i==0){ aLink = Math.floor(Math.random() *nodes);}
else {aLink = Math.floor(Math.random() * (nodes - i)) + i;}
for(k = 0; k < arr[i].nodelinks.length; k ++ )
{
if(aLink == arr[i].nodelinks[k])
{
dublett = true; document.write(i," already in list " );
}
}
if(aLink == i){dublett=true;}

document.write(dublett," Link-->", aLink, "<br>");
if(dublett == false )
{
arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
j ++ ;
}
}
document.write(arr[i].nodelinks, "<br>");
i++;
}
}
</script>