We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I'm a Haskell newbie and reading input data is the most difficult part of the problem for me. I don't see where your code structures the input data into the "grouping" required in this task.

I mean, how is the function "run" (if I understood at least that part) supposed to get T, and then, for 1..T, the value of N and the list of (x,y) as required for this problem? (I understand that we could simply "skip" the initial T but then (until EOF is reached) definitely need to get the N in order to know how many lines (x,y) we must read -- where am I wrong?)

I'm keen to switch from imperative to functional programming, but as far as the "I/O" is concerned, the problem statement "there are T test cases and for each test case..." already contains the declarative "for". And I'd like to write a function that receives a vector of N pairs (x,y), but how to get there without doing "for i in 1..N: read [x, y] and append to the list L" ?

## Functions or Not?

You are viewing a single comment's thread. Return to all comments →

I'm a Haskell newbie and reading input data is the most difficult part of the problem for me. I don't see where your code structures the input data into the "grouping" required in this task.

I mean, how is the function "run" (if I understood at least that part) supposed to get T, and then, for 1..T, the value of N and the list of (x,y) as required for this problem? (I understand that we could simply "skip" the initial T but then (until EOF is reached) definitely need to get the N in order to know how many lines (x,y) we must read -- where am I wrong?)

I'm keen to switch from imperative to functional programming, but as far as the "I/O" is concerned, the problem statement "there are T test cases and for each test case..." already contains the declarative "for". And I'd like to write a function that receives a vector of N pairs (x,y), but how to get there without doing "for i in 1..N: read [x, y] and append to the list L" ?