Fork me on GitHub
#beginners
<
2016-11-26
>
roelofw10:11:05

@dpsutton I was thinking if I changed the acc to (.indexOf x) and compared it with a modular is equal to zero .

roelofw10:11:24

Can I then delete the counter and make the code work without a counter

dominicm13:11:43

@roelof probably not a good general solution, what if you have [3 5 3]

roelofw13:11:17

@dominicm , oke, then I have to think of another way to make the code I made with dpsutton without the counter

roelofw13:11:25

yes, and with the help of dpsutton we made this one :

(fn [s n] (last(reduce (fn [[ acc output] x] (if (= acc n ) [  output] [ (+ acc 1) (conj output x)] ))  

roelofw13:11:45

but I wonder that one can work without a counter

dominicm13:11:47

What inputs do you call this function with sorry?

dpsutton17:11:04

the idea is that you pass it a seq of some time and ask it to drop every nth member. so (drop-nth [1 2 3 4 5 6] 3) => [1 2 4 5]

roelofw18:11:57

@dpsutton yep, and you said it could be done without a counter and I wonder how

dominicm18:11:03

keep-indexed

dpsutton18:11:23

i was thinking without an explicit argument for the counter, and using a mutable inside

dpsutton18:11:28

but that was our first rough draft

roelofw18:11:38

I thought of using indexOf but that does not work as dominicum has pointed out

dpsutton18:11:40

sean mentioned that we could pass that state in and not mutate a var so we did it better

roelofw18:11:30

oke, so the code we made yesterday cannot be improved ?

dpsutton18:11:26

that sentence is always false

bbss18:11:48

I was going to recommend subvec, but that wouldn't teach you anything 🙂

roelofw18:11:25

@dominicm and what is k and v is your code

roelofw18:11:54

I have to look what keep-indexed does . Never heard of that method

dominicm18:11:10

k v, key-value. [1 2] would be k 0 v 1 k 1 v 2

dominicm18:11:22

There are a few -indexed functions about which are handy for these situations

dominicm18:11:32

You could perhaps also do this with a map.

roelofw18:11:17

nice function

roelofw18:11:32

thanks for learning another function

roelofw18:11:05

I see that on the easy exercises can be solved by methods/functions I never heard of

dominicm18:11:18

I didn't know it on the top of my head.

dominicm18:11:29

Google fu improves with time 🙂

roelofw18:11:25

oke , next on my list course google fu 🙂

dominicm18:11:07

A good way to achieve this would be to break it down into a few stages

dominicm18:11:42

The first thing you need to do is index the whole list

dominicm18:11:00

Then you can treat it as "just" data.

roelofw19:11:05

@dominicm thanks

roelofw19:11:01

I still have to work on my developer mind set. Sometimes I cannot figure out which small steps I can take to solve a problem

dominicm19:11:49

In this case, you could try to turn [1 2 3] into [[0 1] [1 2] [2 3]] Then you can filter those into the ones where the first is an nth Then nap over them and get the second value out

dominicm19:11:16

In this case, keep-indexed can do all that for you though

seancorfield20:11:15

I suspect one of you plugins in your Leiningen setup has an old version of tools.namespace being pulled in.

seancorfield20:11:04

The Clojure.spec error points to this

(clojure.tools.namespace.find (:require [ :as io] [clojure.set :as set] [clojure.tools.namespace.file :as file] [clojure.tools.namespace.parse :as parse]) (import ( File FileReader BufferedReader PushbackReader InputStreamReader) (java.util.jar JarFile JarEntry)))
and the import should be :import there

richardh20:11:25

thanks @seancorfield I will check it out

seancorfield20:11:19

I'm on my phone right now but check in your ~/.lein folder and see what plugins you have configured.

richardh20:11:46

{:user
 {:dependencies [[org.clojure/tools.namespace "0.2.3"]]
  :plugins [[cider/cider-nrepl "0.12.0-SNAPSHOT"]]
  :injections [(require '(clojure.tools.namespace repl find))]}}

richardh20:11:54

Pretty old!

richardh20:11:14

I think I can get it from here, thanks.

gowder20:11:25

dear world, does anyone know of a really good tutorial for cl-format? it's about time to learn that, I think...