Notes
![]() ![]() Notes - notes.io |
## struct Puzzle {
## int size;
## Cell *grid;
## };
##
## // Given the assignment at current position, removes all inconsistent values
## // for cells in the same row, column, and cage.
## int
## forward_checking(int position, Puzzle *puzzle) {
## int size = puzzle->size;
## // Removes inconsistent values in the row.
## for (int col = 0; col < size; col++) {
## if (col != position % size) {
## int row_pos = position / size * size + col;
## puzzle->grid[row_pos].domain &= ~puzzle->grid[position].domain;
## if (!puzzle->grid[row_pos].domain) {
## return 0;
## }
## }
## }
## // Removes inconsistent values in the column.
## for (int row = 0; row < size; row++) {
## if (row != position / size) {
## int col_pos = row * size + position % size;
## puzzle->grid[col_pos].domain &= ~puzzle->grid[position].domain;
## if (!puzzle->grid[col_pos].domain) {
## return 0;
## }
## }or (int i = 0; i < puzzle->grid[position].cage->num_cell; i++) {
## int cage_pos = puzzle->grid[position].cage->positions[i];
## puzzle->grid[cage_pos].domain &= get_domain_for_cell(cage_pos, puzzle);
## if (!puzzle->grid[cage_pos].domain) {
## return 0;
## }
## }
## }
## // Removes inconsistent values in the cage.
## for (int i = 0; i < puzzle->grid[position].cage->num_cell; i++) {
## int cage_pos = puzzle->grid[position].cage->positions[i];
## puzzle->grid[cage_pos].domain &= get_domain_for_cell(cage_pos, puzzle);
## if (!puzzle->grid[cage_pos].domain) {
## return 0;
## }
## }
## return 1;
## }
.globl forward_checking
forward_checking:
# Your code goes here :)
lw $t0, 0($a1) #size = puzzle->size
li $t1, 0 #col = 0
lw $t2, 4($a1) #&puzzle->grid
loop1:
bge $t1, $t0, endloop1 # !(col<size)
rem $t7, $a0, $t0 # position%size
beq $t1, $t7, skip1 #(col == position%size)
div $t3, $a0, $t0 #position/size
mul $t3, $t3, $t0 #position / size * size
add $t3, $t3, $t1 #row_pos = position/size * size +col
mul $t3, $t3, 8 #row_pos*8
add $t3, $t2, $t3 #&puzzle->grid[row_pos]
lw $t4, 0($t3) #puzzle->grid[row_pos].domain
mul $t5, $a0, 8 #position*8
add $t5, $t2, $t5 #&puzzle->grid[position]
lw $t6, 0($t5) #puzzle->grid[position].domain
not $t6, $t6 #~puzzle->grid[position].domain
and $t4, $t4, $t6
sw $t4, 0($t3)
bne $t4, $0, skip1 #!0
li $v0, 0
jr $ra
skip1:
addi $t1, $t1, 1 #col++
j loop1
endloop1:
li $t1, 0 #row = 0
loop2:
bge $t1, $t0, endloop2 # !(row<size)
div $t7, $a0, $t0 # position/size
beq $t1, $t7, skip2 #(row == position/size)
mul $t3, $t1, $t0 #row*size
rem $t8, $a0, $t0 #position % size
add $t3, $t3, $t8 #col_pos = row * size + position % size
mul $t3, $t3, 8 #row_pos*8
add $t3, $t2, $t3 #&puzzle->grid[row_pos]
lw $t4, 0($t3) #puzzle->grid[row_pos].domain
mul $t5, $a0, 8 #position*8
add $t5, $t2, $t5 #&puzzle->grid[position]
lw $t6, 0($t5) #puzzle->grid[position].domain
not $t6, $t6 #~puzzle->grid[position].domain
and $t4, $t4, $t6
sw $t4, 0($t3)
bne $t4, $0, skip2 #!0
li $v0, 0
jr $ra
skip2:
addi $t1, $t1, 1 #row++
j loop2
endloop2:
sub $sp, $sp, 28
sw $ra, 0($sp)
sw $s0, 4($sp)
sw $s1, 8($sp)
sw $s2, 12($sp)
sw $s3, 16($sp)
sw $s4, 20($sp)
sw $s5, 24($sp)
move $s2, $a1
move $s0, $t2 #&puzzle->grid
li $s1, 0 #i = 0
mul $t0, $a0, 8 #position*8
add $t1, $s0, $t0 #&puzzle->grid[position]
lw $s3, 4($t1) #&puzzle->grid[position].cage
lw $s4, 8($s3) #puzzle->grid[position].cage->num_cell
loop3:
bge $s1, $s4, endloop3 #!(i<puzzle->grid[position].cage->num_cell)
lw $t2, 12($s3) #&puzzle->grid[position].cage->positions
mul $t1, $s1, 4 #i*4.text
## struct Puzzle {
## int size;
## Cell *grid;
## };
##
## // Given the assignment at current position, removes all inconsistent values
## // for cells in the same row, column, and cage.
## int
## forward_checking(int position, Puzzle *puzzle) {
## int size = puzzle->size;
## // Removes inconsistent values in the row.
## for (int col = 0; col < size; col++) {
## if (col != position % size) {
## int row_pos = position / size * size + col;
## puzzle->grid[row_pos].domain &= ~puzzle->grid[position].domain;
## if (!puzzle->grid[row_pos].domain) {
## return 0;
## }
## }
## }
## // Removes inconsistent values in the column.
## for (int row = 0; row < size; row++) {
## if (row != position / size) {
## int col_pos = row * size + position % size;
## puzzle->grid[col_pos].domain &= ~puzzle->grid[position].domain;
## if (!puzzle->grid[col_pos].domain) {
## return 0;
## }
## }or (int i = 0; i < puzzle->grid[position].cage->num_cell; i++) {
## int cage_pos = puzzle->grid[position].cage->positions[i];
## puzzle->grid[cage_pos].domain &= get_domain_for_cell(cage_pos, puzzle);
## if (!puzzle->grid[cage_pos].domain) {
## return 0;
## }
## }
## }
## // Removes inconsistent values in the cage.
## for (int i = 0; i < puzzle->grid[position].cage->num_cell; i++) {
## int cage_pos = puzzle->grid[position].cage->positions[i];
## puzzle->grid[cage_pos].domain &= get_domain_for_cell(cage_pos, puzzle);
## if (!puzzle->grid[cage_pos].domain) {
## return 0;
## }
## }
## return 1;
## }
.globl forward_checking
forward_checking:
# Your code goes here :)
lw $t0, 0($a1) #size = puzzle->size
li $t1, 0 #col = 0
lw $t2, 4($a1) #&puzzle->grid
loop1:
bge $t1, $t0, endloop1 # !(col<size)
rem $t7, $a0, $t0 # position%size
beq $t1, $t7, skip1 #(col == position%size)
div $t3, $a0, $t0 #position/size
mul $t3, $t3, $t0 #position / size * size
add $t3, $t3, $t1 #row_pos = position/size * size +col
mul $t3, $t3, 8 #row_pos*8
add $t3, $t2, $t3 #&puzzle->grid[row_pos]
lw $t4, 0($t3) #puzzle->grid[row_pos].domain
mul $t5, $a0, 8 #position*8
add $t5, $t2, $t5 #&puzzle->grid[position]
lw $t6, 0($t5) #puzzle->grid[position].domain
not $t6, $t6 #~puzzle->grid[position].domain
and $t4, $t4, $t6
sw $t4, 0($t3)
bne $t4, $0, skip1 #!0
li $v0, 0
jr $ra
skip1:
addi $t1, $t1, 1 #col++
j loop1
endloop1:
li $t1, 0 #row = 0
loop2:
bge $t1, $t0, endloop2 # !(row<size)
div $t7, $a0, $t0 # position/size
beq $t1, $t7, skip2 #(row == position/size)
mul $t3, $t1, $t0 #row*size
rem $t8, $a0, $t0 #position % size
add $t3, $t3, $t8 #col_pos = row * size + position % size
mul $t3, $t3, 8 #row_pos*8
add $t3, $t2, $t3 #&puzzle->grid[row_pos]
lw $t4, 0($t3) #puzzle->grid[row_pos].domain
mul $t5, $a0, 8 #position*8
add $t5, $t2, $t5 #&puzzle->grid[position]
lw $t6, 0($t5) #puzzle->grid[position].domain
not $t6, $t6 #~puzzle->grid[position].domain
and $t4, $t4, $t6
sw $t4, 0($t3)
bne $t4, $0, skip2 #!0
li $v0, 0
jr $ra
skip2:
addi $t1, $t1, 1 #row++
j loop2
endloop2:
sub $sp, $sp, 28
sw $ra, 0($sp)
sw $s0, 4($sp)
sw $s1, 8($sp)
sw $s2, 12($sp)
sw $s3, 16($sp)
sw $s4, 20($sp)
sw $s5, 24($sp)
move $s2, $a1
move $s0, $t2 #&puzzle->grid
li $s1, 0 #i = 0
mul $t0, $a0, 8 #position*8
add $t1, $s0, $t0 #&puzzle->grid[position]
lw $s3, 4($t1) #&puzzle->grid[position].cage
lw $s4, 8($s3) #puzzle->grid[position].cage->num_cell
loop3:
bge $s1, $s4, endloop3 #!(i<puzzle->grid[position].cage->num_cell)
lw $t2, 12($s3) #&puzzle->grid[position].cage->positions
mul $t1, $s1, 4 #i*4
add $t3, $t2, $t1 #&puzzle->grid[position].cage->positions[i]
lw $t3, 0($t3) #cage_pos = puzzle->grid[position].cage->positions[i]
move $a0, $t3
mul $t3, $t3, 8 #cage_pos*8
add $s5, $s0, $t3 #&puzzle->grid[cage_pos]
lw $s4, 0($s5) #puzzle->grid[cage_pos].domain
jal get_domain_for_cell
move $t0, $v0
and $s4, $s4, $t0
sw $s4, 0($s5)
move $a1, $s2
bne $s4, $0, skip3 #!0
lw $ra, 0($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
lw $s5, 24($sp)
add $sp, $sp, 28
li $v0, 0
jr $ra
skip3:
add $s1, $s1, 1 #i++
j loop3
endloop3:
lw $ra, 0($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
lw $s5, 24($sp)
add $sp, $sp, 28
li $v0, 1
jr $ra
add $t3, $t2, $t1 #&puzzle->grid[position].cage->positions[i]
lw $t3, 0($t3) #cage_pos = puzzle->grid[position].cage->positions[i]
move $a0, $t3
mul $t3, $t3, 8 #cage_pos*8
add $s5, $s0, $t3 #&puzzle->grid[cage_pos]
lw $s4, 0($s5) #puzzle->grid[cage_pos].domain
jal get_domain_for_cell
move $t0, $v0
and $s4, $s4, $t0
sw $s4, 0($s5)
move $a1, $s2
bne $s4, $0, skip3 #!0
lw $ra, 0($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
lw $s5, 24($sp)
add $sp, $sp, 28
li $v0, 0
jr $ra
skip3:
add $s1, $s1, 1 #i++
j loop3
endloop3:
lw $ra, 0($sp)
lw $s0, 4($sp)
lw $s1, 8($sp)
lw $s2, 12($sp)
lw $s3, 16($sp)
lw $s4, 20($sp)
lw $s5, 24($sp)
add $sp, $sp, 28
li $v0, 1
jr $ra
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team