CodeEval – Digit Statistics

Log in to view this post.

Posted in CodeEval, Java | Comments Off

CodeEval – Read More

Log in to view this post.

Posted in CodeEval, Java | Comments Off

CodeEval – Big Digits

Log in to view this post.

Posted in CodeEval, Java | Comments Off

CodeEval – Game Of Life

Log in to view this post.

Posted in CodeEval, Java | Comments Off

CodeEval – Nice Angles

Log in to view this post.

Posted in CodeEval, Java | Leave a comment

CodeEval – Guess The Number

Log in to view this post.

Posted in CodeEval, Java | Leave a comment

CodeEval – Card Number Validation

Log in to view this post.

Posted in CodeEval, Java | Leave a comment

CodeEval – Without Repetitions

Log in to view this post.

Posted in CodeEval, Java | Leave a comment

CodeEval – Slang Favor

Log in to view this post.

Posted in CodeEval, Java | Leave a comment

r/dailyprogrammer – [Easy] Roll the Dies

This is my solution to a programming challenge found at reddit.com/r/dailyprogrammer. This problem can be found at Roll the Dies.

Josh


public class Easy {
	public static void main(String[] args) {	
		for (int i : rollDice("4d6")) {		// example data
			System.out.print(i + " ");
		}
	}
	
	private static int[] rollDice(String s) {		
		String diceData[] = s.split("d");
		int[] result = new int[Integer.parseInt(diceData[0])];		
		for (int i = 0; i < result.length; i++) {
			result[i] = (int)(Math.random() * Integer.parseInt(diceData[1]) + 1);
		}		
		return result;
	}
}

Posted in Java, r/dailyprogrammer | Leave a comment