I am trying to format text in the shape of a rectangle; At present, I have been properly appropriately dropped, but the last line is not as detailed as possible.
To minimize or minimize, I am trying to calculate the optimum field width. / P>
I'm completely trapped. The code below shows relevant work, it is currently trapped in an infinite loop. Where am i going
One way to note, what is the best way to debug the Haskell code? (Yes, I am very new to this.)
Comparison of the length of the optimum fieldwhich line until the length of the line above is equal to the line below, then return the width of that field, To be true
Module main where imported system import data. List main = don (f: _) & lt; - getArgs xs & lt; - getContents putStr (show (bestfieldwidth maxlineLength xs)) bestFieldWidth :: Int - & gt; String - & gt; Int BestFried Wideth _ [] = 0 Bestfield Wide Line Langnet X. | Length (final input) == Length (main input) = LINEELG | Otherwise = best field width (length (reset (line-laneth-1) xs)) xs where input = line xs rect :: int -> string -> [string] rect_ [] = [] rect line Lang xs | length input Input = tray = [input] | otherwise take the = lane input: reset lane (drop-down input) All responses are appreciated. Thanks.
I It was thought that if someone wants to do another nator, then I will put a real solution here, please keep in mind that this was written by a fool, so this is probably not the most beautiful solution.
MaxFieldWidth :: Int maxFieldWidth = 30 rect :: string - & gt; string rect xs = (unlike (peak (bestfoldwidth) (line input) input) where input = items \ n '' 'change xs - Coin with maximum desired width as point Should be taken n bestFieldWidth :: Int- & gt; [String] - & gt; Int BestFlindwidth _ [] = Error "Best FieldWidth: Blank List" Bestfilldwath NX | N == 6 = 6 | 1 == (length (final input)) = n | Otherwise = (BestfieldWidth (N-1) XS) where input = Chunk N (Xs Excellence) piece :: Int -> [A] - & gt; [[A]] chuck n [] = [] chuck n xs = ys: chuck n js where (ys, zs) = split at n xs items reploid :: eq a => A - & gt; A - & gt; [A] - & gt; [A] Items replay _ _ [] = [] Replace item RR C (X: X) | C == x = r: item replaces c r xs | Otherwise = x: item CRX *
Comments
Post a Comment