Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*Question 2 FINAL FINAL*)
- local
- fun min var1 var2 = if var1<var2 then var1 else var2
- fun makeMinFirst var [] = [] |
- makeMinFirst var (x::xs) = (min var x):: (makeMinFirst var xs)
- in
- fun max_city [] _ = [] |
- max_city (west::xs) north = makeMinFirst west north :: max_city xs north
- end;
- local
- fun transpo ([]::_) = []
- |transpo rows =
- (map hd rows) :: transpo (map tl rows);
- fun initList 0 = [] | initList size = (~1):: (initList (size-1));
- fun correctLine [] _ _ _= [] |
- correctLine (north::xs) var numOfRepeats maxRepatNorth =
- if((var=north) andalso (numOfRepeats=1) andalso (maxRepatNorth >= 1)) then var::(initList (length xs))
- else if ((var=north) andalso (numOfRepeats >1 ) andalso (maxRepatNorth = 1)) then var::correctLine xs var (numOfRepeats-1) maxRepatNorth
- else if ((var=north) andalso numOfRepeats >1) then (~1)::correctLine xs var (numOfRepeats-1) (maxRepatNorth-1)
- else if ((north > var) andalso (maxRepatNorth = 0)) then var::(initList (length xs))
- else (~1)::correctLine xs var numOfRepeats maxRepatNorth ;
- fun maxRepeat x [] repeats = repeats |
- maxRepeat x (y::ys) repeats = if(x=y) then maxRepeat x ys (repeats+1) else maxRepeat x ys repeats ;
- fun apearannceTillIndexOfWest _ 0 _ repeatance = repeatance |
- apearannceTillIndexOfWest [] _ _ repeatance = repeatance|
- apearannceTillIndexOfWest (west::xs) lineNum var repeatance= if(var=west) then (apearannceTillIndexOfWest xs (lineNum-1) var (repeatance+1))
- else apearannceTillIndexOfWest xs (lineNum-1) var repeatance ;
- fun buildLine x west north lineNum = correctLine north x (apearannceTillIndexOfWest west lineNum x 0) (maxRepeat x north 0) ;
- fun buildMat [] _ _ _ = [] |
- buildMat (x::xs) west north lineNum= (buildLine x west north lineNum)::(buildMat xs west north (lineNum+1));
- fun unionLine [] [] = [] |
- unionLine (x::xs) (y::ys) = if(x=(~1)) then y::unionLine xs ys else x::unionLine xs ys;
- fun unionmMat [] [] = [] |
- unionmMat (x::xs) (y::ys) = (unionLine x y)::(unionmMat xs ys);
- fun buildUnionMat west north = unionmMat (buildMat west west north 1) (transpo (buildMat north north west 1));
- fun replaceZero [] = [] |
- replaceZero (x::xs) = if(x=(~1)) then (0 :: replaceZero xs) else x::replaceZero xs ;
- fun makeZero [] = [] |
- makeZero (x::xs) = replaceZero x:: makeZero xs;
- in
- fun min_city west north = makeZero (buildUnionMat west north)
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement