Giter Site home page Giter Site logo

Comments (3)

iHiD avatar iHiD commented on July 29, 2024

Thanks for this. I've opened a PR for what I consider to be an essential change.

I think it would be nice to have an "optimal" solution in the mentor notes here too, so we still have something to teach the people that get the minimal solution first time.

A few other suggestions:

  • I think initialize be private too.
  • luhn_sum % 10 == 0 - I like .zero? here. I also like modulo(10) but that's more personal preference.

from website-copy.

emcoding avatar emcoding commented on July 29, 2024

Thanks for the PR and catching that! 🏅

I think initialize be private too.

initialize is private by design, and it looks like by convention, it is positioned in the public interface, without actually being public.
(What I found: Normally, a subclass can override its parent's visibility, because Ruby adds a call to super that makes the change possible. 🙃 My guess is that that magic has been taken out for initialize.)

luhn_sum % 10 == 0 - I like .zero?

I felt it's too much depending on personal taste to add it to the notes. It's always debatable what should and shouldn't be in the notes, so this was just my judgment call. And if there wasn't much else to talk about in the notes, I probably would have mentioned it.
Also, it should have come up in earlier exercises, and we can't repeat everything that has been handled before. But still: just a judgment call.

I think it would be nice to have an "optimal" solution in the mentor notes here too

  • It is marked as a todo.

  • I have rarely seen a first submission that hit the MVS since I started mentoring Luhn. I mentored over 20 in the last month or so. (Which, from a Track Anatomy POV, I don't consider a good sign.)

  • I haven't found an optimal solution yet.
    That's also because in my mind, I considered Luhn not to be the 'closing' of the mid-level exercises, but the start of the most advanced ones. And, a great opportunity to talk about mixins and such.

  • The Notes are quite crowded already, and the optimal solution is probably a completely different strategy and outcome. I expect that in upcoming weeks, some of the notes can be moved 'down' to other/new core exercises, and that would make room for the new optimal solution.

Let's discuss that optimal solution first. Then worry about how to squeeze it into the Notes.

from website-copy.

tenebrousedge avatar tenebrousedge commented on July 29, 2024

I think that the approach given in the notes is somewhat flawed.

require 'scanf'
PAIRS = (0..9).zip([0, 2, 4, 6, 8, 1, 3, 5, 7, 9])
def luhn_sum(string)
  string.delete(' ').reverse.scanf("%1d%1d") do | even, odd = 0 |
    even + PAIRS[odd]
  end.sum
end

It's not necessary to perform multiplication in the loop, and scanf allows us to chunk and typecast the string in one go.

from website-copy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.