FAQ
Hi!

Do you guys know Project Euler <http://projecteuler.net>?
What I want to do is to solve as many problems as I can with the Go
language.

I never want to recreate the basic output stuff and so on every problem I
solve.
I also want to learn test driven programming and want to use the Go testing
possibilities.

Therefore I want to implement every solution as a function or group of
functions.

Is it possible to write one CLI tool accepting a number from Stdin or as a
command line argument, so that I could call the solution of a problem
directly?

Maybe with a map[int]solution where solution is an interface that contains
a Solve() function?
This function would then call the actual functions and would contain all
parameters as hard coded constant values?

My problem now is:
How can I prepare such a map? (Or maybe a slice if this would be better)
How can I call functions that don't exist yet - because I didn't solve a
problem already?

Another solution would be, if it would be possible to call a function by
the value of a string that I have given the program via Stdin. Is this
possible?

Or have I a fundamentally flaw in my ideas?

Greetings and thank you.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Caleb Doxsey at Feb 16, 2014 at 11:37 pm
    You could just make a map:

    var solutions = map[int]func(){
       1: func() {
         // write code here
       }
    }

    func main() {
       var problem int // get this from stdin, or os.Args, or use flag
       // you can check for existence in a map:
       f, ok := solutions[problem]
       if !ok {
         panic("or log, or whatever")
       }
       f()
    }

    On Sun, Feb 16, 2014 at 4:31 PM, Cyru Sol wrote:

    Hi!

    Do you guys know Project Euler <http://projecteuler.net>?
    What I want to do is to solve as many problems as I can with the Go
    language.

    I never want to recreate the basic output stuff and so on every problem I
    solve.
    I also want to learn test driven programming and want to use the Go
    testing possibilities.

    Therefore I want to implement every solution as a function or group of
    functions.

    Is it possible to write one CLI tool accepting a number from Stdin or as a
    command line argument, so that I could call the solution of a problem
    directly?

    Maybe with a map[int]solution where solution is an interface that contains
    a Solve() function?
    This function would then call the actual functions and would contain all
    parameters as hard coded constant values?

    My problem now is:
    How can I prepare such a map? (Or maybe a slice if this would be better)
    How can I call functions that don't exist yet - because I didn't solve a
    problem already?

    Another solution would be, if it would be possible to call a function by
    the value of a string that I have given the program via Stdin. Is this
    possible?

    Or have I a fundamentally flaw in my ideas?

    Greetings and thank you.

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Cyru Sol at Feb 17, 2014 at 3:25 am
    Thank you, it was easy to make use of that.

    -> https://github.com/cyrusol/projecteuler

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 16, '14 at 11:33p
activeFeb 17, '14 at 3:25a
posts3
users2
websitegolang.org

2 users in discussion

Cyru Sol: 2 posts Caleb Doxsey: 1 post

People

Translate

site design / logo © 2022 Grokbase