Cancel a digit

Post here to share useful tips and tricks, to ask questions about using your DM42 or to report software-related problems
Post Reply
michel.lample
Posts: 20
Joined: Wed May 03, 2017 5:09 pm

Cancel a digit

Post by michel.lample »

Hi all
I'm looking for a simple way to cancel the n-th digit of a number
By eg: 123456 4 XEQ"Raz" -->120456

My on-the-fly code is :

Code: Select all

01▸LBL "Raz" @ (Y n --- Y') raz n-th digit of Y
@------------------------------------------------
02 10↑X
03 RCL ST Y
04 RCL ST Y
05 ÷
06 IP
07 LASTX
08 FP
09 10
10 ×
11 FP
12 10
13 ÷
14 +
15 X<>Y
16 ×
17 RTN
Well... 6 floating point operations for that! :shock:
I'm stumped: I expected to find a shorter code or a mathematical trick but ... need a little holiday :?:

Maybe some of you have a good idea ???
Thanks

Michel
dlachieze
Posts: 614
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: Cancel a digit

Post by dlachieze »

Here is a slightly shorter version:

Code: Select all

00 { 24-Byte Prgm }
01▸LBL "Raz" @ (Y n --- Y') raz n-th digit of Y
@------------------------------------------------
02 10↑X
03 RCL ST Y
04 RCL ST Y
05 ÷
06 FP
07 10
08 STO÷ ST Z
09 ×
10 IP
11 ×
12 -
13 RTN
DM42: 00425 - DM41X: β00066 - WP43: 00042
whuyse
Posts: 198
Joined: Thu Dec 21, 2017 1:23 pm

Re: Cancel a digit

Post by whuyse »

Yes, a challenge!

Code: Select all

00 { 21-Byte Prgm }
01▸LBL "Raz"
02 10↑X
03 RCL ST Y
04 X<>Y
05 MOD
06 STO- ST Y
07 LASTX
08 10
09 ÷
10 MOD
11 +
12 END
Cheers, Werner
41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE, DM15L
dlachieze
Posts: 614
Joined: Thu May 04, 2017 12:20 pm
Location: France

Re: Cancel a digit

Post by dlachieze »

whuyse wrote:
Tue Jul 14, 2020 9:51 am
Yes, a challenge!
Great program! I didn't think about MOD... learning something everyday.
DM42: 00425 - DM41X: β00066 - WP43: 00042
IonX
Posts: 11
Joined: Fri Jun 05, 2020 5:38 am

Re: Cancel a digit

Post by IonX »

Abit of fun, string version but it can display up to 34 digits.

Code: Select all

00 { 29-Byte Prgm }
01▸LBL "RAZ"
02 CLA
03 X<>Y
04 AIP
05 RCL ST Y
06 +/-
07 AROT
08 ATOX
09 ├"×"
10 RCL ST T
11 1
12 -
13 AROT
14 AVIEW
15 END
User avatar
PierreMengisen
Posts: 306
Joined: Wed Nov 29, 2017 1:38 pm
Location: Neuchâtel CH

Re: Cancel a digit

Post by PierreMengisen »

Bravo, very good solution without floating point. The best in my opinion.
Pierre
[TI59 with PC100C; TI-84 Plus CE-T; HP41CV with HP IL loop & 2*82161A DCD & 82162 TP; HP15C; HP28S; DM41; DM41L; DM42; DM41X]
IonX
Posts: 11
Joined: Fri Jun 05, 2020 5:38 am

Re: Cancel a digit

Post by IonX »

whuyse wrote:
Tue Jul 14, 2020 9:51 am
Yes, a challenge!

Code: Select all

00 { 25-Byte Prgm }
01▸LBL "Raz"
02 10↑X
03 RCL ST Y
04 X<>Y
05 MOD
06 STO- ST Y
07 LASTX
08 10
09 ÷
10 MOD
11 +

12 CLA
13 AIP
14 AVIEW

15 END
Cheers, Werner
Actually Werner code can display upto 34 digits as well on DM42, just need to add CLA,AIP,AVIEW. So Werner code is the best, 4 bytes less...!!!

Have fun DM42...!!!
User avatar
PierreMengisen
Posts: 306
Joined: Wed Nov 29, 2017 1:38 pm
Location: Neuchâtel CH

Re: Cancel a digit

Post by PierreMengisen »

All solutions are good. But since the basic problem is a string problem, I prefer the non-algebraic solution. But if you're looking for the solution using the least amount of programming bytes, then you are right ...
Love to all.
Pierre
[TI59 with PC100C; TI-84 Plus CE-T; HP41CV with HP IL loop & 2*82161A DCD & 82162 TP; HP15C; HP28S; DM41; DM41L; DM42; DM41X]
michel.lample
Posts: 20
Joined: Wed May 03, 2017 5:09 pm

Re: Cancel a digit

Post by michel.lample »

PierreMengisen wrote:
Sat Jul 18, 2020 3:36 pm
All solutions are good. But since the basic problem is a string problem.....,
Rightissime, Pierre: it is a string problem.
That reminds me of my student days when we had to keep our programs in the 38 steps of the old HP33.

Thank you all for your help
Michel
Post Reply