Skip to main content
added 112 characters in body
Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

or as J.M. suggested with one call to get the quotient and the remainder

With[{n = 781049}, Reverse[Reap[NestList[Block[{q, r}, 
 {q, r} = QuotientRemainder[#, 10]; Sow[r]; q] &, n, IntegerLength[n]]][[-1, 1]]]]

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings. Without giving explicit timings you can safely assume, that every function will be slower than IntegerDigits.

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

or as J.M. suggested with one call to get the quotient and the remainder

With[{n = 781049}, Reverse[Reap[NestList[Block[{q, r}, 
 {q, r} = QuotientRemainder[#, 10]; Sow[r]; q] &, n, IntegerLength[n]]][[-1, 1]]]]

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings.

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

or as J.M. suggested with one call to get the quotient and the remainder

With[{n = 781049}, Reverse[Reap[NestList[Block[{q, r}, 
 {q, r} = QuotientRemainder[#, 10]; Sow[r]; q] &, n, IntegerLength[n]]][[-1, 1]]]]

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings. Without giving explicit timings you can safely assume, that every function will be slower than IntegerDigits.

added 231 characters in body
Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

or as J.M. suggested with one call to get the quotient and the remainder

With[{n = 781049}, Reverse[Reap[NestList[Block[{q, r}, 
 {q, r} = QuotientRemainder[#, 10]; Sow[r]; q] &, n, IntegerLength[n]]][[-1, 1]]]]

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings.

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings.

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

or as J.M. suggested with one call to get the quotient and the remainder

With[{n = 781049}, Reverse[Reap[NestList[Block[{q, r}, 
 {q, r} = QuotientRemainder[#, 10]; Sow[r]; q] &, n, IntegerLength[n]]][[-1, 1]]]]

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings.

Source Link
halirutan
  • 113.4k
  • 7
  • 266
  • 479

This is pretty easy if you understood that we live in a world of base 10 and the principles of division with rest:

n = 781049;
Rest@Reverse[Flatten@Last@Reap@FixedPointList[(Sow[Mod[#, 10]]; Quotient[#, 10]) &, n]]
(* {7, 8, 1, 0, 4, 9} *)

If you really prefer shorter methods, than you could go with

IntegerDigits[n]

or maybe

ToExpression@StringCases[ToString[n], DigitCharacter]

if you like strings.