PDA

Click to See Complete Forum and Search --> : [RESOLVED] Very simple sequence problem


wossname
Jul 11th, 2005, 09:48 AM
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?

opus
Jul 11th, 2005, 03:49 PM
Yes, its clumsy
I'd use
Output = 3-(Input mod 3)

wossname
Jul 12th, 2005, 05:06 AM
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.

zaza
Jul 12th, 2005, 04:29 PM
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?

bao_ho
Jul 24th, 2005, 03:37 AM
<head>
<script>
for(x=1;x<15;x++) document.write(2-((x+2)%3));
</script>
</head>