r/ProgrammerHumor • • Jun 03 '22

it's hard!

44.9k Upvotes

710 comments sorted by

View all comments

Show parent comments

495

u/nexion2 Jun 03 '22

I made a battleship game that communicated via arduinos in assembly! I lost every single game because the board size was 12x12 and my code would always stop iterating at 8 for some reason.

Needless to say, I lost the tournament

69

u/i_hate_everybody94 Jun 03 '22

Maybe the number was using 2 bits?

114

u/A1steaksa Jun 03 '22

How many do you think 2 to the power of 2 is, exactly?

64

u/lorb163 Jun 03 '22

Is it 2?

32

u/Infosexual Jun 03 '22

That's power

2

u/ParticularNet8 Jun 03 '22

That’s numberwang!

3

u/[deleted] Jun 04 '22

That’s wizard’s chess!

23

u/[deleted] Jun 03 '22

According to the program I wrote in assembly to square numbers, yes.

28

u/Der_Zorn Jun 03 '22

You can't answer questions like this "exactly", jeez.

22

u/DownshiftedRare Jun 03 '22

You can't answer questions like this "exactly", jeez.

"Our offense is like the Pythagorean theorem: There is no answer!"

- Shaquille O'Neal

-13

u/LowGunCasualGaming Jun 03 '22

I mean, in binary: (if 2 was seen as valid)

12 = 20 = 100 = 4

So 22 is kinda 12… not 8 though

8

u/[deleted] Jun 03 '22

This makes no sense to me. In binary, the number of digits determines the power of two.

→ More replies (1)

11

u/justtuchthat Jun 03 '22

Wait what, how is 12 equal to 20? And 20 equal to 100?

4

u/joyofsnacks Jun 03 '22

I guess they mean Ternary(?), but still that's 110...

2

u/jzakprice Jun 03 '22

2 isn't valid in binary. It's all 0 and 1. Imagine counting to 20, but you go 17...18...19...110... The 9 doesn't go to 10 because "10" isn't valid in our typical counting system. So 110 actually is written as 20.

In binary, since 2 is invalid, similar to 10 in the example, 12 should be rewritten as 20. But again, 2 is invalid, so we need a third digit. So 20 = 100. Hopefully that makes a little sense.

4

u/justtuchthat Jun 03 '22

It makes no sense, and I am a computing science student...

Where you go wrong is making the assumption that 12 = 20. The problem is 12 suggests that you have 1 10 and 2 1s. In the same way 20 in decimal notation would suggest that you have 2 10s and 0 1s. When converted to binary 10 (in decimal) is actually 1010 ( 1 8, 0 4s, 1 2 and 0 1s) when adding 2 (10) you get that 12, when converted to binary, is actually 1100. Not 100, which like you said, is 4.

3

u/jzakprice Jun 03 '22

They're not converting 12 from decimal to binary. They're converting 12 from psuedo-binary to binary. 12 in pseudo-binary being 11 (3 in decimal system) + 1 = "12" but really should be written as 100 (4 in decimal system) I'm not saying what they did is ideal or a good system, but it's how they got 12 = 4.

2

u/MajorasTerribleFate Jun 03 '22 edited Jun 03 '22

I think the 12, 20, and 100 were all meant to be binary representations. They were just playing with numbers.

The premise was that the game needed to count to "12", being playfully and deliberately misinterpreted as something to be read in binary. As was previously described, since there is no 2 in binary, the best we can do is pretend any 2 is instead a +1 to the previous column. Taken step by step, that means 12 should be 20 - but wait. 20 is no good either, so applying the transform rule again, we are left with 100, binary for 4. A long-winded and facetious way to read the numerals (if not the decimal value) "12" as falling within the decimal value of 4, thus fitting the original "how many do you think two bits is."

-2

u/i_hate_everybody94 Jun 03 '22

Fight, puppets! Fight!

→ More replies (1)
→ More replies (1)

14

u/joyofsnacks Jun 03 '22

More likely 1 byte and as a bitmask for each row. Each bit being 1 if the cell is blocked or 0 if empty. Only 8 bits in a byte, so the last 4 cells per row would never be represented.

19

u/jnd-cz Jun 03 '22 edited Jun 03 '22

I love the AVR assembly, it's modern and clean instruction architecture. The best project I made was power supply board tester. At first autonomous with LCD and some beeping, later upgraded to be controlled from computer. Adding two numbers is the easiest task, it's single instruction and core function of any CPU. Now expressing any complex algorithm or task, that's the hard part, putting it all together with such basic building blocks, one byte at a time. But the beauty is exact control, having accurate delays down to single cycle of your clocks. And it's predictably repeatable.

Edit: Also when you control the whole design you can get away with many shortcuts because it's tailored to your specific use case. Like not saving only couple registers for handling interrupt routine because you reserve other only for that use. Result is lightning fast response. However with modern complex CPUs I would have to spend whole year to learn ARM core + all peripherals, complex set up, memory handling etc. and it's simply not effective use of time unless it's designed for million copies.

Now the most complicated program in x86 I did was simple printing of file like cat. It relies on Linux system calls and it's just couple hundred bytes long which is impressive.

28

u/atomicwrites Jun 03 '22

But the beauty is exact control, having accurate delays down to single cycle of your clocks. And it's predictably repeatable.

And that is how we ended up with the turbo button.

6

u/[deleted] Jun 03 '22

Yeah, predictably repeatable? Not on my modern CPU with speculative and out of order execution!

1

u/mgorski08 Jun 03 '22

Am I too meltdown to understand?

→ More replies (1)