Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,867,298 members, 6,881,123 topics. Date: Wednesday, 25 May 2022 at 09:19 PM

Google Code Jam Contest 2013 - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Google Code Jam Contest 2013 (4352 Views)

Nigeria Represented In Google Code Jam, Russians Dominate / Google Code Jam 2012 Registration Is Open / Marek Cygan Wins Google Code Jam 2005 (2) (3) (4)

(1) (2) (Reply) (Go Down)

Google Code Jam Contest 2013 by WhiZTiM(m): 8:12pm On Mar 22, 2013
Hello Nairalanders!
...I just stumbled upon this competition posted on Facebook by a young Egyptian Facebook friend(subscribed) of mine who works at google...

... I have read through and made enquiries... And this contest sure looks promising to our good Nairaland coders...
You can use almost any popular programming language that at least has its compiler and/or standard library free.

Its the Google Code Jam 2013!
Registration opened on Tuesday, March 12, 2013 at 19:00 UTC (12:00 PM Pacific Time (PT) in the United States) and ends on Sunday, April 14, 2013 at 0:00 UTC (Saturday, April 13, 2013 at
5:00 PM PT).

I want to encourage the few programmers here to give it a shot if they would be available... The timing is quite flexible...
Site here:
http://code.google.com/codejam

the schedules. . . and everything you need to know or prepare for is there in the link provided...
Re: Google Code Jam Contest 2013 by Fayimora(m): 2:23pm On Mar 23, 2013
Good luck to whoever is participating! Buzz me on twitter if you make it to the final round.
Re: Google Code Jam Contest 2013 by WhiZTiM(m): 8:46pm On Mar 23, 2013
Fayimora: Good luck to whoever is participating! Buzz me on twitter if you make it to the final round.
hmn... Wish I could participate, but my semester exams wouldnt let me... Two questions...
1. Why wouldn't you participate??
2. Why should you be contacted on twitter if any Nairalander makes it to the finals? (... I hope its either a job offer or extra reward!)
Re: Google Code Jam Contest 2013 by lordZOUGA(m): 9:05pm On Mar 23, 2013
WhiZTiM:
hmn... Wish I could participate, but my semester exams wouldnt let me... Two questions...
but this does not exactly qualify as an excuse.
Re: Google Code Jam Contest 2013 by Javanian: 9:08pm On Mar 23, 2013
Please i heard you are given just 5 minutes for the first round, is it true?
Re: Google Code Jam Contest 2013 by WhiZTiM(m): 10:10pm On Mar 23, 2013
lordZOUGA:
but this does not exactly qualify as an excuse.
...maybe... ...or maybe not.
Sometimes, for me as an undergraduate, hustling great GPAs is my priority...

Javanian:
: Please i heard you are given just 5 minutes for the first round, is it true?
nope... If I correctly remember what I was told.you can solve any question(s) within the days alotted to your timezone.. Once you are sure you are done with a question, you DOWNLOAD input test cases(a text file) frm Google and you have just limited time(maybe 5mins) to UPLOAD output (the text file generated by your program) back to the Competition's server.
Re: Google Code Jam Contest 2013 by Fayimora(m): 9:09pm On Mar 29, 2013
WhiZTiM:
hmn... Wish I could participate, but my semester exams wouldnt let me... Two questions...
1. Why wouldn't you participate??
2. Why should you be contacted on twitter if any Nairalander makes it to the finals? (... I hope its either a job offer or extra reward!)


1. I'm very very busy. Where I work, you never have the time for stuffs like these... It's practically a waste of time!
2. Job offer, maybe but highly unlikely considering you might not be willing to re-locate. Nevertheless, the finals are in England(btw Google's offices at LDN are great! ), I'll like to meet whoever makes it wink. I don't mind gaining a few more geeky/nerdy friends.

Also, why would I stress myself when the finals are in LDN? lol. I *might* have attempted if it was ...... Zurich?

Re: Google Code Jam Contest 2013 by Otuabaroku: 10:30am On Mar 30, 2013
@ Fayimora, I thought you were based in England. Why would you want to attend the event if it was based in Zurich but not England?
Re: Google Code Jam Contest 2013 by naijaswag1: 11:49am On Mar 30, 2013
Feeble minds. Humans are always in a habit of making excuses for their shortcomings. If your shallow minds cannot contend with strong reasoning, stop making silly excuses.
Re: Google Code Jam Contest 2013 by Fayimora(m): 2:46pm On Mar 30, 2013
Otuabaroku: @ Fayimora, I thought you were based in England. Why would you want to attend the event if it was based in Zurich but not England?
Because I love traveling wink
Re: Google Code Jam Contest 2013 by Fayimora(m): 3:12pm On Mar 30, 2013
naija_swag: Feeble minds. Humans are always in a habit of making excuses for their shortcomings. If your shallow minds cannot contend with strong reasoning, stop making silly excuses.
Hmmm ........ if you were referring to me then you really have no idea what I do.
Re: Google Code Jam Contest 2013 by Nobody: 12:58pm On Apr 01, 2013
Fayimora:
Hmmm ........ if you were referring to me then you really have no idea what I do.
.
Go-Go dancer?
Re: Google Code Jam Contest 2013 by Nobody: 1:09pm On Apr 01, 2013
Fayimora:
btw Google's offices at LDN are great.
.
Like really awesome! I kinda have a soft spot for the hedge your bet garden. Spectacular view!
Re: Google Code Jam Contest 2013 by Otuabaroku: 11:11am On Apr 03, 2013
I tried solving the last qualifying google codejam for 2012 at the link http://code.google.com/codejam/contest/1460488/dashboard.

My java solution for the challenge is thus:

import java.io.*;
import java.util.*;

public class Googlechan {
static char[] keys={' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
static char[] values={' ','y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q'};
static Map<Character,Character> Translator;
public static void main(String[] args) throws Exception{

Map<Integer,ArrayList<String>> output = new LinkedHashMap<Integer,ArrayList<String>>();
BufferedWriter fileout = new BufferedWriter(new FileWriter("E:/output1.txt"wink);
BufferedReader file = new BufferedReader(new FileReader("E:/input123.txt"wink);

String dataset;
int cnt=1;

puplateTranslator(keys,values);
while((dataset=file.readLine())!=null){

ArrayList<String> outans = new ArrayList<String>();
char[] data=dataset.toCharArray();
StringBuilder temp = new StringBuilder();
for(int i=0;i<data.length;i++)
{


temp.append(Translator.get(data[i]));

}
outans.add(temp.toString());
output.put(cnt,outans);
cnt++;

}

for(Integer key:output.keySet())
{

fileout.write("Case #"+key+":"wink;
fileout.write(" "wink;
ArrayList<String> ans=output.get(key);

if(ans!=null){
for(String val:ans)
{

fileout.write(val);
}

fileout.newLine();
}



}
fileout.close();


}


public static void puplateTranslator(char[] keys,char[] values){
Translator=new LinkedHashMap<Character,Character>();
for(int i=0;i<keys.length;i++)
{
Translator.put(keys[i],values[i]);
}

}

}





The model solution provided by google in python was so portable that I'm asking my fellow Java developer is there a similar data structure in java to replicate same? The link to the question and the model solution is http://code.google.com/codejam/contest/1460488/dashboard. Thanks in anticipation.
Re: Google Code Jam Contest 2013 by Nobody: 12:45pm On Apr 03, 2013
Otuabaroku:

public class Googlechan {
static char[] keys={' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
static char[] values={' ','y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q'};
static Map<Character,Character> Translator;
public static void main(String[] args) throws Exception{

Map<Integer,ArrayList<String>> output = new HashMap<Integer,ArrayList<String>>();
BufferedWriter fileout = new BufferedWriter(new FileWriter("E:/output13.txt"wink);
BufferedReader file = new BufferedReader(new FileReader("E:/input12.txt"wink);
String dataset;
int cnt=1;

puplateTranslator(keys,values);
while((dataset=file.readLine())!=null){
ArrayList<String> outans = new ArrayList<String>();
String[] data=dataset.split(" "wink;
for(int i=0;i<data.length;i++)
{

String tempans =data[i];
if(tempans!=null)
{
StringBuilder temp = new StringBuilder();
for(int j=0;j<tempans.length();j++)
{
char ian=tempans.charAt(j);
temp.append(Translator.get(ian));
}
outans.add(temp.toString());
}


}
output.put(cnt,outans);
cnt++;
}

for(Integer key:output.keySet())
{



System.out.print("Case #"+key+":"wink;
fileout.write("Case #"+key+":"wink;
ArrayList<String> ans=output.get(key);

if(ans!=null){
for(String val:ans)
{
int k=0;



if( k%2!=0)
{


System.out.print(val);
fileout.write(val);
}
else
{

System.out.print(" "wink;
System.out.print(val);
fileout.write(" "wink;
fileout.write(val);


}
k++;

}

System.out.println();
fileout.newLine();
}



}
fileout.close();


}

public static void puplateTranslator(char[] keys,char[] values){
Translator=new HashMap<Character,Character>();
for(int i=0;i<keys.length;i++)
{
Translator.put(keys[i],values[i]);
}

}

}


Re: Google Code Jam Contest 2013 by Nobody: 12:47pm On Apr 03, 2013
Sorry 'bout that, was conducting an experiment. Didn't work. Seun why?
Re: Google Code Jam Contest 2013 by Otuabaroku: 6:21pm On Apr 04, 2013
Thanks The_Writer. At least now is looking okay.

Still playing with the practice section of the Google codejam.

For this particular task "You receive a credit C at a local store and would like to buy two items. You first walk through the store and create a list L of all available items. From this list you would like to buy two items that add up to the entire value of the credit. The solution you provide will consist of the two integers indicating the positions of the items in your list (smaller number first)"

My code below passed for the small input data( http://code.google.com/codejam/contest/351101/dashboard#s=p0) but failed the large input file. Could anyone take a look to see where I'm getting the bug as I seem not to see it.


import java.util.*;
import java.io.*;

public class CreditService {

static Map<Integer,ArrayList<Integer>> result = new LinkedHashMap<Integer,ArrayList<Integer>>();

public static ArrayList<Integer> two_sum_problem(int arr[], int sum) {
ArrayList<Integer> anstemp = new ArrayList<Integer>();

for (int i = 0; i < arr.length; i++) {
int lookFor = sum - arr[i];
int index;
boolean status=false;
for(int j=0;j<arr.length;j++)
{
if(lookFor==arr[j]){
if(i==j)
{
index=j+1;
}
index=j;
anstemp.add((i+1));
anstemp.add((index+1));
status=true;

}
}


if(status)
break;
}


return anstemp;
}


public static void main(String[] args) throws Exception{
BufferedWriter output=new BufferedWriter(new FileWriter("E:/output13.txt"wink);
Scanner file = new Scanner(new FileReader("E:/input123.txt"wink);
int cnt=0;
int cnt2 =file.nextInt();
while(cnt<cnt2)
{
int sum=file.nextInt();

int datainterator =file.nextInt();

int[] dataset = new int[datainterator];
for(int i=0;i<datainterator;i++)
{
dataset[i]=file.nextInt();
System.out.print(dataset[i]);
}
System.out.println();
ArrayList<Integer> temp = two_sum_problem(dataset,sum);
result.put((cnt+1), temp);
System.out.println(temp);
cnt++;
}

for (Integer currKey : result.keySet()) {




System.out.print("Case #"+currKey+":"wink;
output.write("Case #"+currKey+":"wink;


ArrayList<Integer> diffMapValue = result.get(currKey);
for(Integer val:diffMapValue)
{
int cnt1=0;
if(cnt1%2!=0)
{

System.out.print(val);
output.write(String.valueOf(val));
}
else{
System.out.print(" "wink;
System.out.print(val);
output.write(" "wink;
output.write(String.valueOf(val));

}
cnt1++;
}
System.out.println();
output.newLine();
}
output.close();
}
}


http://code.google.com/codejam/contest/351101/dashboard#s=p0
Re: Google Code Jam Contest 2013 by Otuabaroku: 10:52am On Apr 06, 2013
Common guys let share ideas.

This particular solution scaled through the small and large input data.

The task:The Latin alphabet contains 26 characters and telephones only have ten digits on the keypad. We would like to make it easier to write a message to your friend using a sequence of keypresses to indicate the desired characters. The letters are mapped onto the digits as shown below. To insert the character B for instance, the program would press 22. In order to insert two characters in sequence from the same key, the user must pause before pressing the key a second time. The space character ' ' should be printed to indicate a pause. For example, 2 2 indicates AA whereas 22 indicates B.( http://code.google.com/codejam/contest/351101/dashboard#s=p2)



My code:

import java.util.*;
import java.io.*;
public class Anotherone {
static char[] keys={' ','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
static String[] values={"0","2","22","222","3","33","333","4","44","444","5","55","555","6","66","666","7","77","777","7777","8","88","888","9","99","999","9999"};
static char[] seta={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
static int[] valueset={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
static Map<Character,String> Translator;
static Map<Character,Integer> Translator2;
public static void main(String[] args) throws Exception{

Map<Integer,ArrayList<String>> output = new LinkedHashMap<Integer,ArrayList<String>>();
BufferedWriter fileout = new BufferedWriter(new FileWriter("E:/output1.txt"wink);
BufferedReader file = new BufferedReader(new FileReader("E:/input123.txt"wink);

String dataset;
int cnt=1;

puplateTranslator(keys,values);
puplateTranslator2(seta, valueset);


while((dataset=file.readLine())!=null){

ArrayList<String> outans = new ArrayList<String>();
char[] data=dataset.toCharArray();
StringBuilder temp = new StringBuilder();
for(int i=0;i<data.length;i++)
{

if(i>0&&(Translator2.get(data[i])==Translator2.get(data[i-1])))
{


temp.append(" "wink;
temp.append(Translator.get(data[i]));
continue;

}
temp.append(Translator.get(data[i]));





}
outans.add(temp.toString());
output.put(cnt,outans);
cnt++;

}

for(Integer key:output.keySet())
{



System.out.print("Case #"+key+":"wink;
System.out.print(" "wink;
fileout.write("Case #"+key+":"wink;
fileout.write(" "wink;
ArrayList<String> ans=output.get(key);

if(ans!=null){
for(String val:ans)
{



System.out.print(val);
fileout.write(val);


}

System.out.println();
fileout.newLine();
}



}
fileout.close();


}

public static void puplateTranslator(char[] keys,String[] values){
Translator=new LinkedHashMap<Character,String>();
for(int i=0;i<keys.length;i++)
{
Translator.put(keys[i],values[i]);
}

}

public static void puplateTranslator2(char[] keys, int[] values){
Translator2=new LinkedHashMap<Character,Integer>();
for(int i=0;i<keys.length;i++)
{
Translator2.put(keys[i],values[i]);
}

}

}


What do you think about my solution?

http://code.google.com/codejam/contest/351101/dashboard#s=p2
Re: Google Code Jam Contest 2013 by Fayimora(m): 1:56pm On Apr 07, 2013
Otuabaroku: I tried solving the last qualifying google codejam for 2012 at the link http://code.google.com/codejam/contest/1460488/dashboard.

My java solution for the challenge is thus:

..............................

The model solution provided by google in python was so portable that I'm asking my fellow Java developer is there a similar data structure in java to replicate same? The link to the question and the model solution is http://code.google.com/codejam/contest/1460488/dashboard. Thanks in anticipation.


Here is mine

Code is on Gist
Raw link: https://gist.github.com/fayimora/5330382

The actual solution is on lines 12 - 17

Re: Google Code Jam Contest 2013 by Otuabaroku: 3:59pm On Apr 07, 2013
Hi Fayimora, your Scala implementation is cool. Check out their solution in python:
translate_to_english = {
' ': ' ', 'a': 'y', 'b': 'h', 'c': 'e', 'd': 's',
'e': 'o', 'f': 'c', 'g': 'v', 'h': 'x', 'i': 'd',
'j': 'u', 'k': 'i', 'l': 'g', 'm': 'l', 'n': 'b',
'o': 'k', 'p': 'r', 'q': 'z', 'r': 't', 's': 'n',
't': 'w', 'u': 'j', 'v': 'p', 'w': 'f', 'x': 'm',
'y': 'a', 'z': 'q'}

for tc in xrange(1, int(raw_input()) + 1):
english = ''.join(
[translate_to_english[ch] for ch in raw_input()])
print 'Case #%d: %s' % (tc, english)
(http://code.google.com/codejam/contest/1460488/dashboard#s=a&a=0)

It looks so cool. Do you reckon any data structure in java to implement it this way? Also have you tried the You received credit task ? Let me see how do solved it. Thanks for responding, at least let us discuss and share ideas.
Re: Google Code Jam Contest 2013 by Fayimora(m): 5:02pm On Apr 07, 2013

There is really nothing so elegant about that solution. They simply hardcoded the dictionary. You can do the same with a hash map in Java but it's going to be ugly.

Mind giving me a link to the task?(You received credit)
Re: Google Code Jam Contest 2013 by Otuabaroku: 6:17pm On Apr 07, 2013
I used hashmap in my implementation too. The link to the You received credit is http://code.google.com/codejam/contest/351101/dashboard#s=p0
Re: Google Code Jam Contest 2013 by naijaswag1: 11:13pm On Apr 10, 2013
What is the running time of all these 'cool' solutions? That's what you guys should be after if you are thinking of participating in google codejam.
Re: Google Code Jam Contest 2013 by truthisbitter: 1:06am On Apr 11, 2013
^
Google code jam doesn't test for running time. They just give you a set of input and you have to upload a file that contains the correct solution. They then compare your file, byte for byte with the answer. If diff == 0, then you are correct. Of course, if others upload before you, then have the advantage.
Re: Google Code Jam Contest 2013 by naijaswag1: 7:45am On Apr 11, 2013
The important thing is to have an efficient code. If you can come up with an efficient code within the stipulated time, there are more chances of you getting it uploaded or getting to the next round. How about you rush and upload rubbish that is correct in record time but ends up not passing the test when grading for that round begins?
Re: Google Code Jam Contest 2013 by Fayimora(m): 11:54pm On Apr 11, 2013
Otuabaroku: I used hashmap in my implementation too. The link to the You received credit is http://code.google.com/codejam/contest/351101/dashboard#s=p0
I'll look at this when I get back from work tomorrow

naija_swag: The important thing is to have an efficient code.
Sorry but when it comes to competitions like codejam, that's very wrong! The most important thing is to have a solution wink.
Re: Google Code Jam Contest 2013 by naijaswag1: 6:53am On Apr 12, 2013
Fayimora:

Sorry but when it comes to competitions like codejam, that's very wrong! The most important thing is to have a solution wink.

FYI the qualification round starts today. Go and post nonsense code that is correct but takes hours to run and expect to get to the next round.
Re: Google Code Jam Contest 2013 by lordZOUGA(m): 7:02am On Apr 12, 2013
naija_swag:

FYI the qualification round starts today. Go and post nonsense code that is correct but takes hours to run and expect to get to the next round.
you are bitter
Re: Google Code Jam Contest 2013 by naijaswag1: 10:59am On Apr 12, 2013
lordZOUGA:
you are bitter

The truth is damned bitter. To Nigerians it's a snake venom. No apologizes. If you want to be among the world's best, say no to mediocrity.
Re: Google Code Jam Contest 2013 by Otuabaroku: 1:23pm On Apr 12, 2013
Hi naija_swag, I was actually looking for guys like you to share ideas, that's the main intent of posting some of my solutions.Of course, to participate in the competition, there is no room for mediocrity. Regarding the running time of the code at stage of competition, i reckon it is as important as the solution itself.

What do think about the solutions I have posted so far and could you post your solutions, so we can learn as well.
Re: Google Code Jam Contest 2013 by skydancer: 12:10am On Apr 13, 2013
I'm on this now. First problem here... will post c# answer shortly...

Tic-Tac-Toe-Tomek is a game played on a 4 x 4 square board. The board starts empty, except that a single 'T' symbol may appear in one of the 16 squares. There are two players: X and O. They take turns to make moves, with X starting. In each move a player puts her symbol in one of the empty squares. Player X's symbol is 'X', and player O's symbol is 'O'.

After a player's move, if there is a row, column or a diagonal containing 4 of that player's symbols, or containing 3 of her symbols and the 'T' symbol, she wins and the game ends. Otherwise the game continues with the other player's move. If all of the fields are filled with symbols and nobody won, the game ends in a draw. See the sample input for examples of various winning positions.

Given an 4 x 4 board description containing 'X', 'O', 'T' and '.' characters (where '.' represents an empty square), describing the current state of a game, determine the status of the Tic-Tac-Toe-Tomek game going on. The statuses to choose from are:

"X won" (the game is over, and X won)
"O won" (the game is over, and O won)
"Draw" (the game is over, and it ended in a draw)
"Game has not completed" (the game is not over yet)
Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of 4 lines with 4 characters each, with each character being 'X', 'O', '.' or 'T' (quotes for clarity only). Each test case is followed by an empty line.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is one of the statuses given above. Make sure to get the statuses exactly right. When you run your code on the sample input, it should create the sample output exactly, including the "Case #1: ", the capital letter "O" rather than the number "0", and so on.

Limits

The game board provided will represent a valid state that was reached through play of the game Tic-Tac-Toe-Tomek as described above.
Re: Google Code Jam Contest 2013 by Fayimora(m): 12:23am On Apr 13, 2013
ok Mr @naija_swag For the last time, YOU DO NOT SUBMIT CODE TO GET POINTS! You submit a result! The code you submit is just complementary! Is it really that hard to comprehend?

@Otuabaroku As for Store Credit, it is way too simple for a competition.

Disclaimer: My solution is purely functional. I could replace lines 12-19 with a one-liner but I'll probably have to always read that line 3 times to remember what it does.


Code on Gist: https://gist.github.com/fayimora/5376302

If you are looking for something more comprehendible, see this:



Code on Gist: https://gist.github.com/fayimora/5376272


Please note that for both solutions, the actual 'solution' is on lines 12-19, inclusive. Everything else is either error checking or fancy input processing.

Enjoy!

(1) (2) (Reply)

I Just Developed A Professional Hymnal Android App Called "InstaHymn" / Help On How A Make An App A Trial Version With C# / Andela Will Empower Africa's Next Generation Of Great Technical Leaders

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 217
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.