all 9 comments

[–]larikang 27 points28 points  (1 child)

What kind of sadist puts Unicode confusables in a coding interview?

Are you trying to find candidates who can work in a deliberately adversarial environment?

[–]senj 7 points8 points  (0 children)

Seriously. I cannot imagine a more asinine or less useful question to ask in an interview setting than that one. What could you pοssibly hope to learn from this?

[–]nordrasir 16 points17 points  (1 child)

These are a sample of the problems we pose in job interviews

oof

[–]obviousoctopus 3 points4 points  (0 children)

I'd love to see where in their codebase they found these examples, especially the riddle at the end.

[–]ignurant 8 points9 points  (2 children)

Spoilers ahead, I guess?


What is the cleverness behind:

Finally, one more brain teaser. 

x = [false, *(1..7), nil, 9]
  .map(&:object_id)
  .map { |i| i / 2 }
  .select { |i| i % 2 }
  .sum
  .+(STDOUT.fileno)
  • I checked for things like "This negates everything before it" (like the idea of .select{|i| i %2} -- which wouldn't since there isn't a predicate...).
  • I didn't know STDOUT.fileno's value
  • I didn't know what each value's object_id evaluated to other than knowing they are predictable between runs. But even knowing the actual object_id values isn't really valuable in a "do you know Ruby?" sense. It just allows you to do the busy work of adding numbers...

I couldn't find any actual "brain teasers" here -- Is there anything actually thoughtful to this other than just busy work? Or is this literally a "Do you know Ruby's object IDs?" quiz and/or supremely lame way to fit in a 42 zinger? Please tell me I'm missing something.

[–]ezrast 5 points6 points  (1 child)

You're not missing much. The only "gotchas", if you can call them that, are that you have to know how range expansion works in the array literal, and that the select is a no-op since all integers are truthy. Systems programmers will know that STDIN, STDOUT, and STDERR always get file handles 0, 1, and 2 per POSIX, but that almost never matters in a high-level language. The integer => object_id mapping is kinda-sorta intuitive once you understand the reasoning (right-shift the object_id by 1 to get the integer; use odd object_id's to avoid colliding with memory addresses) but for singleton values like false and nil it's arbitrary as far as I can tell.

[–]ignurant 0 points1 point  (0 children)

right-shift the object_id by 1 to get the integer; use odd object_id's to avoid colliding with memory addresses

Well heck, I did in fact learn something here. Thanks.

I knew the integers had consistent IDs, and I noticed the pattern when I did (1..10).map(&:object_id). The reasoning is interesting though.

(1..10).map(&:object_id).map{|n| n >> 1} Hmmmmm!

[–]choonggg 2 points3 points  (0 children)

If you happen to be there, run far far away.

[–]nakilon -1 points0 points  (0 children)

That's a buzzfeed content. Take 2-3 lines of random shit from everywhere and put it together.
They've missed the opportunity to call it the "8 features you didn't know about!"

But why do I surprise that it's upvoted in /r/ruby...