public class PracticeTest2015
{
	public static void main(String [] args)
	{
		PracticeTest2015 run = new PracticeTest2015();
		run.doSandP();
		run.doMax1020();
		run.doRelativelyPrime();
		run.doSecret();
	}
	
	public void doSandP()
	{
		System.out.println("\n\n\nSandP\n");
		sAndp(12,15);
	}
	
	public void sAndp(int S, int p)
	{
		boolean firstTime = true;
		do
		{
			if(!firstTime)
			{
				p += 2;
			}
			firstTime = false;
			System.out.printf("%5d%5d%n",S,p);
			if(p % 2 == 0)
			{
				p++;
			}
			if(isPrime(p))
			{
				if(p < S)
				{
					S = S - p;
				}
				else
				{
					S = S - 1;
				}
			}
		}while(S != 0);
		System.out.printf("%n%5d%5d%n",S,p);
	}
	
	public boolean isPrime(int value)
	{
		for(int i = 2; i < value; i++)
		{
			if(value % i == 0)
			{
				return false;
			}
		}
		return true;
	}
	
	public void doMax1020()
	{
		System.out.println("\n\n\nmax1020\n");
		System.out.println("11 and 19 -> " + max1020(11,19));
		System.out.println("20 and 7  -> " + max1020(20,7));
		System.out.println("9 and 21  -> " + max1020(9,21));
		System.out.println("19 and 21 -> " + max1020(19,21));
		System.out.println("3 and 20  -> " + max1020(3,20));
		System.out.println("15 and 13 -> " + max1020(15,13));
		System.out.println("29 and 21 -> " + max1020(29,21));
		System.out.println("9 and 1   -> " + max1020(9,1));
	}
	
	public int max1020(int a, int b)
	{
		if((a > 20 || a < 10) && (b > 20 || b < 10))
		{
			return 0;
		}
		else if(a > 20 || a < 10)
		{
			return b;
		}
		else if(b > 20 || b < 10)
		{
			return a;
		}
		else if (b > a)
		{
			return b;
		}
		return a;
	}
	
	public void doRelativelyPrime()
	{
		System.out.println("\n\n\nrelativelyPrime\n");
		System.out.println("7 and 15    -> " + relativelyPrime(7,15));
		System.out.println("14 and 49   -> " + relativelyPrime(14,49));
		System.out.println("20 and 100  -> " + relativelyPrime(20,100));
		System.out.println("8 and 21    -> " + relativelyPrime(8,21));
		System.out.println("1 and 200   -> " + relativelyPrime(1,200));
		System.out.println("2 and 200   -> " + relativelyPrime(2,200));
		System.out.println("143 and 156 -> " + relativelyPrime(143,156));
	}
	
	public boolean relativelyPrime(int x, int y)
	{
		while(x != y)
		{
			if(x > y)
			{
				x = x - y;
			}
			else
			{
				y = y - x;
			}
		}
		if(x == 1)
		{
			return true;
		}
		return false;
	}
	
	public void doSecret()
	{
		System.out.println("\n\n\nsecret\n");
		secret(20,3);
		System.out.println("\n\n\n");
	}
	
	public void secret(int a, int b)
	{
		while(a % b != 0)
		{
			System.out.println(a + "   " + b);
			if(a > b)
			{
				a = a - b;
			}
			else
			{
				a = a - 1;
			}
		}
		a = a - 1;
		System.out.println(a + "   " + b);
	}
}

/*

SandP

   12   15
   12   17
   11   19
   10   21
   10   23
    9   25
    9   27
    9   29
    8   31
    7   33
    7   35
    7   37
    6   39
    6   41
    5   43
    4   45
    4   47
    3   49
    3   51
    3   53
    2   55
    2   57
    2   59
    1   61

    0   61



max1020

11 and 19 -> 19
20 and 7  -> 20
9 and 21  -> 0
19 and 21 -> 19
3 and 20  -> 20
15 and 13 -> 15
29 and 21 -> 0
9 and 1   -> 0



relativelyPrime

7 and 15    -> true
14 and 49   -> false
20 and 100  -> false
8 and 21    -> true
1 and 200   -> true
2 and 200   -> false
143 and 156 -> false



secret

20   3
17   3
14   3
11   3
8   3
5   3
2   3
1   3
-1   3

*/

Back to APCS Main Page