Weekly Challenge: Word Count (and letter count)

Share
Embed
  • Published on Feb 7, 2019
  • Challenge Page (with solution): www.iamtimcorey.com/courses/c-weekly-challenges/lectures/9122173
    Practice makes perfect, right? Well, mostly, but practice is very important. This series is all about getting you to practice the things you learn. I would encourage you to do every one. See which ones are just easy refreshers and which ones are difficult learning experiences.

Comments • 33

  • Kevin Emmrich
    Kevin Emmrich 7 months ago

    I did some LINQ and had this: "var result = ...." . When I tried to pass "result" back to the calling method, I ran into all sorts of casting issues. There doesn't seem to be any direct way to send back what seems to be a List of tuples(string, int). StackOverflow had examples where you have to create a class that models the tuple pair. Is this the only way?

    • Kevin Emmrich
      Kevin Emmrich 7 months ago

      I figured out how to send a List back to the calling program (with the help of StackOverflow!) so that I could print it out there. Had to create WordModel and LetterModel classes. I just wanted to avoid using WriteLIne() in a called method.

    • IAmTimCorey
      IAmTimCorey  7 months ago

      It does sound like a case for a model and returning a list of that model. Tuples are basically shortcuts for returning a couple pieces of information. This is more than that.

  • Mirko Lantieri
    Mirko Lantieri 7 months ago

    wc = sizeof(variable) / sizeof(variable[0]) ; // variable mustn't be null

    • Mirko Lantieri
      Mirko Lantieri 7 months ago

      @IAmTimCorey I was storing the total size of the text for those who needs help

    • IAmTimCorey
      IAmTimCorey  7 months ago

      Not sure what you are trying to communicate here.

  • adamodimattia
    adamodimattia 7 months ago

    It is a little bit of a mess this task: in the string description it says for the number of characters: excluding white space and including line returns... but below in the results it says: minus line returns and spaces. Then for the total characters what it is actually is all the characters including white spaces but excluding line returns although nowhere in the description it is defined like this, only writing code I realized that I had to remove line returns to have the same result... It is actually a great challenge but I wish it had been more precisely defined :)

    • IAmTimCorey
      IAmTimCorey  7 months ago

      No worries. I'm glad you got it straightened out and enjoyed it in the end.

    • adamodimattia
      adamodimattia 7 months ago

      @IAmTimCorey Yes, true, sorry to have bothered you, I connected two separate conditions into one with additional explanation, never mind :/

    • IAmTimCorey
      IAmTimCorey  7 months ago

      The sheet says "number of characters excluding whitespace and line returns", which is consistent with the code comments and what I did. As for total characters, it said to "count line returns as 1" character.

  • americanmultigenic
    americanmultigenic 8 months ago

    Very interesting to do. Probably (by design) an excellent prompt to want to utilize the filtering & sorting capabilities of LINQ w/ lambda queries. I could not resist then putting "Great Expectations" into the tests array and seeing what Dickens's top 5000 words were. Maybe I'll try that with Proust tomorrow . . . . :-)

    • IAmTimCorey
      IAmTimCorey  8 months ago +1

      Yeah, once you get it all working correctly, there is a lot of fun you can have playing around with it.

  • Amerco
    Amerco 8 months ago

    Great videos,
    I would be very grateful if you could make a tutorial about local userlogin and authorisation in mvc.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      I do have a video on authentication in ASP.NET MVC. The TimCo Retail Manager course also covers authentication but it (right now) is doing WPF as the front-end (although a web-based front-end is coming).

  • 4x4cheesecake _
    4x4cheesecake _ 8 months ago

    Hi Tim :) I've seen a lot of your videos and they helped me a lot so far, thanks for that :) Recently, I started to write my first own program and coincidentally, it contains a lot of string parsing and manipulation so this challenge perfectly fits to the topic I want to learn more about.
    There are no restrictions on how to achieve the goal, are they? I have the gut feeling that regex and LINQ can help a lot to solve this challenge (especially regex since I know it can find line returns pretty easy) but it kinda feels cheaty and I might be wrong anyway^^

    • IAmTimCorey
      IAmTimCorey  8 months ago +1

      There are no restrictions other than what I state in a video. The biggest thing is can you get the job done. Beyond that, I would recommend looking at how to optimize your code and make it even better. For these challenges, I usually change my application three or four times before I'm happy with the result.

  • Mihai Dumitru
    Mihai Dumitru 8 months ago

    Hi Tim, do you plan to allow access to your current and future courses via a subscripton based payment instead a fee per course as it is now? I think it will be ok for both your students and you.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      It is something I am considering but not yet. The danger of a subscription model is two-fold. First, when you just get something as part of a package, you are less likely to actually use it. That's not great for you, the buyer. Second, when you are already paying for a subscription, there is less incentive for me to put out new courses. That's not great for you, either. When I do it, I want it to be done right.

  • TheSpacecraftX
    TheSpacecraftX 8 months ago +1

    This seems a bit simple for a programming challenge no?

    • ZoidbergForPresident
      ZoidbergForPresident 7 months ago

      @Kevin Emmrich ;)

    • Kevin Emmrich
      Kevin Emmrich 7 months ago

      I was not insulted at all. I managed it just fine -- it probably takes me 10x longer than it will in the future (at least I hope that will be true).

    • ZoidbergForPresident
      ZoidbergForPresident 7 months ago

      @Kevin Emmrich I didn't mean to be insulting. I'm sorry if it appeared that way. I'm far from a great and knowledgeable coder. ;)
      But you managed, right?

    • Kevin Emmrich
      Kevin Emmrich 7 months ago

      OK, The programming part was hard for me also (ha, ha). We are different levels here, so what is easy for some is near impossible for others!

    • ZoidbergForPresident
      ZoidbergForPresident 8 months ago

      The programming part is relatively easy indeed, but as Tim said, the difficulty doesn't lie there. :P

  • rekik emnet
    rekik emnet 8 months ago +2

    Split is a key word here

  • ZoidbergForPresident
    ZoidbergForPresident 8 months ago

    Strange: string.length doesn't give the correct number of chars, tabs and cr should return 1 no?

    • ZoidbergForPresident
      ZoidbergForPresident 8 months ago

      @IAmTimCorey Aaaaaaah (I was wondering if it'd count that way), thus the only disparity I get. A string replace of those two should do the trick, no?
      edit: and it did! :P

    • zetadimensions
      zetadimensions 8 months ago

      @TheSpacecraftX On UNIX based systems (macOS and Linux) it's actually line feed (LF). It's carriage return (CR) on Classic Macintosh (pre OS X).

    • TheSpacecraftX
      TheSpacecraftX 8 months ago +2

      On windows newline is both a carriage return and line feed character. On linux /mac it's just a carriage return character.

    • IAmTimCorey
      IAmTimCorey  8 months ago

      Actually, a new line is two characters - chr(10) and chr(13). That's a tricky one.