Skip to content

Instantly share code, notes, and snippets.

View rcongiu's full-sized avatar

Roberto Congiu rcongiu

View GitHub Profile
@rcongiu
rcongiu / giftpairing
Last active September 13, 2021 17:53
def pairGifts(l:Seq[Person]) = {
@tailrec
def innerPair(pairs:Seq[(Person,Person)], b:List[Person], r:List[Person]):Seq[(Person,Person)] = {
// avoid last giving to itself
if(b.size == 2 && b.last == r.last) return pairs :+ (b.head, r.last) :+ (b.last, r.head)
(b, r) match {
case (Nil, Nil) => pairs
case ( (bh :: bt), (rh :: rt)) =>
// avoid one person give to himself. In that case, pick next and put back current
val (recipient, recipients) = if (bh != rh) (rh, rt) else ( rt.head, rh :: rt.tail)

Keybase proof

I hereby claim:

  • I am rcongiu on github.
  • I am drcongiu (https://keybase.io/drcongiu) on keybase.
  • I have a public key ASC1zbptwtMmXIkqD-MG16Vj8Sfl982JyFTzZAE7_9eDiwo

To claim this, I am signing this object: