Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:51:20+00:00 2026-05-30T09:51:20+00:00

I am practicing these problems: http://code.google.com/codejam/contest/32016/dashboard#s=p1&a=1 I believe I have the correct solution, (even

  • 0

I am practicing these problems:
http://code.google.com/codejam/contest/32016/dashboard#s=p1&a=1

I believe I have the correct solution, (even after manual inspection of input and output);
still I keep getting Incorrect Output

Could anyone point out where I could be wrong?

def process_file(file):
    fsock = open(file)
    text = fsock.read()
    fsock.close()
    lines = text.split('\n')
    return lines


def process_lines(lines):
    cur = 1
    ans = []
    while cur < len(lines) - 1:
        N = int(lines[cur])
        cur += 1
        M = int(lines[cur])
        cur += 1
        struct = []
        for i in range(0, M):
            cust_pref = [int(n) for n in lines[cur].split(' ')]
            cust_drinks = [a-1 for a in cust_pref[1::2]]
            cust_drinks_malt_pref = cust_pref[2::2]
            cust_choice = [(cust_drinks[i], cust_drinks_malt_pref[i]) for i in range(0, len(cust_drinks))]
            cur += 1
            struct.append(cust_choice)
        ans.append((N, struct))
    return ans


def process_case(case):
    milkshake_menu = [0] * case[0] # our default menu
    i = 0
    impossible = False
    while i < len(case[1]): # i represents the customer number, case[1] represents customers
        acceptable = False
        customer = case[1][i]
        for drink_preferred in customer:
            if milkshake_menu[drink_preferred[0]] == drink_preferred[1]:
                acceptable = True
                i += 1 # ok, next customer
                break
        if not acceptable:
            for drink_preferred in customer:
                # find a malted preference
                if drink_preferred[1] == 1 and milkshake_menu[drink_preferred[0]] != 1:
                    # he needs a malted one
                    milkshake_menu[drink_preferred[0]] = 1
                    # but then we have to test previous customers, reset i
                    i = 0
                    break
                #if you have come here, the customer does not have a malted preference, or has a unmalted preference that conflicts with other customer
                impossible = True
            #impossible is True, break outer loop
            if impossible:
                break
    if impossible:
       return "IMPOSSIBLE"
    else:
       return " ".join([str(n) for n in milkshake_menu])



if __name__ == "__main__":
    import sys
    filename = sys.argv[1]
    lines = process_file(filename)
    inp = process_lines(lines)
    for k, v in enumerate(inp):
        a = process_case(v)
        print "Case #%d: %s" % (k + 1, a) 

Pastebin Output: http://pastebin.com/uXJQKbSr

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:51:22+00:00Added an answer on May 30, 2026 at 9:51 am

    One thing that looks odd is in the loop

            for drink_preferred in customer:
                # find a malted preference
                if drink_preferred[1] == 1 and milkshake_menu[drink_preferred[0]] != 1:
                    # he needs a malted one
                    milkshake_menu[drink_preferred[0]] = 1
                    # but then we have to test previous customers, reset i
                    i = 0
                    break
                impossible = True
    

    I would expect this to be

            for drink_preferred in customer:
                # find a malted preference
                if drink_preferred[1] == 1 and milkshake_menu[drink_preferred[0]] != 1:
                    # he needs a malted one
                    milkshake_menu[drink_preferred[0]] = 1
                    # but then we have to test previous customers, reset i
                    i = 0
                    break
            else:
                impossible = True
    

    I think at the moment you will judge the task is impossible before having checked all the possibilities.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been practicing some old C++ problems to prepare for a few job
I have been practicing TDD and (some) XP for a few years now and
I have been practicing TDD in C# for several years now and recently have
I've been practicing for an upcoming programming competition and I have stumbled across a
I'm practicing PyQt and (Q)threads by making a simple Twitter client. I have two
I was practicing the dynamic programming problem on SPOJ. But I have no idea
I've recently joined TopCoder and have been practicing in the Practice Rooms for the
I was practicing SRM Problems in Topcoder.I came across this problem Problem Statement: Today
Gists of controller code at bottom of page I have a simple rails nesting
Been practicing with those system calls, but I stucked into this code: #include <stdio.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.