summaryrefslogtreecommitdiff
path: root/48/CH4/EX4.3/eg_4_3.sce
blob: df5c48f063b90c009ea192f39a07c606226dc617 (plain)
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
clc;
n=4;        //four variable kmap
k=[0 0 1 0;
   1 1 1 0;
   0 1 1 1;
   0 1 0 0];
k(:,:,2)=zeros(n,n);     //temporary matrix to know whether a element is paired or not
//declaring notations to display output
var=['y' 'z' 'w' 'x'];
p1=['y^z^' 'y''z' 'yz' 'yz'''];
p2=['w^x^';'w''x';'wx';'wx'''];
//minimum redundant elements accepted while pairing
cmn4=1;
cmn2=1;
temp=1;
disp("The minimal ecpression of the given Kmap ");
disp(k(:,:,1));
disp("is :");
disp(" ")
//16 cells
for i=1:n
    for j=1:n
        if(k(i,j)~=1)
            temp=0;
            break;
         end
    end
end
printf('f=');
if(temp==1)
    printf("1");
    abort;
end
//8 cells
z1=ones(2,4);
z2=ones(4,2);
temp1=['00' '01' '11' '10'];
temp2=temp1';
for i=1:n
        if(i==4)
            t=1;
        else
            t=i+1;
        end
        z=[k(i,:,1);k(t,:,1)];
        if(z==z1)
            k(i,:,2)=[1 1 1 1];
            k(t,:,2)=[1 1 1 1];
            a=strsplit(temp2(i,1));
            b=strsplit(temp2(t,1));
            c=strcmp(a,b);
            for in=1:max(size(c))
                if(c(in)==0 & a(in)=='0')
                    printf('%s''',var(in));
                    printf('+');
                    break;
                 else
                     if(c(in)==0 & a(in)=='1')
                        printf(var(in));
                        printf('+');
                        break;
                      end
                 end
            end
        end
end
for j=1:n
    if(j==4)
        t=1;
    else
        t=j+1;
    end
    z=[k(:,j,1) k(:,t,1)];
    if(z==z2)
        k(:,j,2)=[1;1;1;1];
        k(:,t,2)=[1;1;1;1];
        a=strsplit(temp1(1,j));
        b=strsplit(temp1(1,t));
        c=strcmp(a,b);
        for in=1:max(size(c))
            if(c(in)==0 & a(in)=='0')
                printf('%s''',var(2+in));
                printf('+');
                break;
             else
                 if(c(in)==0 & a(in)=='1')
                     printf(var(2+in));
                     printf('+');
                     break;
                 end
             end
        end
   end
end
//2 cells
z6=[1 1];
z7=z6';
for i=1:n
    for j=1:n
        if(i==n)
            t1=1;
        else
            t1=i+1;
        end
       if(j==n)
            t2=1;
        else
            t2=j+1;
        end
        z8=[k(i,j,1) k(i,t2,1)];
        z9=[k(i,j,2) k(i,t2,2)];
        no1=number_of(z9,1);
        if(z8==z6 & no1<cmn2)
            if(i==3 & i+j==5)
                ;
            else
              k(i,j,2)=1;
              k(i,t2,2)=1;
              a=strsplit(temp1(1,j));
              b=strsplit(temp1(1,t2));
              c=strcmp(a,b);
                for in=1:max(size(c))
                    if(c(in)==0 & a(in)=='0')
                        printf(p1(1,i));
                        printf('%s''',var(2+in));
                        printf("+");
                     end
                     if(c(in)==0 & a(in)=='1')
                         printf(p1(1,i));
                         printf(var(2+in));
                         printf("+");
                     end
                 end
            end
        end
    end
end
for i=1:n
    for j=1:n
        if(i==n)
            t1=1;
        else
            t1=i+1;
        end
       if(j==n)
            t2=1;
        else
            t2=j+1;
        end
        z10=[k(i,j,1);k(t1,j,1)];
        z11=[k(i,j,2);k(t1,j,2)];
        no2=number_of(z11,1);
        if(z10==z7 & no2<cmn2)
          k(i,j,2)=1;
          k(t1,j,2)=1;
          a=strsplit(temp2(i,1));
          b=strsplit(temp2(t1,1));
          c=strcmp(a,b);
            for in=1:max(size(c))
                if(c(in)==0 & a(in)=='0')
                    printf(p2(j,1));
                    printf('%s''',var(in));
                    printf("+");
                 end
                 if(c(in)==0 & a(in)=='1')
                     printf(p2(j,1));
                     printf(var(in));
                     printf("+");
                 end
             end
        end
    end
end
//4 cells
z1=ones(1,4);
z2=ones(4,1);
z3=ones(2,2);
temp1=['00' '01' '11' '10'];
temp2=temp1';
for t=1:n
        z=k(t,:,1);
        no=number_of(k(t,:,2),1);
        if(z==z1 & no<cmn4)
            k(t,:,2)=z1;
            a=strsplit(temp1(1,t));
            for in=1:max(size(a))
                if(a(in)=='0')
                    printf('%s''',var(in));
                 end
                 if(a(in)=='1')
                     printf(var(in));
                 end
             end
             printf("+");
          end
end
for t=1:n
    z=k(:,t,1);
    no=number_of(k(:,t,2),1);
    if(z==z2 & no<cmn4)
        k(:,t,2)=z2;
        a=strsplit(temp2(t,1));
        for in=1:max(size(a))
            if(a(in)=='0')
                printf('%s''',var(2+in));
             end
             if(a(in)=='1')
                 printf(var(2+in));
             end
        end
             printf("+");
    end
end
for i=1:n
    for j=1:n
       if(i==n)
            t1=1;
        else
            t1=i+1;
        end
       if(j==n)
            t2=1;
        else
            t2=j+1;
        end
        z4=[k(i,j,1) k(i,t2,1);k(t1,j,1) k(t1,t2,1)];
        z5=[k(i,j,2) k(i,t2,2);k(t1,j,2) k(t1,t2,2)];
        no=number_of(z5,1);
        if(z4==z3 & no<cmn4)
            k(i,j,2)=1;
            k(i,t2,2)=1;
            k(t1,j,2)=1;
            k(t1,t2,2)=1;
            a=strsplit(temp2(i,1));
            b=strsplit(temp2(t1,1));
            c=strcmp(a,b);
            for in=1:max(size(c))
                if(c(in)==0 & a(in)=='0')
                    printf('%s''',var(in));
                 end
                 if(c(in)==0 & a(in)=='1')
                     printf(var(in));
                 end
             end
            a=strsplit(temp1(1,j));
            b=strsplit(temp1(1,t2));
            c=strcmp(a,b);
            for in=1:max(size(c))
                if(c(in)==0 & a(in)=='0')
                    printf('%s''',var(2+in));
                 end
                 if(c(in)==0 & a(in)=='1')
                     printf(var(2+in));
                 end
             end
             printf("+");
        end
    end
end
//single cell
for i=1:n
    for j=1:n
        if(k(i,j,2)==0 & k(i,j,1)==1)
            a=strsplit(temp1(1,j));
            b=strsplit(temp2(i,1));
            for in=1:max(size(a(:,1)))
                if(a(in,1)=='1')
                    printf(var(in+2));
                else
                    if(a(in,1)=='0')
                        printf('%s''',var(2+in));
                    end
                 end
            end
            for in=1:max(size(b(:,1)))
                if(b(in,1)=='1')
                    printf(var(in));
                else
                    if(b(in,1)=='0')
                        printf('%s''',var(in));
                    end
                 end
            end
            printf("+");
        end
    end
end
printf("0");