December 22, 2024, 07:59:03 AM

1,531,361 Posts in 46,734 Topics by 1,523 Members
› View the most recent posts on the forum.


I decided to step up to Guff's challenge

Started by ncba93ivyase, January 19, 2009, 11:18:13 PM

previous topic - next topic

0 Members and 2 Guests are viewing this topic.

Go Down

ncba93ivyase

my solution for 48:
Code Select
x = str(sum(i**i for i in range(1, 1001)))
print x[-10:]


Looks like JMV got a whoopin', and I thought of guff when I worked towards this clean solution  baddood;

Quote from: ncba93ivyase on June 18, 2014, 07:58:34 PMthis isa great post i will use it in my sig

guff

Quote from: Pancake Persona on January 24, 2009, 11:18:57 AM
my solution for 48:
Code Select
x = str(sum(i**i for i in range(1, 1001)))
print x[-10:]


Looks like JMV got a whoopin', and I thought of guff when I worked towards this clean solution  baddood;
yours is still silly
there's no need whatsoever to assign it to a variable and then have a separate line to print the answer:
Code Select
print str(sum(i**i for i in range(1, 1001)))[-10:]
would make more sense while still sticking to your method

but my solution is still more than ten times faster:
Code Select
print(sum(pow(i, i, 10**10) for i in range(1, 1001)) % 10 ** 10)

akudood;

ncba93ivyase

Quote from: andrƃĀ© the giant on January 24, 2009, 11:28:26 AM
yours is still silly
there's no need whatsoever to assign it to a variable and then have a separate line to print the answer:
Code Select
print str(sum(i**i for i in range(1, 1001)))[-10:]
would make more sense while still sticking to your method

but my solution is still more than ten times faster:
Code Select
print(sum(pow(i, i, 10**10) for i in range(1, 1001)) % 10 ** 10)

akudood;
well then i learned some more today

Quote from: ncba93ivyase on June 18, 2014, 07:58:34 PMthis isa great post i will use it in my sig

guff

oh god i just realized the link in my first post wasn't even to my profile but i fixed it now

also jamie solved problem 4 baddood;

Daddy

Code Select
#!/usr/bin/python
# Filename : Euler_006.py
#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
sumOfSquares, squareOfSums = 0, 0
for i in range(1,101):
sumOfSquares+= i**2
squareOfSums+=i
print squareOfSums**2 - sumOfSquares

Well, my original code was
Code Select
#!/usr/bin/python
# Filename : Euler_006.py
#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
sumOfSquares=0
squareOfSums = 0
Sums = 0
for i in range(1,101):
sumOfSquares+= i**2
Sums+=i
squareOfSums=Sums**2
print squareOfSums - sumOfSquares

because I didn't know you could do math in the print statement, but other than that it was close to what guff had.


guff

Quote from: JMV on January 24, 2009, 06:52:29 PM
...but other than that it was close to what guff had.
uh no i had a one liner  akudood;

the long code i had wasn't anything i used it was just to show lawlz what he probably should have done instead  bassir;

Gladjaframpf

A challenge: Do #79 on paper. I found it surprisingly easy. baddood;

ncba93ivyase

Quote from: JMV on January 24, 2009, 06:52:29 PM
I didn't know you could do math in the print statement, but other than that it was close to what guff had.


That's the very first thing any python guide teaches you. goonish

Quote from: ncba93ivyase on June 18, 2014, 07:58:34 PMthis isa great post i will use it in my sig

Daddy

Quote from: Pancake Persona on January 24, 2009, 10:56:04 PM
That's the very first thing any python guide teaches you. goonish
Well I guess me not reading any guides would be a factor.   n_u

guff

Quote from: Gladjaframpf on January 24, 2009, 10:27:59 PM
A challenge: Do #79 on paper. I found it surprisingly easy. baddood;
that actually does seem doable  baddood;

i'll try it later maybe

also i think i'm going to try and do some of the problems i've already done in c akudood;

Daddy

I did #79 in TextEdit only because I didn't want to waste paper.
[spoiler]73162890[/spoiler]

I had to register another account to test that so when I do it with actual code I won't feel like I cheated by submitting a problem with no programming.  akudood;

guff

Quote from: Pancake Persona on January 24, 2009, 11:23:55 PM
Solved 4:
Code Select
y = []
for i in range(100, 1000):
x = str(i*i)
if x == x[::-1]:
y.append(int(x))
print max(y)


Now I've just got to make a slimmer solution
uh that gives the wrong answer doodhuh;

you're assuming that the asnwer will be a perfect square (hint: it isn't)  akudood;

Daddy

Quote from: guff on January 25, 2009, 10:02:54 AM
uh that gives the wrong answer doodhuh;

you're assuming that the asnwer will be a perfect square (hint: it isn't)  akudood;
I just ran that too and the answer is way off.  doodhuh;

guff


Daddy


Go Up