Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1992
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

[Date Index] [Thread Index] [Author Index]

Search the Archive

Mathematica Journal: One Liners

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Mathematica Journal: One Liners
  • From: ilan at leland.stanford.edu (ilan vardi)
  • Date: Mon, 27 Apr 92 00:47:31 -0700
  • Cc: wri-tech

In the new issue of the Mathematica Journal, One Liners, there is a
program called DigitalRoots which gives the result of iterating the
sum of the digits of an integer. 

 The code given there was 

DigitalRoots[n_]:= FixedPoint[(Plus @@ IntegerDigits[#])&, n]

I have discovered the following more efficient program to compute this:

MyDigitalRoots[n_]:= Mod[n, 9]

There was also a program to reverse the digits of a number:

ReverseInteger[n_]:=  
Module[{m = IntegerDigits[n], i},
       Table[10^i, {i, 0,Length[m]-1}], m]

My program (which only takes One Line) is:

MyReverseInteger[n_]:= Fold[#1 10 + #2&, 0, Reverse[IntegerDigits[n]]]

-Ilan Vardi




  • Prev by Date: Major Symbolic Computation Conference
  • Next by Date: rasterps
  • Previous by thread: Major Symbolic Computation Conference
  • Next by thread: rasterps