Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Flygger19794yThe probably most basic approach would be something like (no actual language targeted, dots for indent):
words = 0
previousCharacterWasSpace = true
for(i = 0; i < length(input); i += 1) {
. if(input[i] != " " && previousCharacterWasSpace) {
. . words += 1
. }
. previousCharacterWasSpace = input[i] == " "
} -
Flygger19794y@C0D4 If control structures are seen as internal functions, then so might any symbol, e.g. assignment or comparison are internal and have functionality that takes input and gives output, sometimes transforming the input.
-
Flygger19794yAlso, if this is all it took to miss the big job, either the job wasn't really that big at all or it was just the first gate you didn't pass.
-
bad-frog5464y@Flygger
thats why i hate everything else than C.
int function (char *str)
{
int count = 0;
int is_word = 0;
while (*str != 0)
{
if (*str != ' ')
{
is_word = 1;
}
if (*str == ' ')
{
count ++;
is_word = 0;
}
}
return (count);
}
everything else is too damn complicated for what it is. -
bad-frog5464y@bad-frog
forgot a clause:
instead of if (*str == ' ') it should be:
if (str == ' ' && is_word == 1)
and obviously the incrementation at the end (str++).
classic me.
tok me 15 seconds. what is that guy learning again? liberal arts? -
Flygger19794y@bad-frog You make a pretty bad example of showing why and how your preferred language is less complicated by doing something at least as complicated and forgetting some integral parts...
-
bad-frog5464y@Flygger
complicated is relative
i like having a language that does exactly what i ask from it, when i ask from it, nothing more, and nothing less.
as for showing the code, tbh, (*str == 0) ? 0:1 i can *understand*.
previouscharacterwasspace i have to *learn by heart*.
that was my point. not showcasing my proficiency in that language... -
@flygger You are not suppose to use any internal function.
I got this
```sentence = " this is a debug message"
def counter(str):
words = 0
prevSpace = True
indx = 0
for i in sentence:
if str[indx] != " " and prevSpace:
words += 1
prevSpace = str[indx] == " "
indx += 1
return words
print(counter(sentence))```
Related Rants
i miss the big job because i could not solve this problem.
A code to count the number of words in the sentence
" this is debug message " without the use of any internal function. Anyone want to help
question
python