Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5322 > unrolled thread
| Started by | dimitris <dimmechan@yahoo.com> |
|---|---|
| First post | 2011-10-02 06:40 +0000 |
| Last post | 2011-10-04 05:30 +0000 |
| Articles | 13 — 9 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
count zeros in a number dimitris <dimmechan@yahoo.com> - 2011-10-02 06:40 +0000
Re: count zeros in a number DC <b.gatessucks@gmail.com> - 2011-10-03 08:20 +0000
Re: count zeros in a number Mark Adler <madler@alumni.caltech.edu> - 2011-10-03 08:22 +0000
Re: count zeros in a number Peter Pein <petsie@dordos.net> - 2011-10-03 08:29 +0000
Re: count zeros in a number Peter Breitfeld <phbrf@t-online.de> - 2011-10-03 08:30 +0000
Re: count zeros in a number "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-03 08:28 +0000
Re: count zeros in a number Stefan Salanski <wutchamacallit27@gmail.com> - 2011-10-04 05:34 +0000
Re: count zeros in a number Richard Fateman <fateman@cs.berkeley.edu> - 2011-10-05 08:14 +0000
Re: count zeros in a number -> Clip[x] = ? "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-06 08:35 +0000
Re: count zeros in a number Mark Adler <madler@alumni.caltech.edu> - 2011-10-06 08:40 +0000
Re: count zeros in a number DrMajorBob <btreat1@austin.rr.com> - 2011-10-06 08:32 +0000
Re: count zeros in a number DrMajorBob <btreat1@austin.rr.com> - 2011-10-04 05:35 +0000
Re: count zeros in a number dimitris <dimmechan@yahoo.com> - 2011-10-04 05:30 +0000
| From | dimitris <dimmechan@yahoo.com> |
|---|---|
| Date | 2011-10-02 06:40 +0000 |
| Subject | count zeros in a number |
| Message-ID | <j69104$rda$1@smc.vnet.net> |
Hello. Consider e.g. the number 24^24*55^55. This number ends with exactly 55 zeros as the following demonstrate In[201]:= Mod[24^24*55^55, 10^55] Mod[24^24*55^55, 10^56] Out[201]= 0 Out[202]= 20000000000000000000000000000000000000000000000000000000 What I want now is a way to count the zeros that a number ends without knowing in advance this number of zeros like in the above example. Thanks in advance. Dimitris
[toc] | [next] | [standalone]
| From | DC <b.gatessucks@gmail.com> |
|---|---|
| Date | 2011-10-03 08:20 +0000 |
| Message-ID | <j6br94$8h2$1@smc.vnet.net> |
| In reply to | #5322 |
Try Last[Split[IntegerDigits[24^24*55^55]]]
[toc] | [prev] | [next] | [standalone]
| From | Mark Adler <madler@alumni.caltech.edu> |
|---|---|
| Date | 2011-10-03 08:22 +0000 |
| Message-ID | <j6brcv$8jj$1@smc.vnet.net> |
| In reply to | #5322 |
Min[IntegerExponent[#, 2], IntegerExponent[#, 5]] &[24^24*55^55] 55
[toc] | [prev] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-10-03 08:29 +0000 |
| Message-ID | <j6brpp$8nd$1@smc.vnet.net> |
| In reply to | #5322 |
Am 02.10.2011 08:40, schrieb dimitris:
> Hello.
>
> Consider e.g. the number 24^24*55^55.
> This number ends with exactly 55 zeros as the following demonstrate
>
> In[201]:= Mod[24^24*55^55, 10^55]
> Mod[24^24*55^55, 10^56]
>
> Out[201]= 0
> Out[202]= 20000000000000000000000000000000000000000000000000000000
>
>
> What I want now is a way to count the zeros that a number ends without
> knowing in advance this number of zeros like in the above example.
>
> Thanks in advance.
> Dimitris
>
Using pattern matching makes this an easy one :-)
In[1]:= TrailingZeros[n_Integer] :=
IntegerDigits[n] /. {___, Except[0], z: ((0) ...)} :> Length[{z}]
TrailingZeros[24^24 55^55]
Out[2]= 55
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2011-10-03 08:30 +0000 |
| Message-ID | <j6brrn$8nu$1@smc.vnet.net> |
| In reply to | #5322 |
dimitris wrote:
I would convert to a string and use a regular expression:
trailingZeros[n_] :=
StringLength@StringCases[ToString[n], RegularExpression["0+$"]]
trailingZeros[24^24 55^55]
Out={55}
trailingZeros[10000!]
Out={2499}
> Hello.
>
> Consider e.g. the number 24^24*55^55.
> This number ends with exactly 55 zeros as the following demonstrate
>
> In[201]:= Mod[24^24*55^55, 10^55]
> Mod[24^24*55^55, 10^56]
>
> Out[201]= 0
> Out[202]= 20000000000000000000000000000000000000000000000000000000
>
>
> What I want now is a way to count the zeros that a number ends without
> knowing in advance this number of zeros like in the above example.
>
> Thanks in advance.
> Dimitris
>
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2011-10-03 08:28 +0000 |
| Message-ID | <j6brmr$8mn$1@smc.vnet.net> |
| In reply to | #5322 |
"dimitris" <dimmechan@yahoo.com> schrieb im Newsbeitrag news:j69104$rda$1@smc.vnet.net... > Hello. > > Consider e.g. the number 24^24*55^55. > This number ends with exactly 55 zeros as the following demonstrate > > In[201]:= Mod[24^24*55^55, 10^55] > Mod[24^24*55^55, 10^56] > > Out[201]= 0 > Out[202]= 20000000000000000000000000000000000000000000000000000000 > > > What I want now is a way to count the zeros that a number ends > without > knowing in advance this number of zeros like in the above example. > > Thanks in advance. > Dimitris > You can use the function f[z_]:=Length[Split[IntegerDigits[z]][[-1]]] z = 24^24*55^55; f[z] 62 Wolfgang
[toc] | [prev] | [next] | [standalone]
| From | Stefan Salanski <wutchamacallit27@gmail.com> |
|---|---|
| Date | 2011-10-04 05:34 +0000 |
| Message-ID | <j6e5ti$kbr$1@smc.vnet.net> |
| In reply to | #5322 |
On Oct 2, 2:40 am, dimitris <dimmec...@yahoo.com> wrote: > Hello. > > Consider e.g. the number 24^24*55^55. > This number ends with exactly 55 zeros as the following demonstrate > > In[201]:= Mod[24^24*55^55, 10^55] > Mod[24^24*55^55, 10^56] > > Out[201]= 0 > Out[202]= 20000000000000000000000000000000000000000000000000000000 > > What I want now is a way to count the zeros that a number ends without > knowing in advance this number of zeros like in the above example. > > Thanks in advance. > Dimitris All these solutions are very interesting, and they all work, but I believe the simplest solution is actually a built in function, specifically: IntegerExponent[]. IntegerExponent[n,b] returns the highest power of b which divides n, which for b=10, is the number of trailing zeroes of n. moreover, the default value of b is already 10, so that IntegerExponent[n] gives the number of trailing zeroes of n. In[1]:= IntegerExponent[24^24*55^55] Out[1]= 55 http://reference.wolfram.com/mathematica/ref/IntegerExponent.html -Stefan Salanski
[toc] | [prev] | [next] | [standalone]
| From | Richard Fateman <fateman@cs.berkeley.edu> |
|---|---|
| Date | 2011-10-05 08:14 +0000 |
| Message-ID | <j6h3kn$74t$1@smc.vnet.net> |
| In reply to | #5355 |
On 10/3/2011 10:34 PM, Stefan Salanski wrote: > > All these solutions are very interesting, and they all work, but I > believe the simplest solution is actually a built in function, > specifically: IntegerExponent[]. > IntegerExponent[n,b] returns the highest power of b which divides n, > which for b=10, is the number of trailing zeroes of n. > why yes, all you need is one esoteric function. Proof that it is esoteric? All the previous posters (me too) were unaware of it. And presumably all the people who read the question and did not post anything ... The first example in the documentation illustrates exactly this usage. RJF
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2011-10-06 08:35 +0000 |
| Subject | Re: count zeros in a number -> Clip[x] = ? |
| Message-ID | <j6jp8n$mcs$1@smc.vnet.net> |
| In reply to | #5404 |
What about setting up a regular column "esoteric of the week" naming
functions that are rarely used ?
I would start with
Clip[x]
which I (shame on me) didn't know until this evening. Did you?
Wolfgang
"Richard Fateman" <fateman@cs.berkeley.edu> schrieb im Newsbeitrag
news:j6h3kn$74t$1@smc.vnet.net...
> On 10/3/2011 10:34 PM, Stefan Salanski wrote:
>
>>
>> All these solutions are very interesting, and they all work, but I
>> believe the simplest solution is actually a built in function,
>> specifically: IntegerExponent[].
>> IntegerExponent[n,b] returns the highest power of b which divides n,
>> which for b=10, is the number of trailing zeroes of n.
>>
> why yes, all you need is one esoteric function.
> Proof that it is esoteric? All the previous posters (me too) were
> unaware of it. And presumably all the people who read the question
> and
> did not post anything ...
>
>
> The first example in the documentation illustrates exactly this
> usage.
>
> RJF
>
>
[toc] | [prev] | [next] | [standalone]
| From | Mark Adler <madler@alumni.caltech.edu> |
|---|---|
| Date | 2011-10-06 08:40 +0000 |
| Message-ID | <j6jphj$mev$1@smc.vnet.net> |
| In reply to | #5404 |
On 2011-10-05 01:14:15 -0700, Richard Fateman said: > Proof that it is esoteric? All the previous posters (me too) were > unaware of it. I posted its use about five replies in. However for some reason I only considered its use with prime numbers to get the exponent of that prime in the integer's factorization (a sort of selective FactorInteger). So my solution used the function twice (on 2 and 5) when it didn't have to. Mark
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-10-06 08:32 +0000 |
| Message-ID | <j6jp2t$mbh$1@smc.vnet.net> |
| In reply to | #5355 |
It would be silly for Stefan not to mention IntegerExponent because it is "esoteric", when he instantly makes it LESS esoteric by showing it to us. Bobby On Wed, 05 Oct 2011 03:03:18 -0500, Richard Fateman <fateman@cs.berkeley.edu> wrote: > On 10/3/2011 10:34 PM, Stefan Salanski wrote: > >> >> All these solutions are very interesting, and they all work, but I >> believe the simplest solution is actually a built in function, >> specifically: IntegerExponent[]. >> IntegerExponent[n,b] returns the highest power of b which divides n, >> which for b=10, is the number of trailing zeroes of n. >> > why yes, all you need is one esoteric function. > Proof that it is esoteric? All the previous posters (me too) were > unaware of it. And presumably all the people who read the question and > did not post anything ... > > > The first example in the documentation illustrates exactly this usage. > > RJF > > -- DrMajorBob@yahoo.com
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-10-04 05:35 +0000 |
| Message-ID | <j6e5uh$kc9$1@smc.vnet.net> |
| In reply to | #5322 |
But the answer is 55, not 62. z = 24^24*55^55; Length[Split[IntegerDigits[z]][[-1]]] 55 Bobby On Mon, 03 Oct 2011 03:22:37 -0500, Dr. Wolfgang Hintze <weh@snafu.de> wrote: > > "dimitris" <dimmechan@yahoo.com> schrieb im Newsbeitrag > news:j69104$rda$1@smc.vnet.net... >> Hello. >> >> Consider e.g. the number 24^24*55^55. >> This number ends with exactly 55 zeros as the following demonstrate >> >> In[201]:= Mod[24^24*55^55, 10^55] >> Mod[24^24*55^55, 10^56] >> >> Out[201]= 0 >> Out[202]= 20000000000000000000000000000000000000000000000000000000 >> >> >> What I want now is a way to count the zeros that a number ends >> without >> knowing in advance this number of zeros like in the above example. >> >> Thanks in advance. >> Dimitris >> > You can use the function > > f[z_]:=Length[Split[IntegerDigits[z]][[-1]]] > z = 24^24*55^55; > f[z] > 62 > > Wolfgang > > -- DrMajorBob@yahoo.com
[toc] | [prev] | [next] | [standalone]
| From | dimitris <dimmechan@yahoo.com> |
|---|---|
| Date | 2011-10-04 05:30 +0000 |
| Message-ID | <j6e5lt$k7a$1@smc.vnet.net> |
| In reply to | #5322 |
On 2 =CF=EA=F4, 09:40, dimitris <dimmec...@yahoo.com> wrote: > Hello. > > Consider e.g. the number 24^24*55^55. > This number ends with exactly 55 zeros as the following demonstrate > > In[201]:= Mod[24^24*55^55, 10^55] > Mod[24^24*55^55, 10^56] > > Out[201]= 0 > Out[202]= 20000000000000000000000000000000000000000000000000000000 > > What I want now is a way to count the zeros that a number ends without > knowing in advance this number of zeros like in the above example. > > Thanks in advance. > Dimitris Thanks a lot to everyone that replied. Dimitris
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web