#WSQ08

--Originally published at Jsph's Blog

#WSQ08

 

Once again, last semester I did this WSQ in python and it was very tricky, today I saw the work of my classmates to achive this one principaly Jorge Padilla’s Blog. Honestly I use his code to practice and understand more about this wsq.

A Lychrel number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. This process is sometimes called the 196-algorithm, after the most famous number associated with the process.

A Reverse-and-add process produces the sum of a number and the number formed by reversing the order of its digits. For example, 56 + 65 = 121. As another example, 125 + 521 = 646.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.

Here’s the code on my git but special thanks to Jorge for share his code.

https://github.com/JsphSalazar/POO/blob/master/WSQ08

Sources:

https://en.wikipedia.org/wiki/Palindrome

https://en.wikipedia.org/wiki/Lychrel_number

http://www.p196.org/ visit this awesome page.


#WSQ08

WSQ08 – Yo soy 196

--Originally published at tc2016blog

This is the most frustrating WSQ I ever made, when I did it in Python, the hard part was all the iterations, but this time I used the previous work from last course to make everything and also I had some help from my friend Ricardo Castillo.

I only have a minor bug on the isNaturalPaly method, but I think I know how to fix that. I’ll update the post when I do.

WSQ08 – Yo soy 196


WSQ08 – Yo soy 196

Yo Soy 196

--Originally published at TC201 Winter 2016 Jorge

This is about palindromes and lycherels. Even though I made this WSQ in Python, I did some research again to refresh my memory.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Famous examples include "A man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "Was it a car or a cat I saw?" and "No 'x' in Nixon".

A Lychrel number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. This process is sometimes called the 196-algorithm, after the most famous number associated with the process. In base ten, no Lychrel numbers have been yet proved to exist, but many, including 196, are suspected on heuristic and statistical grounds.

The reverse-and-add process produces the sum of a number and the number formed by reversing the order of its digits. For example, 56 + 65 = 121. As another example, 125 + 521 = 646.

Some numbers become palindromes quickly after repeated reversal and addition, and are therefore not Lychrel numbers. All one-digit and two-digit numbers eventually become palindromes after repeated reversal and addition.

Yo Soy 196

 

This was a very challenging WSQ, but I finally managed to have it done with some help from internet examples and basic tutorials, almost all of them from YouTube because you know, YouTube's awesome. Anyhow, have a look at my code. Actually I recommend you to check it out on GitHub since I made two classes for this WSQ.

Click here to check out the code where the main method is.

Click here to check out the code which I suppose you're looking for. 

Yo Soy 196

--Originally published at TC201 Winter 2016 Jorge

This is about palindromes and lycherels. Even though I made this WSQ in Python, I did some research again to refresh my memory.

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers. Famous examples include "A man, a plan, a canal, Panama!", "Amor, Roma", "race car", "stack cats", "step on no pets", "taco cat", "put it up", "Was it a car or a cat I saw?" and "No 'x' in Nixon".

A Lychrel number is a natural number that cannot form a palindrome through the iterative process of repeatedly reversing its digits and adding the resulting numbers. This process is sometimes called the 196-algorithm, after the most famous number associated with the process. In base ten, no Lychrel numbers have been yet proved to exist, but many, including 196, are suspected on heuristic and statistical grounds.

The reverse-and-add process produces the sum of a number and the number formed by reversing the order of its digits. For example, 56 + 65 = 121. As another example, 125 + 521 = 646.

Some numbers become palindromes quickly after repeated reversal and addition, and are therefore not Lychrel numbers. All one-digit and two-digit numbers eventually become palindromes after repeated reversal and addition.

Yo Soy 196

 

This was a very challenging WSQ, but I finally managed to have it done with some help from internet examples and basic tutorials, almost all of them from YouTube because you know, YouTube's awesome. Anyhow, have a look at my code. Actually I recommend you to check it out on GitHub since I made two classes for this WSQ.

Click here to check out the code where the main method is.

Click here to check out the code which I suppose you're looking for. 

Cheryl, probably, was a nice gal. Probably not

--Originally published at Ce qui est chouette

Ken…you did this to me…you ruined me. Information, regarding Lychrel Numbers, gathered from…oh, god…Wikipedia.

Lychrel kind of an anagram for Cheryl, Wade VanLandingham’s girlfriend. This Wade guy sucked at making up names.

“¿Qué debería poner?” pregunto yo acerca del blog.
“2” responde Marijose Dávila Diosdado, A01630826, de TC101 Winter 2016.

2

I feel the term playground has not caught up with many of my beloved readers -actually, I only have one reader, Miguel, notice me, Ken D: -so here I go: playground refers to the place where the little object boys and little object girls go play around, show off their methods -totally not a euphemism -and meet class instances, imports and guys of the like. It’s like a playground, but for objects, from classes…and then I, but he said and I go ooh ooh, you go aah aah, Lalalala, Ah Lalala

Back to business, or basics, here’s the playground and the console:

Cheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably not

Now, on with the foolishly long code for the class Lychrel:

Cheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably notCheryl, probably, was a nice gal. Probably not

Once again, I’ve defeated the evil corporation of WSQ’s. I’ve mastered the mastering masteries, Master -they’re to the left of the post.

“Onwards, noble steed!”

-The about guy.


Cheryl, probably, was a nice gal. Probably not

#WWQ08-Yo Soy 196

--Originally published at hermesespinola

This thing was really weird, I mean, it’s useless but it was interesting.
So a lychrel number is a special number, if the repetitive addition of a number with the number formed with inverse of its digits form a palindrome then it’s not a lychrel number.
So, in example: 196 + 691 = 887, 887 + 788 = 1575, … and so forth.

So here I first programmed the YoSoy186 class, before programming LychrelSequence and LychrelNumber, because I wanted to define how the class would work instead of programming it in the first place.
#WWQ08-Yo Soy 196

So because I needed to flip the digits of the numbers, I converted the number to a String. And because in this lynda Java course they said I should use the StringBuilder class to work with string, because it’s expensive to do the string operations with the normal String operators.

And then, in the Lychrel number class, I wrote a lot some fields, getters and setter then I wrote the above algorithm to evaluate if the number is a candidate to be a lychrel number:

public class LychrelNumber {
  private int value;
  private boolean isPalindromeNumber;
  private boolean isLychrel;
 
  public LychrelNumber() {
  }
 
  public LychrelNumber(int number) {
    setValue(number);
  }
 
  public boolean isLychrelNumber() {
    return this.isLychrel;
  }
 
  public boolean isPalindrome() {
    return this.isPalindromeNumber;
  }
 
  public int getValue() {
    return this.value;
  }
 
  private long[] evaluateHelper(long val) {
    StringBuilder reverseStr = (new StringBuilder(Long.
    toString(val))).reverse();
    long reverse = Long.parseLong(reverseStr.toString());
    long add = val + reverse;
    return new long[] {reverse, add};
  }
 
  private void evaluate(long value) {
    long[] r = this.evaluateHelper(value);
    String addStr = Long.toString(r[1]);
    this.isPalindromeNumber = (value == r[0]);
    if (!this.isPalindrome()) {
      for (int i = 0; i < 30; i++) {
        r = evaluateHelper(r[1]);
        addStr = Long.toString(r[1]);
        if (addStr.equals(new StringBuilder(addStr).reverse().toString())) {
          this.isLychrel = false;
          break;
        }
        this.isLychrel = true;
      }
    }
  }
 
  public void setValue(int number) {
    this.value = number;
    this.evaluate((long)this.value);
  }
}

In the code I wrote a private method, which is only called when the setter of the value is called, and another method to reverse and add these numbers. I used a long number because the repetitive addition of the numbers generated huge numbers and the program would run out of memory.

So first, before checking if the number is a lychrel number, I check if it is a palindrome, and then, if it is not, run the code to check if it is a lychrel number (because if it is a palindrome then it’s not a lychrel number). If at some point the addition of the number and the inverse of its digits is a palindrome, the code breaks and sets the isLychrel number variable to true.

For the LychrelNumber class, I used the ArrayList class to be able to append elements to the list, something you can’t do to a normal array easily. I used three lists, for storing the lychrel, non-lychrel, and palindrome sequences. The link says that since the List class is an Interface, you need to declare a specific implementation of this Interface.
All this class does is iterate from the lower bound to the upper bound, and instantiating the LychrelSequence class with that value, and if the number is a palindrome, it’s added to the palindromes list and the non-lychrel list, else, if the number is a lychrel number it is added to the lychrel list, but not all non-lychrel numbers are palindromes).

import java.util.List;
import java.util.ArrayList;
 
public class LychrelSequence {
  private int lower;
  private int upper;
  private List<Integer> lyqSeq;
  private List<Integer> nonLyqSeq;
  private List<Integer> palindromeSeq;
 
  public LychrelSequence(int lowerBound, int upperBound) {
    this.lower = lowerBound;
    this.upper = upperBound;
 
    this.lyqSeq = new ArrayList<>();
    this.nonLyqSeq = new ArrayList<>();
    this.palindromeSeq = new ArrayList<>();
 
    LychrelNumber ln = new LychrelNumber();
    for (int i = this.lower; i <= this.upper; i++) {
      ln.setValue(i);
      if (ln.isPalindrome()) {
        palindromeSeq.add(ln.getValue());
        nonLyqSeq.add(ln.getValue());
      } else if (ln.isLychrelNumber()) {
        lyqSeq.add(ln.getValue());
        System.out.println(“Found a Lychrel number candidate: ” + ln.getValue());
      } else {
        nonLyqSeq.add(ln.getValue());
      }
    }
  }
 
  public int getLowerBound() {
    return this.lower;
  }
 
  public int getUpperBound() {
    return this.upper;
  }
 
  public List<Integer> getPalindromeSequence() {
    return this.palindromeSeq;
  }
 
  public List<Integer> getLychrelSequence() {
    return this.lyqSeq;
  }
 
  public List<Integer> getNonLychrelSequece() {
    return this.nonLyqSeq;
  }
 
 
  public int getNumPalindromes() {
    return this.palindromeSeq.size();
  }
 
  public int getNumLychrels() {
    return this.lyqSeq.size();
  }
 
  public int getNumNonLychrels() {
    return this.nonLyqSeq.size();
  }
}

Something weird I noticed is that you have to use the Integer class when declaring the list, instead of the primitive type int.

#WWQ08-Yo Soy 196

And the here’s the Github repository of this homework.


#WWQ08-Yo Soy 196