-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
digits(n, [base, [pad]]): returns an array of digits of n [close #2737]
- Loading branch information
1 parent
3eb0c05
commit 0d22e92
Showing
1 changed file
with
12 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d22e92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems more useful to me to return the digits in the reverse order of this, i.e. with the ones place always in
a[1]
. That way the place values are the same for all numbers, and the identityn == sum([a[k]*b^(k-1) for k=1:length(a)])
holds.0d22e92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable enough. This was just the order they print in.
0d22e92
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and it respects column major order too.
Can we generalize to take a base vector like APL's encode, (and also inspired by a "zero based" Cartesian)
(note the code is practically the same)
map(n->Alandigits(n,[5,3],3),0:14)
15-element Array{Array{Int64,1},1}:
[0,0,0]
[1,0,0]
[2,0,0]
[0,1,0]
[1,1,0]
[2,1,0]
[0,2,0]
[1,2,0]
[2,2,0]
[0,3,0]
[1,3,0]
[2,3,0]
[0,4,0]
[1,4,0]
[2,4,0]