Message Boards Message Boards

0
|
7275 Views
|
7 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Generate numbers of the form 'abab'?

Posted 5 years ago

Hi I wish to generate a set of 4-digit numbers of the form 'abab' e.g. 2323,4646 etc using digits 0 through 9 including numbers of the type 2222 etc. Thanks for any help.

POSTED BY: jagannath debata
7 Replies
Posted 5 years ago

Or quite simply

a = Range[10, 99]; 100 a + a
POSTED BY: Paul Cleary

Hi,

perhaps this one might work?

100 # + # & /@ Range[10, 99]

But that doesn't do sequences with leading zeros. This works with leading zeros:

StringJoin[#, #] & /@ (StringJoin /@ Tuples[ToString /@ Range[0, 9], 2])

Cheers,

Marco

POSTED BY: Marco Thiel

Thanks all for the help.

POSTED BY: jagannath debata

Or this

Select[Flatten[
  Table[a + 10 b + 100 a + 1000 b, {a, 0, 9}, {b, 0, 9}]], # > 1000 &]
POSTED BY: Hans Dolhaine

Another approach:

aa = RandomInteger[{10, 99}, 50]; aa + 100*aa

gives you 50 of them or you can make it a function

makeNumbers[x_] := 
 Module[{aa}, aa = RandomInteger[{10, 99}, x]; aa + 100*aa]

you can do makeNumbers[50] to get 50 of them.

Note that using this approach you can never get a 0 for a in abab.

You can fix that by doing each digit independently:

aa = RandomInteger[{0, 9}, 50] + 10*RandomInteger[{0, 9}, 50];aa+100*aa

Regards,

Neil

POSTED BY: Neil Singer
Posted 5 years ago

This is an example of another approach:

In[1]:= RandomInteger[{1000, 9999}, 5]

Out[1]= {4369, 2458, 7269, 8315, 9205}
POSTED BY: Hans Milton
Posted 5 years ago

This is one way, there will be many other ways too

a = Tuples[Range[0, 9], {2}]; Select[
 FromDigits /@ Partition[Flatten[Riffle[a, a]], 4], 
 IntegerLength[#] == 4 &]

{1010, 1111, 1212, 1313, 1414, 1515, 1616, 1717, 1818, 1919, 2020, \
2121, 2222, 2323, 2424, 2525, 2626, 2727, 2828, 2929, 3030, 3131, \
3232, 3333, 3434, 3535, 3636, 3737, 3838, 3939, 4040, 4141, 4242, \
4343, 4444, 4545, 4646, 4747, 4848, 4949, 5050, 5151, 5252, 5353, \
5454, 5555, 5656, 5757, 5858, 5959, 6060, 6161, 6262, 6363, 6464, \
6565, 6666, 6767, 6868, 6969, 7070, 7171, 7272, 7373, 7474, 7575, \
7676, 7777, 7878, 7979, 8080, 8181, 8282, 8383, 8484, 8585, 8686, \
8787, 8888, 8989, 9090, 9191, 9292, 9393, 9494, 9595, 9696, 9797, \
POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract