97 points

Reminds me of how I made tic tac toe game for my first university assignment 🤣

permalink
report
reply
41 points

That has a finite number of moves. And then you could possibly generate the code based on that finite set.

permalink
report
parent
reply
42 points

Chess technically has a finite number of moves. Although its a huge number and some have theorized its larger than the number of atoms in the known universe.

permalink
report
parent
reply
7 points

Technically it’s infinite, but that’s because of a stalemate. You can keep repeating the same moves over and over.

permalink
report
parent
reply
40 points

“hey, as long as it works…”

permalink
report
parent
reply
87 points

YandereDev coding chess.

Also who has a variable to store an input and decides to name it “player”?

permalink
report
reply
10 points

Thank you! That was driving me nuts.

permalink
report
parent
reply
1 point

Someone editing a tutorial without knowing what they’re doing

permalink
report
parent
reply
60 points

They’ve still got a long way to go

permalink
report
reply
27 points

Tldr Estimated total number of legal chess positions is (4.822 ± 0.028) * 10⁴⁴

permalink
report
parent
reply
3 points
*

“John Tromp and Peter Österlund estimated the number of legal chess positions with a 95% confidence level at ( 4.822 ± 0.028 ) × 10^44, based on an efficiently computable bijection between integers and chess positions.”

%95 confidenece level? Did they make a poll?

permalink
report
parent
reply
47 points

Is this the same person who coded the odd/even function?

permalink
report
reply
34 points
*

I have a better odd/even function:

bool isEven( long long x ) {  
  if ( x < 0 ) x = -x;  
  if ( x == 1 )  
    return false;  
  if ( x == 2 )  
    return true;  
  return isEven( x - 2 );  
}

This will work for both negative numbers and arbitrarily large integers. I’ve tested it up to 26 but I’m pretty sure it will work up to infinity.

Though serious question: Why are these forums coded in such a way that they ignore single newlines? How hard is it to replace a newline with a br tag?

Edit: added two spaces, should look much better.

Edit2: just looks a bit better lol

Edit3: better now?

permalink
report
parent
reply
18 points

It’s Markdown syntax. You can actually format it nicely in a code block:

bool isEven( long long x ) {
  if ( x < 0 ) x = -x;
  if ( x == 1 )
    return false;
  if ( x == 2 )
    return true;
  return isEven( x - 2 );
}

You do that by adding ``` above and below it. To force single line breaks, you can terminate your sentences with two spaces, or a backslash.

permalink
report
parent
reply
4 points

Ah thank you, the editor in connect isn’t great and doesn’t have the markdown guide or buttons for the preformatted block, so I couldn’t find the character combo to use it (and never would have guessed that lol). Also it keeps giving an error when I edit, though the edit is going through.

permalink
report
parent
reply
11 points

Can you put this in a npm package so I can use it in my project, please?

permalink
report
parent
reply
4 points

Just copy paste it into each source file, I give you permission to reuse the code.

permalink
report
parent
reply
10 points
*

Is this meant to be a joke or is it intended to be a serious solution?

Asking for someone who lacks a sense of humor.

Ok, fine, I’m asking for me. That person is me.

permalink
report
parent
reply
13 points

I want to see how you’d reply if I said it was serious. So let’s go with that. This is the best way to determine if a number is even in c/c++.

permalink
report
parent
reply
8 points

I love the use of recursion. Slick.

permalink
report
parent
reply
7 points

For large numbers, you might get a stack overflow. Depends on whether the compiler recognizes that it’s a tail recursion and then handles it appropriately.

As for why Lemmy ignores single newlines, that’s because it uses Markdown for its comment syntax, which happens to handle newlines that way. If you want a single newline to display, you have to add two spaces at the end of the line.

Here, you really would have wanted to use a code block, though, which you can create with backticks

```
like
so.
```

Normally, this would display “like so.” in a monospace font and handle newlines as you expected:

like
so.
permalink
report
parent
reply
8 points
*

Just need to add some code that saves the base stack pointer, detects when the stack is about to run out, then saves the current number, resets the stack to the original pointer but now with the current number as x and continues on to fix the stack overflow issue. You don’t even have to restore the stack when it’s all unwinding!

The integer overflow issue would be more complicated to solve except it isn’t really an issue because chopping off the upper bits doesn’t affect the eveness of a value.

Oh and I thought of a quick way to verify the result of the algorithm. It should give the same result as this expression that you can use in your test suite:

!(x & 1)

Edit: um, new formatting problem… And that amp shows up in the edit box so it might even keep expanding.

permalink
report
parent
reply
5 points

Some quirk of this version of Markdown I think.
Try putting two spaces at the end of a line before your single newline.

permalink
report
parent
reply
38 points
*

I’ve seen someone code that way. Not since high school, but that’s a way that some people think coding works when they start out writing code.

This person was trying to write a game in (trigger warning: nostalgia) QBasic and had it drawing kindof a Pacman kind of character. And in pseudocode basically what he was doing was:

// Draw character with mouth open at (100, 100)
moveCursorTo(100, 100)
drawLineFromCursorAndMoveCursor(116, 100)
drawLineFromCursorAndMoveCursor(108, 108)
drawLineFromCursorAndMoveCursor(116, 116)
drawLineFromCursorAndMoveCursor(100, 116)
drawLineFromCursorAndMoveCursor(100, 100)

// Wait for half a second.
sleepSeconds(0.5)

// Draw character with mouth closed at (101, 100)
moveCursorTo(101, 100)
drawLineFromCursorAndMoveCursor(109, 100)
drawLineFromCursorAndMoveCursor(117, 108)
drawLineFromCursorAndMoveCursor(109, 116)
drawLineFromCursorAndMoveCursor(101, 116)
drawLineFromCursorAndMoveCursor(101, 100)

// Wait for half a second.
sleepSeconds(0.5)

// Draw character with mouth open at (102, 100)
moveCursorTo(102, 100)
drawLineFromCursorAndMoveCursor(118, 100)
drawLineFromCursorAndMoveCursor(110, 108)
drawLineFromCursorAndMoveCursor(118, 116)
drawLineFromCursorAndMoveCursor(110, 116)
drawLineFromCursorAndMoveCursor(102, 100)

// Wait for half a second.
sleepSeconds(0.5)

...

He hadn’t gotten to the point of working in user controls. (Like “change direction to ‘up’ when user presses the ‘up’ key” or whatever.) And understandably had no idea how that would work if/when he got that far.

permalink
report
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 3.8K

    Monthly active users

  • 1.6K

    Posts

  • 36K

    Comments