1 people like it.
Like the snippet!
divide me.fsx
This script finds all possible divisors of a number
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
|
let checknumber number divisor =
let divided = (float)number / (float)divisor
if divided = floor divided then
divided
|> int
|> printfn "%i = %i * %i" number divisor
let rec finddivisor number divisor numbers =
match numbers with
| head :: tail ->
checknumber number head
finddivisor number head tail
| [] -> printfn "finish"
let divisions number =
let list = [1..number]
finddivisor number list.Head list
let ``find my divisors`` = 12345
divisions ``find my divisors``
|
val checknumber : number:int -> divisor:int -> unit
Full name: Script.checknumber
val number : int
val divisor : int
val divided : float
Multiple items
val float : value:'T -> float (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float
--------------------
type float = System.Double
Full name: Microsoft.FSharp.Core.float
--------------------
type float<'Measure> = float
Full name: Microsoft.FSharp.Core.float<_>
val floor : value:'T -> 'T (requires member Floor)
Full name: Microsoft.FSharp.Core.Operators.floor
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val finddivisor : number:int -> divisor:int -> numbers:int list -> unit
Full name: Script.finddivisor
val numbers : int list
val head : int
val tail : int list
val divisions : number:int -> unit
Full name: Script.divisions
Multiple items
val list : int list
--------------------
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
property List.Head: int
val ( find my divisors ) : int
Full name: Script.( find my divisors )
More information