|
DaveAuld wrote: As you can imagine the operators are desperate to see this commissioned
I have been in such situation as well. The problem was once the replacement was done. They start bitching because the new system was too different. At the end I needed 1 month extra just to make everything I could to look like the old system
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I've got an OED app that opens a built-in version of Netscape 3.
I use it for looking up synonyms of "puke".
And remember CDs that used to be distributed free with computer mags? A lot of them use either Netscape or IE 3/4 embedded.
It's hard to remember them as cutting edge, ain't it?
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
It's been a while since anyone posted one of these, but it's Friday and I just saw this post
List only common parent directories for files[^]
I took a whack at it in C#.
Your assignment, should you choose to accept it, is to write a suitable implementation in your choice of language (except that one).
Given a collection of strings (you may assume no NULLs if you like), return the leading substring common to them all.
I note that his stated result of "/home/nicool/Desktop" should actually include a final slash (/ ).
|
|
|
|
|
1. Enumerate Directories,
2. Inside each directory search whether there is a File.txt, if there is Console.WriteLine(dir + file);
3. If not, go through remaining directories and repeat 2 on each of them.
Tagged: Simple algorithm!
Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem
~! Firewall !~
|
|
|
|
|
No, that's upstream -- this works on the resultant collection of found file names/specs (or any other strings) (step 4 or 5).
|
|
|
|
|
Regardless of language;
Take the shortest string from the list
Test this string against the others, if it StartsWith (however you want to do it) in them all you have the it, if you don't trim back to next '/' and repeat test. If at any point you come across a fail test and it is not the last test element, short circuit the search, trim and repeat.
|
|
|
|
|
Sure, but probably inefficient, in particular I think finding the shortest is a waste of cycles.
I also wouldn't bother sorting them, even though that could lead to only having to find the common portion of the first and last.
Consider a very large collection of very long strings.
|
|
|
|
|
PIEBALDconsult wrote: Consider a very large collection of very long strings.
Thats ok, I'm here till Wednesday....
|
|
|
|
|
You could probably do it with a single pass, by simply moving through the list, comparing / discarding / comparing as you go.
|
|
|
|
|
What I wrote uses a pair of nested for loops -- comparing all the first characters, then all the second characters, etc. until a difference or the end of a string is found.
|
|
|
|
|
Stringsplit the first two paths into two arrays.
Compare the elements until you find a difference.
Compare the common result with the next string.split.
Repeat.
|
|
|
|
|
While the OP wants it to work for the specific case of file specs, the challenge is for it to work in the general case of any collection of strings.
|
|
|
|
|
ok, gotta read the specs better. I got stuck on your first paragraph.
|
|
|
|
|
Here's what I devised.
Obviously, I didn't add any handling of special cases -- it assumes a collection of at least two non-NULL strings.
My first implementation builds up the result in a StringBuilder and spits it out once a difference is found or after all characters have been found to be equal.
public static string
GetCommonPrefixA
(
params string[] List
)
{
System.Text.StringBuilder result = new System.Text.StringBuilder ( List [ 0 ].Length ) ;
for ( int i = 0 ; i < List [ 0 ].Length ; i++ )
{
for ( int j = 1 ; j < List.Length ; j++ )
if ( ( i >= List [ j ].Length ) || ( List [ 0 ] [ i ] != List [ j ] [ i ] ) )
return ( result.ToString() ) ;
result.Append ( List [ 0 ] [ i ] ) ;
}
return ( result.ToString() ) ;
}
This implementation doesn't use a StringBuilder; it simply uses the value from the outer for loop to perform a substring -- this might be better for languages that don't have a StringBuilder.
public static string
GetCommonPrefixB
(
params string[] List
)
{
int i = 0 ;
for ( ; i < List [ 0 ].Length ; i++ )
for ( int j = 1 ; j < List.Length ; j++ )
if ( ( i >= List [ j ].Length ) || ( List [ 0 ] [ i ] != List [ j ] [ i ] ) )
return ( List [ 0 ].Substring ( 0 , i ) ) ;
return ( List [ 0 ].Substring ( 0 , i ) ) ;
}
Because I'm not a fan of having multiple return s, I also devised this third implementation that uses a boolean to stop the loops.
Something I don't like about this is that the outer loop variable (i) is incrememted an extra time.
public static string
GetCommonPrefixC
(
params string[] List
)
{
bool same = true ;
int i = 0 ;
for ( ; same && i < List [ 0 ].Length ; i++ )
for ( int j = List.Length - 1 ; same && j > 0 ; j-- )
same = ( ( i < List [ j ].Length ) && ( List [ 0 ] [ i ] == List [ j ] [ i ] ) ) ;
return ( List [ 0 ].Substring ( 0 , i - 1 ) ) ;
}
Of course a goto would also work and not perform the extra increment.
public static string
GetCommonPrefixD
(
params string[] List
)
{
int i = 0 ;
for ( ; i < List [ 0 ].Length ; i++ )
for ( int j = List.Length - 1 ; j > 0 ; j-- )
if ( ( i >= List [ j ].Length ) || ( List [ 0 ] [ i ] != List [ j ] [ i ] ) )
goto done ;
done: return ( List [ 0 ].Substring ( 0 , i ) ) ;
}
You may have noticed that these last two also run the second for loop (j) as a decrement; the purpose of this is to detect a difference as soon as possible when the collection has been sorted. It also reduces calls to List [ 0 ].Length . These "optimisations" probably won't yield any big improvements, but they're cheap.
modified 15-Sep-14 16:29pm.
|
|
|
|
|
|
|
Wowah!
|
|
|
|
|
|
Nope, thanks I have replied to the message...
|
|
|
|
|
Looks like a gloved fist.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Oracle sucks.
Oracle tools suck - they look like something out of the '90s - they want me to use the command line to install/uninstall stuff. How is this a billion dollar company?
Even then the uninstall didn't work so I'm digging around in the registry because Oracle for .NET has so fragged VS2008 that I cannot even establish a SQL connection anymore. It really is a crappy product.
Seriously, die in a fire.
|
|
|
|
|
Oracle's drivers and file system structure suck and I'd also love something like Management Studio for Oracle.
But as the database is designed for other billion dollar companies, the command line tools are just fine. Admins can run them in scripts, in scheduled jobs at night ... instead of clicking through them again and again for ever virtual machine they have to install.
This statement is false.
|
|
|
|
|
Corinna ? This must have been ages !! What brings you around here ? Lost something in a picture and looking for it ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|
|
I don't know why both cannot be done well.
|
|
|
|
|
Corinna John wrote: I'd also love something like Management Studio for Oracle Why not use TOAD or SQL Developer?
|
|
|
|