-
-
Notifications
You must be signed in to change notification settings - Fork 42
West Midlands | SDC-July | Gabriel Deng | Sprint 2 | Jq-Exercises #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5a87c23
05a73cd
559b941
90d941e
3e85d53
18a062f
d58c8dd
ec7e0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ set -euo pipefail | |
|
|
||
| # TODO: Write a command to output every line in dialogue.txt that contains the string "cure", as well as the line before that line. | ||
| # The output should contain two pairs of two lines of text (with a separator between them). | ||
| grep 'cure' < dialogue.txt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would need to use an option here to show the line before the line containing cure. Hint: check out https://man7.org/linux/man-pages/man1/grep.1.html (-B) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,6 @@ set -euo pipefail | |
|
|
||
| # TODO: Write a command to output the name of every `.txt` file in this directory which contains a line of dialogue said by the Doctor. | ||
| # The output should contain two filenames. | ||
| grep '^Doctor' *.txt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost, you could also just print the file names. Check out |
||
|
|
||
| # cat *.txt | grep '^Doctor' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ set -euo pipefail | |
| # The output should contain 11 lines. | ||
| # Line 3 should be "It contains many lines, and there are some things you may want to do with each of them.". | ||
| # Line 11 should be "We also should remember, when we go shopping, to get 4 items: oranges, cheese, bread, olives.". | ||
| sed 's/, \(^ \) /, /1' input.txt | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't add a space after the comma in the line 11, could you please double check? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,55 @@ | ||
| [{"name": "Ahmed", "city": "London", "scores": [1, 10, 4]}, {"name": "Basia", "city": "London", "scores": [22, 9, 6]}, {"name": "Mehmet", "city": "Birmingham", "scores": [3, 12, 17]}, {"name": "Leila", "city": "London", "scores": [1]}, {"name": "Piotr", "city": "Glasgow", "scores": [15, 2, 25, 11, 8]}, {"name": "Chandra", "city": "Birmingham", "scores": [12, 6]}] | ||
| [ | ||
| { | ||
| "name": "Ahmed", | ||
| "city": "London", | ||
| "scores": [ | ||
| 1, | ||
| 10, | ||
| 4 | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Basia", | ||
| "city": "London", | ||
| "scores": [ | ||
| 22, | ||
| 9, | ||
| 6 | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Mehmet", | ||
| "city": "Birmingham", | ||
| "scores": [ | ||
| 3, | ||
| 12, | ||
| 17 | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Leila", | ||
| "city": "London", | ||
| "scores": [ | ||
| 1 | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Piotr", | ||
| "city": "Glasgow", | ||
| "scores": [ | ||
| 15, | ||
| 2, | ||
| 25, | ||
| 11, | ||
| 8 | ||
| ] | ||
| }, | ||
| { | ||
| "name": "Chandra", | ||
| "city": "Birmingham", | ||
| "scores": [ | ||
| 12, | ||
| 6 | ||
| ] | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ set -euo pipefail | |
| # TODO: Write a command to output just the names of each player along with the number of times they've played the game. | ||
| # Your output should contain 6 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 3" with no quotes. | ||
| jq '.[] | "\(.name) \(.scores | length)"' scores.json | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost! There should be no quotes, I am getting this: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ set -euo pipefail | |
| # TODO: Write a command to output just the names of each player along with the total scores from all of their games added together. | ||
| # Your output should contain 6 lines, each with one word and one number on it. | ||
| # The first line should be "Ahmed 15" with no quotes. | ||
| jq '.[] | "\(.name) \(.scores | add)"' scores.json | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing with quotes. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,61 +5,61 @@ Do not convert any binary numbers to decimal when solving a question unless the | |
| The goal of these exercises is for you to gain an intuition for binary numbers. Using tools to solve the problems defeats the point. | ||
|
|
||
| Convert the decimal number 14 to binary. | ||
| Answer: | ||
| Answer: 1110. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please submit this as a separate PR if possible? One task per pr, I think jq was also a separate one :) |
||
|
|
||
| Convert the binary number 101101 to decimal: | ||
| Answer: | ||
| Answer: 45. | ||
|
|
||
| Which is larger: 1000 or 0111? | ||
| Answer: | ||
| Answer: 1000 is larger. | ||
|
|
||
| Which is larger: 00100 or 01011? | ||
| Answer: | ||
| Answer: 01011 is larger. | ||
|
|
||
| What is 10101 + 01010? | ||
| Answer: | ||
| Answer: 11111. | ||
|
|
||
| What is 10001 + 10001? | ||
| Answer: | ||
| Answer: 100010. | ||
|
|
||
| What's the largest number you can store with 4 bits, if you want to be able to represent the number 0? | ||
| Answer: | ||
| Answer: 15 | ||
|
|
||
| How many bits would you need in order to store the numbers between 0 and 255 inclusive? | ||
| Answer: | ||
| Answer: 8 bits | ||
|
|
||
| How many bits would you need in order to store the numbers between 0 and 3 inclusive? | ||
| Answer: | ||
| Answer: 2 bits | ||
|
|
||
| How many bits would you need in order to store the numbers between 0 and 1000 inclusive? | ||
| Answer: | ||
| Answer: 10 bits | ||
|
|
||
| How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)? | ||
| Answer: | ||
| Answer: When the set of bits in the binary number contains only a single 1 and the rest of the bits are 0s. | ||
|
|
||
| Convert the decimal number 14 to hex. | ||
| Answer: | ||
| Answer: E | ||
|
|
||
| Convert the decimal number 386 to hex. | ||
| Answer: | ||
| Answer: 182 | ||
|
|
||
| Convert the hex number 386 to decimal. | ||
| Answer: | ||
| Answer: (3 x 16^2) + (8 x 16^1) + (6 x 16^0) = 902 | ||
|
|
||
| Convert the hex number B to decimal. | ||
| Answer: | ||
| Answer: 11 | ||
|
|
||
| If reading the byte 0x21 as a number, what decimal number would it mean? | ||
| Answer: | ||
| Answer: 33 | ||
|
|
||
| If reading the byte 0x21 as an ASCII character, what character would it mean? | ||
| Answer: | ||
| Answer: ! | ||
|
|
||
| If reading the byte 0x21 as a greyscale colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? | ||
| Answer: | ||
| Answer: dark grey | ||
|
|
||
| If reading the bytes 0xAA00FF as an RGB colour, as described in "Approaches for Representing Colors and Images", what colour would it mean? | ||
| Answer: | ||
| Answer: a purple color | ||
|
|
||
| If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be? | ||
| Answer: | ||
| Answer: The numbers will be 170, 0 and 255 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note:
-Ashows some invisible characters like$at the end of the line, it was not necessary here.