This week's book giveaway is in the Java in General forum.We're giving away four copies of Java by Comparison (eBook) and have Simon Harrer, Jörg Lenhard, Linus Dietz on-line!See this thread for details.
Win a copy of Java by Comparison (eBook) this week in the Java in General forum!

# Anubrato Roy

Greenhorn
since Mar 22, 2010
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Anubrato Roy

Hi Ryan,

It was amusing to realize that I have stated the rule in a complicated manner.
Taking your hint, if the difference of 2 numbers is odd, then one of them is even and the other odd - which implies that their sum is also odd.
That combined with my logic simply means that the sum of all the digits in the number must be odd.

So here is the revised version -
You like numbers where the sum of digits of the numbers is Odd.

That makes me realize that this is almost identical to Seetharaman's logic, except that I stop only at the first pass of summing up the digits; and not summing up the digits of the sum itself.

Regards,
Anubrato
5 years ago
My take is that Ryan likes numbers where the difference of sum of the alternate digits is odd.

Here is my logic -

Ryan's likes:
25 => 5 – 2 = 3 Odd
144 => (1+4) – 4 = 1 Odd
300 => (3+0) – 0 = 3 Odd

Ryan's dislikes:
24 => 4 – 2 = 2 Even
145 => (1+5) – 4 = 2 Even
400 => (4+0) – 0 = 4 Even

8889 => (8+9) – (8+8) = 1 Odd
97 => 9 -7 = 2 Even

So given all the above, the available options are:
37 => 7 – 3 = 4 Even
64 => 6 – 4 = 2 Even
200 => (2+0) – 0 = 2 Even
1024 => (4+0) – (1+2) = 1 Odd
65535 => (6+5+5) – (3+5) = 8 Even

That leaves 1024 as the only option
5 years ago
Hello All,

I am trying to come up with an algorithm for a Tree as follows -
I have a set of parent-child relationships defined (please see attached file). For each relationship, the parent objct is a node on the tree and all its children are immediate neighbours of this node, as in any tree.
Now, I want to validate a 'sequence' for the tree nodes, which works as following.
Arbitrary 'sequence' numbers are assigned to each node e.g. A=1, B=2, D=3, C=4, F=5, E=6. Now, I want to 'validate' this sequence. The sequence is valid if for every node, all its parent nodes have a lower sequence number than itself.
For example, if for node C, both B and A are parents, then these sequences are valid: A=1, B=2, C=3 or A=2, B=1, C=3.

In the attached diagram, for example, the node A has children B and C. B has children D and E while C has only one child F.
Now, the following sequences are examples of 'valid' sequences -
1. A=1, B=2, C=3, D=4, E=5, F=6
2. A=1, B=2, D=3, C=4, F=5, E=6
1. A=1, C=2, F=3, B=4, D=5, E=6

Can anyone please suggest an efficient algorithm to achieve this?

Regards,
Anubrato
6 years ago