Palindrone tester

Pages: 1234
Jul 14, 2012 at 5:58pm
Ah I've heard about D sharing syntanx between languages. I can see that now haha. That had my confused
Jul 14, 2012 at 6:08pm
dup and reverse are function calls. But you don't need to put empty parentheses like in dup(), if you don't pass arguments.

to!string(n) is a template function call with string as parameter (no parentheses required for a single parameter) and n as argument.

ulong is unsigned long long int. etc.

There are more small differences, but once you learn them, D will appear much like C++ and C. At least it does, to me.
Jul 15, 2012 at 9:33pm
Here's my python solution.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import time
start = time.time()
ls = []

for i in xrange(999, 100, -1):
    for ii in xrange(i, 100, -1):
        string = str(i * ii)
        if string[len(string) - 1 : len(string)] == string[0 : 1]:
            if string[len(string) - 2 : len(string) - 1] == string[1 : 2]:
                if len(string) > 5:
                    if string[len(string) - 3 : len(string) - 2 ] == string[2 : 3]:
                        ls.append(string)
                        break
                else:
                    ls.append(string)
                    break

print ls

max = 0
for i in xrange(0, len(ls) - 1):
   if (int(ls[i]) > max):
       max = int(ls[i])

print max
print " took " + str(time.time() - start) + "seconds"


Not perfect, but it works.
Last edited on Jul 15, 2012 at 9:54pm
Topic archived. No new replies allowed.
Pages: 1234