Re: The Project Euler thread
A little extra time preplanning goes a long way
For 35 you just need a simple sieve and a short rotator method |
Re: The Project Euler thread
one thing you could do is keep anything you do more than once in its own method/function/etc. so you only write code once per program.
an extention of that is to have a library of common functions so you dont need to rewrite them. like one for generating primes and so on so you can just reuse it for many problems. still,100 lines seems pretty excessive for that problem. what part is making it so long? generating the primes should only take a few lines, rotating should only be a few lines, etc. and lastly, theres usually multiple ways to solve a problem and the one that is fastest on paper might not be the fastest to code so you should keep coding time in mind while thinking of how to solve stuff. |
Re: The Project Euler thread
Here's a solution I just wrote for 35 in Python:
This can be optimized further but my point is that the underlying logic is pretty straightforward and you can get a fast program without many lines of code (the above code runs in about half a second on my machine). |
Re: The Project Euler thread
I'm using javascript atm. I'm not sure if that has any relevance but uh yeah. I do reuse a lot of my functions and stuff, and trust me when I say that I'm very familiar with basic concepts such as "fastest paper method might not be fastest to code"
it's not math or problem solving that's difficult for me. I can do more of these problems by hand than almost anyone else. I'm simply not super fluent in programming. a lot of complex algorithms are flying through my head all the time, but figuring out how to convert that into code is sometimes difficult here's the main function I used to check for a circular prime (I use other functions but didn't post them) |
Re: The Project Euler thread
I used PARI/GP only for dealing with really large primes (used C before I knew about PARI/GP)
Even though Ruby is a very slow language, it served me well enough for almost all the remaining problems I solved, and very rarely did my codes go above 20 lines Some people on PE try to solve every problem using ASM but that's just stretching it too far Here's my friend code if anyone wants to add me 7432696421787_8325ecaf1469afb6ad991ac1dacb210c |
Re: The Project Euler thread
My code took 9 minutes :( EDIT: Tried the same algo on PARI/GP and it took 3 seconds |
Re: The Project Euler thread
Thinking of making an extra dummy account and starting fresh, using none of my old libraries.
leonid: problem is much faster in something like C++ Edit: nvm ninja'd, PARI/GP is very fast too for that one apparently XD |
Re: The Project Euler thread
PARI/GP is god
never underestimate PARI/GP |
Re: The Project Euler thread
My only complaint is I can't use GP non-interactively.
So I have to write code somewhere else and copy/paste into the interactive shell. Also since every command is supposed to be 1 line, I need to put a \ at the end of each line, so my code becomes ugly Actually I think I can get it to work somehow, brb.. |
Re: The Project Euler thread
cool |
Re: The Project Euler thread
Quote:
I'm trying to learn a bit of Python at the moment, so that's what I've been coding in. However, at least from my viewpoint, Python is horrifically slow (one source whose credibility I did not check which I found interesting regarding programming languages vs speed: here). On the bright side, in the case that Python is slower than other programming languages I've used, this forces me to come up with more efficient algorithms. Only did the first 15 for now: New friend key: Code:
95430157644057_56e54c547c0f732b3b941aec7177ce58 |
Re: The Project Euler thread
Really messy |
Re: The Project Euler thread
Reuben: even in Python, most problems can be done in under a second
|
Re: The Project Euler thread
I did this RSA problem by manual empirical pattern recognizing with lots of experiments, small examples, and blind guessworks
And then I saw the real way of solving it in the thread. I feel like I cheated through this, but I guess what I learned in this thread will help me on other problems @Reincarnate Check my code in the thread if you want to see what I mean http://projecteuler.net/thread=182&page=4#171693 |
Re: The Project Euler thread
Quote:
|
Re: The Project Euler thread
Quote:
|
Re: The Project Euler thread
PARI/GP
seriously ALL HAIL PARI/GP |
Re: The Project Euler thread
Had me stumped for a few minutes |
Re: The Project Euler thread
I used Ruby this time because GP has no hash tables ?_? |
Re: The Project Euler thread
fun |
Re: The Project Euler thread
I am going to be going through the problems, posting a cumulative timing of all problems from 1 through whatever problem I am on, using Python (including time taken to import any external stuff I write/use for each problem, individually):
So far: Total time for problems 1 through 10: 0.734290 seconds edit: Total time for problems 1 through 25: 3.879866 seconds edit: Total time for problems 1 through 40: 7.787901 seconds |
Re: The Project Euler thread
blah too tired to do more, zzzztime
|
Re: The Project Euler thread
|
Re: The Project Euler thread
Actually one of the easier ones in the upper-400 series, however
|
Re: The Project Euler thread
It's taking inclusion-exclusion to the extreme
Or I'm doing the wrong approach By the way, how does one get his posts become permanent? |
Re: The Project Euler thread
For permanent posts, you must either:
1. Get in early enough to post on the first four pages Or 2: If you're on page 5+, get enough Kudos on your post so an admin can make it permanent. |
Re: The Project Euler thread
God...
31 ms runtime (this solution was tedious as fuck) I liked this problem though since it made me refamiliarize myself with regexes as well as a bit of file I/O |
Re: The Project Euler thread
I hated that one
I don't like those kinds of problems lol I mean, it was pretty easy and trivial but still annoying as fuck and fuck that problem |
Re: The Project Euler thread
The xor cipher one is fun though
|
Re: The Project Euler thread
New award (O: I'm gonna stick to easier ones and eventually get back to p466 By the time I reach it, I should be smart enough to know what to do |
Re: The Project Euler thread
easy |
Re: The Project Euler thread
some of the harder ones though are really beautiful problems, hope you can give them a try at some point (344, 361, and 415 in particular).
|
Re: The Project Euler thread
also update (Python timings):
Total time for problems 1 through 70: 16.428783 seconds |
Re: The Project Euler thread
phew |
Re: The Project Euler thread
Ruby is not the best language if I need to check primality of over 10mil 14-digit numbers |
Re: The Project Euler thread
woot |
Re: The Project Euler thread
Total time for problems 1 through 80: 25.627359 seconds
|
Re: The Project Euler thread
easy |
Re: The Project Euler thread
not easy |
Re: The Project Euler thread
Quote:
|
Re: The Project Euler thread
In Python though yes
|
Re: The Project Euler thread
Son of a...
Just solved problem 88, but it is tricky to get in decent runtime. Right now my best is only 14s. :( EDIT: Oh FFS I am an idiot... much faster way to do this. EDIT: 0.2 seconds -- can't believe I didn't do this in the first place. EDIT: Total time for problems 1 through 90: 28.940158 seconds |
Re: The Project Euler thread
Up to Problem 96, aaaghghghgh Sudoku. Nope. Bedtime
edit: (jk 97, 99, and 100 are quickfodder -- 96 and 98 can diaf) edit: actually 98 isn't horrible either edit: GAURUATUGH FINE I'LL DO SUDOKU. :( going to write the most fucking messiest code in the universe edit: Yay, first 100 down |
Re: The Project Euler thread
really tough |
Re: The Project Euler thread
nice one, leonid
EDIT: Total time for problems 1 through 100: 32.591266 seconds Code:
Problem 1 in 0.000006 s |
Re: The Project Euler thread
OMG finally. |
Re: The Project Euler thread
Wish people read my posts because I take extra time refining my code and explanations
As of now most of the posts I've made recently are still the very last post of each thread |
Re: The Project Euler thread
I read them
I just don't have much to say lol |
Re: The Project Euler thread
I'm talking about my posts in the euler problem threads btw, not this thread
|
Re: The Project Euler thread
OHHH
yeah it kinda sucks, cause nobody reads past the first three posts, let alone the first page |
Re: The Project Euler thread
Quote:
Why do they pick 28,123 when the same is true for all numbers greater than 20,161? |
Re: The Project Euler thread
Quote:
Unless you're asking why the problem writer chose to use that number specifically, in which case I don't know and it's really the writer's free choice. Perhaps he just simply wanted an excuse to use larger numbers, despite the small increase. It does kinda make sense though; once you find the limit of your hand analysis, you have no choice but to use a computer, and only then can you reduce that limit. The problem probably wants to demonstrate an example of this. I just tried this on my own and the 28123 limit is actually pretty easy to prove, and I really do have no idea how to get this down any lower. |
Re: The Project Euler thread
Quote:
I just don't have much to add because I don't find those problems as interesting as some of the harder ones. A comment though, I'm surprised about your approach to 181. That problems seems like it would have been really easy for you to hammer out and execute in quick runtime. edit: Stargroup: Yes that's right -- in practice it's lower but the limit is analytically provable. Here is the proof: http://mathschallenge.net/full/sum_o...undant_numbers |
Re: The Project Euler thread
oh shit that's the method I came up with LOL
|
Re: The Project Euler thread
fair enough
|
Re: The Project Euler thread
Literally took me 3 minutes to solve Now I ran out of easy problems |
Re: The Project Euler thread
first one that I actually used pencil and paper for. |
Re: The Project Euler thread
woot |
Re: The Project Euler thread
Easy A question... Isn't problem 266 a 2-partition problem (NP-complete)? I don't see any way other than having to run an exponential (or pseudo-polynomial) runtime algorithm that takes ages to finish |
Re: The Project Euler thread
There is a way
Every single problem gets tested against the minute-rule before release. Problem 266 is doable in a lot less time than that, even |
Re: The Project Euler thread
But it is a 2-partition problem.. unless mod 10^16 part is giving any twist
|
Re: The Project Euler thread
Idk about this "two partition" thing but FWIW I can output the full result in Python in under 8 seconds
It's hard to say more without spoiling |
Re: The Project Euler thread
http://en.wikipedia.org/wiki/Partition_problem
It's about sums instead of products here, but p266 becomes the same once you put logs on it whatever, I'll get back to this later |
Re: The Project Euler thread
Hard to say more without spoiling, but there's something being overlooked (try to find another kind of problem that this is similar to)
|
Re: The Project Euler thread
level up \o/ |
Re: The Project Euler thread
easy |
Re: The Project Euler thread
easy |
Re: The Project Euler thread
tricky |
Re: The Project Euler thread
Why am I doing physics on PE |
Re: The Project Euler thread
Still a fun little problem
|
Re: The Project Euler thread
Ps try the new problem, easy one
|
Re: The Project Euler thread
After I solve harshad
|
Re: The Project Euler thread
easy |
Re: The Project Euler thread
ok :P |
Re: The Project Euler thread
Nicely done :)
|
Re: The Project Euler thread
Two awards at once |
Re: The Project Euler thread
That was a scary one |
Re: The Project Euler thread
Scary?
|
Re: The Project Euler thread
Just look at this. It's daunting when you first see it |
Re: The Project Euler thread
Oh yeah
For some reason I found that one surprisingly tricky for some reason |
All times are GMT -5. The time now is 10:29 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution