Fork me on GitHub
#beginners
<
2016-11-02
>
agigao00:11:20

any ideas about properly leading incanter dependencies into namespace?

Drew Verlee01:11:18

i’m curious how someone might find the intersections between a vector of points: input: [[1 3] [2 4] [5 6]] output: [[1 4] [5 6]] I started off trying to do this with a reduce, but im not sure how to handle the case when the return value is a merged list.

vandr0iy08:11:45

excuse my ignorance, but how do you find an intersection between some points? don't you need, like, vectors, or straight lines?

Drew Verlee10:11:28

Right, I should have said lines as represented by 2 points.

genmeblog10:11:29

but still your input is not clear, you need 4 points to define two lines

vandr0iy10:11:24

so, like this? input: [[[1 2] [5 6]] [[1 3] [7 8]]] output: [x y]

genmeblog10:11:02

section: Given two points on each line

neurogoo11:11:29

I will continue my server questions. I have clojure server with clojurescript front and I have used cljs-ajax with JSON to transfer data between them. In server side I have used wrap-restful-format to serialize data structures to JSON but it seems really picky on what kind of structure I give it to it

neurogoo11:11:34

So is there better library for handling JSON server side? Or maybe better Clojure specific way to transfer data between server and front?

sveri11:11:24

@neurogoo there is transit: https://github.com/cognitect/transit-clj and several libraries with support for it, I think cljs-ajax has it as default even. I use this middleware with ring: https://github.com/jalehman/ring-transit and it worked out so far

neurogoo14:11:50

Thanks @sveri I will try that

Drew Verlee16:11:22

@tsulej

input: [[1 3] [2 4] [5 6]]
output: [[1 4] [5 6]]
the input would be 3 lines. the output would be the merged lines merge((1,3), (2,4)) => (1,4) and in the case when they dont intersect, then just the original lines/inputs merge((1,4), (5,6)) => [(1,4), (5,6)]. That second aspect is what causes it hard to see how i can use reduce.

Drew Verlee16:11:17

maybe the confusion is because their is only 1 dimension with these “points” more specifically im trying to find if two “times” overlap so the input would be more like (sunday_at_5, sunday_at_7), (sunday_at_4, sunday_at_6)

vandr0iy16:11:34

[1 3] and [2 4] are points, not lines - unless you intend them as vectors starting from origin, but in that case they do not intersect

vandr0iy16:11:53

if I understand you correctly

Drew Verlee16:11:15

@vandr0iy Line1 = 1-to-3 Line2 = 2-to-4 There is only one dimension. so instead of (x,y) this is just (x,x). Does that make sense

vandr0iy16:11:40

ooh... so you're trying to merge some ranges!

Drew Verlee16:11:22

right, so maybe the right word here is range instead of line.

rauh16:11:07

The right term should be "interval", mathematically speaking

Drew Verlee16:11:54

@rauh thanks, i forgot the importance of finding the right word before searching for an answer. Using interval i get a lot better search results.

genmeblog18:11:19

yes, you're looking for merging intervals, you should easily find proper algorithms

genmeblog19:11:47

@drewverlee

(defn merge-intervals [vs]
  (let [sorted (sort (map (comp vec sort) vs))
        f (fn [res el]
            (let [[a b] (first res)
                  [na nb] el]
              (if (< na b)
                (cons [a nb] (rest res))
                (cons el res))))]
    (reverse (reduce f [(first sorted)] (rest sorted)))))

genmeblog19:11:08

I think it can be more optimal

gamecubate19:11:02

A simplification for this:

(vec (flatten (vector [1 2 3] [2 4 5]))) ; returns [1 2 3 2 4 5]
eludes me. Can anyone think of one?

mtkp19:11:06

how about concat?

gamecubate19:11:08

OK. May have it. `(vec (concat

gamecubate19:11:15

yeah i sut spotted it

mtkp19:11:18

nice : )

Drew Verlee22:11:45

@tsulej thanks! Ill give this a look. I see reduce in their which peeks my curiosity as i banged my head trying to make that fit.

mfikes23:11:26

@gamecubate: into often surprises: (into [1 2 3] [2 4 5])

gamecubate23:11:07

Ah yes. Thanks @mfikes. Humbling that, having finished writing a pretty big project in cljs&reagent front-end + node.js backend project, I’m still weak on basic stuff.