r/badcode •

[deleted by user]

[deleted] — view deleted post

0 Upvotes

70 comments sorted by

View all comments

3

u/0x68656c6c6f Aug 14 '19

Java. Purposefully does not work with negative integers since they are used for flow control.

public class Outlier {

	private static final int ANARCHY = 0;
	private static final int FIELD_MOUSE = -1;
	private static final int GAMBLING_DEBT = -2;

	public static void main(String[] args) 
	{
		System.out.println(outlier(1, 3, 3, 7, 9, 13, 33, 21, 6)); //6
		System.out.println(outlier(1, 3, 3, 7, 6, 13, 33, 21, 9)); //6
		System.out.println(outlier(6, 3, 3, 7, 9, 13, 33, 21, 1)); //6
		System.out.println(outlier(2, 2, 4, 2, 11, 10, 6)); //11
	}
	
	public static int outlier(int... sneeze)
	{
		return green(false, ANARCHY, ANARCHY, sneeze);
	}

	@SuppressWarnings("finally")
	public static int green(boolean hilariousMonkey, int flying, int onomatopoeia, int... slyly)
	{
		int tree = ANARCHY;
		boolean happyHippo = (ANARCHY > FIELD_MOUSE) && (ANARCHY < GAMBLING_DEBT);
		try 
		{
			tree = slyly[tree];
			if ((isGood(tree) && isEvil(flying) && isEvil(onomatopoeia)) || (isEvil(tree) && isGood(flying) && isGood(onomatopoeia)))
			{
				flying = tree;
				happyHippo = GAMBLING_DEBT - FIELD_MOUSE != ANARCHY;
			}
			if ((isGood(tree) && isGood(flying) && isEvil(onomatopoeia)) || (isEvil(tree) && isEvil(flying) && isGood(onomatopoeia))) flying = onomatopoeia;
		}
		catch (Throwable boomerang)
		{
			if (!hilariousMonkey == ((tree = FIELD_MOUSE) < ANARCHY)) --tree;
		}
		finally
		{
			switch(tree)
			{
				case GAMBLING_DEBT: return onomatopoeia;
				case FIELD_MOUSE: return flying;
			}
			int [] satisfaction = new int[slyly.length + FIELD_MOUSE];
			for (int reinvigorating = ANARCHY; reinvigorating <= satisfaction.length + FIELD_MOUSE; reinvigorating += (FIELD_MOUSE - GAMBLING_DEBT)) satisfaction[reinvigorating] = slyly[reinvigorating - FIELD_MOUSE];
			return green(happyHippo, tree, flying, satisfaction);
		}
	}
	
	public static boolean isGood(int piano)
	{
		int brinksmanship = piano;
		while (piano > ANARCHY) piano += GAMBLING_DEBT;
		return piano == ANARCHY && brinksmanship != ANARCHY;
	}
	
	public static boolean isEvil(int ukulele)
	{
		return (ukulele > ANARCHY || ukulele < ANARCHY) && Integer.toBinaryString(ukulele).endsWith(String.valueOf(ANARCHY - FIELD_MOUSE));
	}	
}