-
Notifications
You must be signed in to change notification settings - Fork 0
/
ribasen.h
110 lines (95 loc) · 2.39 KB
/
ribasen.h
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
#include "stdlib.h"
#include <iostream>
#include <fstream>
using namespace std;
char result[]={};
int len,max_baseN_width,start_range,x=0,y=0;
enum states {began,continued};
states mode;
ofstream file;
//max_baseN_width play role in incrementing the (len)
//len is length of each array of characters printed or generated
//basen is core function which do the recursive approach for generating the data as baseN
void basen(char baseN_arr[], int baseN_arr_len, int len, int max_baseN_width)
{
if(len == 0)
{
file.open("example.txt", std::ios_base::app);
file<<result<<endl;
file.close();
return;
}
for(int index=0; index < baseN_arr_len; index++)
{
result[max_baseN_width-len]=baseN_arr[index];
basen(baseN_arr, baseN_arr_len, len-1, max_baseN_width);
}
}
void basen(string stopped, char baseN_arr[], int baseN_arr_len, int len, int max_baseN_width, states mode)
{
int start[]={};
if(mode==1)
{
for ( int j = 0; j < stopped.size(); j++)
{
for ( int i = 0; i < baseN_arr_len; i++)
{
if(stopped[j]==baseN_arr[i])
{
start[j]=i;
}
}
}
}
if(len == 0)
{
file.open("example.txt", std::ios_base::app); //opening and appending to the file
file<<result<<endl; //appending data to the file
file.close();
return;
}
if(mode==continued)
{
for(int index=start[x]; index < baseN_arr_len; index++)
{
result[max_baseN_width-len]=baseN_arr[index];
if(x<stopped.size())
{
x++;
start[x];
}
else
{
mode=began;
}
basen(stopped, baseN_arr, baseN_arr_len, len-1, max_baseN_width, mode);
}
}
else if(mode==began)
{
for(int index=0; index < baseN_arr_len; index++)
{
result[max_baseN_width-len]=baseN_arr[index];
basen(stopped, baseN_arr, baseN_arr_len, len-1, max_baseN_width, mode);
}
}
}
//ribasen is core function doing the incrementing feature
void ribasen(string stopped,char baseN_arr[], int baseN_arr_len , int len, int start_range, int max_baseN_width, states mode)
{
if(mode==continued)
{
for(int crnt_len=start_range;crnt_len<len+1;crnt_len++)
{
basen(stopped, baseN_arr, baseN_arr_len, crnt_len, crnt_len, mode);
mode=began;
}
}
else if(mode==began)
{
for(int crnt_len=start_range;crnt_len<len+1;crnt_len++)
{
basen(baseN_arr, baseN_arr_len, crnt_len, crnt_len);
}
}
}