Re: I need help! Substrings
turbosol <[email protected]> Wed, 30 May 2007 07:59:24 -0700 (PDT)
| Newsgroups | gmane.comp.lang.sml.smlnj |
|---|---|
| Message-ID | <[email protected]> |
yes you are correct, the first example should be 0. The class i am in is a
summer class so it is an accelerated class, being completed in only 6.5
weeks instead of the normal 16. Because it is in summer, there are no TA's.
it also doesnt help that my instructor is chineses and speaks very broken
english. for some reason, there seems to be a trend of ESL computer science
teachers. I do have a book, and I have been reading it. I do realize it
seams i am trying to bite off more than i can chew but you also have to
remember that i was put into a higher level class because mine got canceled.
One would think the instructor would take this into consideration, but so
far, nothing. So i apologize if it seems as though i am asking for a lot
here, but then again, you said this is a very simply problem, so i guess i
am not asking for much. I do appreciate all the help I have gotten so far
and am very thankful. thank you for your concerns.
Matthias Blume-3 wrote:
>
> No offense, but does your course have an instructor? TAs? A textbook?
> Which college is that? Who is the instructor? Is there a course
> web page we can look at, so we can get a feel of the bigger picture of
> what kind of course this is and what is being asked of you?
>
> I hope you realize that you have already received more help than you
> could have expected. David MacQueen has kindly taken the time to
> provide you with a fairly detailed reply that you should be able to work
> with. If not, then this may be a sign that, indeed, you have bitten off
> more than you can chew at this point.
>
> The problem you are supposed to program is quite basic and does not
> require more than beginner's programming skills.
> If you can do it in Java but are stuck with SML syntax issues, perhaps
> you can show us what you are trying to do so far? In fact, how
> about you show us your Java code, since this seems to be what you
> know. Then we can talk about how to derive an SML solution from that.
>
> In any case, I'm sure your instructor, your TAs, and your textbook have
> answers, too. Have you asked them? How about your classmates?
>
> By the way, your original problem description looks inconsistent to me.
> Are you sure your first example returns 1? I would think it should
> return 0.
>
> Kind regards,
> Matthias
>
>
> On May 29, 2007, at 11:23 PM, turbosol wrote:
>
>>
>> i appreciate the help, but i must admit, I am a definite beginner
>> in this
>> class, and i am completely lost. also, we are not allowed to use
>> any built
>> in librbaries like string.sub, or anything like that. the -1 is only
>> returned because that is what is asked of me to do it. I have the
>> basic
>> idea as to how to do the program, its just the syntax that is
>> screwing me
>> up. If this were java, i would have no problem. thanks for the
>> pointers,
>> but any more help would be much appreciated.
>>
>>
>>
>> David MacQueen-2 wrote:
>>>
>>> This is almost the same as the library function String.isSubstring,
>>> except for
>>> the type.
>>>
>>> Here is a hint (for a fairly simple, but not optimal solution).
>>> Define two auxiliary functions
>>>
>>> val firstMatch : char * string * int -> int option
>>> fun firstMatch(c: char, s: string, i: int) : int option =
>>> find the index of the first occurrence of character c in
>>> string s starting at index i.
>>> if c is found at index j in s, return SOME j, otherwise return NONE
>>>
>>> val checkRest : string * int * string * int -> bool
>>> fun checkRest(s1, s2, i) : bool =
>>> check that all the characters in string s1, starting at index
>>> 1 (i.e. the second
>>> character) are matched by the corresponding characters in
>>> string s2, starting
>>> at index i. return true if so, or false if there is a
>>> mismatch or s2 is exhausted
>>> before s1
>>>
>>> Once you have these, it should be straightforward to put them
>>> together to define
>>> the function subString function you want.
>>>
>>> By the way, returning -1 for the failure case is bad style. Much
>>> better to return
>>> an int option (NONE or SOME) instead, as I suggested for firstMatch
>>> above.
>>>
>>> Good luck.
>>>
>>> Dave MacQueen
>>>
>>> On May 29, 2007, at 3:41 PM, turbosol wrote:
>>>
>>>>
>>>> So i signed up for my last compscience class so i can graduate...
>>>> the class i
>>>> needed was canceled so i was put into a more difficult class for
>>>> majors.
>>>> Comp science is my minor... anyways, I am currently doing twice the
>>>> work i
>>>> would normally do in half the time. I am lost. if anyone can help
>>>> me, i
>>>> would appreciate it SOOO much.
>>>>
>>>> I need to write a function SubString : string * string -> int that
>>>> checks
>>>> whether the first string is a substring of the second (case
>>>> sensitive).
>>>> return the index position (starting from 0) if the string is a
>>>> substring or
>>>> -1 otherwise. for multiple occurances, just return the index of
>>>> the first
>>>> appearance. you may assume both input parameters are strings.
>>>>
>>>> subString("ab","abcdefg")=> 1
>>>> subString("aaa","aaaa")=>0
>>>> subString("bc","absge") =>-1
>>>> subString("ab","cdabd") => 2
>>>> --
>>>> View this message in context: http://www.nabble.com/I-need-help%21--
>>>> Substrings-tf3836438.html#a10862221
>>>> Sent from the SML/NJ mailing list archive at Nabble.com.
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> --
>>>> ---
>>>> This SF.net email is sponsored by DB2 Express
>>>> Download DB2 Express C - the FREE version of DB2 express and take
>>>> control of your XML. No limits. Just data. Click to get it now.
>>>> http://sourceforge.net/powerbar/db2/
>>>> _______________________________________________
>>>> Smlnj-list mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> ----
>>> This SF.net email is sponsored by DB2 Express
>>> Download DB2 Express C - the FREE version of DB2 express and take
>>> control of your XML. No limits. Just data. Click to get it now.
>>> http://sourceforge.net/powerbar/db2/
>>> _______________________________________________
>>> Smlnj-list mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/I-need-help%21--
>> Substrings-tf3836438.html#a10867231
>> Sent from the SML/NJ mailing list archive at Nabble.com.
>>
>>
>> ----------------------------------------------------------------------
>> ---
>> This SF.net email is sponsored by DB2 Express
>> Download DB2 Express C - the FREE version of DB2 express and take
>> control of your XML. No limits. Just data. Click to get it now.
>> http://sourceforge.net/powerbar/db2/
>> _______________________________________________
>> Smlnj-list mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list
>
>
--
View this message in context: http://www.nabble.com/I-need-help%21--Substrings-tf3836438.html#a10875558
Sent from the SML/NJ mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/