Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 7:15pm On Aug 03, 2017 |
orimion: 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  no |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:36pm On Aug 03, 2017 |
CryptoCoinr: 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 on solitary. that's true but that why regular expressions sell like water |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:31pm On Aug 03, 2017 |
orimion: The original question says the first parameter is a word
But here, it is a phrase 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" |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:18pm On Aug 03, 2017 |
CryptoCoinr: 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. i don't to clarify it because it is so obvious in English is you spell boy as aboy is not a boy again  |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:12pm On Aug 03, 2017 |
justanALIAS: Oooo ... I thought as long as the string is present.. presence mean "boy" not "aboyoy" the two word are different |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:10pm On Aug 03, 2017 |
jidez007: Solution in C++
Got c++ exam tomorrow so I may as well write in c++
#include <iostream>
int len_str(char s[]) { int i = 0; while (1) { if(s[i] == NULL) break; i++; } return i; }
bool cmp_char(char s[], char c[]) {
if(len_str(s) != len_str(c)) { // different lengths return false; }
for(int i = 0; i < len_str(s); i++) { if(s[i] != c[i]) return false; } return true; }
bool find(char word[], char sentence[]) { int word_len = len_str(word); int sen_len = len_str(sentence);
if(word_len > sen_len) { std::cout << "warn: word to find is greater than sentence" << std::endl; return false; }
char temp[word_len+1];
for(int i = 0; i <= sen_len - word_len; i++) {
for(int j = 0; j < word_len; j++) { temp[j] = sentence[i+j]; } // terminate temp word temp[word_len] = NULL;
if(cmp_char(word, temp)) { std::cout << "From position " << i << " to " << i + word_len << std::endl; return true; } }
return false; }
int main() { char sentence[] = "the boy is good"; char word[] = "boy";
if(find(word, sentence)) { std::cout << "Found" << std::endl; } else { std::cout << "Not Found" << std::endl;
} return 0; }
NICE WORK BUT return 1 when matched to "the aboyu is a man" |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:06pm On Aug 03, 2017 |
justanALIAS: Dnt get 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" |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:03pm On Aug 03, 2017 |
edicied: 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? 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" |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 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" |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 9:50am On Aug 03, 2017 |
closed testing result winners will be announced once done |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 3:03pm On Aug 02, 2017 |
justanALIAS: 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 } } ok |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 1:12pm On Aug 02, 2017 |
justanALIAS: package main
import ( "fmt" ) // i made my own len() method  func length(dstring string) int { var counter int for range dstring { counter++ } return counter } func main() { mainstr := "i am a bon boi" substr := "boi" 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] { last := length(substr) di := i + last if substr == mainstr[i:di] { status = true } else { continue } } } if status { return 1 } else { return 0 } } range is inbuilt operator in golang can you scrap it |
Programming › Re: Resources For Algorithms And Data Structure by silento(m): 10:42am On Aug 02, 2017 |
finally we are improving |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 10:39am On Aug 02, 2017 |
pcguru1: Sorry just seeing this, I will post mine the goal is no inbuilt function and yet people still using contains and strpos this is why Nigerians fail algorithm test, even the interview we conducted we spelt it out loud and yet still the same thing. nawa the tire me ooo |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 8:51am On Aug 02, 2017 |
mustaphagreens: Please check the attached images. Nairaland clearly does not allow for indentation.
Language: Python Version: 3.0 Using the in operator def findString(x,y): if x in y: return 1 else: return 0
#an instance of findString print(findString("boy","I am a boy" ))
Done!!! Check out the code below or in the second image #findString without the in operator
def findString(x,y): i=0 p="" while i<=len(y)-1: if (y[i]!=" " and p!=x): p+=y[i] i+=1 elif p==x: return 1 else: i+=1 p="" if p==x: return 1 else: return 0
#client program invoking findString x=input("enter target word:" ) y=input("enter phrase or sentence:" ) print(findString(x,y)) wow that's great nice indentation in your code But can you rewrite the code so that if Len() will not be there the essence of this contest is to make you understand what happen beneath the standard libraries and function anyway you will do great things in python keep on trying you got the heart of a coded indeed |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:46pm On Aug 01, 2017 |
python user without the help of in operator rewrite you code |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 1:46pm On Aug 01, 2017 |
golang hard ooo |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 8:33am On Aug 01, 2017 |
dhtml18: And of course I will be umpire. . . the troll master |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 8:30am On Aug 01, 2017 |
Welete: #python 3.x def wordsearch(x, sent): for x in sent: return 1 break else: return 0
x = input('word: ') sent = input('sentence: ') wordsearch(x, sent) in operator a membership operator only in python I consider it inbuilt function |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 8:29am On Aug 01, 2017 |
Welete: nairaland is messing with my indentation..  no fancy operator |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 8:28am On Aug 01, 2017 |
|
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:43am On Aug 01, 2017 |
Desyner: Clarify please. Custom functions that don't call library function? just a custom function but no library or inbuilt function |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 6:42am On Aug 01, 2017 |
Jaddo19: I Really Dont Understand D Question Fully, Can U Explain Better Pls I hope you understand it now |
Programming › Re: Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 12:13am On Aug 01, 2017 |
3days for the contest to run |
Programming › Contest[closed] : Program A Function to find if a phrase. is in a string by silento(op): 12:11am On Aug 01, 2017*. Modified: 6:48pm On Aug 03, 2017 |
just a simple but powerful function to improve our coding skills beginners onlys so the function will do the following when given a two parameters the first will be a word and second will be a sentence it should be able to detect that the word is in the sentence example function find("boy","obi is a boy"  { code........ return 0 or 1 } the function will return 0 or 1 0 if word not found in the sentence 1 if word is found in the sentence contest is closing on 3rd of this month Note : you are not allowed to use any inbuilt library or functions just from scratch code every thing some time similar to str.find() in python any language is welcomed but c and c ++ Will be more interesting pros are not welcomed just New coders SINCE WE DO NOT HAVE A WINNER I WILL LIKE TO Honor THIS GREAT PROGRAMMERS 1.justanALIAS (golang) 2.jidez007 (c++) please drop your numbers for a little appreciation SOLUTION IN C language
#include <stdio.h>
//FUNCTION THAT CHECKS if a phrase exists in sentence
int found(char* phrase,char *sentence) { //one line function to check lenght int len(char*item){int t=0;while(item[t] !='\0')t++;return t;}
// ckecking length int sent_len = len(sentence); int word_len = len(phrase);
//variables for keeping records and also indexing through string array int c=0,j=0,chk=0;
//for loop to loop through sentence for(c=0;c<sent_len;c++) {
//check if phrase[0] is equal to sentence[c] if(phrase[j]==sentence[c]) { /*if sentence[c-1] is not a whitespace ,and also j==0 and c not ==0 that mean that the phrase is just similar word like 'to' and 'toy' to avoid it such scenario this if statement is must */
if(sentence[c-1] !=32 & j==0 & c !=0) { break; }
//if above evaculation is false then this one increment this record variables else { chk+=1; j+=1; }
}
/* while matching word like 'toma' against 'toys' once it match 'm' to 'y' it will reset record variable to null and it means not matched
*/ else { chk=0; j=0; }
//if chk record variable is equal to phrase lenght then break loop because a match found if((chk==word_len)&(sentence[c+1]==32)) {
break; }
}
if(chk==len(phrase)) return 1; else return 0;
}
int main() {
char r[]="boy are goo"; char t[] = "d boy you boy are goo d"; printf("%d ",found(r,t)); return 0; }
|
Programming › Re: 2017 Generation Of Programmers - What Languages Are You Using? by silento(m): 8:42am On Jul 31, 2017 |
orimion: web? although it is not enough but c and web Google it |
Programming › Re: 2017 Generation Of Programmers - What Languages Are You Using? by silento(m): 9:55pm On Jul 29, 2017 |
php and Python and c and c++ I haven't found anything this Lang can't do if somebody can use c to program an os what else do I need again that it cannot offer |
Programming › Re: I Will Officially Quit Visiting This Section by silento(op): 12:28pm On Jul 28, 2017 |
hahaha that one go be tori master dhtml18
seun act Now all we go force you to act |
Programming › Re: Web Programming Tutorial In Python. by silento(m): 12:23pm On Jul 28, 2017 |
python my wife |
Programming › Re: I Will Officially Quit Visiting This Section by silento(op): 8:03pm On Jul 27, 2017 |
problem with Africans make small money and forget the future seun is lost hope on programming section because it is not generating enough traffic but no problem we will manage it anyhow we see it but mind you one day you will need our help to move your website to the next level na that day you go hear version 3
tutorial on git loading for Newbies
stay tuned for the topic |
Programming › Re: I Will Officially Quit Visiting This Section by silento(op): 4:34pm On Jul 26, 2017 |
seun do something now is time for change |
Programming › Re: I Will Officially Quit Visiting This Section by silento(op): 8:23am On Jul 26, 2017 |
seun why are u mute to this issues is it because you don't have competitors just tell me if naijaloaded is still a forum website like nairaland that will over look this section for a very long period
serious what attracts me to nairaland was the programming section and I know alot of young devs that are here but disappointed with how things are going here
all we are asking is for a mod that can delete useless post and ban spammers
is that much please
I can't die with all this my knowledge on c,cpp,python,php,css,etc
we need to share and evolve all together
you too can learn from others and improve nairaland and don't tell me you love nairaland as it is now I just discovered that you hardly code since last year if you do code at all |