MathGroup Archive 1999

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

Search the Archive

Re: Help needed with List!

  • To: mathgroup at
  • Subject: [mg16938] Re: [mg16909] Help needed with List!
  • From: "Hans J.-I. Michel" <hans at>
  • Date: Thu, 8 Apr 1999 02:32:40 -0400
  • Sender: owner-wri-mathgroup at

On April 6, 1999  question asked was as follows:

-----Original Message-----
From: alvaroo at <alvaroo at>
To: mathgroup at
Subject: [mg16938] [mg16909] Help needed with List!

>Sirs Probably these are FAQs but I am new in this newsgroup and I have not
>been able to solve them. I use Mathematica 3.0:  (i) I need to convert a
>integer number in List format. For example if I had the number 123456 I
>to convert it into {1,2,3,4,5,6}:  Is it possible with an instruction? And,
>(ii) I need to delete from a List A the common elements with other List B:
>for example if A = {1,2,3,4} and B = {1,2} I need to delete by an
>the elements 1, 2 of List B from List A to obtain List C = {3,4}.  I am
>working with integers with 10.000 digits or more so you can appreciate how
>helpful for me it would be to solve these questions.  Thanks in advance.
>-----------== Posted via Deja News, The Discussion Network ==----------
>       Search, Read, Discuss, or Start Your Own

Assuming you are using version 3.0 or later.

(i) To convert an integer into a list of digits in position, Mathematica has
a built in function. The function is called IntegerDigits[n], where n is
your 10,000 or more digit number. (In earlier versions it was Digits[n].) By
default the IntegerDigits[n] function output assumes you want the resulting
list in base 10. If you wish the output in different bases use
IntegerDigits[n, b], where b is your desired base.

For example:

a = your digit here; (please note you may import this number from a file)
b = ....;

Use semicolon in order not to waste memory displaying a 10,000 or more digit

alist = IntegerDigits[a];
blist = IntegerDigits[a];

At this point you have a list if you wish to display them to make certain,
then type in "alist" or "blist: at your next In[] or simply leave off the
semicolons in your declarations.

Now here comes the ambiguous part. Not knowing what kind of numbers you are
dealing with -- I move forward. In base 10 the symbols we have availabe to
us for positional representation are {0,1,2,3,4,5,6,7,8,9}. Now, if any of
your numbers or lists use up every number, then it becomes not too useful
and a waste of computational time to use the Mathematica built in function
for sets (list) -- Complement[alist, blist]. However; Complement[alist,
blist] should return the complement of alist and blist, treating alist as
the universal. The list that gets returned is a list of things in alist but
not in blist. See set theory. You can use {0,1,2,3,4,5,6,7,8,9} as your
universal, in this case you can find if alist or blist is a number, for
example that does not ever have a 9 or 2, etc.

If your list of digits alist and blist have similar elements. If for example
1,2,3,...n elements in alist is identical to 1,2,3,...(n - x) in blist then
your may want to look into the Mathematica built in function Drop[list, n],
where it drops the first n elements from a list. If you do not know the
lengths of your list, also look into Length[list].

This is should get you started.


  • Prev by Date: Re: overwrite separate notebook
  • Next by Date: Dynamic Programming
  • Previous by thread: Help needed with List!
  • Next by thread: Re: Help needed with List!