this post was submitted on 01 Nov 2023
904 points (98.2% liked)

Lemmy Shitpost

26636 readers
3204 users here now

Welcome to Lemmy Shitpost. Here you can shitpost to your hearts content.

Anything and everything goes. Memes, Jokes, Vents and Banter. Though we still have to comply with lemmy.world instance rules. So behave!


Rules:

1. Be Respectful


Refrain from using harmful language pertaining to a protected characteristic: e.g. race, gender, sexuality, disability or religion.

Refrain from being argumentative when responding or commenting to posts/replies. Personal attacks are not welcome here.

...


2. No Illegal Content


Content that violates the law. Any post/comment found to be in breach of common law will be removed and given to the authorities if required.

That means:

-No promoting violence/threats against any individuals

-No CSA content or Revenge Porn

-No sharing private/personal information (Doxxing)

...


3. No Spam


Posting the same post, no matter the intent is against the rules.

-If you have posted content, please refrain from re-posting said content within this community.

-Do not spam posts with intent to harass, annoy, bully, advertise, scam or harm this community.

-No posting Scams/Advertisements/Phishing Links/IP Grabbers

-No Bots, Bots will be banned from the community.

...


4. No Porn/ExplicitContent


-Do not post explicit content. Lemmy.World is not the instance for NSFW content.

-Do not post Gore or Shock Content.

...


5. No Enciting Harassment,Brigading, Doxxing or Witch Hunts


-Do not Brigade other Communities

-No calls to action against other communities/users within Lemmy or outside of Lemmy.

-No Witch Hunts against users/communities.

-No content that harasses members within or outside of the community.

...


6. NSFW should be behind NSFW tags.


-Content that is NSFW should be behind NSFW tags.

-Content that might be distressing should be kept behind NSFW tags.

...

If you see content that is a breach of the rules, please flag and report the comment and a moderator will take action where they can.


Also check out:

Partnered Communities:

1.Memes

2.Lemmy Review

3.Mildly Infuriating

4.Lemmy Be Wholesome

5.No Stupid Questions

6.You Should Know

7.Comedy Heaven

8.Credible Defense

9.Ten Forward

10.LinuxMemes (Linux themed memes)


Reach out to

All communities included on the sidebar are to be made in compliance with the instance rules. Striker

founded 1 year ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] Rentlar@lemmy.ca 105 points 1 year ago* (last edited 1 year ago) (4 children)

They call me a StackOverflow expert:

private bool isEven(int num) {
if (num == 0) return true;
if (num == 1) return false;
if (num < 0) return isEven(-1 * num);
return isEven(num - 2);
}
[–] nyoooom@lemmy.world 35 points 1 year ago (1 children)
bool isEven(int num) {
 return num == 0 || !isEven(num - (num > 0 ? 1 : -1));
}
load more comments (1 replies)
[–] Johanno@feddit.de 16 points 1 year ago* (last edited 1 year ago)

StackoverflowException.

What do I do now?

Nvm. Got it.

  if(num % 2 == 0){
       int num1 = num/2
       int num2 = num/2
       return isEven(num1) && isEven(num2)   
  } 

if(num % 3 == 0){
      int num1 = num/3
      int num2 = num/3
      int num3 = num/3
      return isEven(num1) && isEven(num2) && isEven(num3) 
}

Obviously we need to check each part of the division to make sure if they are even or not. /s

load more comments (2 replies)
[–] snek@lemmy.world 86 points 1 year ago* (last edited 1 year ago) (2 children)

I shit you not but one coworker I had dared call himself a data scientist and did something really similar to this but in Python and in production code. He should never have been hired. Coding in python was a requirement. I spent a good year sorting out through his spaghetti code and eventually rebuilt everything he had been working on because it was so bad that it only worked on his computer and he always pip freezes all requirements, and since he never used a virtual environment that meant we got a list of ALL packages he had installed on pip for a project. Out of those 100, only about 20 were relevant to the project.

[–] surewhynotlem@lemmy.world 48 points 1 year ago (2 children)

In prod??

Listen up folks. This is why we do code reviews. This right here.

[–] herrvogel@lemmy.world 16 points 1 year ago* (last edited 1 year ago)

Code reviews mean fuck all when the "senior" developer doing the review is someone who implements an entire API endpoint group in one single thousand-something lines magic function that is impossible to decipher for mere humans.

load more comments (1 replies)
load more comments (1 replies)
[–] Agent641@lemmy.world 79 points 1 year ago* (last edited 1 year ago) (1 children)

Just print True all the time. Half the time it will be correct and the client will be happy, and the other half the time, they will open a ticket that will be marked as duplicate and closed.

[–] Rouxibeau@lemmy.world 24 points 1 year ago (1 children)

Reminds me of the fake thermometers being sold during the peak of COVID that weren't actually thermometers but just displayed numbers to make people think they were.

load more comments (1 replies)
[–] Skyline969@lemmy.ca 67 points 1 year ago* (last edited 1 year ago) (1 children)

Wow. Amateur hour over here. There's a much easier way to write this.

A case select:

select(number){
    case 1:
        return false;
    case 2:
        return true;
}

And so on.

[–] robotica@lemmy.world 13 points 1 year ago* (last edited 1 year ago) (1 children)

Don't forget that you can have fall-through cases, so you can simplify it even further:

switch (number) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 9:
      ...
load more comments (1 replies)
[–] lobut@lemmy.ca 45 points 1 year ago (1 children)

Just do a while loop and subtract 2 if it's positive or plus 2 is it's negative until it reaches 1 or 0 and that's how you know, easy! /s

[–] KoboldCoterie@pawb.social 48 points 1 year ago (5 children)

God, it's so obvious, you can do it in only two lines of code.

if (number == 1 || number == 3 || number == 5 || number == 7 || number == 9...) return false;
else return true;
load more comments (5 replies)
[–] ParsnipWitch@feddit.de 41 points 1 year ago (1 children)

The number of comments posting a better solution is funny and somewhat concerning.

[–] elauso@feddit.de 24 points 1 year ago

Yeah, "just use modulo" - no shit, you must be some kind of master programmer

[–] Enkers@sh.itjust.works 41 points 1 year ago* (last edited 1 year ago) (3 children)

This is your brain on python:

def is_even (num):
     return num in [x*2 for x in range(sys.maxsize / 2)]
load more comments (3 replies)
[–] affiliate@lemmy.world 40 points 1 year ago (4 children)

amateurs

def is_even(n: int):
    if n ==0:
        return True
    elif n < 0:
        return is_even(-n)
    else:
        return not is_even(n-1)
[–] affiliate@lemmy.world 27 points 1 year ago (1 children)

here's a constant time solution:

def is_even(n: int):
    import math
    return sum(math.floor(abs(math.cos(math.pi/2 * n/i))) for i in range(1, 2 ** 63)) > 0

spoileri can't imagine how long it'll take to run, my computer took over 3 minutes to compute one value when the upper bound was replaced with 2^30^. but hey, at least it's O(1).

load more comments (1 replies)
load more comments (3 replies)
[–] rollerbang@sopuli.xyz 33 points 1 year ago* (last edited 1 year ago)

You have to make it easy on yourself and just use a switch with default true for evens, then handle all the odd numbers in individual cases. There, cut your workload in half.

[–] CancerMancer@sh.itjust.works 28 points 1 year ago (2 children)

Because YandereDev is a legendary moron I can't even tell if this is a joke or not.

[–] mob@lemmy.world 16 points 1 year ago (3 children)

How do you think even/odd detectors work? A team of coders has been working on this else if for years...

If you want to help

https://github.com/samuelmarina/is-even

load more comments (3 replies)
load more comments (1 replies)
[–] Karyoplasma@discuss.tchncs.de 28 points 1 year ago (4 children)
while (true){
    if (number == 0) return true;
    if (number == 1) return false;
    number -= 2
}
[–] SamBBMe@lemmy.world 12 points 1 year ago

return !(number % 2)

load more comments (3 replies)
[–] DarkMessiah@lemmy.world 27 points 1 year ago* (last edited 1 year ago) (13 children)

Just in case anyone was looking for a decent way to do it...

if (((number/2) - round(number/2)) == 0) return true;

return false;

Or whatever the rounding function is in your language of choice.

EDIT: removed unnecessary else.

[–] AnxiousOtter@lemmy.world 20 points 1 year ago

Modulo operator my dude.

[–] Acters@lemmy.world 16 points 1 year ago* (last edited 1 year ago)

Every bit aside for the ones bit is even. All you have to do is get the ones bit(the far right) for it being a 1 or 0. Which is the fastest and least amount of code needed.

use bitwise &

// n&1 is true, then odd, or !n&1 is true for even  

 return (!(n & 1));  
load more comments (11 replies)
[–] WhiskyTangoFoxtrot@lemmy.world 26 points 1 year ago (1 children)

Just do npm install isEven and don't worry about it.

[–] where_am_i@sh.itjust.works 15 points 1 year ago (1 children)

looks like it depends on isOdd, which is unmaintained. I have a dependency conflict, what should I do?

load more comments (1 replies)
[–] Smacks@lemmy.world 26 points 1 year ago

Still some of YandereDev's best code

[–] levi@aussie.zone 25 points 1 year ago (13 children)

Oh man, in js we have a package for this magic.

load more comments (13 replies)
[–] BeigeAgenda@lemmy.ca 24 points 1 year ago (22 children)

Good job my young padawan, let me teach you about the modulo operator ...

load more comments (22 replies)
[–] kamen@lemmy.world 23 points 1 year ago (3 children)

Plot twist: it's generated code for the purpose of the joke.

[–] ICastFist@programming.dev 33 points 1 year ago (1 children)

Being yandere dev, that's likely the actual code

load more comments (1 replies)
load more comments (2 replies)
[–] GoosLife@lemmy.world 23 points 1 year ago* (last edited 1 year ago) (1 children)

There is absolutely no need to add a check for each individual number, just do this:

#include 
#include 


int main()
{
	int number = 0;
	int numberToAdd = 1;
	int modifier = 1;

	std::cout << "Is your number [p]ositive or [n]egative? (Default: positive)\n";
	if (std::cin.get() == 'n') {
		modifier *= -1;
	}

	std::cin.ignore(std::numeric_limits::max(), '\n'); // Clear the input buffer

	bool isEven = true;
	bool running = true;

	while (running) {
		std::cout << number << " is " << (isEven ? "even" : "odd") << ".\n";
		std::cout << "Continue? [y/n] (Default: yes)\n";

		if (std::cin.peek() == 'n') {
			running = false;
		}

		number += numberToAdd * modifier;
		isEven = !isEven;

		std::cin.ignore(std::numeric_limits::max(), '\n');
	}

	std::cout << "Your number, " << number << " was " << (isEven ? "even" : "odd") << ".\n";
}```
[–] trashgirlfriend@lemmy.world 12 points 1 year ago (2 children)
load more comments (2 replies)
[–] dwalin@lemmy.world 21 points 1 year ago

Just do a recursive funcion subtracting 2 and stoping on -1 or 0. Easy

[–] callyral@pawb.social 18 points 1 year ago (1 children)

number == 0 is not handled

load more comments (1 replies)
[–] Iceman@lemmy.ca 18 points 1 year ago

OMG they can’t even!

[–] Scubus@sh.itjust.works 16 points 1 year ago (2 children)

string taco = variable.ToString()[variable.ToString().Length - 1];

If (taco == "0" || taco == "2" || taco == "4" || taco == "6" || taco == "8")

return true;

else

return false;

Im something of a coding master myself

load more comments (2 replies)
[–] luthis@lemmy.nz 15 points 1 year ago (1 children)

Ok looks like this might be the source, and I suspect it is actually satirical. Not yanderedev, but yeah... wouldn't put it past him.

https://www.reddit.com/r/ProgrammerHumor/comments/i15h4d/iseven/

load more comments (1 replies)
[–] UNWILLING_PARTICIPANT@sh.itjust.works 14 points 1 year ago (1 children)

We're too swamped for that kind of thinking. Just keep typing or we'll never make our release window

load more comments (1 replies)
[–] Iron_Lynx@lemmy.world 13 points 1 year ago (1 children)

Even the shitposty better version has us:

  • take the absolute value of the input as a variable
  • while that variable is >1, subtract 2. Repeat until this is no longer true
  • if it's now 1, return true. Otherwise, return false.
load more comments (1 replies)
[–] jsdz@lemmy.ml 13 points 1 year ago* (last edited 1 year ago) (3 children)
int is_even(int n)
{
    int result = -1;
    char number[8]; //should be enough
    sprintf(number, "%d", n);

    // check the number
    // TODO: handle negative numbers
    for (char *p=number; *p; p++)
    {
        if (*p=='0' || *p=='2' || *p=='4' || *p=='6' || *p=='8')
            result = 1;
        else if (*p=='1' || *p=='3' || *p=='5' || *p=='7' || *p=='9')
            result = 0;
        else {
           fprintf(stderr, "Your number is wrong!\n");
           exit(1); 
        }
    }
    return result;
}
load more comments (3 replies)
[–] Zaphod@discuss.tchncs.de 12 points 1 year ago (5 children)
[–] luthis@lemmy.nz 15 points 1 year ago

From what I've heard about yanderedev... it's possible this is actually real.

load more comments (4 replies)
load more comments
view more: next ›