r/shittyprogramming • • May 03 '21

How can it be illegal to have cp on my computer? Coreutils is free software, isn't it?

74 Upvotes

r/shittyprogramming • • May 02 '21

Tower of Code: isEven(n)

106 Upvotes

Welcome to Tower of Code! In Tower of Code, the goal is to make code such that each line is smaller than the next, whilst being as tall as possible. For a simple example, the following function, which just returns true, is a valid tower:

         function t(){
        {{{{{{{{{{{{{{{
       {{{{{{{{{{{{{{{{{
      {{return true;}}}}}
     }}}}}}}}}}}}}}}}}}}}}
    }}}}}}}}};;;;;;;;;;;;;;

Your goal is to make a tower for the isEven function, which has the following specification:

        _____                   __       __
 ()     | __|                  / /       \ \
 __  __ | |_¯__  __ __  __    | /  __     \ |
 || / _)| _| \ \/ // _\ | ¯¯\ { }  | ¯¯\  { }
 || _¯\| __ \  / |{_/ ||¯|| | \  ||¯||  / |
 || (¯ /|   |  \/  \  ¯)|| ||  \ \ || || / /
 ¯¯  ¯¯ ¯¯¯¯¯       ¯¯¯ ¯¯ ¯¯   ¯¯ ¯¯ ¯¯ ¯¯
   /====================================\
   |   Determines if a number is even   |
   |-----------------.------------------|
   |   Example Input | Example Output   |
   |-----------------+------------------|
   |              12 |             true |
   |              35 |            false |
   |              56 |             true |
   |              73 |            false |
   |              92 |             true |
   |             147 |            false |
   \====================================/

Rules for towers:

  1. Every line must be smaller (have fewer characters) than the next
  2. To be a tower, it must be at least 6 lines tall
  3. The code must work reliably
  4. Good style is encouraged, but should not get in the way of towering.

r/shittyprogramming • • May 01 '21

Proposed names for no op instructions

94 Upvotes

On architectures that support variable length no op instructions, I propose the number of bytes the instruction occupies be equal to number of "o"s in the name:

InstructionLength
NOP1 byte
NOOP2 bytes
......
NOOOOOOOOOP9 bytes
......

r/shittyprogramming • • Apr 30 '21

It's just my preference

Thumbnail
youtu.be
78 Upvotes

r/shittyprogramming • • Apr 29 '21

Why specify the 0 if it's the default?

Post image
169 Upvotes

r/shittyprogramming • • Apr 28 '21

What text editor do you use?

29 Upvotes

r/shittyprogramming • • Apr 27 '21

Volvo how

Post image
501 Upvotes

r/shittyprogramming • • Apr 27 '21

I wrote a program to draw a diamond using the "tail" language.

10 Upvotes

The syntax of this language is so simple anyone can master it in seconds!

#! /usr/bin/tail -n+2
  *
 ***
*****
 ***
  *

r/shittyprogramming • • Apr 27 '21

5 Line "is_even" Function

9 Upvotes

I've attempted to solve the infamous "is even" problem, and I've come up with something that is both short (only 5 lines), and extremely fast (I tested with the number 99999999 and it only takes about 0.1 seconds)

behold:

def is_even(num):
    if num%2 == 0:
        print('Even Number')
    else:
        print('Odd')

r/shittyprogramming • • Apr 27 '21

A thing I like to do whenenever I'm bored

67 Upvotes

When I'm bored, I like to fullscreen on a site with a bunch of clickable stuff like youtube, full screen the browser and run the following code:

import pyautogui, random
Resolution = (1920,1080)
pyautogui.FAILSAFE = False #Safety is boring

for times in range(0,1000):
    x = random.choice(range(0,Resolution[0]))
    y = random.choice(range(0,Resolution[1]))
    pyautogui.click(x,y)

r/shittyprogramming • • Apr 23 '21

How to get the speed of C and the awesome syntax of Brainfuck at the same time

Post image
177 Upvotes

r/shittyprogramming • • Apr 23 '21

I've increased my typing speed loads but my code still runs slow - what gives?

18 Upvotes

r/shittyprogramming • • Apr 22 '21

If Youtube created their own IDE

Thumbnail
youtu.be
72 Upvotes

r/shittyprogramming • • Apr 21 '21

We need a leetcode Elite category

6 Upvotes

It's too easy to get into FAANG nowadays and we need to weed out the newbs even more. So I propose a new category of leetcode questions called Elite where the problems are yet to be solved by world experts

EG

  • Write an algorithm to solve Cancer in O(n)
  • Create a data structure to store all your hopes and dreams that can be retrieved in O(1)
  • Write an SQL query to ban all FAANG-sexual users in r/cscareerquestions in O(logn) (or just asap because I can't stand them anymore)

r/shittyprogramming • • Apr 20 '21

Thought I'd share my extensible fizzbuzz solution in C.

55 Upvotes
main(i,v) {
	for (i=0;;i++,v=0) {
		if (i % 3 == 0)
			v+=1;
		if (i % 5 == 0)
			v+=2;
		switch(v) {
			case 0:
				printf("%d\n", i);
				break;
			case 1:
				printf("Fizz\n");
				break;
			case 2:
				printf("Buzz\n");
				break;
			case 3:
				printf("Fizzbuzz\n");
				break;
		}
	}

And here it is extended for fizzbuzzbazz, a new game I just invented.

main(i,v) {
	for (i=0;;i++,v=0) {
		if (i % 3 == 0)
			v+=1;
		if (i % 5 == 0)
			v+=2;
		if (i % 7 == 0)
			v+=4;
		switch(v) {
			case 0:
				printf("%d\n", i);
				break;
			case 1:
				printf("Fizz\n");
				break;
			case 2:
				printf("Buzz\n");
				break;
			case 3:
				printf("FizzBuzz\n");
				break;
			case 4:
				printf("Bazz\n");
				break;
			case 5:
				printf("FizzBazz\n");
				break;
			case 6:
				printf("BuzzBazz\n");
				break;
			case 7:
				printf("FizzBuzzBazz\n"):
				break;
		}
	}
}

r/shittyprogramming • • Apr 20 '21

An Arduino to Determine When you cheat on a Maze

Thumbnail
youtube.com
5 Upvotes

r/shittyprogramming • • Apr 19 '21

7 line "is even" function 🤯

190 Upvotes

I've attempted to solve the infamous "is even" problem, and I've come up with something that is both short (only 7 lines), and extremely fast (I tested with the number 99999999 and it only takes about 3 seconds)

behold:

def is_even(num):
    s = "\\"
    try:
        eval(f"\"{s*num}\"")
        return True
    except SyntaxError:
        return False

how did I make it so fast?

a few ways:

  • it's written in python.
  • it uses eval, one of python's fastest functions
  • it uses strings, which are faster than numbers (the only number this code relies on is the input one...)
  • it makes use of the little-known "\" operator, which is one of the fastest operators in python

replit: https://replit.com/@lllllllllllllol/iseven


r/shittyprogramming • • Apr 16 '21

The "f" is for "fast" 😎

Post image
195 Upvotes

r/shittyprogramming • • Apr 15 '21

I decided to tackle the infamous IsEven() problem. I can't think of the part I'm most proud of.

Post image
129 Upvotes

r/shittyprogramming • • Apr 16 '21

Thought I would share my solution for fizzbuzz in Python if anyone else needs it for an interview

13 Upvotes

[print(i) for i in ["fizzbuzz" if not None in i else "fizz" if i[1] is not None else "buzz" if i[1] is not None else i[2] for i in zip(["fizz" if i % 3 == 0 else None for i in range(1, 101)], ["buzz" if i % 5 == 0 else None for i in range(1, 101)], [i for i in range(1, 101)])]]


r/shittyprogramming • • Apr 15 '21

Useful function for validating that a number falls within a range

45 Upvotes

Today I needed to check if the number a user entered into a textbox was between "0" and "999". The below code yields the correct result for any value that I could think to test. (Empty string is treated as valid, since "required" is a different validation step)

function validateRange(value, minimum, maximum) {
  for(let i = 0; i < value.length; i++) {
    if(value[i] < minimum[i]) {
      return false;
    }
    if(!(value[i] <= maximum[i])) {
      return false;
    }
  }
  return true;
}

I hope you find this function useful in your own projects.

Demo


r/shittyprogramming • • Apr 14 '21

<wrong_sub>this</wrong_sup> The fastest way to clean up disk space on server

Thumbnail
hinty.io
31 Upvotes

r/shittyprogramming • • Apr 14 '21

Why do people say c# isn't a low level language?

Post image
127 Upvotes

r/shittyprogramming • • Apr 12 '21

Stop compiler abuse

113 Upvotes

Every day, compilers are forced to convert addition into the proper xors and bit shifts, Together, we can stop this problem. Instead of using the addition operator, use this function instead:

int recursiveAdd(int a, int b) {
        int xor = a ^ b;
        int and = (a & b) << 1;
        if (and != 0)
                return recursiveAdd(xor, and);
        return xor;
}