Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2014-02-22 23:33:06

Vishalini
Member
Registered: 2014-02-20
Posts: 6

Logic behind the sequence

There is some logic behind this sequence
2,3,4,5,6,6,8,8,9,10,12,12,14,14,15,16,18,18,20,20..
But I cant find what it is..dunno Please help me..

Actually, i have to write a c program to print those numbers.. But, I cant guess, in what basis, these numbers are arranged.. sad

Offline

#2 2014-02-23 00:31:35

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Logic behind the sequence

Maybe: after 10, print the next number if it is prime?


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#3 2014-02-23 01:07:52

Vishalini
Member
Registered: 2014-02-20
Posts: 6

Re: Logic behind the sequence

U mean, after 10.. the numbers 12,14,15 are all prime??? No, its not possible  :'(

Offline

#4 2014-02-23 02:00:01

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Logic behind the sequence

I meant
11 -> 12
13 -> 14
17 -> 18
19 -> 20
etc.


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#5 2014-02-23 04:43:42

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: Logic behind the sequence

Here's my logic, but I don't know C and so I can't help there.

Edit: Hi gAr, I just realised that our methods are much alike - other than my reference to multiples of 6.

x=1
1. Increment x by 1 and print x unless x is a multiple-digit prime for which Mod[x,6]=5.
2. If Mod[x,6]=0, print x again and x+2 twice; but if not, GoTo 1.
3. x = x + 2
4. GoTo 1.

I think my pseudo code works...

Last edited by phrontister (2014-02-23 09:52:18)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#6 2014-02-23 06:39:19

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: Logic behind the sequence

Hi,

Here's my code in Mathematica. The sequence program works, but I don't know how to convert the output column into a one-line row such as in post #1. 

Last edited by phrontister (2014-02-24 10:06:27)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

#7 2014-02-23 15:34:00

gAr
Member
Registered: 2011-01-09
Posts: 3,482

Re: Logic behind the sequence

Hi phrontister,

Nice! I think you may collect the terms and flatten it.


"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense"  - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

#8 2014-02-23 23:21:13

phrontister
Real Member
From: The Land of Tomorrow
Registered: 2009-07-12
Posts: 4,810

Re: Logic behind the sequence

Hi gAr,

Thanks...I'd already tried collecting the terms with Table and some other commands, but nothing worked until I replaced Print with Sow and Reap. Then I used Last to remove "Null" from the front of the list and Flatten to leave just one set of external curly brackets (removing that last set seems to need too much extra code for no real value other than visual, and so I left the brackets there).

Last edited by phrontister (2014-02-23 23:33:11)


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Offline

Board footer

Powered by FluxBB