Recent Posts
SeC Gaming
the Lounge
New Lounge Topic
New Gaming Topic
Due to Bots, Database and Security issues, weve temporarily moved to www.speakeasyclinic.net

You are not connected. Please login or register

Facebook Hacker Cup 2014

View previous topic View next topic Go down  Message [Page 1 of 1]

1 Facebook Hacker Cup 2014 on 2013-11-23, 05:03

Any of the programmers here entering this year?

https://www.facebook.com/hackercup

I'm a little late starting, I forgot about it, but just submitted the first answer. Very Happy

I'll post source code after its finished (else I get disqualified Razz )

View user profile

2 Re: Facebook Hacker Cup 2014 on 2013-11-23, 23:16

I generally don't care about events like those. Or well, any sort of event.

Add to that my general dislike for Facebook. So yeah... no way.

Good luck though Very Happy

View user profile

3 Re: Facebook Hacker Cup 2014 on 2013-11-24, 16:10

Lemmi post the first problem for you Ars, see what you would have been dealing with Razz

Spoiler:
You want to write an image detection system that is able to recognize different geometric shapes. In the first version of the system you settled with just being able to detect filled squares on a grid.

You are given a grid of N×N square cells. Each cell is either white or black. Your task is to detect whether all the black cells form a square shape.

Input
The first line of the input consists of a single number T, the number of test cases.

Each test case starts with a line containing a single integer N. Each of the subsequent N lines contain N characters. Each character is either "." symbolizing a white cell, or "#" symbolizing a black cell. Every test case contains at least one black cell.

Output
For each test case print YES if all the black cells form a completely filled square with edges parallel to the grid of cells. Otherwise print NO.

Constraints
1 = T = 20
1 = N = 20

Example
Test cases 1 and 5 represent valid squares. Case 2 has an extra cell that is outside of the square. Case 3 shows a square not filled inside. And case 4 is a rectangle but not a square.

Spoiler:
Example Input
5
4
..##
..##
....
....
4
..##
..##
#...
....
4
####
#..#
#..#
####
5
#####
#####
#####
#####
.....
5
#####
#####
#####
#####
#####

View user profile

4 Re: Facebook Hacker Cup 2014 on 2013-11-25, 12:37

Congratulations!

You have advanced to Round 1 of the 2014 Hacker Cup! Round 1 will last 24 hours and start December 7, 2013 at 10:00 AM PT. To see the start time in your local time zone, please click here.

The top 500 competitors will advance to Round 2. In addition, anyone who correctly solves as many problems as the competitor in 500th place will also advance to Round 2.

Best of luck and happy hacking,
The Hacker Cup Team
I finished 1632 out of 6242 people. And I started like 2 days late lol, next round I gotta get top 500, which means I gotta actually start straight away haha, should be easy enough. Also I only submitted 2/3 of the problems, 3rd one I couldn't be bothered with.

Heres my code for the problem I posted above, did it in PHP because I felt like it...

Also had to write a quick function for bit shifting the string because when I originally wrote it, I was using binary bit shifting then remembered PHP has a low INT limit so did it in strings instead...

Code:
<?php
/*
 Liam Sheridan
 Facebook Hacker Cup 2014
 Qualification Round - 20 : Square Detector
*/

$input = "square_detector.txt";
$output = "";

$t = 0;
$n = 0;
$file_array = array();
$out = "";

$f= fopen($input,"r");
$t = fgets($f);

for ($i = 0; $i < $t; $i++) {
  $n = fgets($f);
  for ($x = 0; $x < $n; $x++) {
    $file_array[$i] .= str_replace(['.', '#'], ['0', '1'], trim(fgets($f)));
  }
}

fclose($f);

for ($i = 1; $i <= count($file_array); $i++) {
  $output.= 'Case #' .$i. ': ' . calculate($file_array[$i-1],$i);
  if ($i < count($file_array)){
    $output .= "\n";
  }
 
}
file_put_contents("output.txt", $output);

function calculate($data,$i){
  $wh = sqrt(strlen($data));
  $s = substr_count($data, '1');
  if (fmod(sqrt($s), 1) == 0){
    $matrix = matrix($wh,sqrt($s));
    if (in_array($data, $matrix)) {
      return 'YES';
    }else{
      return 'NO';
    }  
  }else{
    return 'NO';
  }
}

function matrix($wh,$s){
  $needle = '';
  $valid = array();
  for ($i = 0; $i < $s; $i++) {
    for ($z = 0; $z < $s; $z++) {$needle.= '1';}
    for ($x = 0; $x < $wh-$s; $x++) {$needle.= '0';}
  }
  $o = ($wh *$wh)-strlen($needle);
  for ($i = 0; $i < $o; $i++) { $needle.= '0';}
  for ($i = 0; $i <= $wh-$s; $i++) {
    for ($z = 0; $z <= $wh-$s; $z++) {
      $valid[] = $needle;  
      $needle  = shiftR($needle,1);
    }
      if ($s > 1) {$needle  = shiftR($needle,$s-1);}
  }
  return $valid;
}

function shiftR($s,$v){
  $r = substr($s, 0, -$v);
  for ($i = 0; $i < $v; $i++) {$r = "0" . $r;}
  return $r;
}


?>

View user profile

5 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:11

Go you!

How many entrants were there altogether?

View user profile

6 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:13

Guest


Guest
6242

Says so right there derp

7 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:15

Thats the number that finished, not qualified.

At least, thats how I'm reading it.

View user profile

8 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:30

7515 that entered total

View user profile

9 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:35

if I started on time, I would have finished about 700ish with the two answeres i submitted. If I had done the 3rd one as well, I would have been top 50. But Like I said I started 2 days late, totally forgot about it

View user profile

10 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:41

Basically only doing it cos I want a T-Shirt, and just missed out on one last year haha.

Who gets T-shirts?

The top 100 finishers from Round 2 will get t-shirts.

How many people advance?

Qualification round: Everyone who gets at least one problem right will advance to Round 1.
Round 1: The top 500 finishers will advance to Round 2. Everyone that gets the same number of points as the person in 500th place will also advance to Round 2.
Round 2: The top 100 finishers will advance to Round 3.
Round 3: The top 25 finishers will advance to the onsite final.
SO I need to be top 100 in round 2.

Heres some info on how to solve the 3 problems for the qualifying.
https://www.facebook.com/notes/facebook-hacker-cup/2014-qualification-round-solutions/775180192497884

For problem above (first one) I used this meathod thats mentioned..

Another idea of a very inefficient, but easy to implement algorithm is that you can iterate over all the possible grid formations that form a square, there is an order of N^3 of them. Now all you need to check is whether one of the grids matches your input exactly!

View user profile

11 Re: Facebook Hacker Cup 2014 on 2013-11-25, 13:48

[quote="RStudios"]

[code]<?php
/*
Liam Sheridan
Facebook Hacker Cup 2014
Qualification Round - 20 : Square Detector
*/
http://www.radiohillingdon.com/team1/team_liam_sheridan.php

looking good R Very Happy

View user profile

12 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:02

LOL, nope not me Razz

View user profile

13 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:06

Guest


Guest
R posted his pic before

14 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:12

Yeah I did Razz

Plus i'm practically un-googleable, you may find my facebook if you dig enough, and maybe my tribal-wars account

View user profile

15 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:15

RStudios wrote:LOL, nope not me Razz
we all know you are an aging radio presenter. you cant hide it forever.

View user profile

16 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:17

Guest


Guest
Hes not old but he does look like a programmer Wink 0

17 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:30

Ewwwww, PHP D:

Congratulations though. Is there any particularly good prize, or do you only get t-shirts?

View user profile

18 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:40

LOL, top 100 in round 2 get t-shirts....

Top 25 in round 3 goto the on site final at Facebook offices in Menlo Park, California, USA . The Flights, hotels and meal allowances are paid for.

The final prize money is shite tho;

1st Place: $10,000 USD
2nd Place: $2,000 USD
3rd Place: $1,000 USD
4th-25th Place: $100 USD

View user profile

19 Re: Facebook Hacker Cup 2014 on 2013-11-25, 14:41

And I always use PHP for the early questions, as its quicker to code and debug. In round 2 I'll switch to c++, because PHP will bottleneck.

View user profile

Sponsored content


View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum