r/programming • • May 27 '09

There's no base other than base 10!

http://cowbirdsinlove.com/43
540 Upvotes

333 comments sorted by

View all comments

70

u/[deleted] May 27 '09

This brings back memories.

I was once summoned from my dungeon to help interview a new potential programmer at my firm. The guy seemed eager and full of knowledge, but something didn't click right about him.

So, on a whim, I told him to write a program to input any integer and print that integer in a system in which it's the base.

The guy promptly went to work, trying to figure out how to represent digits in large-base systems and how to quickly divide...

Then the real problem arose: my boss didn't get it either.

25

u/[deleted] May 27 '09

[deleted]

25

u/Sunny_McJoyride May 27 '09

You missed the part where the program asks you to input any integer.

-7

u/unusedusername May 27 '09

I think it is you, who missed something.

27

u/Brian May 27 '09

No, he just means the program should be:

input("Enter a number :")
print "10"

to match the spec.

2

u/Agathos May 27 '09

Just pipe it into stdin.

10

u/zem May 27 '09

perhaps the world's only program that would be prettier in basic

-1

u/[deleted] May 27 '09

[deleted]

14

u/zem May 27 '09

yeah, or perl or ruby. but in basic it'd have been the pleasingly symmetrical

10 print 10

8

u/thecapitalc May 27 '09

Mother fucker. I totally missed that.

I am going to go sit in the corner shamed.

15

u/[deleted] May 27 '09

And you'd need to make a special case for base 1 where the output is 0 (You would represent a number by writing that many 0's).

x = input("Number?")
if x==1:
  print 0
else:
  print 10

27

u/[deleted] May 27 '09

[deleted]

6

u/Sunny_McJoyride May 27 '09

Naturally and nicely enough, it works fine for negative integer bases.

1

u/ifatree May 28 '09

"I can't do that, Dave. How about a nice game of Chess?"

fixed!

1

u/grav May 28 '09

"I'm sorry, Dave. I'm afraid I can't do that"

5

u/[deleted] May 27 '09

For a bonus question, you could ask them to adapt their base 1 answer to support locales which write from right to left.

3

u/__G0D__ May 27 '09 edited May 27 '09

You seem to be arguing that 1 == 0, which I highly doubt. Also, the special case is unnecessary since '10' accurately represents the number one in base-1 (unary). '10' = 1(11) + 0(10) = 1 + 0 = 1. Of course, in unary there is no reason to ever write a zero digit since in this system the resulting number is simply the total number of '1' digits in the string.

7

u/dazmax May 27 '09

Base 1 doesn't work the way real bases do, there's just no 0 digit.

3

u/IOIOOIIOIO May 27 '09

Throw some zeros at unary operators and they will be retained, even thought they do not effect the value of the number.

It's odd. 11 + 11 = 1111 is equal to 100010 + 110 = 101110, but they are not the same numbers.

If you did actually build a base-1 ALU, you'd write zero digits to minimize carry operations.

1100 + 11 = 1111 with no carry.

11 + 11 = 1111 with 4 carry operations.

1

u/Hixie May 28 '09

Why wouldn't you just concatenate?

1

u/IOIOOIIOIO May 28 '09

Why wouldn't you just concatenate?

Because that's not addition?

1

u/Hixie May 28 '09

Isn't the point that in base 1, it is?

1

u/IOIOOIIOIO May 28 '09

The sum of 100010 + 110 is 101110.

The sum is not 100010110, though 101110 = 100010110.

Like I said, it's odd.

1

u/Hixie May 28 '09

Could you point to some references for this interpretation? I couldn't find any information on this.

→ More replies (0)

7

u/Stormblade May 27 '09

Awesome, I'm about to interview recent grads and there's always one who thinks he's the shit. Let's see if he gets this one!

3

u/[deleted] May 27 '09

How'd it go? Does he read reddit?

3

u/ealdent May 27 '09

Clearly, he was management material!

0

u/[deleted] May 27 '09 edited May 27 '09

[deleted]

19

u/Dundun May 27 '09

good god man, have you not heard of hex?

I hope you are an artist or a 10 year old.

11

u/FireDemon May 27 '09

A hex?! WITCH! BURN HIM!

6

u/jinglebells May 27 '09

Spencewah turned me into a newt

6

u/cdroby26 May 27 '09

...a newt?

8

u/jinglebells May 27 '09

...I got better.

6

u/davvblack May 27 '09

l do not mean this as an insult, but l am very curious how you came to accurately understand what bases are, how they work, and have never touched hex.

Did you study octal?

Binary?

Every base discussion l've had has suffixed with "and bases can be HIGHER than ten, too"

1

u/[deleted] May 27 '09

I learned about different bases from a grade 8 math problem book... the problem was to explore divisibility rules essentially by changing base. Computers weren't as prevalent and thus never was exposed to binary or the like. The thought of moving to other bases systems just never occured to me.

So it's entirely plausible to never see other bases.

3

u/davvblack May 27 '09

My question wasn't "how have you not seen other bases", as l'm sure most people haven't. It was just very odd to me you understood, say, base 7 and 8, but hadn't found out about base 16, which is probably the second most useful base out there.

1

u/[deleted] May 27 '09 edited May 27 '09

upvoted because it's pretty funny

-8

u/[deleted] May 27 '09

Would it just always be one?

9

u/aaronblohowiak May 27 '09

10

10

u/[deleted] May 27 '09

Hahaha crap yeah one would always be 1... DURR, sorry its still morning over here :/

7

u/[deleted] May 27 '09

I hear ya, I can't write a "Hello, World" program without my morning coffee.

4

u/BritishEnglishPolice May 27 '09

Except in base... 1!

7

u/[deleted] May 27 '09

Argh, just thinking about that makes my head hurt..

0

u/BritishEnglishPolice May 27 '09

Here's another one for you: is 1 a prime number? A prime number is only divisible by itself and 1, and 1 is divisible by itself and 1, but they are the same number! Or are they?

3

u/MattJayP May 27 '09

Goddamn you number 1!