Results 1 to 5 of 5

Thread: [RESOLVED] Very simple sequence problem

Hybrid View

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Resolved [RESOLVED] Very simple sequence problem

    Given the input sequence 1,2,3,4,5,6,7,8,9........

    how do you convert it to 2,1,0,2,1,0,2,1,0.........

    All I have at the moment is this:

    Output = (3-(Input mod 3)) mod 3

    Which does work but it looks a bit clumsy, anyone know a better way?
    I don't live here any more.

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Very simple sequence problem

    Yes, its clumsy
    I'd use
    Output = 3-(Input mod 3)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Very simple sequence problem

    Despite the fact it doesn't work?

    if input is 0 then your version will output (3-0 = 3) there are no threes in my desired sequence, hence the extra mod.
    I don't live here any more.

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: [RESOLVED] Very simple sequence problem

    Don't reckon you'll find a better way, my furry friend. It's a repeating sequence, so there's no 1 to 1 correspondence between the first and second sequences. It does, however, repeat with a period of 3 and the obvious (natural) way to do this is to do a "mod". It's in inverse order, so you need a "3 - ". And if you want to use 0 rather than 3, you need to "mod" it again. Three transformations, three operations. Couldn't be easier.

    Obviously you knew this, so I don't know why I'm bothering.


    zaza


    Have you noticed how mendhak has a barcode as his avatar now instead of a three-eyed frog (see other posts in this section)? Is that because he has a price on his head?

  5. #5
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Re: [RESOLVED] Very simple sequence problem

    <head>
    <script>
    for(x=1;x<15;x++) document.write(2-((x+2)%3));
    </script>
    </head>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width