Message Boards Message Boards

0
|
3509 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Selecting numbers with a specified leading digit?

Posted 2 years ago

I have a list like this:- The list

Here numbers with the leading digit 1 are 10, 16, and 1. How can I compute this result in Mathematica?

POSTED BY: Ajit Kumar Sahoo
4 Replies
Posted 2 years ago

Another approach, that works for lists of integers.

ResourceFunction["Collatz"][3] // Select[IntegerDigits /* First@# == 1 &]
(* {10, 16, 1} *)

ResourceFunction["Collatz"][121] // Select[IntegerDigits /* First@# == 1 &]
(* {121, 182, 137, 103, 155, 175, 1186, 1780, 1336, 167, 1132, 1276,
1438, 1079, 1619, 1822, 1367, 1154, 1732, 1300, 122, 184, 106, 160,
10, 16, 1} *)
POSTED BY: Rohit Namjoshi

Wow... Very short and precise. Loved it !!!

POSTED BY: Ajit Kumar Sahoo

I think this could help

num = {3, 10, 5, 16, 8, 0.01, 4, 2, 1, 77, 18, 92, 4, 100};
exp = 10^# & /@ (Log[10, N[num]] // IntegerPart)
num[[#]] & /@ Position[IntegerPart[num/exp], 1] // Flatten
POSTED BY: Hans Dolhaine

Thanks, this works really great. Loved it !!!

POSTED BY: Ajit Kumar Sahoo
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract