May. 3rd, 2019

juan_gandhi: (Default)
Problem: given a list of pairs of nonnegative integers, where pairs represent edges of a directed graph, check if the graph is a linear order.

Solutions:
def isLinear(src: List[(Int, Int)]): Boolean = {
  val m = src.toMap.withDefaultValue(-1)
  val tails = m.values.toSet
  src.isEmpty || (src.size == m.size) && {
    src find { case (a,_) => !tails(a) } match {
      case Some((start,_)) =>
        val visited =
          Stream.iterate(start)(m).takeWhile(0 <=).take(src.size+2)
        visited.length == src.size + 1
      case None => false
    }
  }
}
juan_gandhi: (Default)
https://medium.com/fast-company/i-built-a-bot-to-apply-to-thousands-of-jobs-at-once-heres-what-i-learned-46ece659593e

80% of positions are filled via a connection. Recruiters only recruit to armies. Seems like if a position is offered by a recruiter, it's already a bad signal.

My experience too. I can split my jobs into two slots:

recruiters: the company sucks, employment is about a year, shitty position (see recent Habr's confessions of a programmer)

connections: getting right in; red carpet; Staying there for at least 3 years, or until shit happens (it always does).

 

Reminds me two types of marriage, btw.

juan_gandhi: (Default)
A friend just asked, what's a monad. She's a paleontologist.
Here's what I wrote.

If you write code, you have functions. A function takes an argument. But where do we have the arguments? Can be a list of arguments, an Optional argument, a Future argument, an argument depending on other arguments.
There is a way to generalize lifting a function to all these kinds of "argument inside". If our "argument provider" can take a function and produce something that takes a provider and returns a provider, the lifting operation is called `map`. If `map` is available, the provider is a functor.
Now imagine we have a function that returns another provider. So we have a provider inside a provider. It sucks, no way to reach the data. But! If there is a `flatten`, takes a provider of providers and produces a provider of values, it's better. And there's a symmetrical operation, take a value, wrap it into a provider. If these operations are reasonably balanced, we have a MONAD. This `data provider` with properties described above.

This is a programming aspect of monads; formally, they come from category theory. 

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

August 2025

S M T W T F S
      12
3456789
10 11 12 13141516
171819 20212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 21st, 2025 09:24 am
Powered by Dreamwidth Studios