10 ways to solve Scrabble Score on Exercism

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 พ.ย. 2024

ความคิดเห็น • 17

  • @iosimion
    @iosimion 7 หลายเดือนก่อน +6

    About the ASCII code difference between lower case and upper case, it was actually very good design. There are exactly 2^5 characters between corresponding letters ('a' and 'A' etc.), which means that it's enough to use bitwise OR to transform from upper-case to lower-case: c | 0b100000 or c | 0x20. Also, it's not very difficult to transform for lower-case to upper-case.

    • @exercism_org
      @exercism_org  7 หลายเดือนก่อน +2

      Yeah - we go on to discover that in the next solution we show! :)

    • @nitkonigde1381
      @nitkonigde1381 6 หลายเดือนก่อน

      I guess you can do xor to get to uppercase, in Python this yields "Z": chr(ord('z') ^ 0x20)

    • @iosimion
      @iosimion 6 หลายเดือนก่อน +2

      @@nitkonigde1381 I think it's NAND - AND with the bitwise complement of 0x20. XOR toggles between lower case and upper case.

    • @nitkonigde1381
      @nitkonigde1381 6 หลายเดือนก่อน

      @@iosimion Thanks!

  • @tellu5493
    @tellu5493 7 หลายเดือนก่อน +5

    Very cool.

  • @computersciencestudentriverbat
    @computersciencestudentriverbat 7 หลายเดือนก่อน +3

    Another great video! I really like what ya'll are doing. I really hope more folks (students and job-seekers especially) find Exercism. I think Exercism does a great service of being a learning tool first and foremost. Keep it up :-)

    • @exercism_org
      @exercism_org  6 หลายเดือนก่อน

      Thanks so much!

  • @EthanBradley1231
    @EthanBradley1231 3 หลายเดือนก่อน +3

    The Rust solution using an array looks like a really clever idea for performance, but a match statement would be better in pretty much every way.
    First, as Jeremy pointed out, the array isn't very readable. It's hard to tell what letter maps to what score. A match statement would make that clear.
    Second, using an array instead of a hash map is smart for performance, but if you use a match statement then the compiler builds the lookup table for you, resulting in the same runtime performance benefit.
    Third, it looks clever to use `c.to_ascii_lowercase() as usize - 97` to convert to a number that can be used to index into the array, but again, using a match statement lets the compiler do that for you.
    Fourth, if you use a match statement that maps all non-ascii-lowercase characters to 0, then you don't need to filter for `is_ascii_alphabetic()`. In fact, the `to_ascii_lowercase()` method already contains an `if self.is_ascii_uppercase()`, so the filter is duplicating that check.

    • @exercism_org
      @exercism_org  3 หลายเดือนก่อน

      Agree with everything you said. It's fascinating though, isn't it :D

    • @petre-gx1oh
      @petre-gx1oh หลายเดือนก่อน

      Thank you for this, good to know.

  • @robinheyer708
    @robinheyer708 7 หลายเดือนก่อน +4

    23:20 Heh, a-Z is not consecutive in ASCII, that's a bit daft...
    25:27 Hold on, lowercase and uppercase are exactly 32 apart? Brilliant!
    I've done plenty of -'a' and -'A' conversions and fell into the trap of the former and never even considered the latter. In hindsight I've been pretty silly to think they just put some symbols in between the two cases because _they_ were being dumb. :P How much of my code demonstrates this ignorance...?

    • @exercism_org
      @exercism_org  7 หลายเดือนก่อน +1

      Ha! Yes - I enjoyed my learning journey there being so on display 😂

    • @robinheyer708
      @robinheyer708 7 หลายเดือนก่อน +3

      I'd like to see a poll of how many people knew that already. And then I'd like to see a poll of how many people answered truthfully.

    • @exercism_org
      @exercism_org  7 หลายเดือนก่อน +1

      Ha. Yes! :D