Skip to content

Commit e108f6c

Browse files
committed
added day 9
1 parent d2f3d59 commit e108f6c

File tree

6 files changed

+185
-0
lines changed

6 files changed

+185
-0
lines changed

crates/day-9/structs/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "day-9-structs"
3+
version = "0.0.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

crates/day-9/structs/src/main.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::fmt::Display;
2+
3+
fn main() {
4+
let mut light = TrafficLight::new();
5+
println!("{}", light);
6+
println!("{:?}", light);
7+
light.turn_green();
8+
println!("{:?}", light);
9+
}
10+
11+
impl std::fmt::Display for TrafficLight {
12+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13+
write!(f, "Traffic light is {}", self.color)
14+
}
15+
}
16+
17+
#[derive(Debug)]
18+
struct TrafficLight {
19+
color: TrafficLightColor,
20+
}
21+
22+
impl TrafficLight {
23+
pub fn new() -> Self {
24+
Self {
25+
color: TrafficLightColor::Red,
26+
}
27+
}
28+
29+
pub fn get_state(&self) -> &TrafficLightColor {
30+
&self.color
31+
}
32+
33+
pub fn turn_green(&mut self) {
34+
self.color = TrafficLightColor::Green
35+
}
36+
}
37+
38+
#[derive(Debug)]
39+
enum TrafficLightColor {
40+
Red,
41+
Yellow,
42+
Green,
43+
}
44+
45+
impl Display for TrafficLightColor {
46+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
47+
let color_string = match self {
48+
TrafficLightColor::Green => "green",
49+
TrafficLightColor::Red => "red",
50+
TrafficLightColor::Yellow => "yellow",
51+
};
52+
write!(f, "{}", color_string)
53+
}
54+
}

javascript/day-9/package-lock.json

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

javascript/day-9/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"@types/node": "^16.11.12"
4+
}
5+
}

javascript/day-9/src/structs.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class TrafficLight {
2+
color: TrafficLightColor;
3+
4+
constructor() {
5+
this.color = TrafficLightColor.Red;
6+
}
7+
8+
getState(): TrafficLightColor {
9+
return this.color;
10+
}
11+
12+
turnGreen() {
13+
this.color = TrafficLightColor.Green;
14+
}
15+
}
16+
17+
enum TrafficLightColor {
18+
Red = "red",
19+
Yellow = "yellow",
20+
Green = "green",
21+
}
22+
23+
const light = new TrafficLight();
24+
console.log(light.getState());
25+
light.turnGreen();
26+
console.log(light.getState());

javascript/day-9/tsconfig.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"include": ["src/**/*", "test/**/*"],
3+
"exclude": ["node_modules"],
4+
"compilerOptions": {
5+
/* Basic Options */
6+
// "incremental": true, /* Enable incremental compilation */
7+
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
8+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
9+
"lib": [
10+
"es2020"
11+
] /* Specify library files to be included in the compilation. */,
12+
"resolveJsonModule": true,
13+
// "allowJs": true, /* Allow javascript files to be compiled. */
14+
// "checkJs": true, /* Report errors in .js files. */
15+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
16+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
17+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
18+
"sourceMap": true /* Generates corresponding '.map' file. */,
19+
// "outFile": "./", /* Concatenate and emit output to single file. */
20+
"outDir": "./dist" /* Redirect output structure to the directory. */,
21+
"rootDir": "./" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
22+
// "composite": true, /* Enable project compilation */
23+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
24+
// "removeComments": true, /* Do not emit comments to output. */
25+
// "noEmit": true, /* Do not emit outputs. */
26+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
27+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
28+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
29+
/* Strict Type-Checking Options */
30+
"strict": true /* Enable all strict type-checking options. */,
31+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
32+
// "strictNullChecks": true, /* Enable strict null checks. */
33+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
34+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
35+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
36+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
37+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
38+
/* Additional Checks */
39+
// "noUnusedLocals": true, /* Report errors on unused locals. */
40+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
41+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
42+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
43+
/* Module Resolution Options */
44+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48+
// "typeRoots": [], /* List of folders to include type definitions from. */
49+
"typeRoots": ["./types", "./node_modules/@types"],
50+
// "types": [], /* Type declaration files to be included in compilation. */
51+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
52+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
53+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
54+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
55+
/* Source Map Options */
56+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60+
/* Experimental Options */
61+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
62+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
63+
/* Advanced Options */
64+
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
65+
}
66+
}

0 commit comments

Comments
 (0)