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