How to resolve the algorithm Loops/With multiple ranges step by step in the F# programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/With multiple ranges step by step in the F# programming language
Table of Contents
Problem Statement
Some languages allow multiple loop ranges, such as the PL/I example (snippet) below.
Simulate/translate the above PL/I program snippet as best as possible in your language, with particular emphasis on the do loop construct. The do index must be incremented/decremented in the same order shown. If feasible, add commas to the two output numbers (being displayed). Show all output here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Loops/With multiple ranges step by step in the F# programming language
Source code in the fsharp programming language
// 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)
You may also check:How to resolve the algorithm Balanced ternary step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Random sentence from book step by step in the Julia programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the OCaml programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Nim programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the blz programming language