diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-10-15 15:02:59 +0300 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-10-15 15:02:59 +0300 |
commit | 714f574a0029af1fd7de0989eda28df46f5bec4f (patch) | |
tree | 8606fd0eaa357450e3bb248e3550bf9cc617ea61 | |
parent | 99fcc543354860ed485b6ded092db4229adcaa16 (diff) | |
download | cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.gz cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.tar.bz2 cs-y13-714f574a0029af1fd7de0989eda28df46f5bec4f.zip |
feat: cs lesson 4 material
-rw-r--r-- | .envrc | 3 | ||||
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | devenv.lock | 116 | ||||
-rw-r--r-- | devenv.nix | 45 | ||||
-rw-r--r-- | devenv.yaml | 15 | ||||
-rw-r--r-- | lesson4.py | 37 | ||||
-rw-r--r-- | queue.py | 23 |
7 files changed, 248 insertions, 0 deletions
@@ -0,0 +1,3 @@ +source_url "https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc" "sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0=" + +use devenv
\ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d058db --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..2ad56cd --- /dev/null +++ b/devenv.lock @@ -0,0 +1,116 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1728740426, + "owner": "cachix", + "repo": "devenv", + "rev": "ef61728d91ad5eb91f86cdbcc16070602e7afa16", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1716977621, + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "4267e705586473d3e5c8d50299e71503f16a6fb6", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1728740863, + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3f9ad65a0bf298ed5847629a57808b97e6e8077", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1728778939, + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ff68f91754be6f3427e4986d7949e6273659be1d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..f208755 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,45 @@ +{ pkgs, lib, config, inputs, ... }: + +{ + # https://devenv.sh/basics/ + env.GREET = "devenv"; + + # https://devenv.sh/packages/ + packages = [ pkgs.git ]; + + # https://devenv.sh/languages/ + # languages.rust.enable = true; + languages.python.enable = true; + # https://devenv.sh/processes/ + # processes.cargo-watch.exec = "cargo-watch"; + + # https://devenv.sh/services/ + # services.postgres.enable = true; + + # https://devenv.sh/scripts/ + scripts.hello.exec = '' + echo hello from $GREET + ''; + + enterShell = '' + hello + git --version + ''; + + # https://devenv.sh/tasks/ + # tasks = { + # "myproj:setup".exec = "mytool build"; + # "devenv:enterShell".after = [ "myproj:setup" ]; + # }; + + # https://devenv.sh/tests/ + enterTest = '' + echo "Running tests" + git --version | grep --color=auto "${pkgs.git.version}" + ''; + + # https://devenv.sh/pre-commit-hooks/ + # pre-commit.hooks.shellcheck.enable = true; + + # See full reference at https://devenv.sh/reference/options/ +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..116a2ad --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,15 @@ +# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json +inputs: + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling + +# If you're using non-OSS software, you can set allowUnfree to true. +# allowUnfree: true + +# If you're willing to use a package that's vulnerable +# permittedInsecurePackages: +# - "openssl-1.1.1w" + +# If you have more than one devenv you can merge them +#imports: +# - ./backend diff --git a/lesson4.py b/lesson4.py new file mode 100644 index 0000000..e99f231 --- /dev/null +++ b/lesson4.py @@ -0,0 +1,37 @@ +stack = [None for index in range(0,10)] +basePointer = 0 +topPointer = -1 +stackFull = 10 + +def push(item): + global stack, topPointer + topPointer += 1 + if topPointer >= stackFull: + print("ERROR Cannot insert more.") + return + stack[topPointer] = item + print(stack) +def pop(): + global stack, topPointer + if topPointer < basePointer: + print("ERROR List is empty, cannot pop.") + return + itemPopped = stack[topPointer] + print(f"I popped this {itemPopped}") + stack[topPointer] = None + topPointer -= 1 + print(stack) +def test(): + push(1) + push(2) + push(69) + + pop() + pop() + + print(stack) + + pop() + pop() + +test() diff --git a/queue.py b/queue.py new file mode 100644 index 0000000..4235a7f --- /dev/null +++ b/queue.py @@ -0,0 +1,23 @@ +queue = [None for index in range(0, 10)] +frontPointer = 0 +rearPointer = -1 +queueLength = 0 +queueFull = 10 +def dequeue(): + global queue, queueLength, queueFull, rearPointer + +def enqueue(item): + global queue, queueLength, queueFull, rearPointer + if queueLength < queueFull: + if rearPointer < len(queue) - 1: + rearPointer += 1 + else: + rearPointer = 0 + queueLength += 1 + queue[rearPointer] = item + print(queue) + return + print("ERROR queue length exceeded!") + return +for i in range(13): + enqueue(10 * i) |