Live data from Hacker News

Proof You Can Become a Better Programmer

new2code.com

1–10 of 26 posts

Re: Proof You Can Become a Better Programmer

#2
I slightly prefer the 'worse' solution for the second problem, at least in terms of substance, not necessarily style. The trick the 'improved' version does with uniq seems a little hacky to me, somehow.

The first problem has a clear improvement.

I just checked ruby doc and 'reduce' and 'inject' seem to be synonyms, as far as I can tell.

Re: Proof You Can Become a Better Programmer

#6
I've never used Ruby before, but I learned something interesting when Googling what I thought was a weakness in his preferred solution to the first problem: Apparently, in Ruby, integer types have two internal representations that are flexibly switched between as needed. One representation uses a fixed size (analogous to long/int64 in other languages) and the other representation, Bignum, has an arbitrary size (analogous to Java's BigDecimal). So the simple (1..n).reduce(:lcm) approach should work for n of arbitrary size, though I don't think it's the most efficient approach.

Re: Proof You Can Become a Better Programmer

#7
Here is a recipe for a successful shitpost on hacker news:

1. Write a blog post about your experience with X. Your description shall not be complete nor correct.

2. Wrap it around with a thesis on a random topic, which is semi-related to your experience, and which is by no means proven by your description.

3. ??

4. profit!

Re: Proof You Can Become a Better Programmer

#8
post #5

What on earth does he mean by saying that "the reduce method [instead of inject] is performance friendly and a more "Ruby way" of doing things"? `reduce` is an alias for `inject`...

Based on the linked github page[1], it looks like that comment was an extrapolation from a guideline in Airbnb's Ruby Style Guide, where Airbnb prefers the use of `reduce` instead of `inject`:

- Prefer `reduce` over `inject`.

I haven't seen any other evidence to show reduce is more performance friendly.

[1]: https://github.com/airbnb/ruby#collections

Re: Proof You Can Become a Better Programmer

#10
Problem 2 is underspecified so both answers might be wrong. Should the output on the string "aaaabbbaa" be "a4b3a2" or "a6b3"? Or is that invalid input? I don't think you can reasonably answer the problem without an example like this.
Post reply on HN