Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,199,371 members, 7,971,360 topics. Date: Thursday, 10 October 2024 at 08:43 AM |
Nairaland Forum / Science/Technology / Programming / Contest[closed] : Program A Function to find if a phrase. is in a string (4015 Views)
Php Function To Generate A Random Expression / User Defined Function To Validate Regular Expression In Javascript / I Can Program A Html Css Javascript Website For 1k (2) (3) (4)
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 5:13pm On Aug 02, 2017 |
Omo, the kind of codes flying about here na be am o |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 5:17pm On Aug 02, 2017 |
dhtml18: Huh? |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by jidez007: 5:23pm On Aug 02, 2017 |
Solution in C++ Got c++ exam tomorrow so I may as well write in c++
|
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 5:24pm On Aug 02, 2017 |
CryptoCoinr: I've figured out the BB Code for code so here's my JS submission again, with indentation undestroyed:
To preserve indentation, wrap your code with [ code ] actual code goes here... [/ code ] instead of [ quote ] [/ quote ] (no spaces between the [, "code" and ]). |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by greatface(m): 5:24pm On Aug 02, 2017 |
Implemented in python 3 def length(s): |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by orimion(m): 8:23pm On Aug 02, 2017 |
Haskell
the first two functions (words' and finder) are helper functions there is a builtin "words" function that does what " words' " did hence the quote Normally, we wouldn't return an Int we would return a Maybe Int but as per the spec.. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 9:50am On Aug 03, 2017 |
closed testing result winners will be announced once done |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by edicied: 12:13pm On Aug 03, 2017 |
I no even understand the question self Op are you saying in a String for example "The boy is here" we should check for if the words "The" "BOy" or "Here" is there? |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by greatface(m): 1:00pm On Aug 03, 2017 |
greatface:Looking At My Code Now I Saw A Lot Of Programming And Logical Errors. Well, I Did That With My Chinco Phone Meant For Calls. I Will Post The Updated version later. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by shittu123(m): 1:11pm On Aug 03, 2017 |
def lenght(x): |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 4:02pm On Aug 03, 2017 |
shittu123:def lenght(x): No in-built functions |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 5:59pm On Aug 03, 2017 |
[quote author=justanALIAS post=59077579] I dont think so but i will try. By the way, the above code is buggy; see d fixed version: package main import ( "fmt" ) func length(dstring string) int { // i made my own len() method var counter int for range dstring { counter++ } return counter } func main() { mainstr := "i am a bon boni" substr := "i am" fmt.Println(check(mainstr, substr)) } func check(mainstr string, substr string) int{ var status bool = false for i, _ := range mainstr { if mainstr[i] == substr[0] { if length(mainstr[i:]) >= length(substr) { last := len(substr) di := i + last var rangeof string = mainstr[i:di] if substr == rangeof{ status = true } else { continue } } else { continue } } } if status { return 1 } else { return 0 } } [/quote NICE WORK BUT your code returns 1 when "i am" matched against "i ammy" |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 6:01pm On Aug 03, 2017 |
[quote author=silento post=59118512][/quote] Dnt get |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:03pm On Aug 03, 2017 |
edicied: the program will able to match a phrase like "under it" if matched to " my bed is under it but am cool" it will return 1 to show that match was found but 0 when "under" matched to"my bed is underneath it" |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:06pm On Aug 03, 2017 |
justanALIAS: the program is expected to return 1 in this case: "i am" => to "i am a boy" and 0 in this case : "i am" => "i ammy is a boy" |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 6:06pm On Aug 03, 2017 |
silento: I noticed this but I don't think you clarified it in the OP so I'm working on a fix for my solution now. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by Nobody: 6:06pm On Aug 03, 2017 |
silento:Oooo ... I thought as long as the string is present.. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:10pm On Aug 03, 2017 |
jidez007: NICE WORK BUT return 1 when matched to "the aboyu is a man" |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:12pm On Aug 03, 2017 |
justanALIAS:presence mean "boy" not "aboyoy" the two word are different |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:18pm On Aug 03, 2017 |
CryptoCoinr: i don't to clarify it because it is so obvious in English is you spell boy as aboy is not a boy again |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by orimion(m): 6:19pm On Aug 03, 2017 |
The original question says the first parameter is a word silento: But here, it is a phrase silento: |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 6:29pm On Aug 03, 2017 |
silento: Um, no it isn't. As orimion said above, your question was unclear and even the inbuilt functions of various languages, or JS at least, finds "words" whether they are fragments or solitary. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:31pm On Aug 03, 2017 |
orimion: if you are on a computer open up your browser and press ctrl+f now type "word" and click the button for whole words did you browser highlighted "words" to be "word" if it didn't then i think you got your answer we are here to learn you will only find examples all over the internet with this bug of matching "boy" to be same with "boym" |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 6:36pm On Aug 03, 2017 |
CryptoCoinr: that's true but that why regular expressions sell like water |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 6:40pm On Aug 03, 2017 |
silento: Oh yes, I'm aware of regex and its awesome text manipulation capabilities but AFAIK, you need to use JS's inbuilt functions if you want to go the regex route. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by orimion(m): 6:54pm On Aug 03, 2017 |
silento: I don't think you understand me I was making the distinction between a word and a phrase in the question spec, the example given was "boy" & "i am a boy" should return 1 (i.e word and sentence) but the part i quoted earlier, "i am" & "i am a boy" (i.e phrase and sentence) I pointed this out because in my solution, i split the sentence into a list of words first (as per the question) then check if the word is in the list obviously it's not going to work in the second situation (phrase & sentence) PS. as for the challenge, chrome doesn't have "match whole word" and so highlighted "words" for "word" PPS. did you even try my haskell solution |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by mustaphagreens(m): 6:55pm On Aug 03, 2017 |
silento:Mr silento, Please could you enlighten me on the problem with my code? Your problem specification states: Function should return: 0 if word is not a subset of the sentence 1 if otherwise. That's precisely what findString was constructed for. |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 7:15pm On Aug 03, 2017 |
orimion: no |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(m): 7:30pm On Aug 03, 2017 |
I hope you guys learned a lot from this tiny problem if some company paid you to wrote a code for them like this one and a after you code has this bug kiss it goodbye I know alot of dudes on nl that will know that matching any occurrence is a bug if you think I cheated you guys go to stackoverflow and you will see that 86% of there code has this bug while alot of devs there have solved it which others stick with inbuilt buggy function please check the first page and drop your number if your name is mentioned |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by mustaphagreens(m): 7:33pm On Aug 03, 2017 |
silento:Could you please provide answer to the question I asked earlier? |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by CryptoCoinr(f): 7:35pm On Aug 03, 2017 |
silento: I'm pretty sure an interviewer for a job would be clearer than you are with the specifications. 3 Likes 1 Share |
Re: Contest[closed] : Program A Function to find if a phrase. is in a string by edicied: 8:07pm On Aug 03, 2017 |
Another challenge please am loving this |
Test Your Knowledge Of Excel On This / Who Studied Computer Engineering At Unilag? / Best Server Side Language Your Opinion
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 94 |