Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

algorithm - Simple row transposition cipher -


for lisp class, given simple row transposition cipher homework, tried solve in haskell, too. basically, 1 splits string rows of length n, , transposes result. concatenation of resulting list of lists of chars encrypted string. decoding little harder, since there may missing elements in last row of input (incomplete columns in result), have taken care of.

this solution in haskell:

import data.list import data.ratio import data.list.split  encode :: string -> int -> string encode s n = concat . transpose $ chunk n s  decode :: string -> int -> string decode s n = take len $ encode s' rows     s'     = foldr (insertat " ") s idxs           rows   = ceiling (len % n)           idxs   = take (n-filled) [n*rows-1,(n-1)*rows-1..]           filled = len - n * (rows - 1)           len    = length s  insertat :: [a] -> int -> [a] -> [a] insertat xs ys = pre ++ xs ++ post     (pre,post) = splitat ys 

it job, not sure, whether considered idiomatic haskell, since fiddling indices not feel declarative. improved, , if yes, how?

by way: there akin insertat in haskell 98? i.e. function inserting element or list @ given index list.

note: not part of homework, due today anyway.

i looking @ encode , decode problems differently. encode breaks data n-column matrix, transposes (into n-row matrix) , concatenates rows. decode breaks data n row matrix, transposes (into n columm matrix) , concatenates rows.

so i'd start defining 2 functions - 1 make array n column matrix:

chunk:: int -> [a] -> [[a]] chunk n = chunk' n (length as)   chunk' n l | l <= n    = [as]                       | otherwise = : chunk' n (l-n) rest                            (some, rest) = splitat n 

and slice array n row matrix:

slice :: int -> [a] -> [[a]] slice n = chunk (q+1) front ++ chunk q   (q,r) = length `divmod` n         (front, back) = splitat (r*(q+1)) 

now, encoding , decoding easy:

encode :: int -> [a] -> [a] encode = ((concat . transpose) .). chunk decode :: int -> [a] -> [a] decode = ((concat . transpose) .). slice 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -