Skip to content

Instantly share code, notes, and snippets.

@MikaelFangel
Last active September 11, 2023 14:46
Show Gist options
  • Save MikaelFangel/40556eef6cc5039774cb019460a9d050 to your computer and use it in GitHub Desktop.
Save MikaelFangel/40556eef6cc5039774cb019460a9d050 to your computer and use it in GitHub Desktop.
How to read 2D array from console in F#
open System
// Create a rectangular array of chars
let read2DCharArray rowCount colCount =
let rows = [| for _ in 1 .. rowCount -> Console.ReadLine() |> Array.ofSeq |]
Array2D.init rowCount colCount (fun i j -> rows[i][j])
// Create a jagged array of chars
let read2DCharArrayJagged rows =
[| for _ in 1 .. rows -> Console.ReadLine() |> Array.ofSeq |]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment