Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Clever. Caching a large range of computations and then using it over multiple requests. This efficiency rests on the assumption that the cache will persists from one call to the next.

    The other downsides are that it is overkill for small ranges, and does not cover larger ranges.

  • Custom User Avatar

    Not a valid solution. I think you missed the point of the exercise.

    This "solution" is like looking at the answer sheet and then just returning look-ups from its answer set. It doesn't show that one knows how the answer set was calculated.

  • Custom User Avatar

    My apologies for not adding value. What I should have said is that, yes, this solution will work, but that a switch-statement would be better practice and easier to read. The switch-statement was created to replace if-statements like these.

  • Custom User Avatar

    All valid points. Look-up tables are a time-tested optimisation in several computing solutions.

    The only thing that this solution falls afoul of is that the problem specifically asks one to COMPUTE the value.

  • Custom User Avatar

    Lol! "Actually", maybe learn to read. (Oh look, other people can do ad hominem attacks too. Shocker) As I stated in my comment, the problem statement says "compute", it does not say "use a lookup table". Also, no generalization was made as I was specifically referring to this kata, and not computing in general.

    Using lookup tables is an established technique for many computing solutions. However, it was not what was asked for in this problem, so it is understandable why other programmers are calling you out.

    The problem statement clearly asks you to compute the value (emphasis added):

    Write a function that COMPUTES the nth smallest Hamming number.
    ...
    Your code should be able to COMPUTE all of the smallest 5,000...

    I intended no offense, just accuracy. That you took it personally is regrettable.

  • Custom User Avatar
  • Custom User Avatar

    I like seeing an ES2015 implementation, BUT this does away with polymorphism entirely. Run-time checking of types is the naive (and ultimately more fragile) solution.

    Re-writing this problem in a non-polymorphic way is clearly not best practice.

  • Custom User Avatar

    Very clever. Readable too.

  • Custom User Avatar

    Using pattern matching and guards on the value of n, would takeaway all this unnecessary complexity.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Downvote.
    A look-up table is not a valid solution as it does not compute the value: "Write a function that computes the nth smallest Hamming number."

  • Custom User Avatar

    Downvote.
    A look-up table is not a valid solution as it does not compute the value: "Write a function that computes the nth smallest Hamming number."

  • Loading more items...