Programming 12

Put your programming skills to the test in these challenges.

Re: Programming 12

Post by gh0stelement on Fri Jun 03, 2011 10:03 pm
([msg=58083]see Re: Programming 12[/msg])

fashizzlepop wrote:Make sure you have your script logged in, open the challenge page, grab the challenge, solve it, and submit it. :)


I have been doing that: I am using httplib and HTTPConnection (python). My problem is that when I make my get request I get one string and then make my post request the html code has another string and the website is expecting the second string to be the one I am using. Im not sure how to make it so both requests use the same page.
gh0stelement
New User
New User
 
Posts: 2
Joined: Wed Jun 01, 2011 2:40 pm
Blog: View Blog (0)


Re: Programming 12

Post by adamcaa on Sat Jun 04, 2011 11:27 am
([msg=58090]see Re: Programming 12[/msg])

Only a guess, but it sounds to me like you're making a second request to the server in between getting the text that needs to be processed and posting the answer to the server. I'm curious to see what it turns out to be.

I've done programming missions 1,2,and 11 in perl. I want to learn python to so i'm going to do this mission in python. If I come accross something pertaining to this solution I'll try and help out.

[update] Alright! I've finished this level in Python!
Last edited by adamcaa on Sun Jun 05, 2011 2:12 pm, edited 1 time in total.
adamcaa
New User
New User
 
Posts: 10
Joined: Fri May 27, 2011 9:33 pm
Blog: View Blog (0)


Re: Programming 12

Post by fashizzlepop on Sat Jun 04, 2011 1:16 pm
([msg=58094]see Re: Programming 12[/msg])

Edit: sorry, not sure what's wrong yet. Unless you are accidentally accessing the mission page twice.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2304
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Programming 12

Post by adamcaa on Sat Jun 04, 2011 4:49 pm
([msg=58107]see Re: Programming 12[/msg])

gh0stelement wrote:I have been doing that: I am using httplib and HTTPConnection (python). My problem is that when I make my get request I get one string and then make my post request the html code has another string and the website is expecting the second string to be the one I am using. Im not sure how to make it so both requests use the same page.


OK, I've learned a little Python now. I coded a script that connects,logs in, gets to the missions page retrieves the text to be processed(although I haven't written the method to process it yet), and then it submits 'test' results.

Taking a look through Wireshark everything is working correctly. if you haven't fired up Wireshark I highly recommend doing so. It will shine some light on the interaction. Is your script submitting do you get the wrong answer page?

[update] I've finished this level. If you want me to take a look at your script I can.
adamcaa
New User
New User
 
Posts: 10
Joined: Fri May 27, 2011 9:33 pm
Blog: View Blog (0)


Re: Programming 12

Post by zyewni on Wed May 09, 2012 7:59 pm
([msg=66249]see Re: Programming 12[/msg])

I'm sharing this because although I feel like an idiot, my stupid mistake is very mildly amusing and more importantly, maybe I can spare someone a headache in the future if they happen to be making my mistake.

I did this one with a php script, same as I did the other programming missions I've done, that logs itself into the site, gets the source for the challenge, then posts the responses back to the site - ran in to two problems though.

First, the additional requirement this time of posting submit as well as the solution held me back for a full half hour - I had to check the forums to find this out, which I try to do only if I'm absolutely stumped.

Secondly, and more stupidly, my program kept coming back with the wrong product at the end. What I did for the program was to parse the source, duplicate the string, loop for the number of characters in the string, deal with the first character accordingly, then chop off the first character before the string repeats.

After manually verifying (several times) that it was sorting primes and composites correctly, I decided to see how many times the loop was iterating - and it was always half the length of the original string.

It turns out I had set the loop to iterate as many times as the number of characters in the string I was chopping up instead of the original. Therefore, when the two equalized (halfway point), it quit looping. D'OH! :oops: Changed it to count the characters in the ORIGINAL, UNMODIFIED string, and it worked the first time I ran it.

tl;dr: If you're using string length as the number of times your loop should loop, make sure it's not a string that you're gradually shortening, especially if you've already duplicated the string for safekeeping.

Also, huge thanks to Defience for posting examples to test against - I wonder how long it would have taken me to catch my mistake without that.
zyewni
New User
New User
 
Posts: 3
Joined: Sun May 06, 2012 12:28 am
Blog: View Blog (0)


Re: Programming 12

Post by wan26 on Thu Jun 21, 2012 11:45 pm
([msg=67454]see Re: Programming 12[/msg])

Libcurl saves the day again, except i missed out the following important detail,

Code: Select all
string thirdvalue = "&submitbutton=Submit";


While my code has more lines than I presumed it would have been, it is very quick on execution. Much more satisfying as well, std::accumulate comes in handy btw :]
User avatar
wan26
Experienced User
Experienced User
 
Posts: 91
Joined: Sun Jan 22, 2012 6:46 pm
Blog: View Blog (0)


Re: Programming 12

Post by byotic on Thu May 22, 2014 6:59 pm
([msg=80908]see Re: Programming 12[/msg])

these is the script I wrote (for you C# lovers):
Code: Select all
[STAThreadAttribute]
        public static void Manipulate(string s)
        {
            int prime = 0;
            int composite = 0;
            string str = "";
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == '2' || s[i] == '3' || s[i] == '5' || s[i] == '7')
                {
                    prime += int.Parse(s[i].ToString());
                }
                else if (s[i] == '4' || s[i] == '6' || s[i] == '8' || s[i] == '9')
                {
                    composite+= int.Parse(s[i].ToString());
                }
                else if (s[i] != '0' && s[i] != '1' && str.Length<25)
                {
                    str += ((char)(s[i] + 1));
                   
                }
            }
            int multiply = prime * composite;
            Clipboard.SetText(str + multiply);
        }
        [STAThreadAttribute]
        static void Main(string[] args)
        {
            Manipulate(Console.ReadLine());
        }


and I get a seemingly legit string. But somehow i'm wrong... Can you give me a lead on what am I doing wrong?
byotic
New User
New User
 
Posts: 1
Joined: Sat Jan 25, 2014 9:18 am
Blog: View Blog (0)


Previous

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests