instruction stringlengths 71 95.1k |
|---|
To avoid plagiarism in my university, I am going to modify the problem.
Henry likes to jump from building to building. The heights of each building are given as a list of H numbers. We also number their indices 0,1,…,n−1 from left to right. I want to find out the number of all the buildings that Henry can jump to with ... |
I've been programming for 3 months now, and I've just come across Linked List, and I'm not gonna lie, I've been struggling a little. I wrote this code to practice on Linked Lists. The purpose is to add a Node in a desired position. Even though it works, I'm wondering if there would be more efficient and synthetic solut... |
This code represents an Entity Component that holds and manipulates an entity's local and world transforms, dealing with hierarchy and translation/rotation/scale transformations. The code is written in C++17.
This code was not built for performance or memory efficiency. It was built more as a way to learn how to suppor... |
I'm building a selenium web scraper for basketball-reference.com that takes a player name and returns data in either a JSON format or Pandas DataFrame object. The class in question is one of many that will scrape a particular table on a player's basketball reference page, in this case the per-season totals. I have been... |
My project explores some ideas i've had regarding alternate data structures to the unorderd_map and map, and aiming the exploration to key sets with a non uniform distribution and key sets with common prefix's. I've posted the code to GitHub in full. see -> FlashRadixTree.
I posted a request for review here for version... |
My project I am working on requires the following functionality for the processed messages:
each message has a priority
messages with higher priorities should have precedence over the ones with lower priority
if a burst of high priority messages is sent, they should not complete starve lower priority messages (in this... |
I made this Rock Paper Scissors game using C++. This is my first time doing it and it took me around 3 hours.
I know that since I am unexperienced, there is probably a much easier and shorter way of making it. Please help me out and give me feedback on things I could improve on.
#include <iostream>
#include <stdlib.h>
... |
I am trying to sort all the divisors of a given number in the most efficient way.
Below is my code for sorting the divisors:
num = 100;
end = num ** (1 / 2);
divisors = [1];
disvisorPairs = [];
pairCount = 0;
for (var i = 2; i <= end; i++) {
if (num % i == 0) {
divisors.push(i);
pair = num / i;
if (pair... |
I've developed a React authentication system for my application and would like to receive feedback on its correctness and potential improvements. Below is an overview of the key components and functionalities of the system:
App.tsx: This file serves as the entry point for the application. It checks the user's authenti... |
My goal of this when I started writing it was simply that it be able to record thousandths of a second in a very performant and accurate way. I'm not sure I have achieved the performance aspect of that though, and I am not sure how to check the accuracy. I haven't done a lot of C programming before, but I feel like the... |
Please help with improving this application. It is a guessing game, for learning the values of the sine function, and boosting brain power in the process.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simplified Example... |
The working code in full is here.
It's a To-Do App with a TypeScript backend, written as practice for an upcoming 4-hour interview for a TypeScript backend role. My colleague and I would like to know, does this implementation violate any commonly held TS best practices or employ unidiomatic patterns? Neither of us have... |
Background
Here is an awkward pattern I've come up with to handle initializing the ID of an MPU for an embedded system based on the fairly unique factory self-test values stored in the MPU registers. (the MPU is the Inversense MPU-9250). The code will eventually be put on github/gitlab so the goal was to move all chip-... |
from flask import Flask, request, jsonify
import hashlib
import random
import string
app = Flask(__name__)
url_mapping = {}
def generate_short_url(url):
hash_object = hashlib.md5(url.encode())
return hash_object.hexdigest()[:6] # Shortened URL is the first 6 characters of the MD5 hash
def is_short_url_uniq... |
I just wanted to have some advice on those remediation scripts; what do you think?
The idea is to detect every 7-Zip installed on the computer and search for those not up to date and uninstall them.
Got some Struggle with placing correctly the exits code used by Intune.
Detection Script:
$64bits = Get-ItemProperty HKLM... |
I made a simple script that notifies a Telegram Channel when a new youtube video is uploaded upon a YouTube channel:
index.php
<?php
// Bootstrap Sentry
require_once "./sentry.php";
// Sentry also requires Settings as well therefore wqe use require
$settings = require("./config.php");
use Sentry\Severity;
$traceId = r... |
I am working on a module named PinCoordinates that detects when X-axis and Y-axis inputs go high. This will be programmed onto an Altera MAX V CPLD. I am constructing a laser grid array that has a total of 50 lasers. There are 25 X-axis lasers and 25 for the y-axis. On the opposite end of the array, there are photodiod... |
I was recently working through the PintOS projects and became curious if there was a better way to do some string processing in C. Specifically, instead of strtok_r, I wanted to know if robust read-only tokenizer alternatives existed. I could not find any so I made my own and ended up creating some string searching fun... |
I've been looking to have "smarter" or "better" enum functionality in C#. There are a few GitHub/NuGet projects out there, but they seem to target newer versions of .NET and I wanted this to be able to work with Framework 4.6 and newer - so it's in a NetStandard 2.0 library. The feature set is similar to enums but with... |
This is a follow-up question for Gaussian Fisheye Image Generator Implementation in C++ and An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. I am trying to implement image rotation function in this post. The example output:
Image Input
Output
The experimental implem... |
I have this GitHub repository. In Wiki Game, players agree on random source and target articles, and attempt to navigate from the source to the target using least number of links. If there is a tie, the player who reached the target the earliest wins.
Code
package com.github.coderodde.wikipedia.game.killer.fx;
import... |
The Problem
John keeps a backup of his old personal phone book as a text file. On
each line of the file he can find the phone number (formated as
+X-abc-def-ghij where X stands for one or two digits), the corresponding name between < and > and the address.
Unfortunately everything is mixed, things are not always in th... |
I am making a simple, (hopefully) fool-proof Minecraft installer for my friends, some of whom can't comprehend folders and zip files in addition to running a school-provided device, thus lacking certain functionalities (e.g., they can't install Java using the installer and must therefore fiddle around with zip files an... |
I need to perform a deep copy of a binary tree using the Morris traversal.
I think I managed to do it, that is the code below returns what I expect; however, I am not 100% sure I have covered every corner case.
I would appreciate it if someone could confirm my implementation:
Doesn't create new nodes on top of existin... |
I have a file with a bunch of primes. For this purpose we can say that the contents of this file called "primes" are as follows:
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,... |
I am currently implementing the EZSP and the underlying ASHv2 protocols in Rust with the intention to use them on an embedded smart home gateway to control ZigBee devices.
In this review I present you the ASHv2 host, which constitutes the external interface of the ASHv2 library and is being used by the EZSP library (no... |
Write an efficient function in the Python language called SmartSearch. This function will receive a sorted arr array of integers of size \$n\$ containing at the beginning \$m\$ "significant numbers" and the rest of the numbers are "fictitious numbers" whose value is 9999. The function also receives a number \$x\$ to b... |
This is the code that I tried to approach to the traveling salesman problem in a new way. As you can see, it does not give such great results. Can I get this idea further, or should I quit to approach this problem from this way?
So the thing that I tried there is using centre of mass to calculate where the cities are... |
I wrote this two player tic-tac-toe program in bash. To make a move you enter a number between 0 and 8 which corresponds to the square:
0|1|2
3|4|5
6|7|8
This is my code:
#!/usr/bin/env bash
declare -r BOARD_SIZE=9
declare -r DEFAULT_SQUARE_VALUE=-
declare -ra PLAYERS=(O X)
draw_board() {
for i in {1..3}
do
... |
I have a function which does firebase set and update operations, but it looks messy. I want to shrink it but also make sure that it works the same. Any ideas?
const handleUserSelect = async (user: Users) => {
if (!currentUser) return;
const combinedId =
currentUser.uid > user.uid
? currentUser.... |
I have written my own basic implementation of the Observer pattern. Please code review it as you feel. This is a one file implementation, and any feedback no matter how small is appreciated.
One sticky point is I was unsure on the implementation of RemoveObserver, so this may not be optimal. Could I have used Ranges ... |
The requirement is to define a macro which takes a single argument that is a string literal.
My first try at it was to surround it with empty string literals (I got this from Modern C):
#define SV(str) (sizeof("" str "") - 1)
Now if I do:
int main(void)
{
static const char *const s = "hello";
char word[] = ... |
I came across this question which asks to create a function which will return true/false based on the passed array containing all the letters to make up the passed word. Each letter from array can only be used once.
Here's my attempt:
const checkArray = (word, arr) => {
let good = true
word.split('').forEach(le... |
Relates to this and this.
Simply put; I want to be able to distribute a total reward among network, where the distribution diminishes according to the depth of the network but the total sum of distributed rewards equals the initial total reward. As well as this I want to be able to support graph structures of the form:... |
This is a follow-up question for A recursive_copy_if Template Function Implementation in C++ and recursive_invocable and recursive_project_invocable Concept Implementation in C++. I am trying to implement recursive_copy_if template function with unwrap level in this post.
The experimental implementation
recursive_copy... |
The code below works as intended: write data by iterating over columns, while iterating over rows while iterating over sheets.
func createXlSXFile(sheets []Sheet) (*bytes.Buffer, error) {
file := excelize.NewFile()
file.SetSheetName("Sheet1", sheets[0].Title)
defer func() {
if err := file.Close(... |
Write an efficient function in the Python language called SmartSearch, this function will receive a sorted arr array of integers of size n containing beginning "yes significant numbers" and the rest of the numbers are "fictitious numbers" whose value is 9999. As the number of functions receive x to search in the array.... |
I would like to ask you give me some feedback about my bot https://github.com/shatentor/vpn_bot. Now I`m a beginner programmer, so your advices will be very helpful.
1
1
1
|
I have a working code to have 2 search bars with dropdown suggestions, selectable by both mouse and arrow keys in TypeScript and Fresh/Preact. In there I have to explicitly declare individual hooks for different lists:
const list1 = ['rabbits', 'raccoons', 'reindeer', 'red pandas', 'rhinoceroses', 'river otters', 'ratt... |
I'm creating a program that will hopefully operate like linux terminal (basic commands) for learning purposes.
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
/*
type FileDir struct {
Name string
Permissions string
Owner string
ModifyDate int64
Size int32
... |
I wrote this code:
PROJECTS_LIST = [
project if not project.update({"project_id": project_id}) else None for project_id, project in PROJECTS.items()
]
where PROJECTS is a dict. The goal is to convert a dict like {"project123": {"a": "b"}} to [{"project_id": "project123", "a": "b"}]
I worry that this isn't the best... |
Prior Notification
This follows a previous review of mine that addressed the core helper function named make_skippable.
The composition implementation presented here is heavily inspired by another review that already introduced the basic concept: Function composition in C++. Thanks to Nestor for providing the pattern.... |
A previous solution of this code has been posted on Code Review before.
This solution is more complicated then that one, but more performant (see the below)
Why is this another Question instead of a answer on the original Question?
This solution works fundamentally different then the original.
It feels big enough of... |
I wrote this to check files for successful compression with LZ4.
Any advice is welcome.
Particularly regarding raising exceptions and error handling.
import sys
def check_lz4_header(file_path):
with open(file_path, 'rb') as file:
header = file.read(4) # Read the first 4 bytes (typical size of LZ4 header)
... |
I've been working on a Python script that fetches student data from an API using multiple threads for concurrency. The script retrieves both student information and prospectus data and saves them to JSON files.
I would appreciate feedback on the following aspects of the code:
Exception Handling: The current exception ... |
I updated the code to a working state. My previous question. Even if this code working I wonder if I can write this code in a more efficient way. Maybe less for loops Etc.
from tkinter import *
import math
import random
class city:
def __init__(self,coordinates,name):
self.coordinates = coordinates
... |
from fastapi import APIRouter, HTTPException, status
from api.database import database, user_table
from api.models.user import UserIn
from api.security import authenticate_user, get_password_hash, get_user, create_access_token
router = APIRouter()
@router.post("/register", status_code=201)
async def register(user: U... |
I need your thoughts and comments to at least improve my programming skills. For those who didn't know, I'm new at coding in C so some conventions in this language were new to me due to the fact that I got introduce to high-level languages such as Python and Java first. Suggestions and criticisms are highly appreciated... |
Following is my code for a library management system. I am pretty new to OOD and trying to learn it. I am specially looking for ways where any design patterns can be useful here. I tried to make classes so that I follow Single Responsibility principle. Would appreciate any feedback for it.
/*
This class is similar to a... |
Below is a C version of a lexer for the Monkey programming language, originally written in Go, as presented in the book Writing An Interpreter In Go.
LOC: 371. (Excluding the tests.)
Language:
Copy pasting from the book:
Here is how we bind values to names in Monkey:
let age = 1;
let name = "Monkey";
let result = 10... |
Problem Statement:
Given two sparse vectors, compute their dot product.
Implement class SparseVector:
SparseVector(nums) Initializes the object with the vector nums
dotProduct(vec) Compute the dot product between the instance of SparseVector and vec
A sparse vector is a vector that has mostly zero values, you should st... |
Problem Description
Printing the result of adding two numpy arrays together is very ugly.
Here we will use these numpy arrays as an example:
import numpy as np
arr_2d = np.array([[3, 3, 3],
[3, 3, 1],
[2, 3, 1]])
arr_1d = np.array([3,4,5])
Here are a few of the ugly ways to print the formula arr_2d + arr... |
This is a follow-up question for recursive_find and recursive_find_if_not Template Functions Implementation in C++ and A recursive_copy_if Template Function Implementation with Unwrap Level Implementation in C++. I am trying to implement recursive_remove and recursive_remove_if template function in this post. recursive... |
this sql query runs on SQL Server.
execution run takes 22 seconds, and i wonder if this code can be optimized, so it runs faster
select id, mdt8_status, mmmin1st_status,
CASE
WHEN mdt8_status IS NULL OR mmmin1st_status IS NULL
THEN NULL
WHEN mdt8_status = 0 OR mmmin1st_status = 0 THEN 0
WHEN mdt8_st... |
I tried using dynamic programming to get a solution to the Secretary Problem. It seems to me it's working with with expected result. I really didn't want to use std::vector and things like that, because I wanted to learn about C-style arrays. Things I want to know:
if there is any problem with the code
commenting
rea... |
Context
I've been working on a Django-based Google Authentication application, designed to manage OAuth authentication without relying on libraries such as django-allauth. This is primarily intended for a backend that interfaces with a React frontend through API requests. My main goal is to establish authentication usi... |
This is the class that I created. It works with Django models and stores some user states.
Do I need to divide it? Maybe some pattern I need to use?
class User:
def __init__(self, telegram_id):
self.telegram_id = telegram_id
self.ids_cards_to_review = set()
self.ids_of_created_cards = set()... |
I have a class, Word, that has a String representing a word and an Enum representing the difficulty of the word. Then I have another class, Vocab, that has an ArrayList of Word-objects. I want to sort my ArrayList by either difficulty or by the alphabetical order of the word.
I figured I should use a Comparator, and he... |
The question is from: https://www.learncpp.com/cpp-tutorial/member-functions/
Create a struct called IntPair that holds two integers. Add a member function named print that prints the value of the two integers
Here's the code I have written, with main() already provided for exercising the struct:
#include <iostream>
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.