Solve a Holy Knight's tour: Difference between revisions
Content added Content deleted
m (→JS ES6: (made one function less partial - for case where problem lacks a starting '1')) |
m (→JS ES6: (changed one name)) |
||
Line 2,053: | Line 2,053: | ||
}; |
}; |
||
// |
// showLine :: Int -> Int -> String -> Maybe (Int, Int) -> |
||
// [(Int, Int, String)] -> String |
// [(Int, Int, String)] -> String |
||
const |
const showLine = curry((intCell, strFiller, maybeStart, xs) => { |
||
const |
const |
||
blnSoln = maybeStart.nothing, |
blnSoln = maybeStart.nothing, |
||
Line 2,067: | Line 2,067: | ||
(blnSoln ? sVal : ( |
(blnSoln ? sVal : ( |
||
iRow === startRow && |
iRow === startRow && |
||
iCol === startCol ? '1' : '0' |
iCol === startCol ? '1' : '0') |
||
) |
|||
) |
) |
||
}), { |
}), { |
||
Line 2,112: | Line 2,113: | ||
startXY = take(2, lstTriples[0]), |
startXY = take(2, lstTriples[0]), |
||
strMap = 'PROBLEM ' + (parseInt(iProblem, 10) + 1) + '.\n\n' + |
strMap = 'PROBLEM ' + (parseInt(iProblem, 10) + 1) + '.\n\n' + |
||
unlines(map( |
unlines(map(showLine(cellWidth, ' ', { |
||
nothing: false, |
nothing: false, |
||
just: startXY |
just: startXY |
||
Line 2,118: | Line 2,119: | ||
strSoln = 'First solution found in c. ' + |
strSoln = 'First solution found in c. ' + |
||
intMSeconds + ' milliseconds:\n\n' + |
intMSeconds + ' milliseconds:\n\n' + |
||
unlines(map( |
unlines(map(showLine(cellWidth, ' ', { |
||
nothing: true, |
nothing: true, |
||
just: startXY |
just: startXY |