Loops/With multiple ranges: Difference between revisions
Content added Content deleted
No edit summary |
(Realize in F#) |
||
Line 1,303: | Line 1,303: | ||
</pre> |
</pre> |
||
=={{header|F_Sharp|F#}}== |
|||
<lang fsharp> |
|||
// Loops/With multiple ranges. Nigel Galloway: June 13th., 2022 |
|||
let x,y,z,one,three,seven=5,-5,-2,1,3,7 |
|||
let Range=[-three..three..pown 3 3]@[-7..x..seven]@[555..550-y]@[22..-three.. -28]@[1927..1939]@[x..z..y]@[pown 11 x..(pown 11 x)+1] |
|||
printfn "Sum=%d Product=%d" (Range|>Seq.sumBy(abs)) (Range|>Seq.filter((<>)0)|>Seq.fold(fun n g->if abs n<pown 2 27 then n*g else n) 1) |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Sum=348173 Product=-793618560 |
|||
</pre> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
Factor doesn't have any special support for this sort of thing, but we can store iterable <code>range</code> objects in a collection and loop over them. |
Factor doesn't have any special support for this sort of thing, but we can store iterable <code>range</code> objects in a collection and loop over them. |
||
Line 1,342: | Line 1,353: | ||
prod= -793,618,560 |
prod= -793,618,560 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |