Simple renumbering exercise


#1

I have a list from 1 to 20. I want to renumber every element starting with 8 and above to a new sequence starting at 15.

So far I’m able to get the starting element of the new sequence but I’m kindda stuck there :frowning: any help would be much appreciated

 


#2

20160209-3


#3

If I understood correctly…


#4

Vikram i LOVE you solution. a>=X?a-8+Y:a; A is the value im looking for >= bigger or equal to X What’s the ? for? A - 8 (why is it 8)? +Y the value i want to add :a gives me the final value Am i right?

 

I endedup using that

n>=X?(n-X)+Y:n;

 

Still wondering what the ? is for?


#5

Here’s what i came up with so far

n>=X&&n<=Y?(n-X)+Y:n;

 

Next step is to truncate the list to only have the modified value


#6

The ? and : in a conditional statement separates the various arguments.

(test)?(if true,this result):(if false, this result)


#7

To truncate the list you might need to do something like this.

20160209-3a


#8

ahhh make sense. Can i nest another if, say using >= ?


#9

You can nest conditional statements within (if true, this result) and (if false, this result)

It could begin to get complicated and confusing.


#10

Im just trying to combine those 2

n<=X?(n-X)+Z:n

n>=Y?(n-Y)+Z:n

 

Basically i want to renumber but only withing a range. Im sure you wil come up with a better solution ahahahah but im still curious about the code

 

 


#11

20160209-3b


#12

Did someone said i love you lately? :slight_smile:

Thanks a million, that was a great learning exercise for me.


#13

Ok i speak too fast :slight_smile: but we’re close :slight_smile:

If we start at 5, then 5 needs to change to 105 and 5 to 106 right?

 


#14

20160209-3d


#15

Now it’s official… i love you :slight_smile:


#16

:slight_smile:


#17

Love is in the air.