Skip to content

Commit c6dc9c4

Browse files
authored
Lm binary task action (#2)
* number-systems qanda formatting * numbers-expected * num sys checker * tests for numsys * fix diffing * test bin task action * finalise readme for merge --------- Co-authored-by: l <l>
1 parent 2f36a31 commit c6dc9c4

File tree

4 files changed

+75
-42
lines changed

4 files changed

+75
-42
lines changed

.github/workflows/test-sdc-tasks.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ jobs:
3939
if: contains(steps.changed-files.outputs.modified_files, 'shell-pipelines/')
4040
run: ./test-sdc.sh shell-pipelines
4141
shell: bash
42+
- name: test number-systems
43+
id: test-number-systems
44+
if: contains(steps.changed-files.outputs.modified_files, 'number-systems/')
45+
run: ./test-sdc.sh number-systems
46+
shell: bash
4247
- name: make output comment
43-
if: steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y'
48+
if: steps.test-individual-shell-tools.outputs.attempted == 'y' || steps.test-jq.outputs.attempted == 'y' || steps.test-shell-pipelines.outputs.attempted == 'y' || steps.test-number-systems.outputs.attempted == 'y'
4449
env:
4550
GH_TOKEN: ${{ github.token }}
4651
ISSUE_URL: ${{ github.event.pull_request.html_url }}

expect/number-systems/README.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"answers": [0, 1110, 45, 1000, "01011", 11111, 100010, 15, 8, 2, "(10$|10[^0-9])", "VOLUNTEER_CHECK", "E", 182, 902, 11, 33, "VOLUNTEER_CHECK", "VOLUNTEER_CHECK", "VOLUNTEER_CHECK", "VOLUNTEER_CHECK"]}

number-systems/README.md

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,62 @@ Do not convert any binary numbers to decimal when solving a question unless the
44

55
The goal of these exercises is for you to gain an intuition for binary numbers. Using tools to solve the problems defeats the point.
66

7-
Convert the decimal number 14 to binary.
8-
Answer:
7+
Q1: Convert the decimal number 14 to binary.
8+
Answer:
99

10-
Convert the binary number 101101 to decimal:
11-
Answer:
10+
Q2: Convert the binary number 101101 to decimal:
11+
Answer:
1212

13-
Which is larger: 1000 or 0111?
14-
Answer:
13+
Q3: Which is larger: 1000 or 0111?
14+
Answer:
1515

16-
Which is larger: 00100 or 01011?
17-
Answer:
16+
Q4: Which is larger: 00100 or 01011?
17+
Answer:
1818

19-
What is 10101 + 01010?
20-
Answer:
19+
Q5: What is 10101 + 01010?
20+
Answer:
2121

22-
What is 10001 + 10001?
23-
Answer:
22+
Q6: What is 10001 + 10001?
23+
Answer:
2424

25-
What's the largest number you can store with 4 bits, if you want to be able to represent the number 0?
26-
Answer:
25+
Q7: What's the largest number you can store with 4 bits, if you want to be able to represent the number 0?
26+
Answer:
2727

28-
How many bits would you need in order to store the numbers between 0 and 255 inclusive?
29-
Answer:
28+
Q8: How many bits would you need in order to store the numbers between 0 and 255 inclusive?
29+
Answer:
3030

31-
How many bits would you need in order to store the numbers between 0 and 3 inclusive?
32-
Answer:
31+
Q9: How many bits would you need in order to store the numbers between 0 and 3 inclusive?
32+
Answer:
3333

34-
How many bits would you need in order to store the numbers between 0 and 1000 inclusive?
35-
Answer:
34+
Q10: How many bits would you need in order to store the numbers between 0 and 1000 inclusive?
35+
Answer:
3636

37-
How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)?
38-
Answer:
37+
Q11: How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)?
38+
Answer:
3939

40-
Convert the decimal number 14 to hex.
41-
Answer:
40+
Q12: Convert the decimal number 14 to hex.
41+
Answer:
42+
43+
Q13: Convert the decimal number 386 to hex.
44+
Answer:
4245

43-
Convert the decimal number 386 to hex.
44-
Answer:
46+
Q14: Convert the hex number 386 to decimal.
47+
Answer:
4548

46-
Convert the hex number 386 to decimal.
47-
Answer:
49+
Q15: Convert the hex number B to decimal.
50+
Answer:
4851

49-
Convert the hex number B to decimal.
50-
Answer:
52+
Q16: If reading the byte 0x21 as a number, what decimal number would it mean?
53+
Answer:
5154

52-
If reading the byte 0x21 as a number, what decimal number would it mean?
53-
Answer:
55+
Q17: If reading the byte 0x21 as an ASCII character, what character would it mean?
56+
Answer:
5457

55-
If reading the byte 0x21 as an ASCII character, what character would it mean?
56-
Answer:
58+
Q18: If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
59+
Answer:
5760

58-
If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
59-
Answer:
61+
Q19: If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
62+
Answer:
6063

61-
If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean?
62-
Answer:
63-
64-
If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be?
65-
Answer:
64+
Q20: If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be?
65+
Answer:

test-sdc.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,33 @@ elif [[ "$1" == "jq" ]]; then
102102
fi
103103
fi
104104
cat testoutput.txt
105+
elif [[ "$1" == "number-systems" ]]; then
106+
pass=0
107+
for question in $(seq 1 17); do
108+
answer=$(jq -r ".answers[$question]" expect/number-systems/README.json)
109+
if [[ "$answer" == "VOLUNTEER_CHECK" ]]; then
110+
continue
111+
fi
112+
nextq=$(($question+1))
113+
Q_START=$(grep -n "Q$question:" number-systems/README.md | cut -d: -f1)
114+
ANS_START=$(($Q_START + 1))
115+
NEXT_Q_START=$(grep -n "Q$nextq:" number-systems/README.md | cut -d: -f1)
116+
ANS_END=$(($NEXT_Q_START - 1))
117+
sed -n "$ANS_START,${ANS_END}p;${NEXT_Q_START}q" number-systems/README.md | cut -d: -f2- > answerfile
118+
grep --quiet -iE $answer answerfile
119+
if [ $? -eq 0 ]; then
120+
pass=$(($pass+1))
121+
else
122+
echo "Please try Q$question again, or have the volunteer check this." >> testoutput.txt
123+
fi
124+
rm answerfile
125+
done
126+
echo "You passed $pass/20 tasks." >> testoutput.txt
127+
if [ -v GITHUB_OUTPUT ]; then
128+
echo "attempted=y" >> "$GITHUB_OUTPUT"
129+
fi
130+
echo "Please let a volunteer check the answers for questions 11, 17, 18, 19, and 20."
131+
cat testoutput.txt
105132
else
106133
echo "Please run this with a valid test directory name as argument"
107134
fi

0 commit comments

Comments
 (0)