Skip to content

Commit 5e809dc

Browse files
committed
Add files for Feb ACSL
1 parent 9f60da6 commit 5e809dc

14 files changed

+209
-1
lines changed

_posts/2018-12-05-code-style-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ is `theorem_johnny_postulate.java`.
9494
Johnny Postulate
9595
ACSL theorem
9696
Contest #1 2018-19
97-
Acton Boxborough Regional High School
97+
Acton-Boxborough Regional High School
9898
Senior Division
9999
*/
100100

_posts/2019-02-24-feb-psets.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: post
3+
title: PSETS for Feb ACSL
4+
date: 2019-02-24
5+
summary: Topics include Boolean Algebra, Data Structures, and FSA/Regular Expressions.
6+
categories: comp3
7+
---
8+
9+
Below are the self-contained guides to the February ACSL contest.
10+
They include topic explanations, useful resources, practice exercises, and answers.
11+
12+
* [Boolean Algebra]({{ site.url }}/cpt-blog/tutorials/boolean-algebra.pdf)
13+
* [Data Structures]({{ site.url }}/cpt-blog/tutorials/data-structures.pdf)
14+
* [FSA/Regular Expressions]({{ site.url }}/cpt-blog/tutorials/fsa-regex.pdf)

_posts/2019-02-26-feb-contests.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
layout: post
3+
title: Practice Contests for Feb ACSL
4+
date: 2019-02-26
5+
author: Sanjit Bhat
6+
summary: Problems and solutions from 2016-17 and 2017-18 February ACSL
7+
categories: comp3
8+
---
9+
10+
# 2016-17 Contest
11+
12+
* [Short answers]({{ site.url }}/cpt-blog/contests/16-17/c3/c_3_sr.pdf)
13+
14+
* [Short answer solutions]({{ site.url }}/cpt-blog/contests/16-17/c3/c_3_sr_sol.pdf)
15+
16+
* [Coding problem]({{ site.url }}/cpt-blog/contests/16-17/c3/c_3_lights_out_sr.pdf) (including test data)
17+
18+
* [Sanjit's solution]({{ site.url }}/cpt-blog/contests/16-17/c3/lights_sanjit_bhat.java) to coding problem
19+
20+
# 2017-18 Contest
21+
22+
* [Short answers]({{ site.url }}/cpt-blog/contests/17-18/c3/c_3_sr.pdf)
23+
24+
* [Short answer solutions]({{ site.url }}/cpt-blog/contests/17-18/c3/c_3_sr_sol.pdf)
25+
26+
* [Coding problem]({{ site.url }}/cpt-blog/contests/17-18/c3/c_3_walk_sr.pdf) (including test data)
27+
28+
* [Sanjit's solution]({{ site.url }}/cpt-blog/contests/17-18/c3/walk_sanjit_bhat.java) to coding problem
135 KB
Binary file not shown.

contests/16-17/c3/c_3_sr.pdf

88.8 KB
Binary file not shown.

contests/16-17/c3/c_3_sr_sol.pdf

72.5 KB
Binary file not shown.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
Sanjit Bhat
3+
ACSL Lights Out
4+
Contest #3 2016-17
5+
Acton-Boxborough Regional High School
6+
Senior Division
7+
*/
8+
9+
import java.io.*;
10+
import java.math.BigInteger;
11+
import java.util.*;
12+
13+
public class lights_sanjit_bhat {
14+
static String your_name = "Sanjit Bhat";
15+
static String prob_name = "lights";
16+
17+
public static void main(String[] args) throws IOException {
18+
Scanner sc = new Scanner(new File(prob_name + ".in"));
19+
PrintWriter out = new PrintWriter(new FileWriter(prob_name + ".out"), true);
20+
out.println(your_name);
21+
22+
// read in all the boards, condense each into one string, and convert it to binary
23+
String[] boards_bin = new String[6];
24+
for (int i = 0; i < 6; i++) {
25+
StringBuilder board_hex = new StringBuilder();
26+
for (int j = 0; j < 4; j++) {
27+
board_hex.append(sc.next());
28+
}
29+
30+
// convert board to binary
31+
String postfix = hexToBin(board_hex.toString());
32+
33+
// pad each binary string to make it fill entire board
34+
StringBuilder zero_prefix = new StringBuilder();
35+
for (int j = 0; j < 64 - postfix.length(); j++) {
36+
zero_prefix.append("0");
37+
}
38+
boards_bin[i] = zero_prefix.toString() + postfix;
39+
}
40+
41+
for (int test_case = 0; test_case < 5; test_case++) {
42+
try {
43+
String prev_board = boards_bin[test_case];
44+
String future_board = boards_bin[test_case+1];
45+
46+
// calculate array of differences between strings
47+
// this shows whether it was in change "radius"
48+
boolean[] diffs = new boolean[64];
49+
for (int char_pos = 0; char_pos < 64; char_pos++) {
50+
if (prev_board.charAt(char_pos) != future_board.charAt(char_pos)) {
51+
diffs[char_pos] = true;
52+
}
53+
}
54+
55+
int press_loc = -1;
56+
// find a diff that is the only one in its row - corresponds to top or bottom of star
57+
// there might only be one (x in bottom-most or top-most part of screen) or two (change in middle of screen)
58+
for (int i = 0; i < 8; i++) {
59+
int num_diffs = 0;
60+
int diff_loc = -1;
61+
for (int j = i*8; j < (i+1)*8; j++) {
62+
if (diffs[j]) {
63+
num_diffs++;
64+
diff_loc = j;
65+
}
66+
}
67+
68+
// look at locations 2 rows above and 2 rows below for center of press
69+
if (num_diffs == 1) {
70+
if (diff_loc-16 >= 0 && diffs[diff_loc-16]) press_loc = diff_loc-16;
71+
if (diff_loc+16 < 64 && diffs[diff_loc+16]) press_loc = diff_loc+16;
72+
}
73+
}
74+
75+
// convert from index notation to row, col notation
76+
int row = (press_loc / 8) + 1;
77+
int col = (press_loc % 8) + 1;
78+
out.println(row + "" + col);
79+
} catch (Exception e) {
80+
out.println("Something's wrong with this test case");
81+
e.printStackTrace();
82+
}
83+
}
84+
sc.close();
85+
out.close();
86+
}
87+
88+
static String hexToBin(String s) {
89+
return new BigInteger(s, 16).toString(2);
90+
}
91+
}

contests/17-18/c3/c_3_sr.pdf

614 KB
Binary file not shown.

contests/17-18/c3/c_3_sr_sol.pdf

623 KB
Binary file not shown.

contests/17-18/c3/c_3_walk_sr.pdf

203 KB
Binary file not shown.

0 commit comments

Comments
 (0)