| You are not logged in. Login Now | register | search | |||||||||
|
| |||
| Author | Message | ||
| 5 new of 45 responses total. | |||
|
cross |
Another day, and no additional posts. Okay, here's the Java version:
/**
* Test of something for John Remmers.
*/
public class Find1stBlank {
/**
* Find the first all-blank string in the passed regular expression.
*/
public static int Find1stBlank(String[] strings) {
for (int i = 0; i < strings.length; i++)
if (strings[i].matches("^\\s+$"))
return(i);
return(-1);
}
/**
* Main program entry point.
*/
public static void main(String[] args) {
String[] strings = { "This ", " is", "a", "string" };
System.out.println("Find1stBlank == " + Find1stBlank(strings));
String[] strs = { " But this ", " is ", " ", " a blank." };
System.out.println("Find1stBlank == " + Find1stBlank(strs));
}
}
| ||
|
remmers |
Responses #40 and #41 illustrate the effect of language primitives (in this case, regular expressions) on the shape of a solution. (Aside: This item has showed up as a shared bookmark on del.icio.us. Have a look at http://del.icio.us/tag/grex/ and http://del.icio.us/url/93a9640a15e68aef7b1d7837f006cc01 ...) | ||
|
yecril71pl |
How is it that nobody has come up with a solution that uses "come from"? | ||
|
nharmon |
I've never liked "come from" because it can really confuse you when you're debugging something. Like, you'll be wondering why a certain line was never executed only to find out later that it was because the line before it was associated with a "come from" much later on in the program. | ||
|
mkay |
Here is my C solution, an example for good readability :D :
int i = 0, j = 0;
while ((j = (j + 1) * !matrix[i][j]) < N && (i += !!matrix[i][j]) < N)
;
if (i < N)
printf("First all-zero row is %d\n", i);
| ||
|
Response Not Possible: You are Not Logged In |
- Backtalk version 1.3.30 - Copyright 1996-2006, Jan Wolter and Steve Weiss