Skip to main content
March 15, 2022
Question

How do I get Odd numbers 1-100

  • March 15, 2022
  • 6 replies
  • 0 views

How do I get Odd numbers 1-100 ?

    6 replies

    gopalk2865
    Participating Frequently
    March 15, 2022

    Hi, See below code.

    a!forEach(
        items: enumerate(100)+1,
        expression: if(
          mod(fv!item,2)=0,
          {},
          fv!item
        )
      )

    harshitb6843
    March 15, 2022

    Out of context tho, but are these some assignment questions that you have to complete and submit? [emoticon:98f842990f454422aa6a04953955f9d9]

    gopalk2865
    Participating Frequently
    March 15, 2022

    [emoticon:d6dd260102fd406884fc96b8bc59760b] looks like interview questions.

    andrewh0007
    March 15, 2022

    If you're looking for pure performance then this is a better option. For 100 numbers though the difference is essentially non-existent.

    where(
      apply(
        fn!mod,
        1 + enumerate(100000),
        2
      ) <> 0
    )

    October 13, 2024

    a!localVariables(
      local!start:1, 
      local!end:100,
      local!dif: local!end-local!start,
      local!list:odd(enumerate(local!dif)+local!start),
      union(
        local!list,
        local!list
      )
    )

    October 14, 2024

    a!localVariables(
    local!values : a!forEach(
    items: enumerate(100)+1,
    expression: if(
    mod(fv!item,2) = 0,
    0,
    odd(fv!item)
    )
    ),
    local!odds : remove(local!values,wherecontains({null(),0},local!values)),
    local!odds
    )