If the granularity of arrival/departure times is shorter than the interval you attend the party, there's a subtlety. Say intervals (6:00,11:00) (6:00,8:10) (8:30,11:00), then arriving at 7:50 and leaving 8:50 gives you some time with 3 celebrities, even though 7:50 is not a celebrity-arrival time, and celebrity-occupancy never reaches 3. (If you spoof that the celebrities arrive earlier, by the amount of time you attend the party, the algorithm should account for this. – Except, if the best time is really early, this will tell you to arrive before the party starts…)

Thank-you for publishing these courses. Inspiration led me to trying out an algorithm to only traverse the celebrity list once. https://gist.github.com/HeilTec/d0aff148a943e29c9c6c436ce0b5fb5a

no matter how I think of it, the code at 13:45 is wrong, and there should be "or" instead of "and" at the loop where check celebrity is in the range time, because if she was already in, she is counted, and if she was going to go out within that time as well, she is also counted, so I can't understand why there is an AND instead of OR

yo where's puzzle 1

First

If the granularity of arrival/departure times is shorter than the interval you attend the party, there's a subtlety. Say intervals (6:00,11:00) (6:00,8:10) (8:30,11:00), then arriving at 7:50 and leaving 8:50 gives you some time with 3 celebrities, even though 7:50 is not a celebrity-arrival time, and celebrity-occupancy never reaches 3. (If you spoof that the celebrities arrive earlier, by the amount of time you attend the party, the algorithm should account for this. – Except, if the best time is really early, this will tell you to arrive before the party starts…)

Thank-you for publishing these courses.

Inspiration led me to trying out an algorithm to only traverse the celebrity list once.

https://gist.github.com/HeilTec/d0aff148a943e29c9c6c436ce0b5fb5a

(… pardon my JavaScript ๐

this course is for?

Here is simple answer… https://github.com/concretesteelbond/codding_puzzle/blob/master/puzzle_2.py

Thank for this puzzle, Professor

max(celebrity_list, key= celebrity_list.count)

python inbuilt

I keep thinking this can be done in better then O(n^2). Any ideas?

How about this code:??

celebTimings = [(6, 7), (6, 12), (6, 7), (7, 8), (7, 10), (8, 9), (8, 10), (9, 12),

(9, 10), (10, 11), (10, 12), (11, 12)]

key = []

for i in range(0,12):

key.append(0)

for s,e in celebTimings:

for k in range(s, e):

key[k-1] +=1

print("Best time to atttend the party is at {}o'clock, {} celebrities will be there".format(key.index(max(key))+1,max(key)))

<?php

$sched = [[6,8],[6,12],[6,7],[7,8],[7,10],[8,9],[8,10],[9,12],[9,10],[10,11],[10,12],[11,12]];

$countList = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

// Run the $sched through 1 time.

for ($i=0; $i < count($sched) ; $i++) {

// Inner loop best case 1 time. Worst case 24 times.

for ($j=$sched[$i][0]; $j <$sched[$i][1] ; $j++) {

$countList[$j] = $countList[$j]+1;

}

}

// Find the index and max to print out.

$count = 0;

$index = 0;

$max = 0;

foreach($countList as $n){

echo '[ '.$count.', '.$n.' ] <br>';

if($n > $max){

$max = $n;

$index = $count;

}

$count++;

}

echo 'The most celebrities are to find at '.($index+1).' oclock.'.$max.' celebs will be there.';

?>

MIT buy erase friendly boards please :p

no matter how I think of it, the code at 13:45 is wrong, and there should be "or" instead of "and" at the loop where check celebrity is in the range time, because if she was already in, she is counted, and if she was going to go out within that time as well, she is also counted, so I can't understand why there is an AND instead of OR