0

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

Comments
  • 6
    Stick your homework up your lazy ass.
  • 0
    The 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] == " "
    }
  • 1
    @Flygger does for() and if() count as functions though? 😏
  • 0
    @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.
  • 1
    Also, 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.
  • 1
    return 4;

    This uses only an external function, namely my Big Brain.
  • 0
    @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.
  • 0
    @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?
  • 1
    @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...
  • 0
    @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...
  • 0
    @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))```
Add Comment