FrankKair / polyglot-euler

📜 Project Euler solutions in various programming languages

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create most used functions lib

murilocamargos opened this issue · comments

There's a lot of problems in Project Euler that relies on the same kind of operations, e.g., prime testing, prime generator, fibonacci sequence, and so on. It would be nice to have these kind of functions in file shared by all solutions as a lib.

What you guys think about that?

Hey, @murilocamargos.
I think this is a nice idea. Maybe we could have a directory on the root of the project called libs/ or helpers/. Which one do you guys prefer?

And in that case, we should always strive for the most performant and efficient algorithms possible, since we'll be relying on these functions for the other problems.

What do you think, @fredericojordan?

I created this pull request with an example in Elixir. Is this sort of what we want?

#9

Although it's nice to have these functions readily available, I think that coming up with them is part of the fun.
Designing your own algorithm and trying to optimize it's implementation for the problem in hand is what I like the most about these problems! 🙃

This would be only the most used functions. From what I've seen solving some problems, having a function for checking if a number is prime or not wasn't a decisive factor to actually solve the problem. Also, I think having a helpers file doesn't stop you from optimizing them as well, this would actually be encouraged!

Well, I guess we can sort of be in the middle on this one.

We can have the directory but everyone is free to use whatever algorithm they want, given that the answer is correct.

How does that sound?

What is nice about this is that we can discuss the algorithms out of the context of the problems.
Like, should someone open an pull request for Fibonacci, we'd discuss a way to maximise its performance and all.
That way, this repo could also be used to discuss and learn algorithms 😊

Sure! Why not?

Can I join the discussion?

I think what is nice when you finish your problem is looking at the forum and trying to find someone that thought what you done before you even started the Project. My point is: I think we can create a directory inside the project with some categories.
If you like to know how to find a fibonacci number in Elixir you can search on docs/fibonacci/.
If you want some prime testing function in Python, you can go on docs/primes/ and search for something inside.

Nevertheless at my point of view this should be well documented. Copy and paste code is never fun as understand how that code works and what's going on with the code that you just saw and we can compare 'same stuff' on different languages.

My only issue with this idea is that sometimes there are slightly different goals in each problem. For example, let's say one problem needs the fibonacci number at certain index while the other only has to generate them continuously.
There will be cases where one implementation works best in a specific problem and some other implementation works best for a second problem.
Having a lib do that for you would either have to take this in consideration or wouldn't be of much use.

Specific to the case that you(@fredericojordan) described, finding a Fibonacci number is a single problem and can be isolated. The specific part of the problem can use some 'black box' of a Fibonacci number generator.
The case is: the solution of the problem use some concepts and that concepts should be able to be isolated on a lib.

Of course, that is my opinion. I think the decision should be made on the project big picture.