Skip to content

Instantly share code, notes, and snippets.

View Luhua-codes's full-sized avatar
🍣

Luhua-codes

🍣
  • Canada
View GitHub Profile
//Q1
let num = 10;
//Q2
let add8 = num + 8;
//Q3
let subtract6 = num - 6;
//Q4
//challenge 2
function findStudentName(studentList, sn) {
studentList = studentList.sort(function (a, b) {
return a.sn - b.sn
});
return studentList[sn - 1].name;
}
function findStudent(studentList, sn) {
studentList = studentList.sort(function (a, b) {
@Luhua-codes
Luhua-codes / Arrays.js
Last active August 8, 2021 01:23
STEMing UP 2021 Arrays II Slide 10 Challenge
/* Arrays II slide 10*/
//https://www.w3schools.com/jsref/jsref_findindex.asp
let groceryList = [{ // use curly brackets and key/value pairs (attributes of "object") syntax to make array of objects
item: "milk", purchased: false
}, {
item: "salad", purchased: false
}, {
item: "cereal", purchased: false
}, {
item: "juice", purchased: false
@Luhua-codes
Luhua-codes / Miniane.java
Last active May 15, 2021 06:58
Print out asterisks according to user choice
import java.util.*;
import java.io.*;
public class Miniane {
public static void printTree(int height) throws FileNotFoundException { //This is the correct exception to throw
File file = new File("test.txt");
PrintWriter out = new PrintWriter(file);
for(int i = 1; i <= height; i++){ //Use i=1 so that * will be repeated i times for each line
out.println("*".repeat(i)); //string.repeat will return the string repeated [int] amount of times
}
@Luhua-codes
Luhua-codes / Miniane.java
Last active April 21, 2021 06:33
sorting algorithm
import java.util.*;
public class Miniane {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int[] ints = new int[5];
int lengthi = ints.length;
for (int i = 0; i < ints.length; i++){
@Luhua-codes
Luhua-codes / SP_meeting3
Last active May 8, 2021 21:50
STEMpowerment Meeting 3 with Mary-Emma code
x1 = [0 1 4;2 3 5;2 6 3];
y1 = [0 4 5;7 8 6;3 1 5];
z1 = [0 2 1;5 6 6;2 8 8];
c = [6 3 0;5 6 4; 0 2 3];
patch(x1,y1,z1,c)
view(3)
v1 = [0 0 0;2 7 0;2 3 0;2 7 5;2 3 2]
f1 = [1 2 3;1 2 4;1 3 5]
patch('Faces', f1,'Vertices',v1,'FaceColor','magenta')
@Luhua-codes
Luhua-codes / nodes.py
Created April 9, 2021 21:14
sending Elon Musk to hell with nodes?
class Node:
def __init__(self, label: str, edges: list):
self.label = label
self.edges = edges
def __str__(self):
size = len(self.edges)
return 'Node {self.label} has {size} edges, {self.edges}'.format(self=self, size=size)
def add_outgoing_edge(self, newEdge):
@Luhua-codes
Luhua-codes / shapes.m
Created April 4, 2021 15:24
using MATLAB patch function
function shapes(n)
function test(n)
axis('equal');
view ([-1 -1 1]);
xlabel('x');
ylabel('y');
zlabel('z');
%draw lab section 8 Last name A-J
@Luhua-codes
Luhua-codes / Display Houses.py
Created March 26, 2021 03:15
Starter code to read in house listings from a csv file
import csv
def getData(dataFile):
headings = [] # list for headings of data
rows = [] # list for rows of data
with open(dataFile, 'r') as file:
reader = csv.reader(file) # create csv reader object
headings = next(reader) # store headings using 1st row of file
@Luhua-codes
Luhua-codes / A3Q3.java
Last active March 15, 2021 03:48
MATH1014 Assignment 3 Question 3
public class A3Q3 {
static double dydx(double x){
double k = 0.5, a = 2, b = 1;
return k * (a - x) * Math.pow((b - x), 0.5);
}
static double euler(double n){
double solution = 0, x0 = 0, t = 0, x, slope, h = 1/n;