Printing Odd Numbers

Can anyone help me out how to create a service, whose input should be two lists(of numbers) and output should be a list of numbers. The output should be list of odd numbers, from both the input lists

Hi Moudhgalya,

is there any information about the ordering of the numbers from the two lists (i.e. first the numbers of the first list, then the numbers of the second list, or should the resulting list be sorted by any specific criteria)?

Did you check the IS Built-In Services Reference for the pub.math-Folder and the pub.util-Folder for helpful services?

Here is some pseudo code as a starting point:

  • Define empty result list
  • LOOP over first input list
    – Check if current number is odd (might result in an implementation of an helper service)
    – Branch on if odd
    — Odd: add to result list
    — Even: do nothing
  • LOOP over second input list
    – Check if current number is odd (might result in an implementation of an helper service)
    – Branch on if odd
    — Odd: add to result list
    — Even: do nothing
  • add sorting/filtering here if neccessary

Regards,
Holger

1 Like

Hi Holger ,

I just want to print the odd numbers from both list(input list-1 and input list-2) to result (output list)

Regards,
Moudhgalya Dhavan.

Hi Moudhgalya,

in the PSUtilities package (this package is available in the Samples section of the TechCommunity) there is a service named ps.util.math:modDivideInts, which can be used as the helper service I have mentioned in my pseudo code above.
Input numerator will be the value to be checked and denominator will be set to 2.
Then check for the output of remainder for 0 (=even) or 1 (=odd).

Regards,
Holger

Hi Moudhgalya,

Below is just an outline logic for implementing your requirement.

  1. If input 1 and input 2 are not empty then make temp string list using pub.list.addStringList

  2. Use LOOP to iterate through temp list

  3. Do mod 2 like → number % 2

  4. If result is 1 then odd number then make add to output list else ignore

This should work out.

Regards,
Jacob