Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Error - Google Foobar

To anyone who has done Google's Foobar challenge before, have you ever encountered an error like this?

Verifying solution...
{
"bytes" : "CAAaIgogQ291bGQgbm90IGZpbmQgJ2Fuc3dlcicgZnVuY3Rpb24"
}

I've tested my solution in Visual Studio, and it works fine, and it gives accurate output. I only have 36 hours remaining to submit my solution, and this is the final challenge, so I would really like to get credit for completing it. Here's the code I'm trying to verify:

from fractions import *
from math import factorial as fac

def cycle_index(n):
    return [(coeff(term), term) for term in foo(n, n)]

def foo(n, lim):
    soln_set = []
    if n > 0:
        for x in range(lim, 0, -1):
            if x == 1:
                soln_set.append([(1, n)])
            else:
                for y in range(int(n / x), 0, -1):
                    recurse = foo(n - x * y, x - 1)
                    if len(recurse) == 0:
                        soln_set.append([(x, y)])
                    for soln in recurse:
                        soln_set.append([(x, y)] + soln)
    return soln_set

def coeff(term):
    val = 1
    for x, y in term:
        val *= fac(y) * x ** y
    return Fraction(1, val)

def cross(cycle_a, cycle_b):
    term = []
    for len_a, freq_a in cycle_a:
        for len_b, freq_b in cycle_b:
            lcm = len_a * len_b / gcd(len_a, len_b)
            term.append((lcm, int(len_a * freq_a * len_b * freq_b / lcm)))
    return term

def answer(w, h, s):
    total = 0
    cycidx_cols = cycle_index(w)
    cycidx_rows = cycle_index(h)
    for col_coeff, col_cycle in cycidx_cols:
        for row_coeff, row_cycle in cycidx_rows:
            coeff = col_coeff * row_coeff
            cycle = cross(col_cycle, row_cycle)
            value = 1
            for _, power in cycle:
                value *= s ** power
            total += coeff * value
    return total

I found someone else's solution last week and verified it through Foobar, but I wanted to write my own to get a deeper understanding. I've compared results side-by-side, and they are exact, so I know my code gives accurate results.

Out of curiosity, I just retried verifying the other person's solution again, and now I am getting the same error with a slightly different output even though it worked just fine when I tried last week:

Verifying solution...
{
"bytes" : "CAEQARABEAEQARABEAEQARABEAEQAQ"
}

I'm not sure where else to go. I was so excited that I had come up with my own solution to the challenge, but now I'm panicking that it won't matter. Any suggestions?

UPDATE - June 29, 2018, 6:00pm CST
The deadline passed for me last night, and I was unable to submit my code in time. I made sure to use the recruitme command before time ran out just in case I got booted out. However, I am still able to view my current status, and it let me request another Level 5 challenge. So, I will be checking periodically to see if the test cases start showing up again, and I will be sure to update this when they do. I would highly recommend that anyone on lower levels wait until I confirm that this issue is fixed before attempting to request another challenge.

UPDATE - June 30, 2018, 5:00am CST
According to the pattern found by @RobertAnsel, I have completed the challenge. I confirmed this pattern by hardcoding the answer function to output solutions to the test cases given in the instructions. The resulting errors matched exactly with the predicted output. I also found an interesting thread on Google's Support Forum (linked here) where something similar happened to a bunch of Foobar challengers. It seems like their error was fixed by Google after about three days, but unfortunately, it also looks like a lot of people who timed out were not given another chance. Nevertheless, this will probably resolve itself within the next day or two. I will continue trying to verify and submit my solution until I am successful.

UPDATE - July 4, 2018, 12:00am CST This issue seems to have been more or less resolved. Refer to the chosen answer for more details. Thanks a ton to @RobertAnsel for all the help! Some additional info: I was able to verify my current challenge, but upon submission, I was told that my time for the problem had expired. After logging in again, I was able to request a new challenge. I noticed I was also able to use the recruitme command again. I am not sure if this means they did not receive the first request or if you are allowed to use that command multiple times. Regardless, I am relieved that I am able to continue forward with Foobar. Best of luck to the rest of you!

like image 869
Kody Puebla Avatar asked Jun 27 '18 16:06

Kody Puebla


People also ask

Is Google Foobar challenge real?

Google Foobar challenge is a secret hiring process of Google to recruiting top programmers and developers around the world. This is a way through which they provide direct interviews to the individual who cleared the challenge.

What happens if you fail a Google Foobar challenge?

If you fail on the first few levels, there are no lives. If you fail you're done, and you can't come back. In my opinion don't start Foobar until you are almost as skilled as a Google Software Engineer. It's plain and simple: you have one shot at Foobar.

What happens if you complete Google Foobar?

After completing this round, you get a referral link that you can share with a friend. The third round can have Google Interview level questions (I haven't appeared in one yet, read this on the internet). There are THREE questions to be completed with 7 days (168 hours) in hand for each question.

Is there a time limit for Google Foobar?

There are five levels: Level 1 has one challenge with a time limit of 48 hours (2 days). Level 2 has two challenges with a time limit of 72 hours (3 days) per challenge. Level 3 has three challenges with a time limit of 96 hours (4 days) per challenge.


1 Answers

This may not be the answer you're looking for, but that first "bytes" string is a base64 encoding of the following error message:

"Could not find 'answer' function".

I've done the Foobar challenge myself, and that should only happen if you are trying to verify a file that is missing a defined "answer" function, which obviously you are not. Are you certain that the spec they provide has 3 arguments vs an array with 3 items?

The second message (CAEQARABEAEQARABEAEQARABEAEQAQ), while valid base64, doesn't map to ASCII or UTF-8. After some closer analysis of some of the other strings others have posted, I've concluded that this is the base64 encoded version of the test output. It isn't very human readable, but I believe it is 11 2-byte chunks, the first of which is unhelpful, but the following 10 are the test result for each of the corresponding test cases. In the case of this message it converts to binary as:

0000100000000001 <- unknown pre-pended info
0001000000000001 <- passing test 1
0001000000000001 <- passing test 2
0001000000000001 <- passing test 3
0001000000000001 <- passing test 4
0001000000000001 <- passing test 5
0001000000000001 <- passing test 6
0001000000000001 <- passing test 7
0001000000000001 <- passing test 8
0001000000000001 <- passing test 9
0001000000000001 <- passing test 10

The '1's at the end of each of these lines indicates that all 10 tests are passing.

A failing test case is represented by the following string:

0001000000000000 <- failing test case

This should help you (and others) continue testing to achieve fully passing tests (you can complete your own analysis with tools like this one: https://cryptii.com/base64-to-binary), but unfortunately this will not help you move forward with your final submission until Google remediates the issue on their end.

UPDATE: July 2, 8PM PDT After reaching out to a couple of Google recruiters about the issue they were able to confirm that the issue was identified and is believed to be resolved today. If you re-save your code after making a change to it (whitespace should be fine), you should be able to test and submit correctly. Alternatively, you may now be able to request a new challenge anyway.

like image 189
Robert Ansel Avatar answered Sep 29 '22 03:09

Robert Ansel