Am I misunderstanding the problem here? In the context of compression why would it just be about counting letters? Why wouldn't you just use a hash of character counts if that is all you care about? Don't you want to maintain the form of the string also so you can unpack the original value?
Proof You Can Become a Better Programmer
11–20 of 26 posts
Re: Proof You Can Become a Better Programmer
#12I 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.
> "#{x}#{input.split('').count(x)}"
Just because Ruby apparently allows you to do that much in a formatting directive doesn't mean you should.
Re: Proof You Can Become a Better Programmer
#13Also, you can contribute to open source.
Btw, this project I'm contributing to called AudioKit (if you are interested in audio stuff on Apple hw, you should definitely check it out) is looking for contributors
Re: Proof You Can Become a Better Programmer
#14What 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
I prefer `reduce` too, because it feels conceptually easier to understand (similarly `foldl`, though Ruby doesn't have that).
Re: Proof You Can Become a Better Programmer
#15The second are more ruby/functional lang specific.
I mean, if the tests pass.. amirite?
Re: Proof You Can Become a Better Programmer
#16I'd love to see more on how he manages his "to learn" pile using Evernote. My current strategy is to let things I want to read live in open browser tabs until my browser crashes. Rinse & repeat.
Re: Proof You Can Become a Better Programmer
#17For the LCM example, the second solution doesn't show any understanding of the underlying problem. The point of project Euler is to think about algorithms -- not to take advantage of "batteries included" features of programming language standard libraries.
For the duplicate counting problem, while the second answer is shorter, it's a bad solution. Just a few of the problems: it calls `split` many times instead of once; `count` can be called directly on a string; `chars` is the right way to get the characters of a string in Ruby; and finally the problem can be solved in 1-2 passes over the data using something like Ruby's `Enumerable#group_by` or Python's `itertools.groupby` rather than in a number of passes proportional to the length of the data -- O(n) rather than O(n^2).
Re: Proof You Can Become a Better Programmer
#18Problem 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.
Re: Proof You Can Become a Better Programmer
#19You don't become a better programmer by doing Project Euler like problems. Pick a real world project that's of interest to you and try to implement it. When starting out, it's not the worst idea to pick something that's been implemented quite a few times so that you can reference other people's work if you get stuck. You'll be surprised how much you can learn from implementing e.g. ls. Also, you can contribute to ope…
Also pairing with someone who's more experienced than you.
Re: Proof You Can Become a Better Programmer
#20You don't become a better programmer by doing Project Euler like problems. Pick a real world project that's of interest to you and try to implement it. When starting out, it's not the worst idea to pick something that's been implemented quite a few times so that you can reference other people's work if you get stuck. You'll be surprised how much you can learn from implementing e.g. ls. Also, you can contribute to ope…