tungwaiyip.info

 

home

about me

links

my software

Media

Yucatán Photos

St Lucia Photos

Photo Album

Videos

Blog

< February 2010 >
SuMoTuWeThFrSa
  1 2 3 4 5 6
7 8 910111213
14151617181920
21222324252627
28      

past articles »

Click for San Francisco, California Forecast

San Francisco, USA

 

Refrigerator Madness solution (Facebook programming puzzle)

Refrigerator Madness is the second Facebook programming puzzle I have tried. The problem description is complicated. I won't try to repeat it here but to suggest you to refer to the original facebook page.

To solve this problem it is necessary to see through the smokescreen. Instead of thinking how much Red Bull a Facebook engineer likes to drink, it is easier to map it to a problem known as Two-Sided Matching. A model with intuitive meaning is a marriage matchup between a group of man and woman. Each man has his list of preferred woman and each woman has her list of preferred man. The marriage is considered stable if there are no two people of opposite sex who were not married to each other but would both prefer to be.

For the Refrigerator Madness problem just map the engineer from the upper 50th percentile to "man" and lower 50th percentile to "woman" (or vice versa). The matching condition is equivalent to the stable marriage criteria.

At this point the problem can be solved by applying the Gale-Shapley algorithm. Write the code and it's done!

2010.02.22 [] - comments (5)

 

 

Comments (5)

I don't know python at all. Your link to code, is it real code or psuedo code? If it is real code did it work?

Posted by Madhu at Mon Mar 1 14:59:39 2010



I think your preference computations are incomplete. What happens if a drink is in the list of both Upper Engineer and Lower Engineer but it appears before in Upper Engineer's list than in Lower Engineer's list? In this case you need to add the base value and I don't see that you are doing that.

Posted by Madhu at Mon Mar 1 17:26:07 2010



Yes, it is real code, verified by the Facebook robot.

Regarding the condition you're raise, it is checked below -

  elif A[i] not in B[:i]:

You need to know Python's slice operation to understand how it works.

Posted by Wai Yip Tung at Mon Mar 1 19:01:08 2010



Thanks for the response but aren't you just checking for if the drinks are in the same position and if the drink is not in the lower engineer list but what about the drink exists in the both the upper enigneer and lower engineer list but it appear earlier position in the upper engineer list than in the lower engineer list. Please can you show me where is that check done in your code.

Posted by Madhu at Mon Mar 1 20:38:33 2010



B[i] != B[:i]

I hope you have not missed the colon. B[:i] means a sub-list of everything up to index i. So if B is [a,b,c,d], B[:2] is [a,b]. This checking covered 2 cases in the problem description.

Posted by Wai Yip Tung at Tue Mar 2 15:23:04 2010



Please add your comment

Name:


E-mail (not shown):


Your website (optional):


Comment:


In order to deter spammers, we would like to ask you a question about this article:

Which city am I based in? (hint: check the weather box on the left column.)

past articles »

 

BBC News

 

Labour MPs call for hacking probe (06 Sep 2010)

 

Bipolar 'not linked to violence' (06 Sep 2010)

 

Housing group 'near administration' (07 Sep 2010)

 

MPs back AV referendum bill (06 Sep 2010)

 

Tube workers begin 24-hour strike (06 Sep 2010)

 

Scam fear over electricity credit (06 Sep 2010)

 

Iran 'hampers IAEA investigation' (06 Sep 2010)

 

Obama unveils building plan (06 Sep 2010)

 

France faces pension plan strike (06 Sep 2010)

 

MoD names two killed UK soldiers (06 Sep 2010)

more »

 

Slashdot News for nerds, stuff that matters

 

Google Says Microsoft Is Driving Antitrust Review (2010-09-07T00:20:00Z)

 

Aging Star System Leaves Strange Death Spiral (2010-09-06T23:25:00Z)

 

American Business Embraces 'Gamification' (2010-09-06T22:36:00Z)

 

Plagiarizing a Takedown Notice (2010-09-06T21:40:00Z)

 

Sony Has Lost the PS3 Hacking War (2010-09-06T20:53:00Z)

 

UK's Royal Mail Launches First Intelligent Stamps (2010-09-06T20:01:00Z)

 

WikiLeaks Calls For Assange To Step Down (2010-09-06T19:10:00Z)

 

Programming Things I Wish I Knew Earlier (2010-09-06T18:14:00Z)

more »

 

TechPsychic Tech Rumors and Invented News

 

TechPsychic: AT&T: more money, says it's disruptive in funding from. (08 May 2010)

 

TechPsychic: I know that Apple is close to Apple Dominates, Hires ex-Googler - Yes, Android phones. (08 May 2010)

 

TechPsychic: AT&T says: Facebook Connect. (08 May 2010)

 

TechPsychic: Google's Nexus One of Google Chrome Release Adds Support subscriptions accounted for Amazon: Apple. (08 May 2010)

 

TechPsychic: Another stat: Twitter's Design of this is giving rise of BlackBerry Foursquare Map App store end. (07 May 2010)

 

TechPsychic: Like educational sales Up around Apple iPad makes money Plan costs half an Apple. (07 May 2010)

 

TechPsychic: Instead added extensions, social Networks than double, everyone jumps in Silicon Valley? (07 May 2010)

 

TechPsychic: So why iTunes App lets Social Networks Verizon Wireless Internet. (07 May 2010)

more »

 

SF Gate

 

Lawyer says Iranian woman could be stoned soon (2010-09-06T19:54:30UTC)

 

No body found in Pittsburg dump after 3 days (2010-09-06T07:42:40UTC)

 

Tight California races head into final frenzy (2010-09-06T12:39:06UTC)

 

Economy blamed for drop in births (2010-09-06T13:37:54UTC)

 

Obama assails GOP, promotes new jobs program (2010-09-06T20:26:24UTC)

 

US won't say if blowout preventer on way to shore (2010-09-06T20:25:23UTC)

 

Foster City's Hillbarn Theatre gets bell back (2010-09-06T17:38:14UTC)

 

Hassle in Haight over McDonald's menu change (2010-09-06T14:38:38UTC)

 

Air Products boosts Airgas acquisition offer (2010-09-06T21:33:46UTC)

 

UK regulators want Avandia diabetes pill pulled (2010-09-06T21:11:46UTC)

 

Revis returns to Jets after agreeing to deal (2010-09-06T21:10:44UTC)

 

Obama assails GOP, promotes new jobs program (2010-09-06T20:57:31UTC)

 

Matusz wins 4th straight, leads O's over Yanks 4-3 (2010-09-06T20:54:32UTC)

 

Presented By: (06 Sep 2010)

more »

 

Asia Times Online

 

Taiwan in a rice wine stew (3 Sep 2010)

 

Inspectors miss the flight to Kyrgyzstan (3 Sep 2010)

 

LIFE IN TALIBANISTAN : Married to the mob (3 Sep 2010)

 

Old Korea hand points new finger of blame (3 Sep 2010)

 

New case for US reparations in Laos (3 Sep 2010)

 

BOOK REVIEW : Al-Qaeda and counter-terrorism (3 Sep 2010)

 

Deripaska on US mission (3 Sep 2010)

 

IMF stumps up Pakistan aid (3 Sep 2010)

 

MARKET RAP : Confused - but forward (3 Sep 2010)

 

IT WORLD : Delhi targets Google, Skype (3 Sep 2010)

 

THE MOGAMBO GURU : Bernanke blows his cover (3 Sep 2010)

more »

 


Site feed Updated: 2010-Sep-06 19:00