2020-03-25

juan_gandhi: (Default)
2020-03-25 06:23 pm
Entry tags:

Netflix problem

object model {
  type MovieId = Long
  type UserId  = Long
  case class View(userId: UserId, movieId: MovieId)
}
import model._

object Solution extends App {
  def diverseMovies(views: Seq[View], numMovie: Int): Set[MovieId] = {
    def choose(except: Set[UserId] = Set.empty): MovieId = {
      views.collect { case view if !except(view.userId) => view }.
            groupBy(_.movieId).mapValues(_.size).maxBy(_._2)._1
    }
    
    def viewersOf(movie: MovieId) =
      views.filter(_.movieId equals movie).map(_.userId).toSet
    
    val result: (List[MovieId], Set[UserId]) =
      ((List.empty[MovieId], Set.empty[UserId])/:(1 to numMovie)) ({
        case ((movies: List[MovieId], ignoredUsers: Set[MovieId]), _) => {
          val movie = choose(ignoredUsers)
          (movie::movies, ignoredUsers ++ viewersOf(movie))
        }
      })
    result._1.toSet
      
  }
}
juan_gandhi: (Default)
2020-03-25 06:47 pm
Entry tags:

шо творится

"Approximately one half of the patients at Kaiser Permanente’s San Jose hospital are confirmed or suspected cases of the new coronavirus according to a Los Angeles Times report." https://www.msn.com/en-us/news/us/coronavirus-slams-south-bay-kaiser-hospital-report/ar-BB11IeuF?ocid=hplocalnews