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-12-27 13:58

>>120
Macros are syntax transformers.

Name: Anonymous 2014-12-27 13:59

>>118
I think the real problem is that none of them read their TAPL and so all those languages' type systems are shit.

Name: Anonymous 2014-12-27 15:30

>>118
You misunderstand, I really don't get what's impressive about it. Not many languages might do these simple optimizations, but that doesn't change the fact that they are basic.

Name: Anonymous 2014-12-29 7:32

>>121
Macros can have side effects too. They are extensions of the compiler.

>>123
A basic algorithm is more impressive than a complex one, provided they do the same thing.

Name: Anonymous 2014-12-29 11:27

>>113

how about now?

func pushup(in []uint) {
lim := len(in)-1
for idx := 0; idx < lim; idx = idx + 1 {
for ;lim >= 0 && in[lim]==0;lim = lim-1 {
}
if lim <= idx {
return
}
if in[idx] == 0 {
in[idx] = in[lim]
in[lim] = 0
lim = lim - 1
}
}
}

Name: Anonymous 2014-12-29 17:52

>>105
I'm just speaking from my experience. I've never done x86, but beating compilers on the 68k is pretty easy.

Name: Anonymous 2015-01-05 16:37

can we just bump the old thread tyvm

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