Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29690 > unrolled thread

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

Started byjonas.thornvall@gmail.com
First post2016-02-26 04:50 -0800
Last post2016-02-29 13:52 -0800
Articles 20 on this page of 21 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 04:50 -0800
    Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:13 -0800
      Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:15 -0800
        Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:22 -0800
          Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:27 -0800
            Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 05:49 -0800
              Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 06:05 -0800
                Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:30 -0800
                  Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:35 -0800
                    Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:41 -0800
                      Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 07:58 -0800
                        Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:10 -0800
                          Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 09:36 -0800
                            Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 10:42 -0800
    Re: Exhausting link pairs between nodes using math.rand in a uniform network. "Chris M. Thomasson" <nospam@no-spam.ws> - 2016-02-26 12:13 -0800
      Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-26 14:52 -0800
        Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-27 13:27 -0800
        Re: Exhausting link pairs between nodes using math.rand in a uniform network. Luuk <luuk@invalid.lan> - 2016-02-28 17:36 +0100
          Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:24 -0800
            Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 11:58 -0800
              Re: Exhausting link pairs between nodes using math.rand in a uniform network. jonas.thornvall@gmail.com - 2016-02-29 13:52 -0800

Page 1 of 2  [1] 2  Next page →


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

Fromjonas.thornvall@gmail.com
Date2016-02-26 04:50 -0800
SubjectExhausting link pairs between nodes using math.rand in a uniform network.
Message-ID<7ccc75ef-3d8a-498b-823e-574b94799162@googlegroups.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>

[toc] | [next] | [standalone]


#29694

Fromjonas.thornvall@gmail.com
Date2016-02-26 05:13 -0800
Message-ID<25d67df9-f31a-4c9b-b53e-2a5f3d1d2506@googlegroups.com>
In reply to#29690
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. 

[toc] | [prev] | [next] | [standalone]


#29696

Fromjonas.thornvall@gmail.com
Date2016-02-26 05:15 -0800
Message-ID<f9846150-9602-4664-91d0-3ec40706eb01@googlegroups.com>
In reply to#29694
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 : "" };
} 

[toc] | [prev] | [next] | [standalone]


#29697

Fromjonas.thornvall@gmail.com
Date2016-02-26 05:22 -0800
Message-ID<eaafc9ed-aee8-4a63-9b80-bd836e66252f@googlegroups.com>
In reply to#29696
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 : [] };
} 

[toc] | [prev] | [next] | [standalone]


#29698

Fromjonas.thornvall@gmail.com
Date2016-02-26 05:27 -0800
Message-ID<2f6c8a08-a15b-439d-afe8-211824b13621@googlegroups.com>
In reply to#29697
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){ } ?

[toc] | [prev] | [next] | [standalone]


#29699

Fromjonas.thornvall@gmail.com
Date2016-02-26 05:49 -0800
Message-ID<b3e46030-3ec9-40bc-b801-ad5b18f0d3ac@googlegroups.com>
In reply to#29698
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>

[toc] | [prev] | [next] | [standalone]


#29700

Fromjonas.thornvall@gmail.com
Date2016-02-26 06:05 -0800
Message-ID<7a00760a-23c5-45eb-8694-f1c04037c01f@googlegroups.com>
In reply to#29699
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...

[toc] | [prev] | [next] | [standalone]


#29702

Fromjonas.thornvall@gmail.com
Date2016-02-26 07:30 -0800
Message-ID<31643adf-d609-488c-9aad-dae54bcf32a5@googlegroups.com>
In reply to#29700
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>

[toc] | [prev] | [next] | [standalone]


#29703

Fromjonas.thornvall@gmail.com
Date2016-02-26 07:35 -0800
Message-ID<aa38623b-5538-4a49-a25f-0a4efe012165@googlegroups.com>
In reply to#29702
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>

[toc] | [prev] | [next] | [standalone]


#29704

Fromjonas.thornvall@gmail.com
Date2016-02-26 07:41 -0800
Message-ID<55293fc0-6397-4417-ae53-eca2cf64e7d8@googlegroups.com>
In reply to#29703
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>

[toc] | [prev] | [next] | [standalone]


#29706

Fromjonas.thornvall@gmail.com
Date2016-02-26 07:58 -0800
Message-ID<bc567223-a37a-4b68-9f74-1ab465a46895@googlegroups.com>
In reply to#29704
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>

[toc] | [prev] | [next] | [standalone]


#29707

Fromjonas.thornvall@gmail.com
Date2016-02-26 09:10 -0800
Message-ID<f544d63c-29f7-44ef-85b8-38f736eccf9b@googlegroups.com>
In reply to#29706
Den fredag 26 februari 2016 kl. 16:58:51 UTC+1 skrev jonas.t...@gmail.com:
> 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>

Removed the counter at each node but it is obvious that one need to check it..

[toc] | [prev] | [next] | [standalone]


#29708

Fromjonas.thornvall@gmail.com
Date2016-02-26 09:36 -0800
Message-ID<288bc908-22f3-41c8-b60a-ec9bcb7035c7@googlegroups.com>
In reply to#29707
Den fredag 26 februari 2016 kl. 18:11:01 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 16:58:51 UTC+1 skrev jonas.t...@gmail.com:
> > 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>
> 
> Removed the counter at each node but it is obvious that one need to check it..

It seems my combinatoric sucks not all combinations of linka are possible!!!
So i think it is correct now, you just run it until it finds a valid combination. But howto test for indefinite loop?????????

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

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

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; 
            }
         }
         if(aLink == i){dublett=true;}
      
         document.write(i,"]",dublett," Link-->", aLink, "<br>");
         if(dublett == false && arr[aLink].nroflinks<links)
         {
            arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
            arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
            arr[i].nroflinks ++ ; 
            arr[aLink].nroflinks ++ ; 
            j ++ ;
         }
      }
   
    document.write("THIS NODE ",i,"]",arr[i].nodelinks,"<BR>"); 
    document.write("NEXT NODE ",i+1,"]",arr[i+1].nodelinks,"<BR>"); 
   i++;
   }
   for (z=0;z<links;z++) {
     document.write("ALL NODES ",arr[z].nodelinks, "<BR>");
     }
}
</script>

[toc] | [prev] | [next] | [standalone]


#29711

Fromjonas.thornvall@gmail.com
Date2016-02-26 10:42 -0800
Message-ID<2964baa1-3ec0-4ce4-88a7-410e86d01b21@googlegroups.com>
In reply to#29708
Den fredag 26 februari 2016 kl. 18:36:41 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 18:11:01 UTC+1 skrev jonas.t...@gmail.com:
> > Den fredag 26 februari 2016 kl. 16:58:51 UTC+1 skrev jonas.t...@gmail.com:
> > > 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>
> > 
> > Removed the counter at each node but it is obvious that one need to check it..
> 
> It seems my combinatoric sucks not all combinations of linka are possible!!!
> So i think it is correct now, you just run it until it finds a valid combination. But howto test for indefinite loop?????????
> 
> <script type="text/javascript">
> arr = new Array();nodes = 9; links = 4;
> 
> for(k = 0; k < nodes; k ++ )
> {
>    arr[k] =   { nodelinks : [],nroflinks : 0 };
> }
> 
> 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; 
>             }
>          }
>          if(aLink == i){dublett=true;}
>       
>          document.write(i,"]",dublett," Link-->", aLink, "<br>");
>          if(dublett == false && arr[aLink].nroflinks<links)
>          {
>             arr[i].nodelinks[arr[i].nodelinks.length] = aLink;
>             arr[aLink].nodelinks[arr[aLink].nodelinks.length] = i;
>             arr[i].nroflinks ++ ; 
>             arr[aLink].nroflinks ++ ; 
>             j ++ ;
>          }
>       }
>    
>     document.write("THIS NODE ",i,"]",arr[i].nodelinks,"<BR>"); 
>     document.write("NEXT NODE ",i+1,"]",arr[i+1].nodelinks,"<BR>"); 
>    i++;
>    }
>    for (z=0;z<links;z++) {
>      document.write("ALL NODES ",arr[z].nodelinks, "<BR>");
>      }
> }
> </script>

Is seem one can solve the loop by checking if all possible  remaining options been tried, and then break out of loop and generate a new network.

I now realise that for example 4 nodes 3 links configuration will lead to a loop if that solution is found when you do 7 nodes 3 links if that configuration found you will just keep looping.

So there is only a subsets of all networks using n-1 that actually bring a solution.

[toc] | [prev] | [next] | [standalone]


#29712

From"Chris M. Thomasson" <nospam@no-spam.ws>
Date2016-02-26 12:13 -0800
Message-ID<naqbl4$o4q$1@gioia.aioe.org>
In reply to#29690
On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
> A short snippet to exhaust possible links
[...]

FWIW, perhaps you might be interested in Optimal Channel Networks.

Something like:

http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120

?

[toc] | [prev] | [next] | [standalone]


#29713

Fromjonas.thornvall@gmail.com
Date2016-02-26 14:52 -0800
Message-ID<af92cc53-0a4e-429a-a68b-7d671e048631@googlegroups.com>
In reply to#29712
Den fredag 26 februari 2016 kl. 21:13:35 UTC+1 skrev Chris M. Thomasson:
> On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
> > A short snippet to exhaust possible links
> [...]
> 
> FWIW, perhaps you might be interested in Optimal Channel Networks.
> 
> Something like:
> 
> http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120
> 
> ?

http://jt.node365.se/nodes8.html

Three days of fiddling and i have finally started my journey to hyperspace.
You can expand number of links and it will expand the nodetree to keep it uniform. You can rearrange the nodetreee drag and drop sort of.

But whatever you do not press mulitple it will cause an infinite loop in the time continuum 

[toc] | [prev] | [next] | [standalone]


#29718

Fromjonas.thornvall@gmail.com
Date2016-02-27 13:27 -0800
Message-ID<f1576704-795e-4ce6-a0c2-1721e1af6bb0@googlegroups.com>
In reply to#29713
Den fredag 26 februari 2016 kl. 23:52:23 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 26 februari 2016 kl. 21:13:35 UTC+1 skrev Chris M. Thomasson:
> > On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
> > > A short snippet to exhaust possible links
> > [...]
> > 
> > FWIW, perhaps you might be interested in Optimal Channel Networks.
> > 
> > Something like:
> > 
> > http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120
> > 
> > ?
> 
> http://jt.node365.se/nodes8.html
> 
> Three days of fiddling and i have finally started my journey to hyperspace.
> You can expand number of links and it will expand the nodetree to keep it uniform. You can rearrange the nodetreee drag and drop sort of.
> 
> But whatever you do not press mulitple it will cause an infinite loop in the time continuum

Tomorrow i will find the bug for autogenerate node deep bigger than one.

http://jt.node365.se/nodes11.html

[toc] | [prev] | [next] | [standalone]


#29719

FromLuuk <luuk@invalid.lan>
Date2016-02-28 17:36 +0100
Message-ID<56d321fc$0$24124$e4fe514c@news.xs4all.nl>
In reply to#29713
On 26-02-16 23:52, jonas.thornvall@gmail.com wrote:
> Den fredag 26 februari 2016 kl. 21:13:35 UTC+1 skrev Chris M. Thomasson:
>> On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
>>> A short snippet to exhaust possible links
>> [...]
>>
>> FWIW, perhaps you might be interested in Optimal Channel Networks.
>>
>> Something like:
>>
>> http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120
>>
>> ?
>
> http://jt.node365.se/nodes8.html
>
> Three days of fiddling and i have finally started my journey to hyperspace.
> You can expand number of links and it will expand the nodetree to keep it uniform. You can rearrange the nodetreee drag and drop sort of.
>
> But whatever you do not press mulitple it will cause an infinite loop in the time continuum
>

and do not drop a node on another one, because that will effectivly 
reduce the number of nodes by 1...

;)

[toc] | [prev] | [next] | [standalone]


#29733

Fromjonas.thornvall@gmail.com
Date2016-02-29 11:24 -0800
Message-ID<066f90de-864b-475b-b25b-4b8567f62bd4@googlegroups.com>
In reply to#29719
Den söndag 28 februari 2016 kl. 17:36:55 UTC+1 skrev Luuk:
> On 26-02-16 23:52, jonas.thornvall@gmail.com wrote:
> > Den fredag 26 februari 2016 kl. 21:13:35 UTC+1 skrev Chris M. Thomasson:
> >> On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
> >>> A short snippet to exhaust possible links
> >> [...]
> >>
> >> FWIW, perhaps you might be interested in Optimal Channel Networks.
> >>
> >> Something like:
> >>
> >> http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120
> >>
> >> ?
> >
> > http://jt.node365.se/nodes8.html
> >
> > Three days of fiddling and i have finally started my journey to hyperspace.
> > You can expand number of links and it will expand the nodetree to keep it uniform. You can rearrange the nodetreee drag and drop sort of.
> >
> > But whatever you do not press mulitple it will cause an infinite loop in the time continuum
> >
> 
> and do not drop a node on another one, because that will effectivly 
> reduce the number of nodes by 1...
> 
> ;)

I got the multiple to work without the thing hangin, so it recognize a working from a noneworking. Well except for the last pair seem occasionally think a working is noneworking some condition missing.

http://jt.node365.se/mydebug1.html

[toc] | [prev] | [next] | [standalone]


#29734

Fromjonas.thornvall@gmail.com
Date2016-02-29 11:58 -0800
Message-ID<d52009ae-2c00-4dd4-96c7-8fbd76f422a0@googlegroups.com>
In reply to#29733
Den måndag 29 februari 2016 kl. 20:25:10 UTC+1 skrev jonas.t...@gmail.com:
> Den söndag 28 februari 2016 kl. 17:36:55 UTC+1 skrev Luuk:
> > On 26-02-16 23:52, jonas.thornvall@gmail.com wrote:
> > > Den fredag 26 februari 2016 kl. 21:13:35 UTC+1 skrev Chris M. Thomasson:
> > >> On 2/26/2016 4:50 AM, jonas.thornvall@gmail.com wrote:
> > >>> A short snippet to exhaust possible links
> > >> [...]
> > >>
> > >> FWIW, perhaps you might be interested in Optimal Channel Networks.
> > >>
> > >> Something like:
> > >>
> > >> http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3845120
> > >>
> > >> ?
> > >
> > > http://jt.node365.se/nodes8.html
> > >
> > > Three days of fiddling and i have finally started my journey to hyperspace.
> > > You can expand number of links and it will expand the nodetree to keep it uniform. You can rearrange the nodetreee drag and drop sort of.
> > >
> > > But whatever you do not press mulitple it will cause an infinite loop in the time continuum
> > >
> > 
> > and do not drop a node on another one, because that will effectivly 
> > reduce the number of nodes by 1...
> > 
> > ;)
> 
> I got the multiple to work without the thing hangin, so it recognize a working from a noneworking. Well except for the last pair seem occasionally think a working is noneworking some condition missing.
> 
> http://jt.node365.se/mydebug1.html

I am not sure if it is related to the halting problem but this program knows when it gets stuck in a  loop with exhausted links, and then break out using return.

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web