[ create a new paste ] login | about

Link: http://codepad.org/WhHDxJAZ    [ raw code | output | fork ]

C++, pasted on Sep 13:
#include <iostream>

using namespace std;

void initializeSequence(int sequence[], int size); // fill the array with numbers 1-size
void createSequence(int sequence[],int sequnceArraySize, int divisor[], int divisorArraySize); //modifies the squence array to contain the hamming sequence
void printSequence(int sequence[],int size); //prints out the array
int findNextTerm(int sequence[], int sequenceIndex, int divisor[], int divisorArraySize, int& testNum); // reutrns true if the test num is part of the hammin sequence
int findDivisor(int divisorArray[], int divisorSize, int testNumber); // returns the divisor of the testNumber if one is found in the divisor array else reutrns 0
bool canFindQuotient(int sequence[], int sequenceIndex, int numToFind); // returns true if the numToFind is in the sequence array in a index below the sequence index 

int main()
{
	char letter;
	// initialize 
	// divisor array
	const int DIVISORSIZE = 3;
	int divisors[DIVISORSIZE] = {2,3,5};
	// sequence array
	const int SEQUENCESIZE = 1000;
	int hammingSequence[SEQUENCESIZE];

	initializeSequence(hammingSequence,SEQUENCESIZE);
	// ask the user for the seed number
	// create the hamming sequence
	createSequence(hammingSequence,SEQUENCESIZE,divisors,DIVISORSIZE);
	// print the sequence
	printSequence(hammingSequence,SEQUENCESIZE);

	cin >> letter;

return(-1);
}
// fill the array with numbers 1 through size
void initializeSequence(int sequence[], int size)
{
	// loops through the array
	for(int i  = 0; i < size; i++)
		// sets the value of the array to the index value +1
		sequence[i] = i+1;
}
//modifies the squence array to contain the hamming sequence
void createSequence(int sequence[],int sequenceArraySize, int divisor[], int divisorArraySize) 
{
	int testNum = 2;
	// loops through each index in the array
	for(int index = 1; index < sequenceArraySize; index++)
	{
		// tests all integers until the array is full
		// adds it to the next position in the array
			sequence[index] = findNextTerm(sequence,index,divisor,divisorArraySize,testNum);
			testNum++;
		
			cout << index << "\t" <<sequence[index] <<  endl; // shows the next term as it is found
	}
}
//prints out the array
void printSequence(int sequence[],int size) 
{
	//loop through the array
	for(int i = 0; i < size; i++)
		// prints out the value of the array and it's position
		cout << sequence[i] << "\t";
}
// reutrns true if the test num is part of the hammin sequence
int findNextTerm(int sequence[], int sequenceIndex, int divisor[], int divisorArraySize, int& testNum) 
{
	int flag = -1;
	// if the test num is divisible by a number in the divisible array
	int divisorNum = 0;
	divisorNum = findDivisor(divisor,divisorArraySize,testNum);
	
	while(flag == -1 ) // catch flag
	{
		
		if(flag != divisorNum)
			// check to see if the quotient can be found in the sequence array
			if(canFindQuotient(sequence,testNum/divisorNum,sequenceIndex))
				// if so return the test num.
				return(testNum);
			// else set increment the test num and try again
			else
			{
				testNum++;
				flag = -1;
			}
		else
			testNum++;

		divisorNum = findDivisor(divisor,divisorArraySize,testNum);
	}
     return(-1);//will never happen
}
// returns the divisor of the testNumber if one is found in the divisor array else reutrns 0
int findDivisor(int divisorArray[], int divisorSize, int testNumber)
{
	//loop through the divisor array 
	for(int index = 0; index < divisorSize; index++)
	{
		// if the test num is divisible by one 
		if(testNumber % divisorArray[index] == 0)
		//return the divisor
			return(divisorArray[index]);
	}
	// else reuturn -1
	return(-1);
}
// returns true if the numToFind is in the sequence array in a index below the sequence index 
bool canFindQuotient(int sequence[], int numToFind, int sequenceIndex) 
{
	//loop through the sequence array up to the currentIndex
	for(int index = 0; index < sequenceIndex; index++)
	{
		// if the numtoFind is in the array return true
		if(numToFind == sequence[index])
		{
			return(true);
		}
	}
	// return false
	return(false);
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
1	2
2	3
3	4
4	5
5	6
6	8
7	9
8	10
9	12
10	15
11	16
12	18
13	20
14	24
15	25
16	27
17	30
18	32
19	36
20	40
21	45
22	48
23	50
24	54
25	60
26	64
27	72
28	75
29	80
30	81
31	90
32	96
33	100
34	108
35	120
36	125
37	128
38	135
39	144
40	150
41	160
42	162
43	180
44	192
45	200
46	216
47	225
48	240
49	243
50	250
51	256
52	270
53	288
54	300
55	320
56	324
57	360
58	375
59	384
60	400
61	405
62	432
63	450
64	480
65	486
66	500
67	512
68	540
69	576
70	600
71	625
72	640
73	648
74	675
75	720
76	729
77	750
78	768
79	800
80	810
81	864
82	900
83	960
84	972
85	1000
86	1024
87	1080
88	1125
89	1152
90	1200
91	1215
92	1250
93	1280
94	1296
95	1350
96	1440
97	1458
98	1500
99	1536
100	1600
101	1620
102	1728
103	1800
104	1875
105	1920
106	1944
107	2000
108	2025
109	2048
110	2160
111	2187
112	2250
113	2304
114	2400
115	2430
116	2500
117	2560
118	2592
119	2700
120	2880
121	2916
122	3000
123	3072
124	3125
125	3200
126	3240
127	3375
128	3456
129	3600
130	3645
131	3750
132	3840
133	3888
134	4000
135	4050
136	4096
137	4320
138	4374
139	4500
140	4608
141	4800
142	4860
143	5000
144	5120
145	5184
146	5400
147	5625
148	5760
149	5832
150	6000
151	6075
152	6144
153	6250
154	6400
155	6480
156	6561
157	6750
158	6912
159	7200
160	7290
161	7500
162	7680
163	7776
164	8000
165	8100
166	8192
167	8640
168	8748
169	9000
170	9216
171	9375
172	9600
173	9720
174	10000
175	10125
176	10240
177	10368
178	10800
179	10935
180	11250
181	11520
182	11664
183	12000
184	12150
185	12288
186	12500
187	12800
188	12960
189	13122
190	13500
191	13824
192	14400
193	14580
194	15000
195	15360
196	15552
197	15625
198	16000
199	16200
200	16384
201	16875
202	17280
203	17496
204	18000
205	18225
206	18432
207	18750
208	19200
209	19440
210	19683
211	20000
212	20250
213	20480
214	20736
215	21600
216	21870
217	22500
218	23040
219	23328
220	24000
221	24300
222	24576
223	25000
224	25600
225	25920
226	26244
227	27000
228	27648
229	28125
230	28800
231	29160
232	30000
233	30375
234	30720
235	31104
236	31250
237	32000
238	32400
239	32768
240	32805
241	33750
242	34560
243	34992
244	36000
245	36450
246	36864
247	37500
248	38400
249	38880
250	39366
251	40000
252	40500
253	40960
254	41472
255	43200
256	43740
257	45000
258	46080
259	46656
260	46875
261	48000
262	48600
263	49152
264	50000
265	50625
266	51200
267	51840
268	52488
269	54000
270	54675
271	55296
272	56250
273	57600
274	58320
275	59049
276	60000
277	60750
278	61440
279	62208
280	62500
281	64000
282	64800
283	65536
284	65610
285	67500
286	69120
287	69984
288	72000
289	72900
290	73728
291	75000
292	76800
293	77760
294	78125
295	78732
296	80000
297	81000
298	81920
299	82944
300	84375
301	86400
302	87480
303	90000
304	91125
305	92160
306	93312
307	93750
308	96000
309	97200
310	98304
311	98415
312	100000
313	101250
314	102400
315	103680
316	104976
317	108000
318	109350
319	110592
320	112500
321	115200
322	116640
323	118098
324	120000
325	121500
326	122880
327	124416
328	125000
329	128000
330	129600
331	131072
332	131220
333	135000
334	138240
335	139968
336	140625
337	144000
338	145800
339	147456
340	150000
341	151875
342	153600
343	155520
344	156250
345	157464
346	160000
347	162000
348	163840
349	164025
350	165888
351	168750
352	172800
353	174960
354	177147
355	180000
356	182250
357	184320
358	186624
359	187500
360	192000
361	194400
362	196608
363	196830
364	200000
365	202500
366	204800
367	207360
368	209952
369	216000
370	218700
371	221184
372	225000
373	230400
374	233280
375	234375
376	236196
377	240000
378	243000
379	245760
380	248832
381	250000
382	253125
383	256000
384	259200
385	262144
386	262440
387	270000
388	273375
389	276480
390	279936
391	281250
392	288000
393	291600
394	294912
395	295245
396	300000
397	303750
398	307200
399	311040
400	312500
401	314928
402	320000
403	324000
404	327680
405	328050
406	331776
407	337500
408	345600
409	349920
410	354294
411	360000
412	364500
413	368640
414	373248
415	375000
416	384000
417	388800
418	390625
419	393216
420	393660
421	400000
422	405000
423	409600
424	414720
425	419904
426	421875
427	432000
428	437400
429	442368
430	450000
431	455625
432	460800
433	466560
434	468750
435	472392
436	480000
437	486000
438	491520
439	492075
440	497664
441	500000
442	506250
443	512000
444	518400
445	524288
446	524880
447	531441
448	540000
449	546750
450	552960
451	559872
452	562500
453	576000
454	583200
455	589824
456	590490
457	600000
458	607500
459	614400
460	622080
461	625000
462	629856
463	640000
464	648000
465	655360
466	656100
467	663552
468	675000
469	691200
470	699840
471	703125
472	708588
473	720000
474	729000
475	737280
476	746496
477	750000
478	759375
479	768000
480	777600
481	781250
482	786432
483	787320
484	800000
485	810000
486	819200
487	820125
488	829440
489	839808
490	843750
491	864000
492	874800
493	884736
494	885735
495	900000
496	911250
497	921600
498	933120
499	937500
500	944784
501	960000
502	972000
503	983040
504	984150
505	995328
506	1000000
507	1012500
508	1024000
509	1036800
510	1048576
511	1049760
512	1062882
513	1080000
514	1093500
515	1105920
516	1119744
517	1125000
518	1152000
519	1166400
520	1171875
521	1179648
522	1180980
523	1200000
524	1215000
525	1228800
526	1244160
527	1250000
528	1259712
529	1265625
530	1280000
531	1296000
532	1310720
533	1312200
534	1327104
535	1350000
536	1366875
537	1382400
538	1399680
539	1406250
540	1417176
541	1440000
542	1458000
543	1474560
544	1476225
545	1492992
546	1500000
547	1518750
548	1536000
549	1555200
550	1562500
551	1572864
552	1574640
553	1594323
554	1600000
555	1620000
556	1638400
557	1640250
558	1658880
559	1679616
560	1687500
561	1728000
562	1749600
563	1769472
564	1771470
565	1800000
566	1822500
567	1843200
568	1866240
569	1875000
570	1889568
571	1920000
572	1944000
573	1953125
574	1966080
575	1968300
576	1990656
577	2000000
578	2025000
579	2048000
580	2073600
581	2097152
582	2099520
583	2109375
584	2125764
585	2160000
586	2187000
587	2211840
588	2239488
589	2250000
590	2278125
591	2304000
592	2332800
593	2343750
594	2359296
595	2361960
596	2400000
597	2430000
598	2457600
599	2460375
600	2488320
601	2500000
602	2519424
603	2531250
604	2560000
605	2592000
606	2621440
607	2624400
608	2654208
609	2657205
610	2700000
611	2733750
612	2764800
613	2799360
614	2812500
615	2834352
616	2880000
617	2916000
618	2949120
619	2952450
620	2985984
621	3000000
622	3037500
623	3072000
624	3110400
625	3125000
626	3145728
627	3149280
628	3188646
629	3200000
630	3240000
631	3276800
632	3280500
633	3317760
634	3359232
635	3375000
636	3456000
637	3499200
638	3515625
639	3538944
640	3542940
641	3600000
642	3645000
643	3686400
644	3732480
645	3750000
646	3779136
647	3796875
648	3840000
649	3888000
650	3906250
651	3932160
652	3936600
653	3981312
654	4000000

Timeout


Create a new paste based on this one


Comments: