Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Why is this function crashing???

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 06-18-2012, 12:56 PM PM User | #1 andricom New to the CF scene   Join Date: Jun 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts Why is this function crashing??? Hi, I'll try to explain what I was trying to do with this functions. say you have four pairs of things, pair 1-1, 2-2, 3-3 and 4-4, and you want to swap one element of each pair and give it to another example 1-4, 2-3, 3-1, 4,2 the only thing I want to make sure is: 1. No element can be paired with 'himself' so no '1-1 or 2-2' after the function. and 2. No repeating assigned elements, so no '1-3, 2-3' after the function. So this would be a way of permute numbers. an this is how I tryed it: Code: ```value = document.myform.three.value; var x = new Array(value); for(a=0;a=0; b=b-1){ if (x[a] == x[b] || x[a]==a){ do { x[a]= Math.floor(Math.random()*value); } while(x[a] == a); b=a; } else { } }``` being 'Value' the number of pairs to permute, which is an external input. This function works fine some times but sometimes it crashes and I can't figure out why I'd apreciate some help please. thanks. PD: I don't care whether there is a specific function to permute numbers, I'd simply like to understand whats wrong with this one. Last edited by andricom; 06-18-2012 at 03:05 PM..
06-18-2012, 04:21 PM   PM User | #2
Dormilich
Senior Coder

Join Date: Jan 2010
Location: Behind the Wall
Posts: 3,086
Thanks: 11
Thanked 327 Times in 323 Posts
__________________
Quote:
 The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
André Behrens, NY Times Software Developer

 06-18-2012, 09:48 PM PM User | #3 sunfighter Senior Coder   Join Date: Jan 2011 Location: Missouri Posts: 3,278 Thanks: 23 Thanked 472 Times in 471 Posts Maybe because it's missing two curly brackets at the end }} If not fixed publish the rest of the code
 06-18-2012, 10:55 PM PM User | #4 andricom New to the CF scene   Join Date: Jun 2012 Posts: 2 Thanks: 0 Thanked 0 Times in 0 Posts thanks, seems I had some bugs in another part of the code.
 06-19-2012, 01:23 AM PM User | #5 Lerura Regular Coder     Join Date: Aug 2005 Location: Denmark Posts: 869 Thanks: 0 Thanked 112 Times in 111 Posts Your script craches when the last pair cannot be made. e.g. if the first 3 pairs becomes 1-2 , 2-4 , 4-1. then the only possible pair left is 3-3. as it fails to validate, the script will try over and over again, but will never succeed. In this case a swap between a random, already set second-value and the remaining second-value is needed Code: `````` this will create: Code: `Pairs = [[3, 1], [2, 4], [4, 3], [1, 2]]` or alike; __________________ Index Dot Html/Css Download a jQuery Library

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 05:17 PM.