News for hackers. Stuff that matters.
Re:Ask HN: What topics/subjects are worth learning for a new... by baron816 on Sunday September 16, 2018 @06:06PM (#18001451)
The question is to make a function that will group the values of a linked list by odds and then evens. So 1->2->3->4->5->6 becomes 1->3->5->2->4->6. The solution essentially comes down to creating filter and concat methods for the LL, so you get something like:

  function groupByOddEven(ll) {
    var odds = ll.filter(isOdd);
    var evens = ll.filter(isEven);

    return odds.concat(evens)
  }
If anyone were to ever get this far on their own and implement the LinkedList class correctly, I would have them make it so that they could make a higher order function that would receive any predicate function and then group by those values first, then its complement.
Re:Ask HN: What topics/subjects are worth learning for a new... by scarface74 on Sunday September 16, 2018 @10:22PM (#18002693)
Is that really representative of the type of problem that your company is trying to solve? If not, why not actually create a simplified version of a real world problem your company solves on a daily basis, with a skeletal non working implementation, and corresponding failing unit tests and tell them to make the unit tests pass? That way you can actually see how proficient they are with the tools they use everyday.

I had two job offers one time. One where the interviewer asked me how I solved real world problems and my experience and one where they wanted me to write a merge sort on the board.

Guess which job I took? I’m not going to be writing a merge sort in real life and I don’t waste my time learning algorithms and studying leet code. I solve real world problems using existing frameworks from the front end to cloud and on prem infrastructure.

Yes I have my geek credentials - started programming almost 35 years ago in 65C02 assembly, did bit twiddling in C for 12 years, etc. but I am way past wanting to reinvent the wheel.

Re:Ask HN: What topics/subjects are worth learning for a new... by TableOnTheRug on Sunday September 16, 2018 @11:45PM (#18003054)
Could you give an example of a simplified version of a real world problem?
Re:Ask HN: What topics/subjects are worth learning for a new... by scarface74 on Tuesday September 18, 2018 @10:41AM (#18015730)
The last time I was responsible for interviewing, the project I was working on dealt with a lot of data transformation - get data from various APIs and databases, transform it and store it somewhere else. This is all .Net and we were storing data in Mongo. So we were always working with lists of strongly typed objects.

One simple problem was given a list of users objects, create a list of the target object and generate a userid from the first initial, first four of the last name.

Then we had an algorithm for how to handle ID clashes. We had failing unit tests for all of the corner cases.

We were hiring contractors and paying them well so we made one of the requirements that you had to know LINQ and EF. Even though we weren’t using EF that often, Linq is Linq and linq queries work the same with in memory lists, EF, and the C# Mongo driver.

It was a requirement that they used Linq instead of foreach loops since Linq gets translated to Sql and MongoQuery instead of doing the processing in memory.

Re:Ask HN: What topics/subjects are worth learning for a new... by enedil on Sunday September 16, 2018 @07:05PM (#18001776)
So in this case you're sure that this is the right abstraction. Here's one that I find equally well fitted: you basically want a stable sort on the list with key function f(x) = 1 - (x % 2) This is also a standard problem. Do you think this abstraction is worse? If so, why and how?
Re:Ask HN: What topics/subjects are worth learning for a new... by jtchang on Sunday September 16, 2018 @07:43PM (#18001976)
My first thought is below. However I'm not sure if this is a good problem to ask unless you want them to iterate on the solution and you mention you want to do in a functional way.

  def groupByOddThenEvens(someList):

	odds = []
	evens = []

	for x in someList:
	  print x
	  if x % 2 == 0:
	     # Even
	     evens.append(x)
	  else:
	     odds.append(x)

	odds.extend(evens)
	return odds
Re:Ask HN: What topics/subjects are worth learning for a new... by yread on Monday September 17, 2018 @05:03AM (#18004246)
somehow everytime i see a question with linked list I'm conditioned to look for in-place solution. Something like

    list = getOddsToTheFront(list)
    list = sortOdds(list)
    list = sortEvens(list)
implementation of helper methods left as an exercise for the reader
Re:Ask HN: What topics/subjects are worth learning for a new... by jdcarr on Sunday September 16, 2018 @08:48PM (#18002288)
Ruby works out pretty nicely in that case!

  def order_list_by_predicate(l, &blk)
    l.partition{|i| blk.call(i)}.flatten
  end

  part(1..6) do |i|
    i % 2 == 1
  end
And you can always sort the incoming list if that's a requirement.
Re:Ask HN: What topics/subjects are worth learning for a new... by justinpombrio on Monday September 17, 2018 @12:49AM (#18003280)

    oddsBeforeEvens = uncurry (++) . Data.List.partition odd
[dead]
Re:Ask HN: What topics/subjects are worth learning for a new... by dang on Tuesday September 18, 2018 @02:15AM (#18012900)
Personal swipes will get you banned here, so please read https://news.ycombinator.com/newsguidelines.html and don't post like this.
Re:Ask HN: What topics/subjects are worth learning for a new... by Aeolun on Sunday September 16, 2018 @06:12PM (#18001487)
Ah, I just see if people realize that Square is a subclass of Rectangle.
Re:Ask HN: What topics/subjects are worth learning for a new... by Zalastax on Sunday September 16, 2018 @06:20PM (#18001545)
But is it though? If your objects are immutable I agree but if you have setHeight and setWidth I don't.
Re:Ask HN: What topics/subjects are worth learning for a new... by Aeolun on Tuesday September 18, 2018 @10:09AM (#18015435)
If you have set width and height, then you don’t need the Square class at all.
Re:Ask HN: What topics/subjects are worth learning for a new... by jonny_eh on Monday September 17, 2018 @02:49AM (#18003727)
It can be mutable if setHeight sets width automatically, and vice-versa.
Re:Ask HN: What topics/subjects are worth learning for a new... by Jare on Monday September 17, 2018 @05:11AM (#18004278)
This is a terrible idea. A rectangle by definition has width and height independent of each other. A square does not fit that description and thus is not a rectangle.

Even if you did something like implementing the square's size as an average of the underlying rectangle's width and height, which would apparently support both classes correctly, you will get in trouble with the semantics or with other, less "fakeable" properties of these objects.

Re:Ask HN: What topics/subjects are worth learning for a new... by zild3d on Monday September 17, 2018 @12:06PM (#18007177)
> A rectangle by definition has width and height independent of each other.

That's not really true though. Definition is a quadrilateral w/ 4 right angles. Width and height can be dependent or not

Re:Ask HN: What topics/subjects are worth learning for a new... by jonny_eh on Monday September 17, 2018 @05:08PM (#18010096)
I've never come across this definition. I've always heard that squares are a subset of rectangles, just as rectangles are a subset of parallelograms.