RolfAndreassen comments on More "Stupid" Questions - Less Wrong

14 Post author: NancyLebovitz 31 July 2013 09:18AM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (495)

You are viewing a single comment's thread. Show more comments above.

Comment author: SilasBarta 01 August 2013 07:19:07PM 1 point [-]

Depends on what you intend to get out of it, but you can go to an amateur hack night ("we're going to implement C-style integers in Ruby", "we're going to implement simulated annealing)", where almost everyone but you will have trouble conceptualizing the problem.

Comment author: RolfAndreassen 03 August 2013 04:57:29AM 1 point [-]

It's just as well this is a stupid-questions thread, but: Doesn't Ruby already have C-style integers? What is it you mean by this phrase which Ruby doesn't have?

Comment author: SilasBarta 03 August 2013 06:23:25PM *  0 points [-]

C-style integers = integers with a fixed possible range of values and the corresponding rollover -- that is, if you get a result too big to be stored in that fixed size, it rolls over from the lowest possible value.

Ruby doesn't implement that limitation. It implements integers through Fixnum and Bignum. The latter is unbounded. The former is bounded but (per the linked doc) automatically converted to the latter if it would exceed its bounds.

Even if it did, it's still useful as an exercise: get a class to respond to addition, etc operations the same way that a C integer would. (And still something most participants will have trouble with.)

Comment author: RolfAndreassen 03 August 2013 08:52:29PM 0 points [-]

Hmm, interesting! Maybe the simplest approach would be to just implement a class with 16 (or 32, whatever) booleans, and do the underlying bit-pattern math. Then on printing, interpret as powers of two, or two's-complement, or whatever you like.

Comment author: SilasBarta 03 August 2013 09:58:32PM 2 points [-]

... and that is what being a big fish in a small pond feels like ;-) That is, most of them there won't even make it that far. At least, that was my experience.

(My approach was the cruder one of just taking a remainder modulo max size after each operation.)

Comment author: RolfAndreassen 04 August 2013 03:11:00AM 0 points [-]

That would work for unsigned integers, but I don't see how it gives you the classic rollover from 32767 to -32768?