# Help with numbers

**URL:** <https://community.unix.com/t/help-with-numbers/274555>\
**Category:** Shell Programming and Scripting\
**Created:** [October 2, 2010, 1:14am UTC](https://community.unix.com/t/help-with-numbers/274555 "2010-10-02T01:14:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![puttster](https://community.unix.com/letter_avatar/puttster/32/5_5575768a8748004e209b776fc1b2916d.png) [@puttster](https://community.unix.com/u/puttster)\
**Post date:** [October 2, 2010, 1:14am UTC](https://community.unix.com/t/help-with-numbers/274555/1 "2010-10-02T01:14:58Z")

</div>

Say I have 3 sets of numbers: 043 5326 90432  
and I want to select the digits that all 3 have in common!  
so to answer my question 3 is the only digit that all 3 have in common!  
Can this be done with 1 command in unix shell? or is it more complicated than I think it is?

I don't want an answer to my question but an idea on how any of you would start this and also I would like help depending on what questions I have!

---

<div class="post-metadata">

**Author:** ![kurumi](https://community.unix.com/letter_avatar/kurumi/32/5_5575768a8748004e209b776fc1b2916d.png) [@kurumi](https://community.unix.com/u/kurumi)\
**Post date:** [October 2, 2010, 1:57am UTC](https://community.unix.com/t/help-with-numbers/274555/2 "2010-10-02T01:57:17Z")

</div>

```nohighlight
$ echo "043 5326 90432" | ruby -e 'a=gets.chomp!.split.map{|x| x.chars.to_a} ;p a[0]&a[1]&a[2]'
["3"]

```

---

<div class="post-metadata">

**Author:** ![durden\_tyler](https://community.unix.com/user_avatar/community.unix.com/durden_tyler/32/1450_2.png) [@durden\_tyler](https://community.unix.com/u/durden_tyler)\
**Post date:** [October 2, 2010, 1:57am UTC](https://community.unix.com/t/help-with-numbers/274555/3 "2010-10-02T01:57:52Z")

</div>

> [@puttster](#):
>
> Say I have 3 sets of numbers: 043 5326 90432  
> and I want to select the digits that all 3 have in common!  
> so to answer my question 3 is the only digit that all 3 have in common!  
> Can this be done with 1 command in unix shell? or is it more complicated than I think it is?  
> I don't want an answer to my question but an idea on how any of you would start this and also I would like help depending on what questions I have!

(a) Remove all digits other than 0 from each number group. If you are left with three 0's (one from each group), then you have your answer.  
(b) Repeat step (a) for the remaining 9 digits.

tyler\_durden

---

<div class="post-metadata">

**Author:** ![puttster](https://community.unix.com/letter_avatar/puttster/32/5_5575768a8748004e209b776fc1b2916d.png) [@puttster](https://community.unix.com/u/puttster)\
**Post date:** [October 2, 2010, 2:11am UTC](https://community.unix.com/t/help-with-numbers/274555/4 "2010-10-02T02:11:12Z")

</div>

> [@durden\_tyler](#):
>
> (a) Remove all digits other than 0 from each number group. If you are left with three 0's (one from each group), then you have your answer.  
> (b) Repeat step (a) for the remaining 9 digits.
> 
> tyler\_durden

what if i had a randomized function that would create random amounts of digits? I wouldn't be able to do it your way if thats how the digits are created in the first place... ( I should have mentioned that beforehand )
