Username [Register?]: | Password [Lost Password?]: Save Password?
Bottom of Page
INTL v5.0 > Discussion Forums > The "Song A Day" Thread Forum > Project Euler > Viewing Thread
Also Here: 1 guest. Moderated by: D drahnier
Page: [ 1 2 3 ] [ Thread Views: 4973 | Total Posts: 61 ]
Rate This Thread: Reply to Thread | Create New Thread | Create New Poll | Convert To Poll | Subscribe To Thread
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
(Originally posted on: 05-11-10 11:24:51 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Some of you may know about Project Euler.

It's a website where they present mathematical programming challenges, and you have to write programs in whatever language you want to get the answer. It's good for learning programming or math or picking up a new language. I've solved 25 of them, the highest one I've solved is #99 and the lowest I haven't solved is 12. I'm using MATLAB, which gives me some shortcuts, but I'm sure a lot of my solutions are a lot slower than they could be.

Anyway, if anyone is interested we can discuss how to solve various problems.
"you look bigger on facebook"
-Amphy
D
Administrator

i didn't have the strength to get it all the way off

Ballkicks: (+1950 / -91)
Posts: 18505 (2.712)
Reg. Date: Mar 2002
Location:
Gender: Male
Reply 1 of 61 (Originally posted on: 05-11-10 01:14:48 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Last night I signed up and was about to get started when I realized I didn't have MATlab on this computer yet, so I decided to save it for later.

ba
INTL Premium Member
Captain of the Cool Kids

and i said, a\re you a gay ass fucker who can't take a baseball up the ass you faggot???? and he said yes........

Ballkicks: (+456 / -62)
Posts: 3134 (0.486)
Reg. Date: Apr 2003
Location: behind you!
Gender: Male
Reply 2 of 61 (Originally posted on: 05-11-10 01:16:04 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

I was about to get started too when I realized that I can't to a damn one of these.
~British Agent
.___.
{O,o} O RLY?
/)__)
-"-"-
emtilt

the cow of horses

Ballkicks: (+486 / -41)
Posts: 5238 (0.769)
Reg. Date: Mar 2002
Location: Last Week
Gender: Male
Reply 3 of 61 (Originally posted on: 05-11-10 02:37:12 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

I was about to get started when I realized that I don't want to because I already spend more of my life programming than I'd like to, and I'd much rather go outside or something.
this is my music i hope you like it
this is music i listen to these are movies i like these are books i like
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 4 of 61 (Originally posted on: 05-11-10 02:46:33 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

BA for the first one you should use modular arithmetic.
"you look bigger on facebook"
-Amphy
ba
INTL Premium Member
Captain of the Cool Kids

and i said, a\re you a gay ass fucker who can't take a baseball up the ass you faggot???? and he said yes........

Ballkicks: (+456 / -62)
Posts: 3134 (0.486)
Reg. Date: Apr 2003
Location: behind you!
Gender: Male
Reply 5 of 61 (Originally posted on: 05-11-10 04:23:25 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Quote:
BA for the first one you should use modular arithmetic.


Is that some kind of sex toy or something? Because I'm not quite sure how that solves this, ztolk.
~British Agent
.___.
{O,o} O RLY?
/)__)
-"-"-
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 6 of 61 (Originally posted on: 05-11-10 04:41:23 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

if (number mod 3)==0 OR (number mod 5)==0

count=count+number;

then watch out for double counting.
"you look bigger on facebook"
-Amphy
Sunn O)))
INTL Alumni
14 year RP master

Zan-beef

Ballkicks: (+761 / -127)
Posts: 5458 (0.8)
Reg. Date: Mar 2002
Location: Laputa
Gender: Male
Reply 7 of 61 (Originally posted on: 05-12-10 12:09:55 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Boycotting until there is a social science version of this.
Guy Tuttle and Ass
Global Moderator

gotta get that VICTORY ROYALE #gamer #memes #LoL

Ballkicks: (+1782 / -130)
Posts: 15966 (2.34)
Reg. Date: Mar 2002
Location: California
Gender: Male
Reply 8 of 61 (Originally posted on: 05-12-10 03:01:50 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

it's called life
antpocas
"Sex is not dating."
"If it were, Santana and I would be dating.


GLEEK

Ballkicks: (+414 / -233)
Posts: 4171 (0.616)
Reg. Date: May 2002
Location: Alaska
Gender: Unspecified
Reply 9 of 61 (Originally posted on: 05-12-10 12:43:03 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Project Euler is fun but I've barely done any of them because I lack the mathematical background needed to do most of the problems.
While solving problem 2, I felt pretty clever after noticing that every third number of the Fibonacci sequence was even (which really should have been obvious from its definition) and wrote a fairly efficient solution based on that.
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 10 of 61 (Originally posted on: 05-12-10 12:59:45 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

The general guideline is that if it takes over a minute, you're probably doing it wrong. Some of mine have been waaaaay over that guideline.
"you look bigger on facebook"
-Amphy
Cunt In Exile
User is currently banned until further notice.

cool story bro

Reply 11 of 61 (Originally posted on: 05-12-10 01:55:20 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Excuse me how do I post in comic sans?
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 12 of 61 (Originally posted on: 05-12-10 02:01:39 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

What do you mean?


"you look bigger on facebook" -Amphy
Cunt In Exile
User is currently banned until further notice.

cool story bro

Reply 13 of 61 (Originally posted on: 05-12-10 02:03:09 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

how do I post in comic sans?
Cunt In Exile
User is currently banned until further notice.

cool story bro

Reply 14 of 61 (Originally posted on: 05-12-10 02:03:51 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

I want to post in comic sans.
Amphytrite
Hard for Drah

I don't really even like hearing about it or reading about it

Ballkicks: (+1869 / -83)
Posts: 6818 (1.123)
Reg. Date: Apr 2004
Location: Cowpenis
Gender: Female
Reply 15 of 61 (Originally posted on: 05-12-10 07:36:16 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Are you sure you want to do that?
Spiff: amphytrite, the anti-tart

Purple: Amphy, scratch my neckfat

Nickolati: when i was 17, fruit loops gave me a boner
poop
$$~~~Crips~~~$$
slooooooooooooots

i'd expect more sorcery in a place called mana pools

Ballkicks: (+731 / -71)
Posts: 7914 (1.167)
Reg. Date: May 2002
Location: Canada
Gender: Male
Reply 16 of 61 (Originally posted on: 05-12-10 10:26:08 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

yo i want to do that too


howd you do that ztolk
D
Administrator

i didn't have the strength to get it all the way off

Ballkicks: (+1950 / -91)
Posts: 18505 (2.712)
Reg. Date: Mar 2002
Location:
Gender: Male
Reply 17 of 61 (Originally posted on: 05-13-10 12:21:34 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Quoted from Ztolk:

What do you mean?



Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 18 of 61 (Originally posted on: 05-13-10 07:51:45 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

I can't tell you in public, cunt in exile might see.

 html 
"you look bigger on facebook"
-Amphy
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 19 of 61 (Originally posted on: 05-13-10 09:30:07 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

On a serious note, does anyone know how to do problem 12 without brute forcing it?
"you look bigger on facebook"
-Amphy
Air Bud
Internet Superstar

Some plants even masturbate into their own vaginas in order to reproduce.

Ballkicks: (+918 / -56)
Posts: 6785 (0.967)
Reg. Date: Sep 2001
Location: TEH INTARNET!
Gender: Male
Reply 20 of 61 (Originally posted on: 05-16-10 11:05:28 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

My guess would be to use some kind of integer factorization algorithm to express each value as its prime factor decomposition (PFD). Then, use the fact that when you express an integer in terms of its PFD, the product of the multiplicities plus 1 (for each unique prime factor) is equal to the number of total divisors of the integer.

For example: 1128 = 2*2*2*3*47, so 2 has multiplicity 3; 3 has multiplicity 1; and 47 has multiplicity 1. So, 1128 has (3+1)(1+1)(1+1) = 4*2*2 = 16 unique divisors: 1, 2, 3, 4, 6, 8, 12, 24, 47, 94, 141, 188, 282, 376, 564, 1128

I love being a math major i'm a serial-killer :)



Oh, and of course, you would use the expression for the sum of consecutive integers: S(n) = n(n+1)/2 to save yourself the effort of actually having to sum the nth triangle term by brute force. I'm sure you already realized that though.
This reply was last edited on 05-16-10 01:02:44 PM by Air Bud.
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 21 of 61 (Originally posted on: 05-16-10 01:11:21 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

so something like

Code:

N=12345;
factors=1;
for i=1:q
p=primes(q) //select from a list of primes.
if mod(N,p)==0
factors=factors*(floor(log(N)/log(p))+1);
end
end



I'm not much of a programmer. There's probably a faster way. Also, one that works.
"you look bigger on facebook"
-Amphy
This reply was last edited on 05-16-10 01:20:18 PM by Ztolk.
Air Bud
Internet Superstar

Some plants even masturbate into their own vaginas in order to reproduce.

Ballkicks: (+918 / -56)
Posts: 6785 (0.967)
Reg. Date: Sep 2001
Location: TEH INTARNET!
Gender: Male
Reply 22 of 61 (Originally posted on: 05-17-10 09:48:08 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

It's my own fault, but INTL is really bad at handling C++ code.

This code should work (I haven't verified it through Project Euler yet). If you want to compile this, you'll need to change the brackets to less/greater-than signs in the include file lists and type definitions at the top. It appears as if INTL strips them out. Also, you'll need to remove the double backslashes inside the tab character literal toward the end of the file.

Code:
#include [iostream]
#include [fstream]
#include [ctime]
#include [vector]
#include [map]
using namespace std;

// Type definitions to make life easier
typedef vector[int] PRIMES;
typedef PRIMES::const_iterator PrIt;
typedef map[long,int] PFD;
typedef PFD::const_iterator PfdIt;

int main(int argc, char** argv)
{
PRIMES primes;
PFD* pfd;

// Read prime numbers from input file
ifstream* infile = new ifstream("primes.txt", ios_base::in);
if (!infile->is_open())
{
cerr << "Error opening prime number database." << endl;
return EXIT_FAILURE;
}

// Load prime numbers from file into vector and close file
while (!infile->eof())
{
long prime;
*infile >> prime; // Read prime from file
primes.push_back(prime); // Store prime in vector
}
infile->close();

bool done = false;
int count = 1;

while (!done)
{
long value = count * (count+1) / 2; // Calculate triangle value
long temp = value;
pfd = new PFD; // Create prime factor decomposition map
PrIt it = primes.begin(); // Set prime number iterator to first prime

// Loop until we have decomposed the integer completely
while (temp != 1)
{
if (temp % *it == 0) // Current prime is a divisor
{
(*pfd)[*it]++; // Increment factor count for this prime
temp = temp / *it; // Divide by prime number
}
else it++; // Prime is not a divisor, move on to the next prime
}

int divisors = 1;

// Process prime factor decomposition map to determine the number of
// divisors for the current integer
for (PfdIt it = pfd->begin(); it != pfd->end(); it++)
divisors *= (it->second + 1);

// Once we've found a number with 500 or more divisors, halt
if (divisors >= 500) done = true;

// Output index, value, and number of divisors
cout << count << '\\t' << value << '\\t' << divisors << endl;
count++; // Increment index

delete pfd; // Delete PFD map object from memory
}

return EXIT_SUCCESS;
}

Air Bud
Internet Superstar

Some plants even masturbate into their own vaginas in order to reproduce.

Ballkicks: (+918 / -56)
Posts: 6785 (0.967)
Reg. Date: Sep 2001
Location: TEH INTARNET!
Gender: Male
Reply 23 of 61 (Originally posted on: 05-17-10 09:58:08 AM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Yup, correct answer. Don't want to spoil it for you, so I'll let you do it yourself.
Ztolk
INTL Premium Member
Rawr.

definitely threw the blue lego

Ballkicks: (+838 / -47)
Posts: 7237 (1.062)
Reg. Date: Mar 2002
Location: r, θ, φ
Gender: Male
Reply 24 of 61 (Originally posted on: 05-17-10 01:36:10 PM)
Edit Post | Edit History | Send PM | Change Title | Reply w/Quote | Report Post | Ignore | Show All Posts

Holy shit. Finally got it with my own ugly, ugly code. I was having massive mental blocks with this one and it was making me feel impotent.


Code:
tic
for q=1:100000
N=q*(q+1)/2;
a=factor(N);
storage=zeros(1,20000);
s=length(a);


for j=1:s
storage(a(j))=storage(a(j))+1;
end
% sort(storage);

num=1;
for i=1:length(storage)
if (storage(i)>0)
num=num*(storage(i)+1);
end
end
if (num>500)
N
end
end
toc


"you look bigger on facebook"
-Amphy
Quick Reply
Page: [ 1 2 3 ] Reply to Thread | Create New Thread | Create New Poll | Convert To Poll | Subscribe To Thread
[ Thread Views: 4973 | Total Posts: 61 ]