News for hackers. Stuff that matters.
Re:Metabase: Why we picked Clojure by dragonwriter on Wednesday December 02, 2015 @05:35PM (#10666368)
> As below, let's produce a sequence of the form [true false false true true true false false false false ...] of exact length 1000 without computing any more than exactly 1000 elements.

So, again, python:

  [i % 2 == 0 for i in range(1000)]
(If you insist on Java, its fairly straightforward, though not a one-liner AFAIK, using Java 8 generators.)
Re:Metabase: Why we picked Clojure by j-pb on Wednesday December 02, 2015 @05:40PM (#10666407)
You misread the question. I didn't mean (map even? (range 1000)), but a sequence of length 1000 where the elements are 1 * true, 2 * false, 3 * true, 4 * false and so on.

To compare it with what your code produces.

[true false false true true true false false false false ...]

[true false true false true false true false true false ...]

Edited for more clarity.

Re:Metabase: Why we picked Clojure by dragonwriter on Wednesday December 02, 2015 @06:22PM (#10666631)
Right, sorry, in python that's something like:

  from itertools import chain, repeat

  chain.from_iterable([repeat(i % 2 != 0, i) for i in range(1,1000)])
In Java 8, I think the solution with streams would be fairly straightforward, something like:

  IntStream.range(1,1001).flatMap(i -> Stream<Boolean>.generate( () -> (x & 1) != 0 ).limit(i))
Re:Metabase: Why we picked Clojure by sokoloff on Wednesday December 02, 2015 @07:11PM (#10666860)
Doesn't that python code give you a list of 500,500 elements, rather than a list of 1000 elements as originally specified?
Re:Metabase: Why we picked Clojure by dragonwriter on Wednesday December 02, 2015 @07:13PM (#10666871)
In both cases yes, and in both cases because I made the same stupid mistake when both languages have good means to do infinite streams and "take" equivalents. (And that's worse in the Java case, since I used those in the inner function but not the outer one.)

So, I think I need to take a break from comment-box programming for a while; its clearly not working out for me today.