Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added implement-shell-tools/.DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions implement-shell-tools/cat/cat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
from pathlib import Path

def cleanInput(listOfFiles):
cleanLinesArr = []

for file in listOfFiles:
grabbedText = Path(file).read_text(encoding="utf-8")
splitLines = grabbedText.split("\n")
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
cleanLinesArr.extend(splitLines)

return cleanLinesArr

args = sys.argv[1:]
flag = None
restIsFiles = []

if len(args) > 0 and args[0] and args[0][0] == "-":
flag = args[0]
restIsFiles = args[1:]
else:
flag = None
restIsFiles = args

def takeSpecifiedAction(cleanLinesArr, flag):
Comment thread
katarzynakaz marked this conversation as resolved.
countingOnlyFullLines = 1

for file in cleanLinesArr:
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
if not flag:
print(file)
elif flag == "-n":
print(f"{countingOnlyFullLines} {file}")
countingOnlyFullLines += 1
elif flag == "-b":
if file == "":
print("")
else:
print(f"{countingOnlyFullLines} {file}")
countingOnlyFullLines += 1
else:
print("incorrect flag")
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated

lines = cleanInput(restIsFiles)
takeSpecifiedAction(lines, flag)
34 changes: 34 additions & 0 deletions implement-shell-tools/ls/ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sys
import os

# `ls -1`
def showAllFilesInDir(directory):
listOfFiles = os.listdir(directory)

for eachFile in listOfFiles:
if eachFile[0] != ".":
print(eachFile)

# `ls -1 sample-files`
def showVisibleInSampleFiles():
listOfFiles = os.listdir("sample-files")
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated

for eachFile in listOfFiles:
if eachFile[0] != ".":
print(eachFile)

# `ls -1 -a sample-files`
def showAllInSampleFiles():
listOfFiles = os.listdir("sample-files")

for eachFile in listOfFiles:
print(eachFile)

argv = sys.argv[1:]

if "-a" in argv:
showAllInSampleFiles()
elif "sample-files" in argv:
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
showVisibleInSampleFiles()
else:
showAllFilesInDir(".")
53 changes: 53 additions & 0 deletions implement-shell-tools/wc/wc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import sys
from pathlib import Path

def calculateCounts(inputFiles):
return {
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
"lines": len(inputFiles.split("\n")) - 1,
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
"words": len(inputFiles.split()),
"bytes": len(inputFiles),
}

# * `wc -l sample-files/3.txt`
# * `wc -l sample-files/*`
def countLines(listOfFiles):
for file in listOfFiles:
content = Path(file).read_text(encoding="utf-8")

counts = calculateCounts(content)
print(f"{counts['lines']} {file}")

# * `wc -w sample-files/3.txt`
def countWords(listOfFiles):
for file in listOfFiles:
content = Path(file).read_text(encoding="utf-8")

# const wordsCounted = content.split(" ").filter(word => word !== "").length;
counts = calculateCounts(content)
print(f"{counts['words']} {file}")

# * `wc -c sample-files/3.txt`
def countBytes(listOfFiles):
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated
for file in listOfFiles:
content = Path(file).read_text(encoding="utf-8")
counts = calculateCounts(content)
print(f"{counts['bytes']} {file}")

# * `wc sample-files/*`
def countAll(listOfFiles):
for file in listOfFiles:
content = Path(file).read_text(encoding="utf-8")
counts = calculateCounts(content)
print(f"{counts['lines']} {counts['words']} {counts['bytes']} {file}")

argv = sys.argv[1:]
files = [arg for arg in argv if not arg.startswith("-")]

if "-l" in argv:
countLines(files)
elif "-w" in argv:
countWords(files)
elif "-c" in argv:
countBytes(files)
else:
countAll(files)
40 changes: 20 additions & 20 deletions number-systems/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is not part of this sprint. You need to do a git restore of the file to get it back to the original state

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue fixed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github doesn't agree. It is showing differences. If you do a restore to the start point of thie PR then this file shouldn't be showing up in the PR list at all.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, that's now done

Answer:1110
Comment thread
katarzynakaz marked this conversation as resolved.
Outdated

Convert the binary number 101101 to decimal:
Answer:
Answer:45

Which is larger: 1000 or 0111?
Answer:
Answer:1000

Which is larger: 00100 or 01011?
Answer:
Answer:01011

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:1111 so 15

How many bits would you need in order to store the numbers between 0 and 255 inclusive?
Answer:
Answer:8 as 2 **8 = 256 0-255

How many bits would you need in order to store the numbers between 0 and 3 inclusive?
Answer:
Answer: 2 **2 0 1 2 3

How many bits would you need in order to store the numbers between 0 and 1000 inclusive?
Answer:
Answer:2** 10 = 1024 so 10

How can you test if a binary number is a power of two (e.g. 1, 2, 4, 8, 16, ...)?
Answer:
Answer: number /2 until it reaches 1, check remainder at each division

Convert the decimal number 14 to hex.
Answer:
Answer: E

Convert the decimal number 386 to hex.
Answer:
Answer:0x182 863/16 =24 %2 24/16=1 %8

Convert the hex number 386 to decimal.
Answer:
Answer: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:33 intensity so grey dark

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:RGB(170, 0, 255)

If reading the bytes 0xAA00FF as a sequence of three one-byte decimal numbers, what decimal numbers would they be?
Answer:
Answer: 170, 0, 255
Loading