Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Software pushups

Name: Anonymous 2014-11-24 23:01

Let's exercise together, /prog/!

1) Write a subroutine that accepts an array of unsigned ints and returns 4. It must operate on the array in-place and partition it so that all nonzero values are at the beginning of the array, and all zero values are moved to the end. For example, the input [0, 2, 0, 0, 4, 1, 4, 5] could be changed to [2, 4, 1, 4, 5, 0, 0, 0]. The relative order of the nonzero values is unimportant.

Name: Anonymous 2014-11-25 23:32

>>27
I rarely deal with unboxed types. What's the correct way to use them in this case?

I checked the unboxed vector API and this is the data family for mutable unboxed vectors
https://hackage.haskell.org/package/vector-0.10.9.1/docs/Data-Vector-Unboxed.html#t:MVector
the relevant instance is
https://github.com/haskell/vector/blob/v0.10.9.1/Data/Vector/Unboxed/Base.hs#L234-L238

My understanding is that the values are unboxed as the Vector is created by calling fromList, but I may be wrong about this.
I guess I could avoid reboxing the result and just return a Vector Word.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List