Tries to write Pi using your computer’s CPU. There are many ways to approach this problem, but we wanted a solution that was fairly easy to understand and was readily adaptable to different hardware. In the past few months we have been working on some algorithms and code, with the goal of optimizing this script so that it tries all available combinations before outputting an answer. We believe we have found a solution that will be useful for other programmers trying to do the same thing. Currently this is a

public class Pi {

public static void main(String[] args) {

int max = 1_000_000;

int increment = max / 8;

long startTime = System.currentTimeMillis();

//int stopTime = System.currentTimeMillis() – startTime;

int counter = 0;

while (counter <= max) { String s = ""; for (int i = 0; i < counter; i++) { s += "0"; } if (s.equals(reverse(s))) { System.out.println(counter + "/" + max); } else { if (counter % increment == 0) { // Print every 8th number. This is just for debugging purposes, and you can remove this in your own code if you want. System.out.println(counter); // This line outputs the current number we're trying to reverse to see if it's a palindrome or not. You can comment this out or delete it if you want, but I like to leave it in for debugging purposes because it helps me get a feel for where my program is import java.io.*; import java.util.ArrayList; import java.util.Random; public class Main { static int n; static int[] a; static int[] b; static ArrayList arr = new ArrayList();

static Random r = new Random();

public static void main(String[] args) throws IOException {

n = Integer.parseInt(args[0]);

a = new int[n];

b = new int[n];

for (int i = 0; i < n; i++) { a[i] = r.nextInt(10); b[i] = r.nextInt(10); arr.add(a[i]);arr.add(b[i]); if (i != 0) { // not the first digit of pi, so we need to insert a comma or period into the current digit, as appropriate for its place in pi's decimal expansion if (i == 1) arr.add(1); // decimal point before second digit of pi: 3.,1415... else if ( public static void main(String[] args) { int j; for(j=1;j<10;j++) { System.out.print(""+j); if(j==9) { break; }else { System.out.print(" "); } }//end for loop for one side of Pi System.out.print(" 3.");//Print the decimal point after the 1st digit of Pi. //count from 0 to 9,999,999 while also checking if it is a palindrome or not. int palindromeCheck = 0;//counter for while loop while(palindromeCheck < 9999999)//will run through 9999999 numbers and see if it's a palindrome or not and then print it out if it is a palindrome. { //convert integer to string String integerToString = Integer.toString(palindromeCheck);//convert palindromeCheck (int) to (string) so we can check if it is a palindrome or not public class Palindrome { public static void main (String[] args) { int x = 999; int y = 999; int largest = 0; Boolean found = false; while (x>100 && y>100) {

if (isPalindrome(x*y)) {

largest = x*y;

found = true;

break;

} else if (x%11==0){ // if x is divisible by 11, no need to check all of the combinations. Only those that are divisible by 11 and vice versa. This optimizes the program to run faster.

y–; // move down to the next number.

} else { // otherwise check all of the combinations until we find the lowest number that is a palindrome. Then move down 1, and repeat.

x–; // move left to the previous number.

}

}

System.out.println(“The largest palindrome is: ” + largest); // output our result! } public static Boolean isPalindrome(int n) { // method to determine whether or not a number is a palindrome int i=0,j=0,k=0;

public class Palindrome

{

public static void main(String[] args) {

String str;

int len, i, palindrome, count = 0;

boolean isPalindrome = false;

//Read the string from the keyboard

System.out.print(“Enter any string : “);

str = new Scanner(System.in).nextLine();

//Convert the string into lowercase

str = str.toLowerCase();

//Remove all whitespaces from the string

str = str.replaceAll(“\\s”, “”);

//Find the length of the string

len = str.length();

for (i = 0; i < len; i++) { palindrome = 1; for (int j = 0; j < len/2 && palindrome == 1; j++) { if (str.charAt(i+j) != str.charAt(len-1-j)) { palindrome = 0; } else { palindrome = 1; } if (palindrome == 1) { import java.util.*; import java.lang.*; import java.io.*; class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner in=new Scanner(System.in); int n=in.nextInt(); int a[]=new int[n]; for(int i=0;i

Leave a Reply