Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs251_group29
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
AYUSH RAJ
cs251_group29
Commits
ede95118
Commit
ede95118
authored
Aug 24, 2016
by
AYUSH RAJ
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lab01
parents
Changes
5
Hide whitespace changes
Inline
Sidebyside
Showing
5 changed files
with
99 additions
and
0 deletions
+99
0
lab01_group29_inlab/adj.m
lab01_group29_inlab/adj.m
+11
0
lab01_group29_inlab/final_state_3.m
lab01_group29_inlab/final_state_3.m
+11
0
lab01_group29_inlab/genmatrix.m
lab01_group29_inlab/genmatrix.m
+11
0
lab01_group29_inlab/lookup_solve_3.m
lab01_group29_inlab/lookup_solve_3.m
+45
0
lab01_group29_inlab/readme.txt
lab01_group29_inlab/readme.txt
+21
0
No files found.
lab01_group29_inlab/adj.m
0 → 100644
View file @
ede95118
function [b] = adj(k,l) %this function returns 1 if k th and l th cells are adjacent and zero otherwise
row_k = floor(k/3); %computing the corresponding row and column corresponding to k th and l th cell
row_l = floor(l/3);
col_k = mod(k,3);
col_l = mod(l,3);
if((row_krow_l)^2+(col_kcol_l)^2
<
=
1
)
b =
1;
else
b =
0;
endif
endfunction
lab01_group29_inlab/final_state_3.m
0 → 100644
View file @
ede95118
function [B] = final_state_3(initial,action) % initial is the matrix to be updated after the operating action
A = genmatrix(); % generate a matrix (9*9) where (i,j)th entry is 1 if i th and j th cells are adjacent and 0 otherwise
action = action';
action = reshape(action,9,1);
action = (A*action);
action = reshape(action,3,3);
action = action';
B = mod((initial + action),2); %computing the effect of action by using the logic given at http://www.ueda.info.waseda.ac.jp/~nkato/lightsout/
return;
endfunction
\ No newline at end of file
lab01_group29_inlab/genmatrix.m
0 → 100644
View file @
ede95118
function
[
A
]
=
genmatrix
()
%this function generates a matrix (9*9) where (i,j)th entry is 1 if i th and j th cells are adjacent and 0 otherwise
A
=
zeros
(
9
);
for
i
=
0
:
8
for
j
=
0
:
8
if
(
adj
(
i
,
j
)
==
1
)
A
(
i
+
1
,
j
+
1
)
=
1
;
endif
end
end
%display(A)
endfunction
lab01_group29_inlab/lookup_solve_3.m
0 → 100644
View file @
ede95118
%A = floor(2*rand(3,3)); % make an abritrary input
%disp('The matrix to be solved is:')
%disp(A); % print it
function
[
answer
]
=
lookup_solve_3
(
A
)
% takes A as an arguement
lookup_matrix
=
[
3
7
4
6
5
1
2
];
% decimal form of the given table
answer
=
zeros
(
3
);
% the required final action matrix
dec_equiv
=
1
;
% to enter the below loop for first time
while
dec_equiv
>
0
% checks decimal equivalent of the last row
for
variable
=
[
2
3
]
action
=
zeros
(
3
);
% action matrix : 0 means no flipping of switch
action
(
variable
,:)
=
A
(
variable

1
,:);
% ith row of action matrix is updated with the (i1)th row of input A
A
=
final_state_3
(
A
,
action
);
answer
=
answer
+
action
;
% each action matrix is added to this final answer matrix
end
dec_equiv
=
4
*
A
(
3
,
1
)
+
2
*
A
(
3
,
2
)
+
A
(
3
,
3
);
% calculates decimal equivalent of the last binary row.
if
(
dec_equiv
>
0
)
num
=
lookup_matrix
(
dec_equiv
);
% num is the corresponding decimal from the lookup_matrix
C
=
zeros
(
3
,
1
);
for
var
=
[
3
2
1
]
% breaking num into binary form and storing it in the row vector C
C
(
var
)
=
mod
(
num
,
2
);
num
=
floor
(
num
/
2
);
end
%change A/
action1
=
zeros
(
3
);
action1
(
1
,:)
=
C
;
% action to be taken in the first row
A
=
final_state_3
(
A
,
action1
);
% state of A after action1
answer
=
answer
+
action1
;
% updating the final answer matrix
answer
=
mod
(
answer
,
2
);
endif
endwhile
answer
=
mod
(
answer
,
2
);
%disp('The answer is :')
%disp(answer);
return
endfunction
lab01_group29_inlab/readme.txt
0 → 100644
View file @
ede95118
Group No  29
Group Name  puzzle
(Ayush Raj , 150050042):100%
(Umesh Kumar , 150050052):100%
(Ankan Sardar , 150050064):100%
Honor Code:
" We pledge on our honor that we have not given or received any unauthorised assistance for this assignment or any previous task!"
citations:
https://en.wikibooks.org/wiki/Octave_Programming_Tutorial
http://www.ueda.info.waseda.ac.jp/~nkato/lightsout/
http://www.gnu.org/software/octave/octave.pdf
http://www.dm.unibo.it/~lenci/teaching/14/maa/octavetut.pdf
Reflection Essay:
We got to know an algorithmic solution to "lights Out" puzzle. We also learnt the implementations of various operations on matrices in octave environment and how to write functions in octave.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment