## WSQ08 – Yo Soy 196. Here is the code FINALLY!!!!!!! for WSQ08.

// Solving Problems with Programming
// Professor Ken Bauer
//
// A01634000
// Jorge Alejandro Flores and Ken Bauer 🙂

// Standard libraries
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

// `BigIntegerLibrary.hh’ includes all of the library headers.
#include “BigIntegerLibrary.hh”

/*
* This function receives a BigInteger n and checks if it is a palindrome
* Return true if n is a palindrome, return false otherwise
*/
bool is_palindrome(BigInteger n){
string str1= bigIntegerToString(n);
string str2=str1;
reverse(str2.begin(), str2.end());
return (str2==str1);
}
/*
* This function receives a BigInteger n and returns the value of n plus the inverse of n.
*/
BigInteger apply196(BigInteger n){
string str1= bigIntegerToString(n);
string str2=str1;
reverse(str1.begin(), str1.end());
return n+ stringToBigInteger(str1);// you need to replace this with code that works
}

/*
* Your main program goes below and should use the two functions above
*/
int main() {
int nl=0;
int pal=0;
int l=0;
BigInteger n;
int low, up;

cout << “Give me the value of your lower bound” << endl;
cin >>low;
cout << “Give me the value of your upper bound” << endl;
cin >>up;

for(int i=low; i<=up; i++){
n=i;

if(is_palindrome (n)==true){
pal=pal+1;
}
else {
int count=0;
bool lych= true;
while (count<=30){
n= apply196(n);
if(is_palindrome(n)==true){
nl=nl+1;
lych=false;
break;
}
else{
count=count+1;
}

}
if (lych){
l=l+1;
}
}
}

cout<<“The analyzed numbers goes from “<<low;
cout<<” to “<<up<<endl;
cout<<“There are “<<pal;
cout<<” palindromes”<<endl;
cout<<“There are “<<l;
cout<<” lychrel numbers”<<endl;
cout<<“There are “<<nl;
cout<<” non-lychrel numbers”<<endl;
return 0;
}

I tried to do it for like 2 months and after a lot of explanations and time I finally did it. Thanks to everyone for your explanations! Ilysm. Here I used like a lot of mastery topics but I’ll just put #masterytopic19 cause I used strings. Also #masterytopic26 cause I made a twitter account. Follow me @amixez. Teacher Ken and other 50 classmates made this possible.

## Un comentario sobre “WSQ08 – Yo Soy 196.”

1. pepemunguia dice: