Posts: 6610
Threads: 73
Joined: May 31, 2014
Reputation:
56
RE: Project Euler
July 3, 2016 at 6:27 am
(July 3, 2016 at 6:20 am)SteelCurtain Wrote: Sure!
To be clear, I didn't actually loop through every number. I skipped evens, and I didn't check for factors after 1/3 of the number I was checking.
Ok, so it looks like you don't really need one then. I just reread your previous post and realized you already did solve that.
I think though it's a similar thing with the triangle numbers, but it's been a while now so can't remember exactly what I did.
Posts: 6610
Threads: 73
Joined: May 31, 2014
Reputation:
56
RE: Project Euler
July 3, 2016 at 6:32 am
(July 3, 2016 at 6:27 am)Irrational Wrote: (July 3, 2016 at 6:20 am)SteelCurtain Wrote: Sure!
To be clear, I didn't actually loop through every number. I skipped evens, and I didn't check for factors after 1/3 of the number I was checking.
Ok, so it looks like you don't really need one then. I just reread your previous post and realized you already did solve that.
I think though it's a similar thing with the triangle numbers, but it's been a while now so can't remember exactly what I did.
I just remembered what I did. Are you doing the same for what you did with the prime summation problem, and then ... depending on whether the number you're checking is a perfect ... or not?
Posts: 152
Threads: 5
Joined: July 2, 2016
Reputation:
3
RE: Project Euler
July 3, 2016 at 6:37 am
I really like these problems, I've been looking for a website like this for ages!
Also, I've never used Python before, but looking at its syntax, I may learn in just for these problems. It just looks so neat!
Posts: 6610
Threads: 73
Joined: May 31, 2014
Reputation:
56
RE: Project Euler
July 3, 2016 at 7:37 am
(July 3, 2016 at 6:37 am)A Handmaid Wrote: I really like these problems, I've been looking for a website like this for ages!
Also, I've never used Python before, but looking at its syntax, I may learn in just for these problems. It just looks so neat!
Yeah, the only thing thus far I've noticed is a problem with Python that other programming languages I've tried do not have is that you can't declare a variable without initializing it. Or at least I don't know of a way to do so.
Posts: 15351
Threads: 118
Joined: January 13, 2014
Reputation:
116
RE: Project Euler
July 3, 2016 at 7:44 am
(This post was last modified: July 3, 2016 at 7:44 am by SteelCurtain.)
Wait, you can declare variables in Python without initializing them.
Code: def main():
a = 5
print(a)
main()
In other languages you'll at least have to declare the variable type, whereas Python will determine the variable type automatically. At least the packaged compiler/shell (IDLE) will.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Posts: 6610
Threads: 73
Joined: May 31, 2014
Reputation:
56
RE: Project Euler
July 3, 2016 at 7:57 am
(July 3, 2016 at 7:44 am)SteelCurtain Wrote: Wait, you can declare variables in Python without initializing them.
Code: def main():
a = 5
print(a)
main()
In other languages you'll at least have to declare the variable type, whereas Python will determine the variable type automatically. At least the packaged compiler/shell (IDLE) will.
Sorry, but can you elaborate on what you did here to show that this is possible? All I see is that you created a procedure that prints the value of 5 and then called it.
Posts: 152
Threads: 5
Joined: July 2, 2016
Reputation:
3
RE: Project Euler
July 3, 2016 at 8:02 am
Well, why would you need uninitialized values?
I can't find a good reason for a language to have one.
Posts: 15351
Threads: 118
Joined: January 13, 2014
Reputation:
116
RE: Project Euler
July 3, 2016 at 8:02 am
(This post was last modified: July 3, 2016 at 8:04 am by SteelCurtain.)
It was just an example of defining a variable 'a' without initializing it first with Python.
For example, in C++, this same code would look like:
Code: #include <iostream>
using namespace std;
int main()
{
int a;
a = 5; //you could technically combine these two lines into 'int a = 5;'
cout << a << endl;
return 0;
}
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
Posts: 6610
Threads: 73
Joined: May 31, 2014
Reputation:
56
RE: Project Euler
July 3, 2016 at 8:06 am
(July 3, 2016 at 8:02 am)A Handmaid Wrote: Well, why would you need uninitialized values?
I can't find a good reason for a language to have one.
I'll include an example code if I remember what it was I was struggling with that made me wish python would let me define variables without assigning values.
Posts: 15351
Threads: 118
Joined: January 13, 2014
Reputation:
116
RE: Project Euler
July 3, 2016 at 8:16 am
Ahh, I see what you mean.
You want to just initialize variables.
I think Python only allows you to do that with lists and tuples.
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
|