#๐Ÿ”’ Pls help with DMOJ quesition 2048

35 messages ยท Page 1 of 1 (latest)

honest veldtBOT
#

@tepid pollen

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tepid pollen
#

Stuck at test case 4

#

IR : Key error

bitter cradle
#

Do you have the full traceback/error?

tepid pollen
#

it's dmoj

#

so I can't see

hot cape
#

Is this a quiz?

tepid pollen
#

no

#

so if you have the answer

#

you can show me

#

but I would like to know the thinking tho

#

I need to train my logic

hot cape
#

Why not just run it in a python shell and get the output

tepid pollen
#

because I don't know the input

hot cape
#

Not sure how you are supposed to code a program when you don't know what the input should be

tepid pollen
#

do you use online judge to solve question?

bitter cradle
tepid pollen
#

alr

#

do you know what is wrong?

bitter cradle
#

It'll be really hard for us to determine this without knowing wha tthe input is

tepid pollen
#

any possible key error for my code?

#

like bugs and stuff

#

key error happen when the key is not found right?

bitter cradle
#

mmhmm

#

You're doing some funky stuff with the dictionary key here

    if not all(tiles_num[key] == 1 for key in tiles_num):
        for key in tiles_num.keys():
            if str(int(key) * 2) in tiles_num:
                tiles_num[str(int(key) * 2)] += int(tiles_num[key] / 2)
            elif str(int(key) * 2) not in tiles_num and str((int(tiles_num[key] / 2) * 2) * int(key)) not in tiles_num:
                num = is_power_of_two(int(tiles_num[key] / 2) * 2)
                if str(num * int(key)) in tiles_num:
                    tiles_num[str(num * int(key))] += 1
                else:
                    max_num = max(max_num, num * int(key))
            elif str((int(tiles_num[key] / 2) * 2) * int(key)) in tiles_num:
                tiles_num[str(tiles_num[key] * int(key))] += 1

#

My guess is it's somewhere in there

tepid pollen
#

I solve the key error

#

know I stuck at task 6

#

main difference

            elif str((int(tiles_num[key] / 2) * 2) * int(key)) in tiles_num:
                tiles_num[str((int(tiles_num[key] / 2) * 2) * int(key))] += 1
#

do you know why this doesn't work?
2 4 8 16
0 0 0 0
16 2 8 2
0 0 0 0
16

#

32 is the correct answer

#

but it output 16

honest veldtBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.