Replica a number
|
02-03-2022, 10:16 AM
Post: #1
|
|||
|
|||
Replica a number
Good morning,
Is there in HP Prime a command that replaces a series of numbers with other numbers? For example: {1,1,0,0,0,1} --comand--> {1,1,2,2,2,1} all zeroes replaced by 2. Thak you, Roberto |
|||
02-03-2022, 10:20 AM
Post: #2
|
|||
|
|||
RE: Replica a number | |||
02-03-2022, 01:43 PM
Post: #3
|
|||
|
|||
RE: Replica a number
I don't think there is a built in command to do this but it can be done with a simple program such as this one which will replace in list each occurrence of num1 by num2 (it works only for numbers, not for other types of list elements):
Code: EXPORT ReplNum(list,num1,num2) |
|||
02-03-2022, 01:52 PM
Post: #4
|
|||
|
|||
RE: Replica a number
Good day,
there is no command to perform an operation like this, but you can make one: MAKELIST(when((L1(X)) = 1,2,L1(X)),X,1,SIZE(L1),1), here the list you want to change is stored in L1, with L1:=MAKELIST(when((L1(X)) = 1,2,L1(X)),X,1,SIZE(L1),1) you replace the actually stored list. Arno |
|||
02-03-2022, 02:04 PM
Post: #5
|
|||
|
|||
RE: Replica a number
(02-03-2022 10:20 AM)robmio Wrote:(02-03-2022 10:16 AM)robmio Wrote: Good morning, Great: I used a "for" loop: it works, but it slows down the execution of my other programs. Your solution is quick and easy: thank you very much. |
|||
02-03-2022, 02:07 PM
Post: #6
|
|||
|
|||
RE: Replica a number
(02-03-2022 01:43 PM)Didier Lachieze Wrote: I don't think there is a built in command to do this but it can be done with a simple program such as this one which will replace in list each occurrence of num1 by num2 (it works only for numbers, not for other types of list elements): Great: I used a "for" loop: it works, but it slows down the execution of my other programs. Your solution is quick and easy: thank you very much. |
|||
02-03-2022, 02:10 PM
Post: #7
|
|||
|
|||
RE: Replica a number
(02-03-2022 01:52 PM)Arno K Wrote: Good day, Your solution is also faster than my "for" loop. Thanks so much |
|||
02-08-2022, 11:34 AM
Post: #8
|
|||
|
|||
RE: Replica a number
Bonjour
Ces 2 solutions parcourent toute la liste des valeurs, sur de grandes listes où il y a peu de valeurs à remplacer cela peut prendre du temps inutilement. Il y a une autre solution qui consiste à rechercher les valeurs à remplacer puis à arrêter quand il n'y on a plus. A tester ! Hello These 2 solutions go through the whole list of values, on big lists where there are few values to replace it can take time unnecessarily. There is another solution which consists in searching for the values to replace and then stop when there are no more. To be tested! Code:
Sorry for my english |
|||
02-08-2022, 12:50 PM
Post: #9
|
|||
|
|||
RE: Replica a number
(02-08-2022 11:34 AM)Tyann Wrote: Bonjour Excellent "code": very fast. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)