Fork me on GitHub
#beginners
<
2019-12-01
>
readyready1572803:12:49

Let's say I want to set up a Leiningen project for Project Euler problems and I want to do lein run [number]to run any solution but I also want each solution in its own file. What's the best way to set that up in the code? I just need a general idea.

seancorfield04:12:28

@readyready15728 lein run runs the -main function in the :main namespace of the project. Everything after that (such as number in your case) is a command line argument, passed as a string to the -main function (which takes [& args] so (first args) would be the string of the number).

seancorfield04:12:05

Your -main could take that string and load the corresponding file if you follow a convention.

seancorfield04:12:31

I don't know what your Euler problem files would look like. I don't believe you can have just a number as the filename or namespace so you'll need some prefix on the number, maybe e for Euler?

seancorfield04:12:02

Does that give you enough hints and tips to point you in the right direction?

readyready1572804:12:22

If you look at the site they have several hundred problems so I would loading 001.clj, 002.clj, 003.cljetc. I just want to know what's a good way to do that from -mein.

readyready1572804:12:33

Simpler than I thought

Artur Aralin10:12:35

How I can add item to tree?

(def tree {
  :r {
    :v "b"
    :r nil
    :l nil
  }
  :l nil
  :v "a"
})

(insert tree :r "c") =>
{
  :r {
    :v "b"
    :r {
      :v "c"
      :r nil
      :l nil
    }
    :l nil
  }
  :l nil
  :v "a"
}
I think about loop-recur, but I can’t understand how to return head of tree at the end of loop

Chris O’Donnell13:12:03

It's not entirely clear to me how you expect (insert tree :r "c") to behave. Here, you're inserting "c" under [:r :r] , not [:r]. Could you explain in more detail?

Artur Aralin13:12:55

@codonnell I’ll expecting that insert create node in the first :r which be equal nil

Chris O’Donnell13:12:04

In that case, I would personally use loop-recur to find the depth of that node and use the depth to do something like (assoc-in tree (vec (repeat depth :r)) {:v "c" :r nil :l nil})

Artur Aralin15:12:14

Does it efficient solution?

Adrian Smith17:12:49

is anyone running cursive on 2019.3? I'm getting this warning: https://i.imgur.com/5lBu3Ng.png