Leaderboard


Popular Content

Showing content with the highest reputation since 06/25/17 in all areas

  1. 1 point
    import java.util.*; public class lychrel { public static long palin(long n) { long m,p=0; while(n>0) { m=n%10; p=(p*10)+m; n=n/10; } return p; } public static void main(String ar[]) { long a,l,i,j=0,t,it=0; Scanner v=new Scanner(System.in); a=v.nextInt(); l=a+palin(a); t=palin(l); for(i=1;i<=10;i++) { it++; if(l==t) break; else { l=l+palin(l); t=palin(l); } if(i==4) j=l; } if(l!=t) { System.out.println(a+" is a Lychrel Number"); System.out.println("5th iteration of number "+a+" is "+j); } else System.out.println(it); } }
  2. 1 point
  3. 1 point
    Also: http://projecteuler.net/problem=55
  4. 1 point
    Code: #include <iostream> #define BUF_SIZE 100 using namespace std; void putInArray(int num, int* buf){ for(int i=0;i<BUF_SIZE;i++){ buf[i] = num % 10; num = num / 10; } } bool isPalindrom(int* buf){ int i=0, j=BUF_SIZE-1; while(buf[j]==0 && j>0){ j--; } while(i<j){ if(buf[i] != buf[j]){ return false; } i++; j--; } return true; } void applyIteration(int* buf){ int i=0, j=BUF_SIZE-1; while(buf[j]==0 && j>0){ j--; } while(i<=j){ int temp = buf[i] + buf[j]; buf[i++] = temp; buf[j--] = temp; } for(int i=0;i<BUF_SIZE-1;i++){ buf[i+1] += buf[i] / 10; buf[i] = buf[i] % 10; } } bool isLychrel(int* buf){ for(int i=1;i<50;i++){ applyIteration(buf); if(isPalindrom(buf)){ return false; } } return true; } int main() { int buf[BUF_SIZE]; for(int num=0;num<10000;num++){ putInArray(num,buf); if(isLychrel(buf)){ cout << num << " is Lychrel " << endl; } } }