Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

*urgent* Need help to figure out this code problem

Options
  • 03-04-2014 2:08pm
    #1
    Registered Users Posts: 63 ✭✭


    Any coders/mathmaticians out there that could help me with this code problem? If someone could write a solution in python that would be great.:D
    For sure, you have heard about the love that pirates have for gold. Dwarven pirates are even more avaricious. There are a lot of legends and fairy-tales that describe the passion of these small creatures for this metal.
    Let's imagine the situation where three dwarves have found a goblin's chest with N gold coins and have to divide them. Due to ancient rules governing the allocation of loot to pirates in order of seniority, the oldest dwarf should get one coin more than the middle dwarf, and the middle dwarf should get one coin more than the youngest dwarf.
    Help the dwarves to divide the coins in this way, or tell them that this is impossible.
    Input

    You are given integer N (1 ≤ N ≤ 1000).

    Output
    If it is impossible to divide the coins in the way that dwarves want, print -1 (minus one). Otherwise, print the numbers of coins which the oldest, the middle and the youngest dwarfs get (in this order). Separate the numbers with spaces.

    Sample test(s)
    Input
    3

    Output
    2 1 0
    Tagged:


«1

Comments

  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,639 Mod ✭✭✭✭TrueDub


    Well, if it's urgent...

    What have you tried so far? Nobody will do this for you, but people might help you along the way, assuming you've put the effort in upfront.


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    o = 0
    m = 0
    y = 0
    x = 0
    str_n = input(" Enter the number of coins N in the chest ")
    num_n = int(str_n)
    x = num_n % 3
    num_n = num_n - 3
    num_n = num_n / 3
    y = num_n
    m = num_n + 1
    o = num_n + 2

    if x > 0:
    print "-1"
    input("Press Enter to esc")

    else:
    print (str(o) + " " + str(m) + " " + str(y))
    input("Press Enter to esc")

    Tried that code but it won't work!


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,639 Mod ✭✭✭✭TrueDub


    Tried that code but it won't work!

    Doesn't work how? Does it throw an error, or not do the calculation correctly?

    Analysing why it doesn't work will lead you to the fix for that issue.


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Says this when i enter in the code
    Error:Form elements must not have name or id of "submit"


  • Registered Users Posts: 6 brian.gill98


    you should google it!


  • Advertisement
  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,639 Mod ✭✭✭✭TrueDub


    Says this when i enter in the code
    Error:Form elements must not have name or id of "submit"

    So there's your problem - an element on your form (presumably HTML?) has an invalid name or id - submit is obviously a reserved word.

    Look at your HTML and change the offending element.


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Very funny gill


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    The code is not written in HTML its written it python


  • Moderators, Sports Moderators, Regional Abroad Moderators Posts: 2,639 Mod ✭✭✭✭TrueDub


    How do you execute your code?


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    Post the full python code - wrap it in [noparse]
    ...{code here}...
    
    [/noparse] tags to make it easier to read. And tell us how you run your application, because from what I can tell that's not a python error.


  • Advertisement
  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    {o = 0
     m = 0
     y = 0
     x = 0
     str_n = input(" Enter the number of coins N in the chest ")
     num_n = int(str_n)
     x = num_n % 3
     num_n = num_n - 3
     num_n = num_n / 3
     y = num_n
     m = num_n + 1
     o = num_n + 2
     
    if x > 0:
     print "-1"
     input("Press Enter to esc")
     
    else:
     print (str(o) + " " + str(m) + " " + str(y))
     input("Press Enter to esc")}
    


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    rogifish wrote: »
    ..

    :rolleyes:

    Emmet, that code's working grand apart from a small error following execution.
    [touchingvirus@virussys ~]python test.py 
     Enter the number of coins N in the chest 999
    334 333 332
    Press Enter to esc
    Traceback (most recent call last):
      File "test.py", line 19, in <module>
        input("Press Enter to esc")
      File "<string>", line 0
        
        ^
    SyntaxError: unexpected EOF while parsing
    

    How are you trying to run the code?


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    :rolleyes:

    Emmet, that code's working grand apart from a small error following execution.
    [touchingvirus@virussys ~]python test.py 
     Enter the number of coins N in the chest 999
    334 333 332
    Press Enter to esc
    Traceback (most recent call last):
      File "test.py", line 19, in <module>
        input("Press Enter to esc")
      File "<string>", line 0
     
        ^
    SyntaxError: unexpected EOF while parsing
    

    How are you trying to run the code?
    Trying to get it to work for a school project on a webpage


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    Trying to get it to work for a school project on a webpage

    So you are using HTML then. That error you have is because in your HTML page you have an element somewhere with id="submit" which isn't permitted. Change that ID to something else. It's not a python error.

    To compound your problems you appear to have wrote a command line python application, not a web application. There are key differences. For example your app reads input from the "input()" function, which is the keyboard or some other form of input. But a web form sends the number to the python script when you press submit in a thing called a POST variable. See this StackOverflow answer for a simply guide on how to get POST variables sent to a python script - http://stackoverflow.com/questions/464040/how-are-post-and-get-variables-handled-in-python


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    here is the html on the page.
            <div class="container">
    
                <div class="row super-header">
        <div class="col-xs-4">
            <a href="http://www.google.com" target="_blank"><img src="/static/images/logo-google.png"></a>
        </div>
        <div class="col-xs-8">
            <div class="pull-right">
                <strong>
                
                     |
                    
                        <a href="/student-dashboard">Dashboard</a> |
                    
                    <a href="/logout">Sign Out</a>
                
                </strong>
            </div>
        </div>
    </div>
    
                <div class="row main-nav">
                    
                        <nav class="navbar navbar-inverse">
        <div class="navbar-header">
            <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#main-menu">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <div id="main-menu" class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
    			<li><a href="/">Home</a>
    			<li><a href="/about">About</a></li>
    			<li><a href="/announcements">Announcements</a></li>
    			<li><a href="/rules">Rules</a></li>
    			<li><a href="/faqs">FAQs</a></li>
    			<li><a href="/resources">Resources</a></li>
                
                    <li><a href="/standings">Contest Rankings</a></li>
                
    		</ul>
        </div>
    </nav>
                    
                </div>
    
                <div class="row">
    
    				<div style="padding: 0px;" id="main-content" class="col-xs-12">
                        
    
                        
    
    <script type="text/javascript" src="/static/scripts/easyXDM.min.js"></script>
    <script type="text/javascript" src="/static/scripts/CodeforcesRemote.js"></script>
    
    <div style="min-height: 500px;" id="iframeWrapper"><iframe style="width: 100%; height: 442445px;" id="easyXDM_default7697_provider" border="0" src="https://ctc.codeforces.com/ctc/contests/iframe?ctc.authToken=982a9d86675b0af6247bdc07f00c43fef90b2453&amp;ctc.userId=c647679e8bed039a625305fe&amp;ctc.contestId=9&amp;ctc.timestamp=1396532282&amp;ctc.parentUrl=https%3A%2F%2Fwww.calltocode.ie%2Fcf%2Fstart-coding&amp;xdm_e=https%3A%2F%2Fwww.calltocode.ie&amp;xdm_c=default7697&amp;xdm_p=1" frameBorder="0" name="easyXDM_default7697_provider"></iframe></div>
    
    <script type="text/javascript">
    	var url, timestamp, contest_id, student_id, auth_token 
    	url = 'https://ctc.codeforces.com/ctc/contests/iframe' //'http://iframe.codeforces.com/ctc/contests/iframe'
    	timestamp = 1396532282
    	contest_id = 9
    	student_id = 'c647679e8bed039a625305fe'
    	auth_token = '982a9d86675b0af6247bdc07f00c43fef90b2453'
        
    	CodeforcesRemote.injectIframe(
    		url,
    		document.getElementById('iframeWrapper'),
    		timestamp,
    		contest_id,
    		student_id,
    		auth_token
    	);
    </script>
    
    
                    </div>
    
    			</div>
    
            </div>
    
            <script src="/static/scripts/bootstrap.min.js"></script>
    
    


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    I don't understand. You're entering into a competition :confused:. Do you code the HTML for the form, or just the python the page uses? A thorough explanation of what you're doing would be very helpful.


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    that is the html of the page where you test the code you write for a question given on another page. the python code i wrote is to answer that question. the competition gives that webpage online to test your code you wrote. The copetition is "google call to code"


  • Closed Accounts Posts: 31,152 ✭✭✭✭KERSPLAT!


    So is it a school assignment or a Google competition?


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    I have to do it for the school :D


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    I have to do it for the school :D

    Nah, you're evading the question now and I've tried to help. I've explained your issue - you wrote a CLI app which won't work in a web environment.


  • Advertisement
  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Sorry how am i evading the question?


  • Registered Users Posts: 8,584 ✭✭✭TouchingVirus


    You said it was a school project. School projects don't usually end up being Google-backed competitions where you can win prizes for yourself, your teacher and/or your school. The registration date for this competition has ended, and I'm certainly not eligible to participate. So I can't see what you're doing and you're not explaining it incredibly well. I suggest you contact your teacher for help, it sounds to me like the competition site is buggy if you cannot control the HTML on the page and it's throwing an error.


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    yeah was thinking that myself. Thanks for the help anyway!


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Played around with this some more and i'm now getting this :mad: not sure what's wrong maybe if it's something simple someone could help me?
    Can't compile file:
    Traceback (most recent call last):
    Played around some more and now it's telling me this
    File "<string>", line 1, in <module>

    File "20837.py", line 2

    {o = 0

    ^

    SyntaxError: invalid syntax


  • Site Banned Posts: 86 ✭✭Pixie69


    Any coders/mathmaticians out there that could help me with this code problem? If someone could write a solution in python that would be great.:D
    For sure, you have heard about the love that pirates have for gold. Dwarven pirates are even more avaricious. There are a lot of legends and fairy-tales that describe the passion of these small creatures for this metal.
    Let's imagine the situation where three dwarves have found a goblin's chest with N gold coins and have to divide them. Due to ancient rules governing the allocation of loot to pirates in order of seniority, the oldest dwarf should get one coin more than the middle dwarf, and the middle dwarf should get one coin more than the youngest dwarf.
    Help the dwarves to divide the coins in this way, or tell them that this is impossible.

    Input

    You are given integer N (1 ≤ N ≤ 1000).

    Output
    If it is impossible to divide the coins in the way that dwarves want, print -1 (minus one). Otherwise, print the numbers of coins which the oldest, the middle and the youngest dwarfs get (in this order). Separate the numbers with spaces.

    Sample test(s)
    Input
    3

    Output
    2 1 0

    What are you smoking?


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Pixie69 wrote: »
    What are you smoking?
    Ask google :D


  • Registered Users Posts: 1,019 ✭✭✭carlmango11


    The most senior dwarf gets ((N-3)/3)+2 coins. Should be easy enough to code


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Yeah but i don't have much experience coding :/ haven't a clue to be honest


  • Registered Users Posts: 63 ✭✭Emmet Manning 99


    Could really do with the answer tonight guys


  • Advertisement
  • Closed Accounts Posts: 31,152 ✭✭✭✭KERSPLAT!


    The forum is here to help not do your assignment/competition/homework for you


This discussion has been closed.
Advertisement