BrainDen.com - Brain Teasers

## Popular Content

Showing content with the highest reputation on 07/18/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
Also: http://projecteuler.net/problem=55
3. 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; } } }
×

• #### Activity

• Riddles
×
• Create New...
{"ft_lang_label":"__label__en","ft_lang_prob":0.8116,"math_prob":0.9889769,"size":197,"snap":"2020-10-2020-16","text_gpt3_token_len":60,"char_repetition_ratio":0.1658031,"word_repetition_ratio":0.0,"special_character_ratio":0.2893401,"punctuation_ratio":0.0,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99637663,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-22T17:16:40Z\",\"WARC-Record-ID\":\"<urn:uuid:01ab07e2-a2a1-4907-90fe-53fc589e2610>\",\"Content-Length\":\"55755\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e9bbe661-8c6b-4f64-9c49-e6217d2b2878>\",\"WARC-Concurrent-To\":\"<urn:uuid:ce3766c4-a2e0-4a2e-be08-65b8eff53440>\",\"WARC-IP-Address\":\"37.9.174.22\",\"WARC-Target-URI\":\"http://brainden.com/forum/leaderboard/?custom_date_start=1500379200&custom_date_end=1500379200\",\"WARC-Payload-Digest\":\"sha1:L3YDI6EL6LX5KA7NYRKPDNW7AF52WIIM\",\"WARC-Block-Digest\":\"sha1:AA5HC3JEUWUNX74RPFLX6UUNWKYMBJVL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875145708.59_warc_CC-MAIN-20200222150029-20200222180029-00546.warc.gz\"}"}