Nairaland ForumWelcome, Guest: Join Nairaland / Login / Trending / Recent / NewStats: 1063485 members, 1237439 topics. Date: Saturday, 25 May 2013 at 04:00 PM |
Nairaland Forum / Science/Technology / Programming / Simple Code Challenge: C#, Java, C, C++ (9195 Views)
Pls Help, Website For C/c++ Compiler Free Download Windows 7 / What Do I Need In My Computer To Start Programming In Php,java,c++ Sql / Is C# Better Than C/C++? (1) (2) (3) (4)
(0) (1) (2) (3) (4) (Reply) (Go Down)
| Re: Simple Code Challenge: C#, Java, C, C++ by Grey Beard: 1:55pm On Feb 05, 2012 |
Beaf: OK, here's what I mean. In this solution: PatternSearch(patternArray, searchArray3); the method containing the for loop - PatternSearch - is called 3 times. So the same for loop is essentially called 3 times. My question was, can this still count as valid? - Or am I missing something? |
| Re: Simple Code Challenge: C#, Java, C, C++ by Beaf: 4:12pm On Feb 05, 2012 |
candylips: Why not not, bruv? Lets see a different approach, which language are you gonna write in? I've not been able to take up functional programming despite promising to learn Elang and F# since it became public years ago. ![]() How is you functional language journey? |
| Re: Simple Code Challenge: C#, Java, C, C++ by Beaf: 4:17pm On Feb 05, 2012 |
Grey Beard: Lolzzz! You've made the same mistake as many others. Those 3 calls are the function being tested 3 separate times; there are three distinct arrays to test against, each puts the pattern in a different place to catch any mago-mago coding! ![]() All code must get the 3 answers correct. |
| Re: Simple Code Challenge: C#, Java, C, C++ by delomos: 12:40pm On Feb 06, 2012 |
Since we're on the subject of functional programming, some, attacking this with JavaScript , var array1 = [0,8,1,0,0,0,8,6,7,8,9,5,2,6,3,0,7,4,1,1,0,0,7,0,0,8,6,7,8,9,5,9,1,1,3,0]; var array2 = [1,0,0,0,8,6,7,8,9,1,3,0,0,8,5,2,6,3,0,7,4,1,1,0,0,7,0,0,8,6,7,8,9,5,9,1]; var array3 = [1,0,5,2,6,3,0,7,4,1,1,0,0,7,0,0,8,6,7,8,9,5,0,0,8,6,7,8,9,1,3,0,0,8,9,1]; function findPattern(array, array1, array2){ var result=0; for(i=0; i<array.length; i++){ if( array[i] == 1 && array[i+1] == 3 && array[i+2] === 0 && array[i+3] === 0 && array[i+4] == 8|| array1[i] == 1 && array1[i+1] == 3 && array1[i+2] === 0 && array1[i+3] === 0 && array1[i+4] == 8|| array2[i] == 1 && array2[i+1] == 3 && array2[i+2] === 0 && array2[i+3] === 0 && array2[i+4] == {result += 1; } } return result; } alert(findPattern(array3, array2, array1) + " Pattern found!" ;see is in action here: http://jsbin.com/edopas/edit#source (just click render) |
| Re: Simple Code Challenge: C#, Java, C, C++ by Beaf: 2:54am On Feb 09, 2012 |
^ That is wrong, sir. You should read the first page thoroughly and go through the winning submissions. The 3 arrays are meant to be tested individually, and you should get 3 positives not 2. |
| Re: Simple Code Challenge: C#, Java, C, C++ by delomos: 9:59am On Feb 09, 2012 |
Beaf:", a single for loop that will find the following pattern (as a single unit): 1,3,0,0,8" 1,3,0,0,8 should be consecutive , ? Yes, I did read the previous solutions/post before posting. Beaf: it is, findPattern(array, array1, array2) through a single for loop , look carefully again @ what the code is doing. |
| Re: Simple Code Challenge: C#, Java, C, C++ by Beaf: 5:35pm On Feb 09, 2012 |
^ You are wrong, bruv. Everything about your code is totally wrong; from the approach to the method signature to the result. I guess getting the wrong result tells it all (even with the hardcoding); you should have 3 positives, not 2. |
| Re: Simple Code Challenge: C#, Java, C, C++ by csharpjava(m): 12:14pm On Feb 10, 2012 |
I have made some improvements to the code given by Whoelse and I feel this is still the best code so far. See the full Java code below:
|
| Re: Simple Code Challenge: C#, Java, C, C++ by ridott02: 9:27am On Apr 23 |
[quote author=omo_to_dun]C++ Solution: [code] // File: beaf.h #ifndef BEAF_PROBLEM_I #define BEAF_PROBLEM_I /* * Description: Function beaf searches [array] for the first occurence * of the sequence in [pattern]. * * Param : [array] array to be searched. * : [pattern] array containing sequence to search for. * : [ARRAY_LENGTH] size of [array]. * : [PATTERN_LENGTH] size of Brother,I love these but no main it wont run or how do you run it?Is it not java code? |
Dr. Chinedu Emeka Invents Computer Software To Track Criminals / Can A Nigeria Programmer Afford A Range Rover Sport? / World’s Youngest Microsoft Certified Professional Arfa Karim Dies, Aged 16
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health Links: (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) Nairaland - Copyright © 2005 - 2013 Oluwaseun Osewa. All rights reserved. See Privacy Policy & Nairalist. 107.22.156.205 |