It is currently Thu Apr 18, 2024 3:32 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next
Author Message
Offline
 Post subject: Google Code Jam
Post #1 Posted: Tue Apr 03, 2018 5:27 am 
Gosei
User avatar

Posts: 2011
Location: Groningen, NL
Liked others: 202
Was liked: 1087
Rank: Dutch 4D
GD Posts: 645
Universal go server handle: herminator
Last year, a lot of L19'ers were interested and participated in the Google Code Jam. If anyone's interested this year, the qualifiers are coming up (April 6/7).

See: https://code.google.com/codejam/

I'll be participating :)


This post by HermanHiddema was liked by 2 people: bernds, gamesorry
Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #2 Posted: Tue Apr 03, 2018 7:06 am 
Honinbo

Posts: 10905
Liked others: 3651
Was liked: 3374
Good luck, Herman, and good luck to all! :D

_________________
The Adkins Principle:
At some point, doesn't thinking have to go on?
— Winona Adkins

Visualize whirled peas.

Everything with love. Stay safe.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #3 Posted: Tue Apr 03, 2018 7:16 pm 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
I'm going to try, though, I'll be in the airport for Korea this Friday when the qualification round starts. Given that it's for 24 hours, maybe I'll have the chance to get some points.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #4 Posted: Fri Apr 06, 2018 11:58 am 
Tengen

Posts: 4380
Location: North Carolina
Liked others: 499
Was liked: 733
Rank: AGA 3k
GD Posts: 65
OGS: Hyperpape 4k
After last year, I was a little annoyed with not solving more. I wanted to practice and be ready for this year. None of that happened.

Right now, I'm pretty excited about a separate project, and have been working on it every time I get a chance. I think I might try to do the Code Jam, but I can't decide what to spend time on.

_________________
Occupy Babel!

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #5 Posted: Sat Apr 07, 2018 5:22 pm 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
Well, in Korea now. A bit jet lagged, but saw that there is still time to work on the qualification round.

I did the first two problems. I can't seem to see how many you need to solve to advance to Round 1. Is it similar to last year?

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #6 Posted: Sat Apr 07, 2018 5:25 pm 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
I see it now - 25 points. Cool.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #7 Posted: Sat Apr 07, 2018 5:46 pm 
Lives with ko

Posts: 259
Liked others: 46
Was liked: 116
Rank: 2d
Kirby wrote:
I see it now - 25 points. Cool.


And note the score displayed on the standings page is "optimistic", i.e. it assumes you get full points when the hidden results are revealed.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #8 Posted: Sat Apr 07, 2018 6:04 pm 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
Yeah, I get it. That part is the same as last year IIRC.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #9 Posted: Sat Apr 07, 2018 6:39 pm 
Lives in sente

Posts: 902
Location: Fort Collins, CO
Liked others: 319
Was liked: 287
Rank: AGA 3k
Universal go server handle: jeromie
I don't have time to participate this year, but I'm looking forward to the inevitable discussion that crop up around here! I learned a lot last year.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #10 Posted: Sun Apr 08, 2018 1:02 am 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
Well, that was quick - I'm out already. I only attempted the first two problems, and while they passed the small set on the first attempt, the large dataset gave TLE for both. I didn't do any sort of special optimization for either - just breadth first search for the first problem, and pretty much a straightforward implementation of the second.

Oh well. I guess I should have tried the other two problems, too (or thought about perf more, maybe).

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #11 Posted: Sun Apr 08, 2018 4:00 am 
Lives with ko

Posts: 259
Liked others: 46
Was liked: 116
Rank: 2d
Kirby wrote:
Well, that was quick - I'm out already. I only attempted the first two problems, and while they passed the small set on the first attempt, the large dataset gave TLE for both. I didn't do any sort of special optimization for either - just breadth first search for the first problem, and pretty much a straightforward implementation of the second.

Oh well. I guess I should have tried the other two problems, too (or thought about perf more, maybe).


What do you mean by "breadth first search" in this case? The trick to the first one is that there is always one highest possible value swap. We can disregard all trailing Cs, then there is an irrelevant prefix followed by a number of S characters. Swapping the first of those S with the previous C will give you the maximum reduction. Example: SCSCSSS -> SCSSCSS.

In the second one, one has to not implement the quadractic bubble sort. The thing to realize here is that each swap leaves the middle element unchanged, so essentially it ends up sorting two arrays which are interleaved. So, put your input elements into two separate arrays as they come in, run quicksort on each, then look for mismatched elements when interleaving them again.

The one I didn't attempt was the two-rotations case for the cube. Played around with wxmaxima but couldn't really find an equation to give me the angle for a given area. I suppose a binary search could easily have found the right spot but at that point I felt I'd done enough.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #12 Posted: Sun Apr 08, 2018 4:48 am 
Honinbo

Posts: 9545
Liked others: 1600
Was liked: 1711
KGS: Kirby
Tygem: 커비라고해
bernds wrote:

What do you mean by "breadth first search" in this case? The trick to the first one is that there is always one highest possible value swap. We can disregard all trailing Cs, then there is an irrelevant prefix followed by a number of S characters. Swapping the first of those S with the previous C will give you the maximum reduction. Example: SCSCSSS -> SCSSCSS.


I didn't try to do any trick. For any given string, I swap each pair of consecutive characters to generate a bunch of new strings (each one representing a possible hack). I add these to a queue for the breadth first search I'm doing. Every time I pop something off of the queue, I check to see the damage. Also, whenever I add to the queue, I'm actually adding a pair to also indicate how many hacks I did to get that string. The unmodified string has 0 hacks, the first set of hacked strings all have 1 hack, the next iteration has 2 hacks, etc.

Anyway, I didn't try to think of any particular properties of swapping - I just generated all possibilities and explored them all. That's what I meant by BFS.

Quote:
In the second one, one has to not implement the quadractic bubble sort.


I implemented the quadratic bubble sort, literally taking the pseudocode from the problem description.

I guess I should have been trying to think of ways to optimize and make things fast, but I pretty much wrote things up literally to solve the problems, which I guess wasn't enough for the large datasets.

That being said, I still feel I've improved since last year, even though I didn't make it as far. Last year, I think you were able to tell when you got TLE, since it was manual upload of the output file, so I would have caught the fact that my implementations were too slow. And I wrote things up much faster than last year - in around 20 minutes for each problem, which is faster than last year.

So I'll mark it up as a success, even if I'm out so early this year.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #13 Posted: Sun Apr 08, 2018 5:40 am 
Lives in gote

Posts: 502
Liked others: 1
Was liked: 153
Rank: KGS 2k
GD Posts: 100
KGS: Tryss
That must have been... innefficient :shock:

My code for the two first problems (in C#) :

Problem 1 :
Code:
using System;
using System.Collections.Generic;
using System.Linq;

namespace Problem 1
{
    class Program
    {
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            for (int t=1; t<=T; t++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int result = Solve(int.Parse(s[0]), s[1]);

                Console.WriteLine("Case #" + t + ": " + ((result<0)?"IMPOSSIBLE":result.ToString()) );
            }
        }

        static int Solve(int D, string P)
        {
            List<int> instructions = new List<int>();
            int shot = 0;
            int charge = 1;
            for (int i = 0; i < P.Length; i++)
            {
                if (P[i] == 'C')
                {
                    charge *= 2;
                }
                else
                {
                    instructions.Add(charge);
                    shot++;
                }
            }

            if (shot > D)
                return -1;


            int result = 0;
            while ( instructions.Sum() > D )
            {
                int move = shot - 1;
                while( move > 0 && instructions[move] == instructions[move-1] )
                {
                    move--;
                }

                instructions[move] /= 2;
                result++;
            }

            return result;
        }
    }
}


Problem 2 :
Code:
using System;
using System.Collections.Generic;
using System.Linq;


namespace Problem_2
{
    class Program
    {
        static void Main(string[] args)
        {
            int T = int.Parse(Console.ReadLine());
            for (int t = 1; t <= T; t++)
            {
                Console.ReadLine();
                List<int> data = Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToList();
               
                int result = Solve(data);

                Console.WriteLine("Case #" + t + ": " + ((result < 0) ? "OK" : result.ToString()));
            }
        }


        static int Solve(List<int> data)
        {
            List<int> even = data.Where((c, i) => i % 2 == 0).ToList();
            List<int> odd = data.Where((c, i) => i % 2 != 0).ToList();

            even.Sort();
            odd.Sort();

            for( int i = 0; i<odd.Count; i++)
            {
                if (odd[i] < even[i])
                    return 2*i;

                if ((i+1)<even.Count && odd[i] > even[i + 1])
                    return 2*i+1;
            }

            return -1;
        }
    }
}



Note that in my first problem, I completly abstracted the sequence : I don't swap anything,

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #14 Posted: Mon Apr 09, 2018 2:17 am 
Gosei
User avatar

Posts: 2011
Location: Groningen, NL
Liked others: 202
Was liked: 1087
Rank: Dutch 4D
GD Posts: 645
Universal go server handle: herminator
Well, I didn't make it.

For problem 1 my code only solved the small set. I haven't looked at what went wrong with the large but I suspect something like an off by one error or perhaps a floating point inaccuracy from Math.log on large numbers.

For problem 2 I only wrote a quick brute force implementation which solves the small but not the large set.

For problem 3 I still have no idea what went wrong. My solution was quite efficient (equivalent to the more efficient solution mentioned in the analysis) and solved all test cases locally (using the provided test script, adjusted to give all sorts of test cases), but when I submitted it, it reported a failure with "Runtime Error" and I had no real way to debug. Very frustrating :mad:

I didn't start problem 4. After trying various ways to debug problem 3 I didn't feel like continuing, especially not on the math heavy problem 4, so I quit and went to do something more fun :)

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #15 Posted: Mon Apr 09, 2018 5:23 am 
Lives with ko

Posts: 259
Liked others: 46
Was liked: 116
Rank: 2d
HermanHiddema wrote:
For problem 3 I still have no idea what went wrong. My solution was quite efficient (equivalent to the more efficient solution mentioned in the analysis) and solved all test cases locally (using the provided test script, adjusted to give all sorts of test cases), but when I submitted it, it reported a failure with "Runtime Error" and I had no real way to debug.
Which language were you using? Perhaps something turned out not quite as portable between systems as one would hope.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #16 Posted: Mon Apr 09, 2018 11:10 pm 
Gosei
User avatar

Posts: 2011
Location: Groningen, NL
Liked others: 202
Was liked: 1087
Rank: Dutch 4D
GD Posts: 645
Universal go server handle: herminator
bernds wrote:
Which language were you using? Perhaps something turned out not quite as portable between systems as one would hope.


Ruby. My code was:

Code:
tests = gets.to_i
1.upto(tests) do |t|
   area = gets.to_i
   side = [(area/3.0).ceil, 3].max
   rect = side.times.map { [0,0,0] }
   while true
      best = 1.upto(side-2).min_by do |c|
         (-1..1).map do |x|
            (-1..1).map do |y|
               rect[c+x][y]
            end.sum
         end.sum
      end
      puts [best+1, 2].join(' ')
      STDOUT.flush
      x, y = gets.chomp.split.map(&:to_i)
      break if (x == 0 && y == 0)
      return if (x == -1 && y == -1)
      rect[x-1][y-1] = 1
   end
end


I don't think I'm using any special features here which haven't been present in ruby since forever.

The code simple creates a 3*X rectangle large enough that it covers sufficient area for the given test, then it keeps finding the 3x3 subrectangle with the most empty cells and outputs the middle cell thereof until the rectangle is filled.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #17 Posted: Tue Apr 10, 2018 4:25 am 
Lives with ko

Posts: 259
Liked others: 46
Was liked: 116
Rank: 2d
HermanHiddema wrote:
bernds wrote:
Which language were you using? Perhaps something turned out not quite as portable between systems as one would hope.


Ruby. My code was:


When I try to run it from the script, I get:

Your code exited early, in the middle of Case #1.
Your code finishes with exit status 1.
The stderr output of your code is:
herman3.ruby:11:in `block (3 levels) in <main>': undefined method `sum' for [0, 0, 0]:Array (NoMethodError)
from herman3.ruby:8:in `each'
from herman3.ruby:8:in `map'
from herman3.ruby:8:in `block (2 levels) in <main>'
from herman3.ruby:7:in `upto'
from herman3.ruby:7:in `each'
from herman3.ruby:7:in `min_by'
from herman3.ruby:7:in `block in <main>'
from herman3.ruby:2:in `upto'
from herman3.ruby:2:in `<main>'

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #18 Posted: Tue Apr 10, 2018 5:04 am 
Gosei
User avatar

Posts: 2011
Location: Groningen, NL
Liked others: 202
Was liked: 1087
Rank: Dutch 4D
GD Posts: 645
Universal go server handle: herminator
Damn. https://blog.bigbinary.com/2016/11/02/r ... e-sum.html

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

But the contest is 2.3.3

I've been using sum since forever, because it's been in ActiveSupport since forever, so I never realized it wasn't bog standard :/

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #19 Posted: Tue Apr 10, 2018 5:38 am 
Lives with ko

Posts: 259
Liked others: 46
Was liked: 116
Rank: 2d
HermanHiddema wrote:
Damn. https://blog.bigbinary.com/2016/11/02/r ... e-sum.html

$ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

But the contest is 2.3.3

I've been using sum since forever, because it's been in ActiveSupport since forever, so I never realized it wasn't bog standard :/


Sorry to hear that. I knew Python was incompatible with itself, but I didn't know anything about Ruby. I'd kind of like to make a case for using industrial strength languages like C rather than these newfangled shiny but fragile things. Why handicap yourself in a contest?

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam
Post #20 Posted: Tue Apr 10, 2018 6:04 am 
Gosei

Posts: 1590
Liked others: 886
Was liked: 528
Rank: AGA 3k Fox 3d
GD Posts: 61
KGS: dfan
Ruby is over 20 years old, and (speaking as someone who has written more C++ than any other language) I think that when it comes to overall fragility, including how easy it is to introduce subtle bugs, C and C++ are much worse than languages like Ruby and Python.

It is true that you have to be a little careful about making sure that your versions match, which is true for any language with a rich standard library. The current version of Ruby is actually 2.5.1, and the latest version of Ruby 2.3 is 2.3.7, so if you ask me Google is the one who dropped the ball here if they only support 2.3.3.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 24 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group