Programming 1

Put your programming skills to the test in these challenges.

Re: Permanent Programming 1

Post by Rijnzael on Tue Apr 29, 2008 12:01 pm
([msg=1729]see Re: Permanent Programming 1[/msg])

Sepanto, just extract the zip archive and have your program deal only with the contained text file.
Rijnzael
Poster
Poster
 
Posts: 164
Joined: Sun Apr 13, 2008 10:12 am
Location: 128.0.0.0/8
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Morrbo on Wed Apr 30, 2008 1:36 pm
([msg=1741]see Re: Permanent Programming 1[/msg])

hey daniel, this may or may not be the answer to your question, but what was getting frustrated about wash the program was appearing to work, like yours, but not working.

what it was for me, is that i put the initial word in an array, say the word was 'hylsel' and compared it to the line read in from the text file, letter by letter. If the letter was found in the line, it added the possible word to another array, then saw if the next letter (from the first inital array) was found in the possible word. If it wasn't it cleared the second array, if it was it added the word, again. this kept looping through the words in the text file until it reached the end, then it took the value of the array(0) and printed it out.

What i was running into a problem with was the value it was giving me was a POSSIBILITY of the word it could be, go back to the 'hylsel' example, this was giving me the result 'ashley', which looking through it was actually correct - it COULD be ashley, given the letters provided, but obviously wasn't. so i added a check to see if the length of the word read in from the text file was the same exactly length as the word written in, ie. seeing if the result was exactly the same length as 'hylsel', this started giving the result 'shelly' instead of ashley, if the line-read wasn't the same length as the jumbled up word, it would clear the second array.

sorry for the long reply i just tried to give the most detailed explaination/solution to what was fucking up with mine ^^

good luck mate :)
Morrbo
New User
New User
 
Posts: 3
Joined: Tue Apr 29, 2008 9:42 am
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Damascus2k8 on Wed Apr 30, 2008 3:54 pm
([msg=1745]see Re: Permanent Programming 1[/msg])

Well the method i used was completely different from that one,
although not very memory efficient :) but quite fast.

It used three arrays, one for the jumbled words, one for the wordlist and another containing the same wordlist but with the characters in each word sorted alphabetically.

You see i thought that searching through a wordlist for each permutation of a jumbled word would prove to be...welll....just too slow for me :)

So i opted with this method:
basically if you sort the characters in each jumbled word in ascending order, and then do the same with each word in the wordlist when you read the file into an array, you only have to go through the wordlist once for each jumbled word, and when the match is found you just output the word from the original wordlist, which would have the same index as the sorted one (obviously).

Disadvantage is, if you're unlucky it could quite easily come up with duplicate words (ie. dad, ada & add are three dictionary words!).

As for the timing issue of getting the words off the page, well i just copy & pasted from the page into a textbox in my app, hit enter, and it was all quickly formatted and sent to the clipboard ready to paste in the answer box :)

Job Done!


C0362AF19B89E861F21485CE1D2B430E



"Change your thoughts and you change your world!"
Damascus2k8
Experienced User
Experienced User
 
Posts: 68
Joined: Mon Apr 14, 2008 8:18 pm
Location: /root
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Morrbo on Wed Apr 30, 2008 4:05 pm
([msg=1747]see Re: Permanent Programming 1[/msg])

ah yeah that's a pretty nice way to do it. On the duplicate words thing, there's really no way to get round it (assuming in the 'dad' example the textfile had add and dad in it - there would be no way to know :( )

and the formatting thing, i think i must have used the spoiler, actually that was the hardest/most frustrating part of writing it though, nice method btw, a loss less memory intesive than mine :D
Morrbo
New User
New User
 
Posts: 3
Joined: Tue Apr 29, 2008 9:42 am
Blog: View Blog (0)


Re: Permanent Programming 1

Post by sharpskater69 on Wed Apr 30, 2008 5:17 pm
([msg=1750]see Re: Permanent Programming 1[/msg])

My way: test to see if the strings have the same amount of each character, can't go wrong there.


hackthissite/asthktieshci

Morrbo wrote:ah yeah that's a pretty nice way to do it. On the duplicate words thing, there's really no way to get round it (assuming in the 'dad' example the textfile had add and dad in it - there would be no way to know :( )

and the formatting thing, i think i must have used the spoiler, actually that was the hardest/most frustrating part of writing it though, nice method btw, a loss less memory intesive than mine :D


If your method is accurate enough, their won't be duplicates. At least there weren't in mine once I ironed things out. Don't hold me to this, but I really don't think there are 2 words in the list with the same characters and same amount of characters, that's why it should work. I remember wasting time confused on the formatting though. I ended splitting by # and whitespace all in one hit with preg_split.
sharpskater69
New User
New User
 
Posts: 34
Joined: Tue Apr 22, 2008 4:10 pm
Blog: View Blog (0)


Re: Permanent Programming 1

Post by TheMindRapist on Wed Apr 30, 2008 6:13 pm
([msg=1766]see Re: Permanent Programming 1[/msg])

Lol, your ways are hideous.
My way found every possible permutation of the scrambled word using recursion then checked to see if the were in a HashSet.
(The HashSet was the wordlist)
Runtime: <.1 secs
Image
User avatar
TheMindRapist
Contributor
Contributor
 
Posts: 585
Joined: Mon Apr 14, 2008 4:57 pm
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Sepanto on Thu May 01, 2008 8:05 am
([msg=1835]see Re: Permanent Programming 1[/msg])

Does anyone know a code to remove the # ,because I lose time dealing with it!
Sepanto
New User
New User
 
Posts: 7
Joined: Tue Apr 22, 2008 1:16 pm
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Morrbo on Thu May 01, 2008 9:33 am
([msg=1837]see Re: Permanent Programming 1[/msg])

what language sepunto?
Morrbo
New User
New User
 
Posts: 3
Joined: Tue Apr 29, 2008 9:42 am
Blog: View Blog (0)


Re: Permanent Programming 1

Post by danijelfosters on Thu May 01, 2008 9:55 am
([msg=1840]see Re: Permanent Programming 1[/msg])

Thanks everyone for help, but still don't know what's wrong.
I was comparing the input and output several times, everything looks well, the length of a string, the same letters, of course scrambled, so I have no idea what could went wrong.

My programm looks something like that:
*i have 2 text files, one is the word list and another scrambled words, which I just paste in
*1. i remove '#' and '_' from the scrambled file and put it into a String array
*2. i read wordlist into an array
*3. i have 2 for statements which i use to walk through both arrays
*4. i change from string to char so i can sort both words alphabeticaly
*5. and if they are equal, i just print the word into console, and put ',' after it if it's meant to
*6. i just copy the solution from the console, and put it into form.

But something is still wrong, have no idea what could be.
If someone could examine my programm to see what I am doing wrong, i would be verry grateful, he can just paste his mail, so I can send him my solution which is written in Java or he can send me an email on danijelfosters@gmail.com

Sepanto wrote:Does anyone know a code to remove the # ,because I lose time dealing with it!


In java you can use "substring", in C "strncpy".

Thanks mates.
danijelfosters
New User
New User
 
Posts: 5
Joined: Sun Apr 20, 2008 2:26 am
Blog: View Blog (0)


Re: Permanent Programming 1

Post by Damascus2k8 on Thu May 01, 2008 1:06 pm
([msg=1854]see Re: Permanent Programming 1[/msg])

@danijelfosters

Im not quite sure where you could be going wrong because i don't use java for much, unless im decompiling an applet or the like ;)

I found c++ to be a better language to use for this one as you can use the std::string library which has its own stable_sort() function among others, so there is no swapping and changing between string and char types.

Also maybe you are ending up with a comma at the end of the output?


C0362AF19B89E861F21485CE1D2B430E



"Change your thoughts and you change your world!"
Damascus2k8
Experienced User
Experienced User
 
Posts: 68
Joined: Mon Apr 14, 2008 8:18 pm
Location: /root
Blog: View Blog (0)


PreviousNext

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests