Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 DWITE October 27th - My solutions
Index -> CompSci.ca, Contests -> DWITE
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: Fri Oct 28, 2005 9:31 pm   Post subject: DWITE October 27th - My solutions

Here are my solutions, please use them as a source, dont copy and paste and say they are yours!!

Please tell me how i could kiss the code. thanks a lot!



P 1 - 4 Oct 2005.zip
 Description:
Zip needs to be extracted, if you dont know how, you dont deserve my solutions, j/k

Download
 Filename:  P 1 - 4 Oct 2005.zip
 Filesize:  3.17 KB
 Downloaded:  337 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Oct 28, 2005 10:14 pm   Post subject: (No subject)

I've only looked at number 4 so far, but one thing that stood out to me was your huge if structures for checking around. Instead, try using two for loops, from -1 to 1 (or from 1 less than the grid coord to 1 greater than it). Keep in mind you'll have to have an if statement to prevent checking when both for loops are at zero.
MysticVegeta




PostPosted: Fri Oct 28, 2005 11:54 pm   Post subject: (No subject)

yeah, I didnt kiss my code, i was in a rush so i did everything i could from the top of my head, i need practise to be more code lines saver, Smile By the ways, i cant see my attachment anymore, waht happened?
zylum




PostPosted: Sat Oct 29, 2005 12:24 am   Post subject: (No subject)

here's a solution to #5:

code:
var file : int
open : file, "DATA51.txt", get
var ret, d1, d2 : int
var s := "123456789"

proc perms (n, cp : string)
    if length (n) = 0 then
        if strint (cp) mod d2 = 0 then
            ret += 1
        end if
    else
        for i : 1 .. length (n)
            perms (n (1 .. i - 1) + n (i + 1 .. *), cp + n (i))
        end for
    end if
end perms

for i : 1 .. 5
    ret := 0
    get : file, d1, d2
    perms (s (1 .. d1), "")
    put ret
end for
Hikaru79




PostPosted: Sat Oct 29, 2005 8:36 am   Post subject: (No subject)

What exactly do you mean by "kiss my code"? You've used it three times so far, and I still giggle whenever I read it. Does it mean something besides what I think it means? Embarassed
MysticVegeta




PostPosted: Sat Oct 29, 2005 9:21 am   Post subject: (No subject)

KISS - Keep it Simple Student, never heard of it? every teacher says that lol

Anyways, zylum. I cant use that, thats what i did before but it wont give me a perfect, i read your permutations tuts before too. The data file has 5 lines of Data. what if n1 is 9, it takes forever to check for it
it wont execute on time. i know theres some way around it. Even Qiyu spent more than 40 minutes on this problem, rest he took like 10-15 minutes. There is some other way, i think
Cervantes




PostPosted: Sat Oct 29, 2005 9:24 am   Post subject: (No subject)

I was wondering about that too, but I think I've figured it out.
KISS = Keep it Simple, Stupid.

Hard to get because no one would say,
Quote:

yeah, I didnt keep it simple, stupid my code


MysticVegeta wrote:
By the ways, i cant see my attachment anymore, waht happened?

I see your attachment. Confused
MysticVegeta




PostPosted: Sat Oct 29, 2005 11:00 am   Post subject: (No subject)

yeah, now i see it, problem 5 is weird, i think we have to make up the prime factors for the divisor given and then perhaps try it but still confusing.
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Sat Oct 29, 2005 12:21 pm   Post subject: (No subject)

meh, there's only ~360000 permutations of a 9 digit number. thats penuts. its probably that turing is so slow. im sure if you submitted it in c++ it would have been more than fast enough.

i guess ill try to code a faster solution then...
jamonathin




PostPosted: Sat Oct 29, 2005 5:25 pm   Post subject: (No subject)

Cervantes wrote:
I was wondering about that too, but I think I've figured it out.
KISS = Keep it Simple, Stupid.

It is 'Stupid' not 'Student'. Doesn't anyone remember my old signature? . .
MysticVegeta




PostPosted: Sat Oct 29, 2005 9:26 pm   Post subject: (No subject)

jamonathin : our teacher didnt say stupid, because that wouldnt make sense coming from a teacher now would it?

zylum : even C++ will time out. Because there are 5 sets of data. maybe VC++ will compile...?
JackTruong




PostPosted: Sun Oct 30, 2005 12:50 am   Post subject: (No subject)

Problem5 was a tricky one, our initial code (the one we submitted) was actually find the permutation with unique digits, and modulus it to output.

I just worked out another solution, this one's faster, but it won't execute the input of "9 2" in a few seconts.

We had this idea during the competition, but coding it in 14 minutes was a huge task.

Pseudo:
Start with string from 1 to 9, substring it.
Find a multiple of the second number, at or above the string above.
Run a for loop, from the number above, to the reverse of the above string, and incrementing the second number each time.
Run a check for proper digits.
Run a check for unique digits.
Increment a counter.
Output counter.

I typed this post and the "9 2" input is still going. Source code will soon be uploaded to a section of my site dedicated to DWITE; Link..

Other problems are up too, with some partial explanations.
MysticVegeta




PostPosted: Sun Oct 30, 2005 10:42 am   Post subject: (No subject)

wont that time out by substringing the 9 digit string? and reversing it everytime.?
JackTruong




PostPosted: Sun Oct 30, 2005 10:56 am   Post subject: (No subject)

No, it's just a one time event.

Source
MysticVegeta




PostPosted: Sun Oct 30, 2005 12:05 pm   Post subject: (No subject)

I see Jack.
My approach to it is something like this ->

5 12

12345 all divisible by 3 because 1+2+3+4+5 = 15
XXX12 -> XXX satisfies 6 values in each case
XXX24
XXX32
XXX52
So Number of possible values are 6X4= 24

This was the example from the problem.

So my strategy is like this

1) Since we know the divisibility for 2,3,4,5,6,7,8,9,10,11 then we can break up the divisor from 2 - 50 into factors {2..11} where no two factors are alike.

2) Then find the number of possible values by each of the factor ->
Ex: suppose 123456789 is the string and d1 = 10
then,

22 = 5 * 2

XXXXXXX2
XXXXXXX4
XXXXXXX6
XXXXXXX8

Possible values for 2 : (!8)*4 = 40320

XXXXXXX5

8! = 10080

but 5 is not even so intersection of mutiples is 0; so possible number of values is 0, should work with other numbers

EDIT: For prime numbers, http://home.egge.net/~savory/maths1.htm
Display posts from previous:   
   Index -> CompSci.ca, Contests -> DWITE
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 21 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: