PreviousUpNext

5.5.4  Generate a list of numbers

Generate a list of consecutive numbers:

    eval:  1..3
    [1, 2, 3]

Generate a list of odd numbers:

    eval:  [ i for i in 1..10 where i & 1 == 1 ];
    [1, 3, 5, 7, 9]

Generate a list of even numbers as strings:

    eval:  [ sprintf "%d" i for i in 1..10 where i & 1 == 0 ];
    ["2", "4", "6", "8", "10"]

Generate a list of prime pairs:

    eval:  [ (i, i+2) for i in 1..1000 where (isprime i and isprime (i+2)) ];
    [ (1, 3), (3, 5), (5, 7), (11, 13), (17, 19), (29, 31), 
      (41, 43), (59, 61), (71, 73), (101, 103), (107, 109), 
      (137, 139), (149, 151), (179, 181), (191, 193), 
      (197, 199), (227, 229), (239, 241), (269, 271), 
      (281, 283), (311, 313), (347, 349), (419, 421), 
      (431, 433), (461, 463), (521, 523), (569, 571), 
      (599, 601), (617, 619), (641, 643), (659, 661), 
      (809, 811), (821, 823), (827, 829), (857, 859), 
      (881, 883) ]

Comments and suggestions to: bugs@mythryl.org

PreviousUpNext