Skip to content

Instantly share code, notes, and snippets.

@joeyv
Created November 1, 2013 17:36

Revisions

  1. joeyv created this gist Nov 1, 2013.
    74 changes: 74 additions & 0 deletions Sticks.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    import java.util.*;
    public class Sticks{

    public static void main(String []args){

    int sticks, maxStick = 0;
    int userStick = 0, compStick = 0;

    Scanner scan = new Scanner(System.in);
    Random generator = new Random();

    sticks = generator.nextInt(80) + 20;

    if (sticks >= 51){
    maxStick = 5;
    } else if (40 < sticks && sticks <= 50){
    maxStick = 4;
    } else if (30 < sticks && sticks <= 40){
    maxStick = 3;
    } else if (19 < sticks && sticks <= 30){
    maxStick = 2;
    }

    while (sticks >= 0){

    System.out.println ("There is " + sticks + " sticks in the pile.");
    System.out.println ("Take out 1 - " + "" + maxStick + ":");

    userStick = scan.nextInt();

    if (maxStick == 5){
    compStick = generator.nextInt(5) + 1;
    } else if (maxStick == 4){
    compStick = generator.nextInt(4) + 1;
    } else if (maxStick == 3){
    compStick = generator.nextInt(3) + 1;
    } else if (maxStick == 2){
    compStick = generator.nextInt(2) + 1;
    }

    if (userStick > maxStick){
    System.out.println ("Please pick a number 1 - " + "" + maxStick);
    }else {
    continue;
    }

    if (sticks == maxStick){
    compStick -= 1;
    }

    if (sticks == 2){
    compStick = 1;
    } else {
    sticks -= userStick;
    sticks -= compStick;
    }

    if ( compStick == userStick){
    sticks /= 2;
    } else {
    sticks -= userStick;
    sticks -= compStick;
    }

    System.out.println ((userStick) + " " + (compStick));





    }

    }
    }