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?
Printable View
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?
Yes, its clumsy
I'd use
Output = 3-(Input mod 3)
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.
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?
<head>
<script>
for(x=1;x<15;x++) document.write(2-((x+2)%3));
</script>
</head>