Code examples and interviews



  • I thought you might like this one. Trouble is - I'm having a bit of an issue deciding which category to choose to submit this under. You'd be far better of with some kind of enterprisey web 2.0 ajax tagging feature than a simple drop down of choices. ;) So I'm throwing it to the side bar, the name of which doesn't seem to make sense either. Where is the side bar? Can I drink there?

    We're looking for some new developers on our team here at our online travel reservation startup. London being London at the moment, it's proving hard to get good quality candidates to actually show up at an interview. Little did we know how bad the quality can be at times.

    We have a coding test that we give to potential hires. Not terribly hard, it's just a simple string manipulation exercise: Given a string, find all occurences of a substring without using any in built string functions. Obviously you'd never do this in real life, but your run of the mill 'teach yourself c# in 24 hours' developer could probably give it a shot and fool us.

    It does however, weed out a suprisingly number of people - their code doesn't compile, it doesn't work or somtimes they don't read the instructions and submit finger paintings instead. 

    The other day, a "friend" of one of our workmates pointed out the question had been posted to the msdn forums.   

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2940944&SiteID=1

    Technically - not a wtf, posting to forums can be a valuable source of information.  Proving how clueless you are in a public forums, however is.

    There are a couple of classic responses in there, none really good enough for our potential hire, so he had a follow up post the next day:

     http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2947702&SiteID=1

    Being the masochists that we are, we couldn't help but look up some of our potential hire's other questions. A few listed here:

     http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2098703&SiteID=1

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=802585&SiteID=1

     

    And this beauty:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

     

    So many wtfs, so little time. 

     



  • It's called the sidebar because a list of the five most recently posted topics to it shows up in a box in the sidebar on the right^H^H^H^H^Hleft side of the non-forum pages



  • I always thought of it as something secondary to the main front-page article.  That usage resolves fairly neatly with the definitions here: 

     http://www.merriam-webster.com/dictionary/sidebar



  • @MonkeyCode said:

     

    And this beauty:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

    "I deleted everything, completely fucking it all.  Save my ass, for I cannot save it myself."



  • @belgariontheking said:

    @MonkeyCode said:

     

    And this beauty:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

    "I deleted everything, completely fucking it all.  Save my ass, for I cannot save it myself."

     

    Yeah, that one is awesome. And it explains why he is looking for a job in the first place....



  • @MonkeyCode said:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

    Before you phone him to tell him not to bother with the interview, back everything up extra securely. There is no knowing how far that sort of thing can spread... do you really want to bet your database on the belief that speaking to him by phone can't screw your data?



  • @MonkeyCode said:

    And this beauty:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

     

    Wow -- this makes my day a whole lot better, for some sinister reason.



  • The one about the NullReferenceException particularly irritated me because I watched this happen in real-time.

    The explanation/excuse sounded almost the same:  [I]I know what it means, and I tried debugging, but I can't figure out what's causing it, can you help?[/I]

    Isn't this supposed to be second nature to programmers?  If you can't track down an NRE/NPE, the most clear-cut and obvious of all exceptions, then you're in the wrong profession. 

    <hints id="hah_hints"></hints>


  • @MonkeyCode said:

    I thought you might like this one. Trouble is - I'm having a bit of an issue deciding which category to choose to submit this under. You'd be far better of with some kind of enterprisey web 2.0 ajax tagging feature than a simple drop down of choices. ;) So I'm throwing it to the side bar, the name of which doesn't seem to make sense either. Where is the side bar? Can I drink there?

    We're looking for some new developers on our team here at our online travel reservation startup. London being London at the moment, it's proving hard to get good quality candidates to actually show up at an interview. Little did we know how bad the quality can be at times.

    We have a coding test that we give to potential hires. Not terribly hard, it's just a simple string manipulation exercise: Given a string, find all occurences of a substring without using any in built string functions. Obviously you'd never do this in real life, but your run of the mill 'teach yourself c# in 24 hours' developer could probably give it a shot and fool us.

    It does however, weed out a suprisingly number of people - their code doesn't compile, it doesn't work or somtimes they don't read the instructions and submit finger paintings instead. 

    The other day, a "friend" of one of our workmates pointed out the question had been posted to the msdn forums.   

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2940944&SiteID=1

    Technically - not a wtf, posting to forums can be a valuable source of information.  Proving how clueless you are in a public forums, however is.

    There are a couple of classic responses in there, none really good enough for our potential hire, so he had a follow up post the next day:

     http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2947702&SiteID=1

    Being the masochists that we are, we couldn't help but look up some of our potential hire's other questions. A few listed here:

     http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2098703&SiteID=1

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=802585&SiteID=1

     

    And this beauty:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

     

    So many wtfs, so little time. 

     

    how do you know that's the same guy?  Is that word for word the question you asked?  Even then, did you get the question from somewhere or make it up yourself?  Did you verify that that msdn forum name is his somehow?  I mean, you did ask a very generic string searching question. Also, the real WTF is thinking that you can search a string object without using any built in string functions.  Unless you use reflection (which will indirectly use string functions anyways) it will be impossible to do.



  • Oh wow, that was one of the best in a long time.



  • @tster said:

    how do you know that's the same guy?  Is that word for word the question you asked?  Even then, did you get the question from somewhere or make it up yourself?  Did you verify that that msdn forum name is his somehow?  I mean, you did ask a very generic string searching question. Also, the real WTF is thinking that you can search a string object without using any built in string functions.  Unless you use reflection (which will indirectly use string functions anyways) it will be impossible to do.
     

    Whoo hoo! Quoting the entire OP sure is fun!

    Anyway, why wouldn't you be able to use a character array and manually loop and search?

    I assume they are only looking for the person to be able to think for themeselves and solve a problem, so I don't think they are looking for anything that is going to set records in optimization or anything...

    Perhaps I am missing something... but this certainly seems possible to me....



  • @MasterPlanSoftware said:

    but this certainly seems possible to me
    It is obviously possible to implement these things without string functions: the string functions had to have been implemented somehow. I don't know what tster is talking about, either.



  • @tster said:

    the real WTF is thinking that you can search a string object without using any built in string functions

    The .NET String class (as opposed to the string type) can actually be accessed using an index (look it up on MSDN), so it's perfectly possible.



  • @tster said:

    how do you know that's the same guy?  Is that word for word the question you asked?  Even then, did you get the question from somewhere or make it up yourself?  Did you verify that that msdn forum name is his somehow?  I mean, you did ask a very generic string searching question. Also, the real WTF is thinking that you can search a string object without using any built in string functions.  Unless you use reflection (which will indirectly use string functions anyways) it will be impossible to do.

    * Word for word, formatting included, the question we asked. Not sure where it came from, but the string used is a google whack.

    * The question was posted the day we asked several candidates to do the test

    * It's not impossible, the idea is just to get candidates to write a simple loop that iterates through a character array.

    * Apologies if these were your msdn posts ;) 

     



  • @Welbog said:

    @MasterPlanSoftware said:

    but this certainly seems possible to me
    It is obviously possible to implement these things without string functions: the string functions had to have been implemented somehow. I don't know what tster is talking about, either.

     

    Anyone who has ever used base C++ with no string library should be able to accomplish this easily. But I suspect a lot of CS graduates that were/are only exposed to .NET or Java would probably have a lot of issues with this. For better or for worse...

    Yay for 'intro to programming'!



  • would the regular expressions class be considered in the category of built in string functions ?



  • @MasterPlanSoftware said:

    But I suspect a lot of CS graduates that were/are only exposed to .NET or Java would probably have a lot of issues with this.
    The idea that there are such graduates who have never encountered low-level programming before graduation terrifies me. Did you have to terrify me like that?



  • @MasterPlanSoftware said:

    Anyway, why wouldn't you be able to use a character array and manually loop and search?

    I assume they are only looking for the person to be able to think for themeselves and solve a problem, so I don't think they are looking for anything that is going to set records in optimization or anything...

    Perhaps I am missing something... but this certainly seems possible to me....

     That's exactly what we're hoping for. It's a really basic test - loop through a char array and look ahead the next x characters to see if it matches the search string. There are a couple of slight optimizations you can do - but they're not the point of the exercise. It's just to weed out the dead wood - we suggest that they do it at home and spend no more than an hour on it.

    Sadly for the development community, it weeds out ALOT of candidates.

     



  • @pitchingchris said:

    would the regular expressions class be considered in the category of built in string functions ?

     

    I think that would tend to defeat the purpose of the exercise...



  • @Welbog said:

    @MasterPlanSoftware said:

    But I suspect a lot of CS graduates that were/are only exposed to .NET or Java would probably have a lot of issues with this.
    The idea that there are such graduates who have never encountered low-level programming before graduation terrifies me. Did you have to terrify me like that?

     

    Yeah you are right, made me queasy as well... but it had to be said.



  • @pitchingchris said:

    would the regular expressions class be considered in the category of built in string functions ?


    Probably not, but it's definitely using a sledgehammer to crack a walnut.



  • @mfah said:

    @pitchingchris said:

    would the regular expressions class be considered in the category of built in string functions ?

    Probably not, but it's definitely using a sledgehammer to crack a walnut.

     

    You're probably right.. But its the best alternative in a few instances, especially since there's not a 1 - 1 relationship to C++'s  sscanf function.



  • @MonkeyCode said:

    It's just to weed out the dead wood - we suggest that they do it at home and spend no more than an hour on it.
     

    Hell, sounds like something I would let them do on the whiteboard. You would have to allow for the awkwardness and pressure, but it would be beneficial to see their thought process in realtime. I wouldn't even be concerned about syntax in any way. And I would say an hour would be about right in person so you could have a dialogue about things you could improve, potential pitfalls, etc. Again, the thought process would be my main focus there....



  • @pitchingchris said:

    You're probably right.. But its the best alternative in a few instances, especially since there's not a 1 - 1 relationship to C++'s  sscanf function.

     

    Still way overblown. What is wrong for with a for loop and character array? I cannot think of any langauge you shouldn't be able to do that in pretty easily.



  • @pitchingchris said:

    there's not a 1 - 1 relationship to C++'s  sscanf function.


    I tend to view any of the scanf family as a WTF in itself. Useful in very limited circumstances, or for prototyping, but shockingly easy to break (and that's before we even mention buffer overflows). If I found one in production code I'd probably take the person responsible out back and shoot him/her.



  • @mfah said:

    I tend to view any of the scanf family as a WTF in itself. Useful in very limited circumstances, or for prototyping, but shockingly easy to break (and that's before we even mention buffer overflows). If I found one in production code I'd probably take the person responsible out back and shoot him/her.

     Guess I'll be riddled with bullet holes soon...



  • @MonkeyCode said:

    And this beauty: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1263379&SiteID=1

     <hints id="hah_hints"></hints>

    I actually disagree that this story is a WTF or shows any particular stupidity. Who among us hasn't accidentally "DELETE FROM $table" or "rm -rf /". The fact he has no backup plan may NOT be the poster's fault but some other person in his organization.

    That doesn't make it any less funny of course.



  • @Brendan Kidwell said:

    I actually disagree that this story is a WTF or shows any particular stupidity. Who among us hasn't accidentally "DELETE FROM $table" or "rm -rf /". The fact he has no backup plan may NOT be the poster's fault but some other person in his organization.

    That doesn't make it any less funny of course.

     

    Read the rest of his posts then. It is a long pattern of stupidity.



  • @MasterPlanSoftware said:

    @tster said:

    how do you know that's the same guy?  Is that word for word the question you asked?  Even then, did you get the question from somewhere or make it up yourself?  Did you verify that that msdn forum name is his somehow?  I mean, you did ask a very generic string searching question. Also, the real WTF is thinking that you can search a string object without using any built in string functions.  Unless you use reflection (which will indirectly use string functions anyways) it will be impossible to do.
     

    Whoo hoo! Quoting the entire OP sure is fun!

    Anyway, why wouldn't you be able to use a character array and manually loop and search?

    I assume they are only looking for the person to be able to think for themeselves and solve a problem, so I don't think they are looking for anything that is going to set records in optimization or anything...

    Perhaps I am missing something... but this certainly seems possible to me....

     

    I've got a game:  You post a solution, and I will STFU.  Until then, I assert that this task is impossible. remember you cannot use any "external functionality."  Of course, this all depends on the definition of "directly solve."   If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.



  • I believe it was actually "without using any in built string functions". I would assume that ToString () is allowed on the output positions, though.



  • @tster said:

    If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.

    I will make sure to not ask you then.

    A phone call to clear up any requirements that are unclear is not out of the question.  It will be expected in the workplace, after all.  It's not like the prompt was "explain programming to me over the phone.  I want to make a game like Halo"

    If you don't understand the point of the exercise from the prompt, you have some learning to do.  Also, you don't deserve the job. 



  • @MasterPlanSoftware said:

    Hell, sounds like something I would let them do on the whiteboard. You would have to allow for the awkwardness and pressure, but it would be beneficial to see their thought process in realtime. I wouldn't even be concerned about syntax in any way. And I would say an hour would be about right in person so you could have a dialogue about things you could improve, potential pitfalls, etc. Again, the thought process would be my main focus there....

     <hints id="hah_hints"></hints>
    Try asking some stupidly simple recursion question (like, print all the nodes in a tree, which can be done in 4 lines) for the whiteboard.  Seems to weed out, um, 100% of candidates.

    How do these people get degrees? 



  • @tster said:

    If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.
     <hints id="hah_hints"></hints>

    And that seems to be a major part of the problem with 90% of the pool out there - their instructions have to be so specific and perfect that by the time I'm finished writing them, I might as well have just done the job myself.

    If you consider yourself to be anything more than a code monkey, you have to learn to deal with ambiguity.  If I have to give detailed directions, I might as well give them to the computer, whom I at least know will follow them consistently and accurately. 



  •  @tster said:

    I've got a game:  You post a solution, and I will STFU.  Until then, I assert that this task is impossible. remember you cannot use any "external functionality."  Of course, this all depends on the definition of "directly solve."   If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.

    Are you really saying you cannot envision looping through a character array and manually checking for an occurence of a string? Or are you just trying to play word games? I am pretty sure either one rules you out as a candidate anyway, so I don't think employment there would be your choice...



  • @Aaron said:

    @tster said:

    If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.
     

    And that seems to be a major part of the problem with 90% of the pool out there - their instructions have to be so specific and perfect that by the time I'm finished writing them, I might as well have just done the job myself.

    If you consider yourself to be anything more than a code monkey, you have to learn to deal with ambiguity.  If I have to give detailed directions, I might as well give them to the computer, whom I at least know will follow them consistently and accurately. 

    And this, boys and girls, is why I call myself a software developer or software engineer, and NOT a programmer.  Half of software engineering is determining what is needed, the ability to code is often the trivial (by comparison) aspect.



  • @taylonr said:

    And this, boys and girls, is why I call myself a software developer or software engineer, and NOT a programmer. 
     

    So do half of the people who behave this way... Title means nothing. Ask anyone who has interviewed numerous candidates. You will find 'Architects' and 'Engineers' who can barely write a hello world in Java...



  • @taylonr said:

    And this, boys and girls, is why I call myself a software developer or software engineer, and NOT a programmer.

    I just stick with The Architect.



  • Here you go then. I'm not sure how robust it is, but it satisfies the test cases.

    		static void MyInStringTest (String text, String Subtext)
    		{
    			// sanity check
    			if (text.Length < 1 || Subtext.Length < 1 || Subtext.Length > text.Length)
    			{
    				MessageBox.Show ("There is no output.");
    				return;
    			}
    
    			int MaxLen = text.Length - Subtext.Length - 1;
    			string OutputText = "";
    
    			for (int i = 0; ; i++)
    			{
    				// are we there yet?  are we there yet?  are we there yet?  are we there yet?
    				if (i >= MaxLen)
    				{
    					if (OutputText.Length > 1)
    					{
    						// we got something
    						MessageBox.Show (OutputText);
    					}
    					else
    					{
    						// no match
    						MessageBox.Show ("There is no output.");
    					}
    
    					return;
    				}
    
    				// declare in full scope as we'll need it's value outside the for loop
    				int j;
    
    				for (j = 0; j < Subtext.Length; j++)
    				{
    					// don't stomp the originals
    					char SubtextTest = Subtext[j];
    					char TextTest = text[i + j];
    
    					// convert to lower case
    					if (SubtextTest >= 'A' && SubtextTest <= 'Z') {SubtextTest -= 'A'; SubtextTest += 'a';}
    					if (TextTest >= 'A' && TextTest <= 'Z') {TextTest -= 'A'; TextTest += 'a';}
    
    					// test the match
    					if (SubtextTest != TextTest) break;
    				}
    
    				// did we get it?
    				if (j == Subtext.Length)
    				{
    					// compose the output text in accordance with the spec
    					// (sample output stipulates that positions are 1-based)
    					if (OutputText.Length < 1)
    						OutputText = (i + 1).ToString ();
    					else OutputText += ", " + (i + 1).ToString ();
    				}
    			}
    		}

    (Edit - f--king pre tags barf here, you may not get all of it....)



  • @MasterPlanSoftware said:

     @tster said:

    I've got a game:  You post a solution, and I will STFU.  Until then, I assert that this task is impossible. remember you cannot use any "external functionality."  Of course, this all depends on the definition of "directly solve."   If you ask me, this question is worded so poorly that I wouldn't want to work there anyways.

    Are you really saying you cannot envision looping through a character array and manually checking for an occurence of a string? Or are you just trying to play word games? I am pretty sure either one rules you out as a candidate anyway, so I don't think employment there would be your choice...

     

    the requirements did not say you were given a character array.  they said you were given a string, and how you get a character array from a string without using functions/properties/operators (all forms of functionality) from the string class is beyond me.  Obviously I'm playing word games here.  If I was applying for a job at that place I wouldn't be such a prick, but as I am posting on a forum, I have the luxury of the answer to this question not having any bearing on wether I will be able to eat next week.



  • And I thought I had the forum software licked by using the plain text composer... oh well... 

    static void MyInStringTest (String text, String Subtext)
    {
    // sanity check
    if (text.Length < 1 || Subtext.Length < 1 || Subtext.Length > text.Length)
    {
    MessageBox.Show ("There is no output (sanity check fail).");
    return;
    }

    int MaxLen = text.Length - Subtext.Length - 1;
    string OutputText = "";

    for (int i = 0; ; i++)
    {
    // are we there yet? are we there yet? are we there yet? are we there yet?
    if (i >= MaxLen)
    {
    if (OutputText.Length > 1)
    {
    // we got something
    MessageBox.Show (OutputText);
    }
    else
    {
    // no match
    MessageBox.Show ("There is no output.");
    }

    return;
    }

    // declare in full scope as we'll need it's value outside the for loop
    int j;

    for (j = 0; j < Subtext.Length; j++)
    {
    // don't stomp the originals
    char SubtextTest = Subtext[j];
    char TextTest = text[i + j];

    // convert to lower case
    if (SubtextTest >= 'A' && SubtextTest <= 'Z') {SubtextTest -= 'A'; SubtextTest += 'a';}
    if (TextTest >= 'A' && TextTest <= 'Z') {TextTest -= 'A'; TextTest += 'a';}

    // test the match
    if (SubtextTest != TextTest) break;
    }

    // did we get it?
    if (j == Subtext.Length)
    {
    // compose the output text in accordance with the spec
    // (sample output stipulates that positions are 1-based)
    if (OutputText.Length < 1)
    OutputText = (i + 1).ToString ();
    else OutputText += ", " + (i + 1).ToString ();
    }
    }
    }
    The requirement actually said you could use String objects - capital S, not lower case


  • @tster said:

    the requirements did not say you were given a character array.  they said you were given a string, and how you get a character array from a string without using functions/properties/operators (all forms of functionality) from the string class is beyond me.  Obviously I'm playing word games here.  If I was applying for a job at that place I wouldn't be such a prick, but as I am posting on a forum, I have the luxury of the answer to this question not having any bearing on wether I will be able to eat next week.
     

    Being pedantic like you are would get you the job just as much as being pedantic makes you appear intelligent here.

    As everyone here has said, the point of the exercise is to show that you could operate without these classes and understand the underlying concepts. You can easily access a string with an index the same way you would with a character array. Yes, technically this is using the string class, however only a self important smart ass would argue this when given a simple task. 



  • @mfah said:

    The requirement actually said you could use String objects - capital S, not lower case

     

    They are one in the same.

     

    As for being a smart ass, I could really give two shits what you call me.  The simple fact of the matter is that given the wording of the question, the task is impossible.  Perhaps the OP would be impressed the a thoughtful contemplation of just why the task is impossible.  But seeing as how it has been posted on the internet as an example of someone being an idiot not knowing how to answer it, I think that it's important to note that the question itself is loosely defined, and therefor not as straightforward to answer as perhaps originaly thought.  Consider if a good programmer were given the task and spend a long time trying to use reflection or something to get it to work without breaking the rules and then said that they couldn't do it.  Would you immediately think they were stupid?  Interviewers should be careful with their assumptions that people will use the same loose definitions of words that they use, as often interview questions that are sent ahead of time like this are sent by a recruiter or HR person and the interviewee does not have the contact information for someone that could answer questions.



  • @tster said:

    @mfah said:

    The requirement actually said you could use String objects - capital S, not lower case

     

    They are one in the same.

     

    As for being a smart ass, I could really give two shits what you call me.  The simple fact of the matter is that given the wording of the question, the task is impossible.  Perhaps the OP would be impressed the a thoughtful contemplation of just why the task is impossible.  But seeing as how it has been posted on the internet as an example of someone being an idiot not knowing how to answer it, I think that it's important to note that the question itself is loosely defined, and therefor not as straightforward to answer as perhaps originaly thought.  Consider if a good programmer were given the task and spend a long time trying to use reflection or something to get it to work without breaking the rules and then said that they couldn't do it.  Would you immediately think they were stupid?  Interviewers should be careful with their assumptions that people will use the same loose definitions of words that they use, as often interview questions that are sent ahead of time like this are sent by a recruiter or HR person and the interviewee does not have the contact information for someone that could answer questions.

     

    I think you are the only one making assumptions. I think the rules are very clearly spelled out:

    @MonkeyCode said:

    for example, do not use the built-in C# String class to find matches with the lastIndexOf() method. You may however hold Strings while your own algorithm does the matching!).

     

    • Accepts two strings as input: one string is called “text” and the other is called “subtext” in this problem statement.
    • The application matches the subtext against the text, outputting the character positions of the beginning of each match for the subtext within the text.
    • Multiple matches are possible.
    • Matching is case insensitive.
    • If there are no matches, no output is generated.

    If there is any lack of clarity for you, I would consider it YOUR problem, not the OP's.



  • @tster said:

    @mfah said:

    The requirement actually said you could use String objects - capital S, not lower case

     

    They are one in the same.

    MSDN to the rescue: "A string is a sequential collection of Unicode characters, typically used to represent text, while a String is a sequential collection of System.Char objects that represents a string". 



  • @tster said:

    given the wording of the question, the task is impossible

    The problem is that if it's taken literally, "in built string functions" was the only exclusion. The Length and this[index] are both properties. So, they'd get by on a technicality. The MSDN post gives LastIndexOf as an example exclusion. That would be a function whose job is specifically finding a substring. So, I'm sure using the properties Length and "this" would be outside the bounds of exclusion.

    But, I've also heard people refer to everything as "functions", including properties. So, if that is the case here, then yes, it would become impossible because then even Length would be disallowed.



  • @AbbydonKrafts said:

    The problem is that if it's taken literally, "in built string functions" was the only exclusion.

    Actually, if you read the actual requirements that he was given, you wont find that wording. (Holy crap! Who would think to RTFA huh?)

    @MonkeyCode said:

    Write an application that fulfils the following requirements:

     

    Do not use external functionality to directly solve the problem (for example, do not use the built-in C# String class to find matches with the lastIndexOf() method. You may however hold Strings while your own algorithm does the matching!).

     

    • Accepts two strings as input: one string is called “text” and the other is called “subtext” in this problem statement.
    • The application matches the subtext against the text, outputting the character positions of the beginning of each match for the subtext within the text.
    • Multiple matches are possible.
    • Matching is case insensitive.
    • If there are no matches, no output is generated.

     

    Acceptance Criteria:

     

    Input text is Polly put the kettle on, polly put the kettle on, polly put the kettle on we’ll all have tea

     

    Subtext

     

    Polly

    Output

     

    1, 26, 51

    Subtext

     

    polly

    Output

     

    1, 26, 51

    Subtext

     

    ll (ell ell)

    Output

     

    3, 28, 53, 78, 82

    Subtext

     

    x

    Output

     

    There is no output

    Subtext

     

    Polx

    Output

     

    There is no output




  • @AbbydonKrafts said:

    @tster said:
    given the wording of the question, the task is impossible

    The problem is that if it's taken literally, "in built string functions" was the only exclusion. The Length and this[index] are both properties. So, they'd get by on a technicality. The MSDN post gives LastIndexOf as an example exclusion. That would be a function whose job is specifically finding a substring. So, I'm sure using the properties Length and "this" would be outside the bounds of exclusion.

     

    But, I've also heard people refer to everything as "functions", including properties. So, if that is the case here, then yes, it would become impossible because then even Length would be disallowed.

    I don't see anywhere in the problem the use of the word "function" or "functions."   Functionality != functions 



  • @mfah said:

    @tster said:

    @mfah said:

    The requirement actually said you could use String objects - capital S, not lower case

     

    They are one in the same.

    MSDN to the rescue: "A string is a sequential collection of Unicode characters, typically used to represent text, while a String is a sequential collection of System.Char objects that represents a string". 

     

    I don't know what MSDN your refering to here, but the C# keyword "string" is directly mapped to System.String.



  • @MasterPlanSoftware said:

    @tster said:

    *snip* Also, the real WTF is thinking that you can search a string object without using any built in string functions.  Unless you use reflection (which will indirectly use string functions anyways) it will be impossible to do.
     

    Whoo hoo! Quoting the entire OP sure is fun!

    Anyway, why wouldn't you be able to use a character array and manually loop and search?

    *snip*

     

    If  you want to get picky, it depends on whether some_string[0] would directly access a character array making up the string, or if it's actually a call to some_string.[ ](0), in which case it's one of the built in string methods.

     

    Edit: Bleh, a whole conversation about this went on while I was reading other threads.

    More edit: C# properties are just dressed up accessor methods. Plain old methods. Stop pretending they're special.



  • @tster said:

    I don't see anywhere in the problem the use of the word "function" or "functions."   Functionality != functions 

    It was actually in the OP.  But the key thing here is a "letter of the law" vs. "spirit of the law" thing. Most of us would see the most relevant part of the directions as being "to directly solve the problem".  This would mean that indirect is fair game.


Log in to reply