instruction stringlengths 71 95.1k |
|---|
Background
(Feel free to skip; the help center just recommended adding background information :)
A few days ago, I was looking at some code which happened to use a flat array to store a complete binary tree. That got me thinking about calculating some properties of such a tree. The number of nodes in a perfect binary t... |
This is a program I typed up for a project pertaining to GPA calculation. However, I want to find an alternative to if then statements that are NOT conditionals, loops, or arrays. Is there an alternative solution to changing this format?
import java.util.Scanner;
public class Part1 {
public static void main(Strin... |
I wrote a non-cryptographic hash function in C, which I am hoping might be suitable for use in an implementation of hash sets or hash maps.
uint_fast32_t hash_u32(uint_fast32_t x) {
uint_fast32_t h = x;
h = h ^ (h>>16);
h = h * 0xae6a495b;
h = h ^ (h<<16);
h = h * 0xae6a495b;
return h;
}
I've t... |
Given a root of a Binary Search Tree (BST) and a number num, implement
an efficient function findLargestSmallerKey that finds the largest key
in the tree that is smaller than num. If such a number doesn’t exist,
return -1. Assume that all keys in the tree are nonnegative.
The Bst Class is given to me.
public cl... |
I have written this code for a color and font checker on a webpage.
The code is current and not so good. I would really like if I can get comments, reviews or any better approach for my PoC.
PoC: I want to highlight all the colors or fonts which should not be used on the webpage (the domain is defined by me as of now).... |
In my project, I am getting an array of objects from api, and I want to divide the array into 3 three arrays based on the value of the shelf property of each
array element which is an object. Now for doing that I am using formatBooks function inside the same component.
Later on I am passing this formatBooks function as... |
A couple of years ago I wrote a serialisation library for my project. By the time it worked well, but recently I thought it could be modernised. Back then I needed something that looks similar to Boost's serialiser, but also support polymorphism. I need to serialise and deserialise different types of objects from the s... |
I am a fan of f"{strings}" in Python,
However some situations could possibly be dangerous when doing f strings from user input, leaking API keys or even code execution!
So I decided to make something to mitigate these attacks. It works by searching with regex over the input string, and will return an empty string if it... |
I've been messing around with arrays as I'm learning them currently in my book and they gave the idea of a chess board using for loops alongside multidimensional arrays to give them individual values which you can therefore print out.
However, I thought of the old console RPG games from way back and wanted to simply ad... |
We had a question in examination to compute determinant of general square matrix.
Now I had made the normal program using Laplace Formula of determinant, ie, recursive solution.
Now I was thinking of reducing it into Upper Triangle Matrix and then the product of diagonal elements gives the determinant.
The code is fol... |
I needed a reference counted smart pointer for my project, and for some reason early in my project, I decided that I did not like the std::shared_ptr. I can't remember the exact reasons why, but I do remember there was a reason for it. It fell short in some area, but for the life of me I can't remember what it was. Rea... |
I'm writing a toy compiler, which is in a very early stage of development. The lexer contains the following block of code:
let consumeChar (state: LexerState) =
match state.CurrentChar() with
| End -> state
| _ -> { state with Offset = state.Offset + 1u }
let tryConsume (ch: char) (... |
I am learning Java and would like to get feedback on the code I wrote.
I have written an implementation of an algorithm (found here) for converting any decimal Arabic number to Roman numeral string. My concerns are:
The code seems too long for some methods.
It is not clear what is going on in the class (unless you alr... |
I have written a code that finds whether the entered words are anagrams or not. I tested and it works, but I know that there are some details that I must change or modify. So what do you think I have to change in this code?
function findAnagram (firstWord, secondWord) {
var testWord = "";
var c = 0;
while (c < secondWo... |
I recently appeared for interview for code-pairing round and I was asked following question: Electricity Billing System for home. The corresponding power usage of home appliances (Fan, AC, Fridge, Light) was given:
Appliance | Per hour unit consumption
Fan 4
Light 2
AC 10
Fridge 8
The slab chart was given as:
Slab 1 -... |
I am doing a GCSE NEA project for practice.
Customer Loyalty Scheme
The managers of Crawdale Hotel Group have decided to update their customer loyalty
scheme. Customers joining the scheme become silver members. Customers are upgraded
to gold members when they have booked 30 nights’ accommodation and to platinum
... |
I have been typically adding the @transaction.atomic decorator to my endpoints and appreciate if a request fails at any point the data completely rolls back. However, some of my endpoints will make an API call to another API service. If my token for that API service is invalid, I refresh the token. This is all well ... |
In my web application, a user will click a button which will call a function that triggers an AJAX call. That function accepts a single argument. I would like to be able to put that function in place of the anonymous function in the jQuery event handler. I suspect that this is a scoping issue...
Here is my working c... |
I created a small Javascript elevator simulation that works as expected, however, being pretty new to Javascript I can t help but feel like this code in unnecessarily complex. Honestly any feedback would be appreciated.
const doorOpenSpeed = 3
var Elevator = function() {
this.currentFloor = 1;
// 1 floor ever 3 ... |
This is a cut-and-dried Fisher-Yates implementation. As not typically a JS developer, I've tried to incorporate as many best practices as I can. I would appreciate any input as to make it conform to more best practices and continue to be maintainable.
(function fisherYates () {
"use strict";
var shuffle = fun... |
In answering a question on StackOverflow, it occurred to me that a more generic version of GroupBy for C# that delegated membership in each group to a class could be useful.
This is my attempt, but I am unsatisfied with a few things. I don't particularly like the need to constrain the element type to IOrderable - I fee... |
@angus on Unix.SE implemented a tool in C to list upcoming cron jobs in response to a question. I've re-implemented the basic functionality (showing only the next cron job) in Rust, using rustfmt, clippy and TDD to keep it reasonably clean, but it's my first non-trivial program:
use std::ops::RangeInclusive;
pub struc... |
Problem Statement: JNEXT
DevG was challanged to find the just next greater number which can be formed using digits of a given number. Now DevG needs your help to find that just next greater number and win the challenge.
Input
The first line have t number of test cases (1 <= t <= 100). In next 2*t lines for each test c... |
I'm an undergraduate student and I have this assignment on a Discrete Event simulator. Currently I have completed to the end of v1.2 here. Attached also, is an algorithmic overview.
I have wrote my code as such to solve the problem at hand. Even though the code feels correct according to the test cases used to test th... |
I load an array from an API that is available throughout the user's whole session. This data is unlikely to change, so it can be cached safely. I have a DataService that works like this:
get data from the class property (scenario: going to a new route)
if nothing is there, get data from local storage (scenario: reload... |
I've made this implementation of a classroom with teacher and students using mediator pattern. Mediator is the teacher and colleague are studends.
Main function is the following. Main function creates a teacher and then she says will teach to some students. Finally, she try to spread a concept and a student will tell w... |
I tried to implement a stack using Linked Lists. How could I make it more efficient? Any other suggestions will be greatly appreciated. I am a beginner C programmer.
Any other tips to clean up my code?
#include <stdio.h>
#include <stdlib.h>
typedef struct NODE {
int data;
struct NODE* next;
}node;
node* t... |
I have just started learning Rust, and in order to try to get the hang of references, ownership and mutability, I have attempted to make a doubly linked list. It now compiles, and the add function seems to be working as intended.
There is one implementation detail that I am curious about, and in general I'm wondering w... |
I started learning Python and I am preparing Sudoku Solver as my first small project. I am also trying to learn unit testing. I thought it is a good idea to ask for suggestions before I start with GUI. I would appreciate any help.
There are several classes:
Cell - one cell of sudoku board.
Region - holds several cells... |
Find the length of the longest line with given square (MxM) matrix. (vertical, horizontal, or diagonal allowed) (Length of the longest line = number of consecutive 1's)
i.e.)
input:
{
{0,0,0,0,0,0,0,0},
{0,0,1,0,1,0,0,0},
{0,1,0,1,0,0,0,0},
{1,1,1,1,1,1,1,0},
{0,1,0,0,0,1,0,0},
{1,1,0,0,0,0,1,0},
{0,1,0,0,0,0,0,1},
{0... |
I wrote a small module in typescript that augments the angularjs registerComponent function to provide a new way of default values for the component controller.
This module was written to solve the problem of not having a nice non-biolerplatey way of providing default values for components. Another problem it attempts ... |
Given a Binary Search Tree and a number N, the task is to find the
smallest number in the binary search tree that is greater than or
equal to N. Print the value of the element if it exists otherwise
print -1.
Please review the code, the unit tests are just for the demo. please comment about performance thanks.
... |
Some context
I'm implementing a self-closing pairs auto-completion feature in Rubberduck. One of the challenges is that the VBIDE API doesn't allow editing a line of code by "injecting" characters: we have to replace the entire line, and a side-effect of this is that it causes the VBE to parse/compile the line (since i... |
I am writing a Python class which checks if a given number is divisible by numbers 2-11. I am not using the __init__ method which in my opinion is not necessary in this case.
Questions:
How can I convert a given number in to abs(x) without using the __init__ method in every method at once?
How can I check if a number ... |
I'm an active contributing member of Wiktionary and an active member of an active Wiktionary Discord server. Some time ago, several users proposed a bot which would make linking to Wiktionary in Discord much easier (originally one would have had to go to Wiktionary, search their entry, copy the link, and then navigate ... |
This is a controller from an Express app that lets users view and manage articles. There are at least a couple of issues I'd like to address...
The program displays a list of articles in a sidebar that appears on each page. Right now, the app queries the database for article names, caches them, and includes them in the... |
I did research about binary counting, and wanted to make an application in Java that converts a string to binary code:
/**
* This class converts strings by looping through the characters, gets the
* decimal code for each, then divides the number by 2 untill the quotient is 0
*
* @author Mr Pro Pop
*
*/
public c... |
Please take a look at the following code. This is my attempt at understanding concurrent applications.
class Program
{
static void Main(string[] args)
{
var consumers = new List<Consumer>
{
new Consumer(1000),
new Consumer(900),
new Consumer(800),
... |
First time asking a question here.
I made a simple application as a task for a position of a junior programmer, but it did not work out the way I hoped. Nevertheless, I would definitely be interested in code improvement suggestions (sorry for not being more specific, I did not get any feedback by the task creators, so ... |
I am looking for a more efficient way than bruteforcing my way through in the following problem in python 3.
Problem statement:
Input:
An array of n integers, scores, where each score is denoted by scores_j
An array of q integers, lowerLimits, where each lowerLimits_i denotes
the lowerLimit for score range i.
An array... |
This is my first hands-on experience with Rust. The program actually works and I really like how it functions. I'm just very interested in what code improvements I could do.
I wrote an application in Rust to help me manage my php environments.
The binary can be run like:
timpack-cli composer install # run composer ins... |
The challenge was to create a function which performs an in order traversal without using recursion. What I came up with was to use a stack and some clever popping and pushing. I was wondering if there was any way to improve the following solution. Specifically a better way to implement my if(s.empty()) break; line.
ve... |
Some time ago I started writing a blockchain implementation for learning purposes. I used this article as reference. Originally I wrote the code in C# but recently I have rewritten everything to F#. Please review my F# code, although feel free to comment on C# as well if you feel like it.
Hopefully I will continue with... |
This is a class for creating and traversing a BST while also getting its depth and width. I feel like this can be factored down into something more elegant and shorter I also feel like the overall design can be improved.
class BinaryNode {
constructor(val) {
this.val = val
this.left = null
this.right = ... |
I request a review of the following web page, especially on the use of semantic elements:
https://jsfiddle.net/SSteven/qt9d2sfw/
The HTML5 code is:
<!DOCTYPE html>
<html>
<head>
<title>Semantic page</title>
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<style>
... |
I am a javascript noob. I did this program for the sake of learning javascript in a better way. the code is to display matrix live wallpaper in the browser.
Here is the code
<!DOCTYPE html>
<html>
<head>
<title>Hacker Live Wallpaper</title>
</head>
<body>
<div id="wallpaper"></div>
<... |
I wanted to in the most generic way possible write a method in C# to achieve the following.
Take in a string, a set of objects, and a function to access the field of a given object
Look at all of the strings from the fields of these objects to match against provided string
If provided string is not unique in a case in... |
code review friends/teachers! This is a trivial(no dfs/permutations/backtrace required) n queen problem from codeforces: B. 8 Queens, Again!!
input
2
A1 B5 C8 D6 E3 F7 G2 H4
C3 E4 C4 E1 C4 F4 A8 G6
output
Valid
Invalid
Here is my solution:
queen.h
#ifndef QUEEN
#define QUEEN
#include <array>
constexpr int N = 8;
... |
I am currently learning to code in ruby. I have created a small program that iterates through a directory of video files and opens one at random. The program is fully functioning (with the odd issue). The aim of my question is to hopefully gain some insight into how I can better structure the code, or simplify the proc... |
I wrote this program to help me understand how BFS and Queues work. (Also DFS if I replace the queue with a stack).
It works, but I'm curious how well I implemented the algorithm.
Are there any obvious improvements?
For example, I notice that there are duplicate values in the Queue. I understand that I should avoid vis... |
double time_in_seconds() {
std::chrono::time_point<std::chrono::system_clock,std::chrono::microseconds> tp = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(tp.time_since_epoch());
std::time_... |
I'm struggling with organizing my code regarding 'best practise'. In particular how I link a class with its collection class.
I've 2 classes:
class car
{
private $color;
private $model;
private $speed;
public function getColor() {}
public function setColor() {}
public function getModel() {}
... |
I've built a fairly simple tip calculator. What I have so far is a bunch of functions to calculate each tip amount and calling each with eventListener.
It works however trying to see if there's a better approach that would modularize the code. I'm thinking possibilities include passing functions as arguments or functio... |
I am working on a blog with PHP, specially in order to practice OOP.
Since the blogging system will handle users, i thought that a Validation class would be a good idea in order to not repeat code for both login and signup validation.
So far it works, but as you may notice, i'm using static methods from other class her... |
I'm trying to write game server core that I can easy extend to use for various games. From simple online Blackjack session, to MMORPG. Long story short, I came up with this solution:
Firstly, we have common classes for both Server and Client. Those are simple data structures, probably will need to wrap them with Builde... |
I needed to make a base64 file encoder where you can control the read buffer size. This is what I came up with and it's quite fast. It might be able to be simpler but still maintain its performance characteristics. Any suggestions?
def chunked_base64_encode(input, input_size, output, read_size=1024):
"""
Read a... |
I'm simulating my real-world application by using a really simple demo app here, but it has the same concept. The question is MVVM Light Toolkit specific, as the purpose of my project is to learn the workings of the toolkit.
Let's say I have a Main form, inside which I have a UserControl. The Main has a stand-alone Tex... |
I've been coding a Gameboy emulator in C for some time(seems like a common project for people). It's reasonably functional and has some MBC1 support, but has some minor graphical glitches still. I've coded on and off for a long time, but consider myself still very much an amateur and have no professional experience.
... |
Following up on my implementation of Cryptopals Challenge 1, this is my solution to Challenge 3.
Single-byte XOR cipher The hex encoded string:
1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736
... has been XOR'd against a single character. Find the key, decrypt
the message.
You can do this by ha... |
I have to count the number of contiguous sub-arrays whose sum is a perfect square.
For instance, if we have an array:
number = [1,4,2,3,5]
Now the contiguous sub-arrays whose elements sum is a perfect square are:
[1] [4] [4,2,3]
Total count = 3
To solve this problem I took an array which stores the prefix sum and the... |
Fairly new to Python, and I have been doing a few Edabit challenges, to better help with my problem-solving. I have just completed a some what semi-difficult challenge, and I was hoping for some feed back.
The challenge itself:
Create a function that takes an imgur link (as a string) and extracts
the unique id and ... |
Question: Write a program to swap pairs of characters of a String. In
case of odd number of characters last character should remain
unchanged.
Examples:
Input: HI
Output: IH
Input: hello there
Output: ehll ohtree
My Code:
import java.util.*;
class SwappedPairs
{
static String swapPairs(String str)
{
... |
This is an implementation of a general Purpose Parser/Matcher that can operate on any input stream of objects and will return all possible combinations.
In this case I do not value performance that much, but if you find something major, tell me.
This does by design no optimizations before parsing to be easily editable.... |
I created this simple react application for a coding challenge, which is described in the linked README file. Basically, I created the components and helper logic to display dynamic JSON data in a sortable table.
I did not clear the coding challenge and I am looking for some feedback on how this could be done better. ... |
$a=$_GET["a"];
$b=$_GET["b"];
$a=str_replace("%", "\%", $a);
$b=str_replace("%", "\%", $b);
$sql="SELECT * FROM table ";
$sql.="WHERE ColA LIKE :txtA AND ColB LIKE :txtB";
$query = $db->prepare($sql);
$query->bindValue(':txtA', '%'.$a.'%', PDO::PARAM_STR);
$query->bindValue(':txtB', '%'.$b.'%', PDO::PARAM_STR);
$query-... |
A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers.
<?php
function isPalindrome($input) {
return (string) $input === strrev($input);
}
$max = 999;
$min = 100;... |
Summary: The basic calculator which allows the end-user to calculate the value by evaluating the math expression string. It supports all the main arithmetic operators, also extended by modulo and exponent operations. Evaluation does follow the classic arithmetic rules and precedence and does take parentheses into consi... |
Is this a good approach or I've just found a nasty workaround?
I'm using MediatorLiveData class because seems useful to update the source of a LiveData object.
I mean, the majority of tutorials that I've found on internet just use Livedata or MutableLivedata without a dynamic source, in example:
fun search(/*no input p... |
I would like to compare the min/max values of a time-series with a test time-series. Additionally, I would like to compare the time of the "peaks". However, I'm having trouble extracting these features from a Pandas DataFrame.
Given the following data:
def fake_phase_data():
in_li = []
sample_points = 24 * 4
... |
I recently got a homework assignment from my C++ teacher. The verbatim assignment was this:
Write a program that simulates a vending machine. A customer selects and item for purchase and inserts a bill into the vending machine. The vending machine dispenses the purchased item and gives change. Assume that all item pri... |
I trying to see if I implemented these operations correctly and if they could be optimized in any way. The implementations are just the typical implementations found online but I adjusted them to work with pointers. I did not find pseudocode for transplant, it was only described and I am unsure if it does what it is su... |
I'm a newbie in Python.
I need to read a GZ file contains thousands of users.
But I think my code is not optimized in this case. Could anyone can help me? What should I do to improve performance? Or is it standard?
if os.path.isfile("file.gz"):
with gzip.GzipFile("file.gz", 'r') as fin:
for line in fin:... |
I have been learning Probability from Statistics 110 and trying to simulate problems that have an unintuitive answer
from numpy import cumsum
from statistics import mean
from numpy.random import exponential
from random import randint, sample, uniform
from bisect import bisect_left
def mean_of_experiments(experiment_fu... |
I'm creating an XML from a defined schema I need to follow.
This is my code:
using (XmlWriter writer = XmlWriter.Create(desktopPath + "\fatt.xml", settings))
{
writer.WriteStartDocument();
#region FatturaElettronicaHeader 1
writer.WriteStartElement("FatturaElettronicaHeader");
#region DatiTrasmissione 1.1
... |
Just a general code review. I'm looking for my first developer job so anything constructive is awesome. Please, and thank you very much.
I've written this implementation as an exercise and to add to my code base. I've tried to keep most nuts and bolts hidden away in the Node class.
"""AVLTree/Balanced Binary Search Tre... |
vir.php
<?php
require_once '../db.php';
session_start();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$username = trim($_POST['username']);
try{
$Query = "SELECT * FROM users WHERE username = :username";
$statement = $conn->prepare($Query);
$statement->bindValue(':username', $username);
$statement->execute... |
I've recently written a simple progress bar class in C++ to mimic usage of similar libraries I've used in Python. The idea is to take some iterable container (e.g. std::vector), and iterate over the container while printing the progress to stdout. This can be useful when doing some computationally expensive operations ... |
Is there any way to improve this code? Using ES6 style i am using latest stable version of node.js.
const UserSchema = new mongoose.Schema({
date: string;
dateObj: {
year: number,
month: number,
day: number
};
project: string;
task: string;
hours: number;
});
let data = new Data();
data.date = new Date(bod... |
Basically What I have is basket ball App. In which I have Added some levels and difficulties. logic is simply use tupple in enum and I have some methods to update / get current level with new values
I have created following code
enum Difficulty:String {
case easy
case medium
case hard
func getRatioFor... |
I'm learning C and I am currently implementing a memory pool.
I'm writing it in steps, first I implemented a fixed-sized memory pool then I will try to implement a memory pool with a known size of elements but an unknown number of elements and ultimately try to write a generic one that is just a block of memory that ca... |
I am modeling a capacitor which has its capacitance varying according to the DC Bias. The DC Bias is computed by taking the mean of the voltage across the capacitance.
class CAP:
"""
Represents the Capacitor.
"""
def __init__(self, nominal_capacitance):
# Theoretical capacitance without DC Bias ... |
I have a dataframe like:
time_stamp id next_timestamp
0 2010-04-16 11:57:52 string_1 NaT
1 2010-04-16 12:06:16 string_1 NaT
2 2010-04-16 12:40:53 string_2 NaT
I want to fill next_timestamp column, with the next time_stamp that id has (if it exists).
Result would be something li... |
I have a Word Search algorithm, the main function (wsearch) takes a grid of letters as an input and a 'word' to search for. The output is the number of occurence of the 'word' in the grid.
First, I break down the problem into three functions (including wsearch).
The nword is for looking the number of occurence of a 'w... |
I'm currently coding a game of Pentominoes and I would like to hear suggestions on how to improve my code and make it more pythonic.
Rules and goal of the game
There is an 8x8 grid and you have 12 pentominos. The goal of the game is to lay all the pentominos on the grid without any overlapping, nor any pentomino partia... |
Trying to group elements in a list by the their last element. I think this is a good problem to use groupby() from itertools. Here is my solution:
from itertools import groupby
def match_ends(list1):
"""Returns a dictionary of groups of elements whose end elements match
Returns empty dic if given list was e... |
I've implemented a simple program to print out 4 right triangles oriented in different ways to learn Haskell. I'm sure there are more efficient ways of doing what I have done, and I just want some feedback.
All feedback related to the efficiency or quality of my code is welcome.
The four different triangle orientations... |
After seeing Snake coded in 10 minutes, I decided to try a similar challenge, albeit easier. The following is Tic Tac Toe that I coded in 10 minutes. Given the short time frame, I'm sure there are style and convention errors abound, and would appreciate any suggestions :)
I will also specifically ask about one thing -... |
I tried to solve the SPOJ prime number problem below. The code produced correct results, but Time limit exceeded and also memory need around 970M which is not efficient(?)
How can I optimize this code under a time constraint of around few seconds?
Problem
Peter wants to generate some prime numbers for his cryptosystem... |
I'm starting to learn Java (started with C++), and still getting to get used to the syntax and whatnot. For practice, I made a doubly-linked list program. Is there any way this could be improved at all, or is this okay code?
// Doubly Linked-List Practice
package doublylinkedlist;
public class DoublyLinkedList {
node... |
I have a dict that may be 'infinitely' nested and contain several pandas DataFrame's (all the DataFrame's have the same amount of rows).
I want to create a new dict for each row in the DataFrame's, with the row being transformed to a dict (the key's are the column names) and the rest of the dictionary staying the same.... |
I am trying to come up with a good File System Design using C++ / OOP. This is being done to gain an understanding of System Design and Design Patterns.
I have some basic functionality, like reading and writing files, adding and deleting files and folders, calculating the size of files and folders. The design pattern I... |
I need to make the following function time constant - I have already removed if statements and have written it down to one line in the loop.
/******************/
uint8_t dseed[54]; // only 0 and 1 like {0,1,0,1,1,1,0,0,1,0,...}
uint8_t fecb[256];
const unsigned char g[55] = {1, 1, 1, 0, 0, 0, 1, 1, 1, ... |
In the Elm examples I have seen for form handling, they attach each input element with an update handler that sends out a very specific message to update the model according to the new input state.
So you end up with a lot of message definition in your Msg union type.
Alternatives I have seen for "dynamic" or complex f... |
I want to traverse a xml tree until I find the first element whose position matches the path. So if I'm looking for Foo/Bar/FooBar I want to get this:
<Root>
<Foo>
<Bar>
<FooBar /> <!-- This one -->
</Bar>
</Foo>
</Root>
However there could be any number of <FooBar />'s in my way and I only want the... |
I've written a solution to the following leetcode problem:
Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.
Example 1:
Input: nums = [1,1,1], k = 2
Output: 2
Note:
The length of the array is in range [1, 20,000].
The range of numbers ... |
I have the following javascript function validateEmail(value). The goal of the function is to validate the users inputted email as they are typing. So if someone puts nfg@*gmail.com the email will be displayed with the * char crossed out. Anytime there is an invalid character the display will show it striked out. This ... |
I'm writing an Exploratory Data Analysis using R Markdown. First of all, I need to check the "sanity" of the input data set. Among the other check I perform, I need to check if at least one between the variables var_in and var_out are present in the dataset. If at least one is present, the other one can be computed fro... |
I'm looking to improve my coding skills. I am new to programming, and after weeks of research and trial and error - I have successfully wrote this basic program to find a music scale by inputting a Root note and Scale.
Since I am pretty much teaching my self - I am looking for criticism to improve my syntax/programming... |
<?php
require_once '../db.php';
session_start();
// Check if user is logged in using the session variable
if( $_SESSION['logged_in'] != 1 ){
$_SESSION['message'] = "";
header("location: error.php");
} else {
$username = $_SESSION['username'];
}
//here starts the code to insert data on DB, and to make a s... |
I'm trying to read two sufficiently large binary files, comparing them and printing the offset at which they differ. I'm using fread to read the binary files and memcmp to compare them.
#include<stdio.h>
#include<time.h>
clock_t start, end;
int main(int argc, char *argv[])
{
double cpu_time_taken;
FILE *fp1, *... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.