AP Dr22exp 9
AP Dr22exp 9
AP Dr22exp 9
Experiment 3.2
Student Name: Divyansh Rana UID: 21BCS5863
Branch: CSE Section/Group: 632-A
Semester: 5th Date of Performance:25/10/23
Subject Name: Advanced Programming Subject Code: 21CSP-314
Task-1
1 Aim: You are given a number N. In one operation, you can either increase the value of N by 1 or
decrease the value of N by 1.
2 Objective: Determine the minimum number of operations required (possibly zero) to convert number
N to a number P such that binary representation P of is a palindrome.
3 Code:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Math;
Task-2
1 Aim: A 10 x 10 Crossword grid is provided to you, along with a set of words (or names of
places) which need to be filled into the grid. Cells are marked either + or -. Cells marked with a
- are to be filled with the word list.
2 Objective: Complete the crosswordPuzzle function in the editor below. It should return an array of
strings, each representing a row of the finished puzzle.
3 Code:
public static Map<Integer, Integer> solveSets(Set<Set<Integer>> ss, List<List<Integer>> ws,
Map<Integer, Integer> used) {
if (ws.isEmpty()) {
return used;
}
List<Integer> w = ws.remove(0);
boolean ok = true;
int rc = set.iterator().next();
for (int d = 0; d < w.size(); d++) {
if (used.containsKey(rc) && used.get(rc) != w.get(d)) {
ok = false;
break;
}
if (!ok) {
continue;
}