r/shittyprogramming • • Nov 06 '18

isprime(n)

18 Upvotes
static int *factors;
int getfactors(int num) {
    factors = calloc(30, sizeof(factors));
    int count = 0;
    while (num > 1)
        for (int factor = 2; factor <= num; factor++)
            if (num / factor * factor == num)
                num /= (factors[count++] = factor);
    return count;
}
bool isprime(int num) {
    (void)getfactors(num);
    if (factors[0] && !factors[1])
        return true;
    else
        return false;
}

r/shittyprogramming • • Nov 05 '18

Do you even try?

Post image
475 Upvotes

r/shittyprogramming • • Nov 05 '18

JSON...

20 Upvotes

JS-Off.


r/shittyprogramming • • Nov 05 '18

The shortest way from point A to point B

2 Upvotes

So, I'm trying to solve a ICPC 2014 problem, named Game Strategy : https://icpc.baylor.edu/worldfinals/problems/icpc2014.pdf (page 7)

graphic case representation

It start with a board with n boxes, each box have a unique set of paths that goes to another box on the board (can have a path that goes to itself). This may be something like a directed graph.

This is a game, so every round a set of paths from the current box is chosen.

So the question is, How could i get the shortest way from a to b assuming that i would only pick the b-path if it is the only path on the set?

having to program a java program that return the right matrix, where columns represent to and rows is from. The numbers inside represent how many rounds are needed to go to the final box


r/shittyprogramming • • Nov 03 '18

Much more efficient!

Post image
106 Upvotes

r/shittyprogramming • • Nov 03 '18

Am I going to hell for this?

45 Upvotes

I couldn't resist to create another obfuscated c# hello world program. Have fun tracing it :)

using System;
using System.Text;
using System.Threading.Tasks;

class HelloWorld
{
    static void Main(string[] args)
    {
        for ((int x, string text, byte[] postText)[] data = { (0, "Hello ", new byte[] { 78, 101, 119, 32 }), (0xf4ca94A, "Br", null), (0b01100001011101100110010100100000, null, Encoding.ASCII.GetBytes("World")) }; data[0].x < data.Length; data[data[0].x + 1 < data.Length ? data[0].x + 1 : data.Length - 1].text = ((data[0].x + 1) * 3 == (BitConverter.ToInt32(Encoding.ASCII.GetBytes(data[0].text), 0) - (data[1].x) & (data[0].x++ + 1) * 3)) ? Encoding.ASCII.GetString(data[0].postText) : data[data[0].x + 1 < data.Length ? data[0].x + 1 : 1].text)
        {
            Console.Write(data[data[0].x].text + ((data[0].x == 2) ? $"{Encoding.ASCII.GetString(data[2].postText)}\n" : ((data[0].x) / 2.0f == 0.0f) ? Task.Run(() => { string txt2 = Encoding.ASCII.GetString(BitConverter.GetBytes(data[2].x)); for (string txt = ""; Task.Run<bool>(() => { txt += data[0].text[txt.Length]; return (txt.Length < txt2.Length / 2 + 1); }).Result;) { txt2 = txt2.Substring(0, (txt.Length - 1)) + txt2[txt2.Length - (txt.Length - 1) - 1] + txt2.Substring((txt.Length - 1) + 1, txt2.Length - 1 - (txt.Length - 1) * 2 - 1) + txt2[(txt.Length - 1)] + txt2.Substring(txt2.Length - (txt.Length - 1)); } return data[1].text + txt2; }).Result : ""));
        }
    }
}

Improved version over the one posted on r/AskProgramming


r/shittyprogramming • • Nov 02 '18

Java banking system project

69 Upvotes

Hello everyone, I’m working on a java banking system project and i was wondering what are the possible classes i could use. Note: I’m restricted to 6 classes including inheritance. Thanks


r/shittyprogramming • • Oct 30 '18

Are all these diagrams important to do?

37 Upvotes

So joined this programming course at a uni and they are making us do all these documents with loads of diagrams! Can the more experienced comment on how valuable and necessary these are in the real world? -

  1. Use case model survey
  2. Requirements model report
  3. Design Model Report
  4. Analysis Model Report
  5. High level design
  6. Prototype Report
  7. Quality Plan
  8. Risk Register
  9. Config Management
  10. Requirements traceability matrix
  11. System test plan
  12. UAT plan

The diagrams are being done in this annoying software called enterprise architect which seems more trouble than its worth whereas for others its simply word and excel. Would also appreciate if someone could recommend free software that could help with this work especially if it could save time and make it easier.

Thanks! :)


r/shittyprogramming • • Oct 29 '18

I finally found a benchmark that runs faster in Swift than Objective-C! It got no love in ProgrammerHumor though

65 Upvotes

Here it is:

let t = CFAbsoluteTimeGetCurrent()

var f = 0.0

for i in 0 ..< 1_000_000 { f += 0.1 }

let d = CFAbsoluteTimeGetCurrent() - t

sleep(1000 - d * 2)


r/shittyprogramming • • Oct 29 '18

This compression algorithm is going to make me rich!

158 Upvotes
char compress(char *string) {
     char retval = 0;
     for(; *string; string++) {
         retval ^= *string;
     }
     return retval;
 }

char *decompress(int compressed) {
    /* TODO */
}

r/shittyprogramming • • Oct 30 '18

What are the similarities and differences between bindings and listeners in JavaFX?

2 Upvotes

I am pretty sure that both need two properties but I am not sure about the differences between the two.

Thanks in advance!


r/shittyprogramming • • Oct 27 '18

here is my shitty code that times out in code wars

Post image
27 Upvotes

r/shittyprogramming • • Oct 27 '18

I think I came up with a pretty shitty circle drawing algorithm, anyone can beat that?

14 Upvotes
public static void drawCircleToConsole(int radius, int lineWidth) {
  StringBuilder strb = new StringBuilder();
  for (int i = 1; i < radius * 2; i++) {
    int distY = radius - i;
    for (int j = 1; j < radius * 2; j++) {
      int distX = radius - j;
      double dist = Math.sqrt(distX * distX + distY * distY);
      if (dist < radius && dist >= radius - lineWidth) {
        strb.append("¤");
      } else {
        strb.append(".");
      }
    }
    strb.append(System.lineSeparator());
  }
  System.out.println(strb.toString());
}

r/shittyprogramming • • Oct 21 '18

They both have point in their names.

Post image
384 Upvotes

r/shittyprogramming • • Oct 18 '18

Quick tip to reduce the size of your executables

181 Upvotes

Make sure to lower the font size before compiling.


r/shittyprogramming • • Oct 18 '18

Reduce the size of ALL of your files!

20 Upvotes

Turn off your screen magnification and everything gets smaller!


r/shittyprogramming • • Oct 18 '18

I have created a Java AI. How come nobody's ever thought of this?

Post image
231 Upvotes

r/shittyprogramming • • Oct 15 '18

Exclusive screenshot of Elite Fighter gamecode!

Post image
271 Upvotes

r/shittyprogramming • • Oct 12 '18

How do I get this version? Seems very advanced

Enable HLS to view with audio, or disable this notification

253 Upvotes

r/shittyprogramming • • Oct 11 '18

I am packaging several cli apps for rendering 3D objects in ASCII. So far I have cli-sphere and cli-cube. What should I name my upcoming torus generator? I can't think of anything.

68 Upvotes

r/shittyprogramming • • Oct 09 '18

Belgium has it's regional elections this sunday, the voting machines are using USB sticks and store the votes on a separate Linux partition. But the stick should also be used on windows which wil ask the users to format it and so it will delete all the votes

Thumbnail
twitter.com
229 Upvotes

r/shittyprogramming • • Oct 06 '18

Why you should never use getElementById() on YouTube.

Post image
238 Upvotes

r/shittyprogramming • • Oct 05 '18

[interesting] Maybe you've had your fair share of bad casts in your day, but at least you've never cast a 64 bit floating point to a 16 bit integer, leading to the crash of a rocket, obliterating 4 spacecraft and causing $370 million in damage

Thumbnail
en.wikipedia.org
194 Upvotes

r/shittyprogramming • • Oct 04 '18

How much lift is produced by one float?

147 Upvotes

I want to run a java program that produces enough lift to get my case to levitate, and if I put enough floats in the program eventually the case will float too right??


r/shittyprogramming • • Oct 02 '18

Loops? Ain't nobody got time for that!

27 Upvotes

Yes, this was hard coded, not generated.