3 points

Of course there’s an easier way. Just integrate the state of the art API dedicated for this exact problem. https://isevenapi.xyz/

permalink
report
reply
3 points

This is confusing. I’m already using the iSeven API to determine if a number is 7. I’m getting a namespace collision error when I try to load this new API. Bug report filed.

permalink
report
parent
reply
2 points

You could do this in one line…

By removing all the linebreaks.

permalink
report
reply
1 point
*
Deleted by creator
permalink
report
parent
reply

modulo

pseudocode:

if number % 2 == 0
  return "number is even" (is_num_even = 1 or true)
else
  return "number is odd" (is_num_even = 0 or false)

plus you’d want an input validation beforehand

permalink
report
reply
1 point
*

who needs modulo when you can get less characters out of

while (number > 1) {
  number -= 2;
}
return number;

very efficient

edit: or theres the trusty iseven api

permalink
report
parent
reply
1 point

here is somewhat less:

return (number % 2) == 0;

permalink
report
parent
reply
1 point

return !(number & 1);

permalink
report
parent
reply
0 points
#You are an input. You have value! You matter!
if number % 2 == 0
  return "number is even" (is_num_even = 1 or true)
else
  return "number is odd" (is_num_even = 0 or false)

Am I doing it right? /S.

permalink
report
parent
reply
1 point

Don’t put nbsps in code blocks, they show up literally.

permalink
report
parent
reply
1 point

Modulo

permalink
report
reply
1 point

print(theJoke % you);

wooosh

permalink
report
parent
reply
1 point

I’m more of a Gemini myself

permalink
report
parent
reply
1 point

Back when I was learning programming a lot of lessons would make you do something like this, and then show you the real way to do it in the next lesson. My reaction was always “why didn’t you lead with this?”.

permalink
report
reply
2 points

You must see the pain before you confront it.

permalink
report
parent
reply
1 point

Because the point of the lesson is to demonstrate that you can solve the same problem multiple ways where some paths are more efficient than others.

Bad programmers are the ones that find the first solution and implement it no matter how inefficient it is.

Good programmers spend time on figuring out the solution with the least amount broken or inefficient code. You don’t learn this by jumping straight to the best answer every time.

permalink
report
parent
reply

Programming Horror

!programming_horror@programming.dev

Create post

Welcome to Programming Horror!

This is a place to share strange or terrible code you come across.

For more general memes about programming there’s also Programmer Humor.

Looking for mods. If youre interested in moderating the community feel free to dm @Ategon@programming.dev

Rules

  • Keep content in english
  • No advertisements (this includes both code in advertisements and advertisement in posts)
  • No generated code (a person has to have made it)

Credits

  • Icon base made by Lorc under CC BY 3.0 with modifications to add a gradient

Community stats

  • 328

    Monthly active users

  • 26

    Posts

  • 129

    Comments

Community moderators