Fork me on GitHub
#off-topic
<
2016-06-08
>
yogidevbear21:06:23

I'm looking at their 30 day coding challenge stuff and wanted to submit all my solutions using Clojure

yogidevbear21:06:46

I'm looking at the first challenge which is a "Hello World" example

yogidevbear21:06:39

There is supposed to be a value passed in from the system (outside of my code) that I need to print out, but I can't figure out how to actually get that value that's supposedly being passed in

sarcilav21:06:02

do you have the link?

sarcilav21:06:14

in some cases they call your function and it is given as a param

sarcilav21:06:22

and in other cases it is from STDIN

sarcilav21:06:23

let me check

yogidevbear21:06:47

Says

; Enter your code here. Read input from STDIN. Print output to STDOUT
;

sarcilav22:06:21

for this case you can use read-line

yogidevbear22:06:37

How would I do that? Sorry, new to this

sarcilav22:06:06

so you could for example do something like

sarcilav22:06:18

(let [my-var (read-line)]

sarcilav22:06:32

and do whatever you need to do with my my-var

sarcilav22:06:38

or for this example

yogidevbear22:06:42

let me give that a try

yogidevbear22:06:48

Thanks Seb :thumbsup:

sarcilav22:06:53

you are welcome

yogidevbear22:06:00

(let [inputString (read-line)]
  (println "Hello, World.")
  (print inputString))

sarcilav22:06:33

for this case in which you don’t need to hold the var (state), you could do something like

sarcilav22:06:50

(println "Hello, World.")
(print (read-line))

yogidevbear22:06:06

Seems obvious when you point it out 😉

sarcilav22:06:12

I’ve to go out for a couple of hours, but feel free to ping me or DM if you hit any blockers, would be happy to help , I’ll try to answer later, when I’m back

yogidevbear22:06:07

Not sure if this was the best solution, but it worked for one of the FP challenges. Really enjoying the experience.

(fn[num lst]
  (dotimes [i (count lst)]
    (dotimes [j num]
      (println (nth lst i)))))

yogidevbear22:06:00

Where num was an iteration count and lst was... a list of integers to print num times

hrathod23:06:26

@yogidevbear: you could also generate the needed list and then print it all out

hrathod23:06:42

(defn foo [num lst] (doseq [x (flatten (map #(take num (repeat %)) lst))] (println x)))