>
> How come "rest" doesn't just use a virtual sequence to offset the
> original index by 1.
>
You're thinking of "rest-slice", which is a virtual version of "rest".
--
Try New Relic Now & We'll Send You this Cool Shirt
Ne
> I'm glad the final version is so elegant!
>
> Best,
> John.
"Chuck Moore declared that the software problem was solved and that
the remaining problem was hardware."
-- http://www.ultratechnology.com/
With the software problem solved, maybe the remaining problems are
hardware and pure math.
-
On Wed, May 22, 2013 at 8:58 AM, John Benediktsson wrote:
> Using ranges, "iota rest" is just "[1,b)" (and more memory efficient because
> rest causes the virtual sequence to become concrete).
How come "rest" doesn't just use a virtual sequence to offset the
original index by 1.
---
Using ranges, "iota rest" is just "[1,b)" (and more memory efficient because
rest causes the virtual sequence to become concrete).
The filter-combinations word is more efficient than all-combinations [ ... ]
filter because it can ignore or skip the ones that are not triples as it builds
the res
wrote:
>> Oo, or even
>>
>>
>> : triples ( n -- seq )
>> iota rest 3 [ first3 triple? ] filter-combinations ;
Out of all the examples given in several languages, this is by far the
most concise version.
--
Try New Re
On Mon, May 20, 2013 at 10:11 PM, Alex Vondrak wrote:
> Oo, or even
>
>
> : triples ( n -- seq )
> iota rest 3 [ first3 triple? ] filter-combinations ;
Does filter-combinations filter as it builds the list?
Or does it build the list then filter it?
---
Oo, or even
: triples ( n -- seq )
iota rest 3 [ first3 triple? ] filter-combinations ;
On Mon, May 20, 2013 at 7:06 PM, Alex Vondrak wrote:
> Or, going by the algorithms in the wiki:
>
> ```
> USING: arrays kernel locals math math.ranges sequences
> sequences.extras ;
>
> :: triples ( n -
Or, going by the algorithms in the wiki:
```
USING: arrays kernel locals math math.ranges sequences
sequences.extras ;
:: triples ( n -- seq )
n [1,b] [| x |
x n [a,b] [| y |
y n [a,b]
[| z | x sq y sq + z sq = ]
[| z | x y z 3array ]
fi
! Copyright (C) 2013 Your name.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences math math.functions arrays math.combinatorics ;
IN: pythagorean-triples
: a-b-list ( n -- seq )
iota rest 2 all-combinations ;
: a-b-c ( seq1 -- seq2 )
[ first ]
[ second ]
We don't have "list comprehensions", per se - but instead have basic map
and filter operations...
Instead of
[ x for x in range(5) if x % 2 == 0 ]
We would have:
5 iota [ 2 mod zero? ] filter
Instead of
[ x ** 3 for x in foo() ]
We would have:
foo [ 3 ^ ] map
You could use
I was checking out the Rosetta Code site and noticed there is no example of
list comprehension in Factor. How can we simulate this convenient tool?
--
AlienVault Unified Security Management (USM) platform delivers complet
11 matches
Mail list logo