This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-15
Channels
- # admin-announcements (7)
- # alda (1)
- # aws-lambda (1)
- # beginners (12)
- # boot (20)
- # cider (59)
- # cljs-dev (4)
- # cljsrn (69)
- # clojure (232)
- # clojure-austin (3)
- # clojure-austria (1)
- # clojure-belgium (2)
- # clojure-canada (3)
- # clojure-dev (16)
- # clojure-greece (33)
- # clojure-nl (4)
- # clojure-quebec (12)
- # clojure-russia (12)
- # clojure-spec (27)
- # clojure-uk (38)
- # clojurescript (29)
- # community-development (7)
- # component (53)
- # core-async (16)
- # core-logic (1)
- # datascript (7)
- # datomic (11)
- # editors (7)
- # emacs (69)
- # hoplon (157)
- # keechma (1)
- # lambdaisland (2)
- # lein-figwheel (31)
- # leiningen (8)
- # mount (3)
- # off-topic (11)
- # om (23)
- # onyx (64)
- # planck (2)
- # re-frame (18)
- # reagent (21)
- # specter (118)
- # untangled (145)
- # yada (1)
Morning
I've got a pair programming interview at lunchtime in Java and I've been practicing algorithmic problems. Just spent ages trying to write a binary chop imperatively! I've rewired my brain to reach for 'reduce' or at the very least recursive fns. Might reimplement it in Java recursively.
log_2_n search of a sorted list by dividing into successive halves
Sure is
Actually I'm using an index in a while loop but I'm going to implement a few different ways. In this case the return value is the index of the element in the sorted array so index is easier.
i think i’d have int start, mid, end
and keep adjusting them in a loop, if I had to be imperative
My first implementation is just using mid
as start and end are fixed as zero and array length then I just adjust mid
as required, but as I said I will reimplement a couple of ways. Better than the actual work I have to do 😉
nope - I'm checking if element at mid is equal to value I want and if it's not then recalc mid like so:
private static int findMiddleIndex(int i, int[] ints, int middleIndex) {
if (ints[middleIndex] < i)
return middleIndex + ((ints.length - middleIndex + 1) / 2);
else
return middleIndex / 2;
}
Hardest thing is I'm just not used to solving algorithms in Java. I don't practice it and I've virtually never had to do it in work in 19 years!
I don't know what they are going to give me in interview. Just using this for practice.
‘fraid I don’t know enough about type systems to comment on that… Dunno if there are any Haskell experts around here?
you're gonna need something with dependent-types @glenjamin
i thought that might be the case, should have written more testcases. I’m still surprised the code up there passed the few I did have