instruction stringlengths 71 71.9k |
|---|
I've recently started studying C++ (from internet) Made my very first program, calculator. It works, but i'd like to know how could i make this more "advanced"?
#include <iostream>
using namespace std;
int pluss(int num1, int num2)
{
int answer = num1 + num2;
cout << num1 << " + " << num2 << " = " << answer <<... |
Here is my code for implementing an adjacency list from scratch. I would like to get feedback from the experts for optimization.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
/*a single node of an adjacency list*/
typedef struct adjList{
int dest;
struct adjList *next;
} adjList;
/*Image of... |
I wrote a bit of code that takes a file, justifies the text and writes to another file.
It uses a DP approach to minimise a badness metric, which is the amount of undershoot of the line length, cubed (see my answer below, the badness function isn't quite right if there is an overshoot, the badness should be inf - I bel... |
I'm trying to optimize this twiddle computing function:
void twiddle(int N)
{
int i;
for (i=0;i<N;i++)
{
twiddle_table[i].re = (float) cos((float)i * 2.0 * PI /(float)N);
twiddle_table[i].im = (float) - sin((float)i * 2.0 * PI /(float)N);
}
}
where N = 4096 size of twiddle table and could be bigger... |
I have this brute force code, where you input a password and runs through combinations of numbers, lowercase and uppercase letters, and special characters until it match the password given.
The problem with it, is that it took about 2 days just to crack the password "password".
What is a way that I can speed up this pr... |
Please refrain from negative comments about the code being poor and inefficient and not idiomatic. I know that much, and that's why I'm here.
I need a function, that takes a byte array and length and returns a byte array.
The function need to do the following:
Drop any leading zeroes in the byte array
If the array len... |
I am trying to use an algorithm similar to the Apriori algorithm for discovering frequent itemsets. This program hashes 2 strings to an int and maps them in the HashMap. I'm not concerned with how good the hashing algorithm is but whether or not it is a good attempt at my own implementation of counting frequent item se... |
I am learning redux by doing a small project. Everything is working fine, but I need to know how I can refactor such code. For this situation, it might be good to use if conditions like I have done, but what if I need to handle 7-8 languages? It won't be viable to use else if for 7 times. What is the proper way to hand... |
I wrote code to solve the running median challenge using 2 heaps, and I'd appreciate any and all feedback.
Here is the problem:
You have a list of numbers and are scanning them one by one. Calculate
and print the median every time you get a new number.
My code:
//program code
var minHeap;
var maxHeap;
function ma... |
We have an object that needs to be converted to a different type before storing it in database. For that purpose, the library provides an annotation over the field that specifies the appropriate class[given as ClassName.class] to use for converting back & forth.
The class implements an interface of the library that has... |
Description:
Its not a programming challenge but I though to write a small utility which will return the path to a primitive value in a possibly nested object. The idea is not original.
Code:
console.clear();
function each(obj, cb, path) {
path = path || [];
for (let k in obj) {
let val = obj[k];
if (isLea... |
I have written the code below as a BFS implementation. Could someone please review. In particular, I want to know if there could be a memory leak.
#include <iostream>
#include <list>
class Graph
{
int number_of_vertices;
std::list<int> *adjList;
public:
Graph(int number_of_vertices);
void ad... |
I have created a method to check for null/empty values of class properties and if any null property is found I'm stopping the checking process and returning the result as true. I've used a solution from here and following is the code I have implemented:
/// To check the properties of a class for Null/Empty values
/// <... |
I wanted to have a good review on my code I wrote today to read files in C++ line by line. The file can look something like this:
# Program configuration
network.port=30000 # The port the server uses
network.ip=127.0.0.1 # The IP the server uses
Notes:
Lines that start with # won't be processed
Lines that are empty ... |
I have implemented a data structure that allows storage of number of users of a hypothetical application in a tree-like data structure in nodes as per their classification based on categories such as Gender or Country which have specific values such as Male and Female and India, China and USA respectively. The requirem... |
I need to find the substrings within my array. If I have an array: ["abc", "abcd", "abcde", "xyz"], my method should return the array members: abc, abcd, abcde as each is a substring or a superstring of the other, but it should exclude "xyz" as it is not related to other strings in any way.
function find_substrings(arr... |
I have a need to try to automate the testing of a large Web Service with an XML API interface. The framework takes the form of a Mavenised Java project.
The usual maxims apply: must be highly extendable, maintainable and ideally will be relatively data driven: requirement to parameterize the tests to accept different... |
I've an ArrayList of Object that could contain String, Date and Long. The Object list is nearly mandatory. (I obtain this list through reflection, reading all the member variables of an unknown class.)
ArrayList <Object> values = new ArrayList<Object>();
I build dynamically a query for Alfresco cmis from it:
... |
I am able to solve this challenge but when look at my code I know it is not good.
The challenge:
Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don’t know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time... |
I am posting my first project in C++ (and also my first in object-oriented programming), can someone review it and cross check that everything I have coded is alright? If you have any tips to improve my code please tell me. The project is running and working. This is a home assignment and I know there are no default co... |
I've created this program to show how to stop threads in a controlled manner.
Important points in the program:
Starting and waiting for threads
Exception handling
Stopping threads in a controlled manner via the CancellationToken.
Overall simplicity and correctness.
The scenario
3 tasks with access to the same List t... |
This phonebook application has a menu, which sorts by name or category. I do it like this in MainActivity:
Bundle bundle = new Bundle();
Fragment lvFragSortBy = new ListViewFragment();
switch (item.getItemId()) {
case R.id.menuSortOrderName:
item.setChecked(true);
bundle.putString("sortBy", "name... |
I've written a simple log writing class. My code is also hosted on my Github.
Specifically, I am looking for criticism on these items:
Resource management. What is a more correct/safe way to obtaining a hold to stream-like objects?
Clarity. Is my code as clear as it could be?
Error handling. I've only had a few classe... |
I am trying as a part of a bigger job to merge parts of several JPEGs into one huge BMP which will be processed further.
As a start, I tried to just copy a few JPEGs each to his own BMP file. In doing so I noticed that Visual Studio 2015 Community shows increased memory consumption if I repeat the copying of files in ... |
I wrote a library that detects the version of the ECMAScript that is running on JavaScript, and that also allows to check support for few syntax-features.
For the ECMAScript version detection I run 4 checks, each check tests if JavaScript supports some features of a specific ECMAScript version. Until a check is success... |
This is the code I currently have for adding various elements inside the svg and then inside a circle. On the text element I added 3 attributes that are the same. But I haven't found a way to remove this to minimize code.
var node = svg.selectAll("circle")
.data(nodes)
.enter()
.append('g')
.append("circle"... |
I have a little function that parse a nested list of coordinates into a flat list of compressed coordinates. By compressed coordinates, I mean that only the delta (distance) between each coordinates are stored in the list and the float coordinates are transformed in integer.
input = [[-8081441,5685214], [-8081446,56852... |
I'm requesting from a web API information about 20,000 people that I need to update continuously at lightning speed (the web server doesn't throttle the number of requests). I can request an update on 20 people at a time (it's the maximum allowed per request) so i loop the List of people and ask the server info on grou... |
I'm doing a CodeEval challenge, where the object is to find a famous writers name and a year, inside of a random given string.
You have a set of rows with names of famous writers encoded inside. Each row is divided into 2 parts by pipe char (|). The first part has a writer's name. The second part is a "key" to generat... |
I just finished my very simple and beginner-friendly C project and wanted to hear your thoughts and opinions about ways to improve it or something.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void getFile();
void createFile();
int main()
{
createFile();
getFile();
return 0;
}
void createFi... |
This function generates all factors of an input n.
It begins at the square root of n, and checks numbers down to zero. When a factor x is found, then another factor must be n divided by x.
Also, if n is odd, only odd numbers need to be checked.
from math import sqrt
def factors(n):
"""
Generates all factors o... |
I'm a beginner in CSS and need help with a suggestion.
I'm working on a project, in which I managed to position container_main right next to container_menu giving the remaining dimension of the screen, giving it relative position and floating it to the right. container_menu has a dimension and a fixed position specifie... |
This code is a solution for /r/daily_programmer #293.
The idea of this challenge is, you are given input in the form of colored wires:
red wire
green wire
blue wire
...
and you are then to determine if cutting the input wires in the order they are listed will cause the "bomb" to detonate or defuse.
What causes the... |
In the code below I will replace all consecutive equal elements in a list with a new element. In this case I have chosen the new element to simply be the concatenation of all the equal elements, but I want the code to remain adaptable to other situations.
I have the following example:
Input: ["a", "a", "b", "c", "d", ... |
This code is meant to find the length of the largest substring within a string that starts and ends with a given non-empty substring. Here are some examples:
strDist("catcowcat", "cat") → 9
strDist("catcowcat", "cow") → 3
strDist("cccatcowcatxx", "cat") → 9
This is based off this question.
I'm doing this to improve my... |
I'm making a game in Unity and I need to have a inventory/item system, I decided to store my items in simple XML document which I later read from. I'm planning to have different varieties of items and they will all have distinct classes which extend they're base interface. Here's how my hierarchy looks like for now :
I... |
When reading from the Console, it's very easy to get a complete line, you simply call Console.Readline.
When reading from a TCPClient there isn't an equivalent function. You can either read a byte at a time, or read a block (up to a maximum size) in which case an arbitrary amount of data will be returned depending h... |
As you can see from my predicate iterate, I am repeating Z is X-3 and Z is X-2, the scenarios are different if the value is 0 or greater than 0. thus why the duplicates,
Was wondering if there was a way round this
iterate([], []). %Nothing to change
iterate([1|T], T).
iterate([X|T], [Z|T]) :- % Chan... |
I have a table with over 1,000,000 records. I need to replace any names in the text fields with aliases to help de-identify the data. For this example, let's assume the table is TemporaryTest and has two fields: Id (the key field) and IndexedXML (the text field).
I have a second table, AppellationSubstitution, that has... |
In what ways can I make this code more efficient?
I haven't put in comments and descriptions yet. I need to do that.
Ideally, I'd like to make the S, v, r, and K user entered as I did with T. I'm worried this is going to make the program cluttered though.
Is it possible to put this entire thing into a class to make it... |
I'm working on a project (in C++98) that uses a grammar validation service to validate mapping expressions for a small DSL. To simplify the project code, I've written a small interface for using the validator service, which I'm hoping to get some feedback on.
exprval_expressionvalidator.h:
#ifndef EXPRVAL_EXPRESSIONVAL... |
A friend is doing a CS course that has a command line address book as
a term assignment. Although I am a programmer in industry, I don't do
a lot of C++, so I ended up doing this as a learning exercise for C++.
The address book is supposed to read a CSV file named addressBook.csv and parse contacts in the specifie... |
In my application I wrote a pagination code that retrieves data from the server as the user scrolls down. In this case, I need to mantain the current page, whether a request is being processed, and whether the server has more data to serve. I didn't want to use globals, but still needed to mantain these 3 variables sta... |
I wrote a program to copy files with an progress bar that looks similar to Windows built in function. The copy function is run in a separate thread and the tkinter GUI is run in the main thread. This is my first time using threads and queues.
'''
Copy GUI
An attempt to design a copy program using shutil and tkinter to... |
I believe it is very much possible to make this code more efficient, possibly adding interfaces, inheritance or possibly divide the main class into more classes. I will improve some of the code such as blocking withdraws into negative amounts and so forth.
Main class:
import java.util.Scanner;
public class Main
{
p... |
Here I made a program in batch that detects all files with the .user extension. Then it allows the user to pick a username by entering the number associated with that username.
The code is messy, so I will explain.
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
:login_menu
cls
set x=1
set users=
cd "users"... |
The challenge:
Given a string S and a fixed number K, rotate every letter in S by K places (if reach the end of the alphabet, go back to the beginning). Letters should remain the same case. Symbols should remain unencrypted.
Constraints:
K is between 0 and 100. S is a valid ASCII string without spaces, between 1 and 1... |
I have this task of modelling a system where given a group of users each can keep track of their expenses. The basic requirements are as followed:
To be able to give credit to an user.
Find all the transactions of a given user.
Filter out the transaction where either user is borrower or spender.
I have tried few thin... |
This is a problem from here where you're given a magic die, and the objective is to find the minimum number of dice throws (hops) to go from the start point to the end of the board, and win the game.
I am representing the board as a matrix as follows. If the value at a cell is 0, you could go to any of the next 6 place... |
This code takes an item as an argument and deletes all occurrences of the item in the linked list. It works well with my testing. Is there anything that I am missing? Can this code be improved further?
void
LinkedList::DeleteAllOccurences(int key) {
Node *temp = head;
Node *prev = head;
while(temp!=NULL) {
... |
I have another question from same program where is full code, but this question focus only single process/function of that program.
My problem is performance when creating dynamic Image kernel from list of pixels.
List contains multiple single 4 byte Integer which is grayscale of pixel.
I have tried 3 different appro... |
I was working on HackerRank: Circular Array Rotation which is about coming up with an efficient algorithm for array rotations in right-ward manner.
John Watson performs an operation called a right circular rotation on an array of integers. After performing one right circular rotation operation, the array is transform... |
Project Euler Problem 35 asks:
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.
How many circular primes are there below one million?
import itertools
import math
import time
prime_list = []
#num = 14
count = 0
limit = 100000
time.clock()
def ... |
I was wondering if you can give me advice on this solution to assess if an user input string is a palindrome or not.
How can I optimize this solution?
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Palindrome {
public static void main(String[] args)
throw... |
This is my first winsock TCP listener ever written. I can use it for a small framework.
tcp_listener.h:
#pragma once
#include <WinSock2.h>
#include <thread>
class tcp_listener
{
public:
tcp_listener(std::function< void(SOCKET) > callback);
void start(unsigned short port);
private:
SOCKET server;
std::th... |
I have one year of JavaScript/jQuery experience but I feel a bit messy in my code. The point is that I make some code that works but I feel that it can be improved like hell. I look for that, but even if it's sometimes cleaner I don't feel that it's good.
This is a double timepicker component. The selects are customize... |
This supposed to implement a Maybe type that can either hold a value T or "nothing". It's designed to work well with vectors (that's why I take extra care to noexcept constructors whenever possible). I'm governing the actual data with ::std::aligned_storage. Note: The just member function is a reference to the Haskell ... |
Goproxy is a Go package implementing an HTTP proxy.
I am using it to store requests from a client (eg: a web browser) for further processing.
In an http.Request struct, the Body is an io.ReadCloser, it can only be read once.
The problem I faced is that I need to read the Body to store it, but still make it accessible t... |
I am developing a plugin for QGIS (a Geographic Information Systems) software which uses Python. I have several functions where each of them is connected to a QCheckbox. So when a checkbox is checked, the associated function then does the following:
It reads the text of a QComboBox which contains a list of layers.
Ide... |
Can anyone suggest to me how I can make this "nicer"? If you can see any glaring details that I could change to speed things up too, that would be great -- though it's not priority.
public class Tarjans {
private static class Node {
// -1, -1, our node is unvisited
// by default.
public int... |
I have implemented a sortmerge in Scala in one single function. I would like to have it reviewed, so that I can have it well organized, and it is then doing what needs to do.
val a = Array(5, 4, 1, 8, 7, 2, 6, 3)
def mergeSort(a: Array[Int]): Array[Int] = {
val size = a.length
if (size == 1) {
return a
}
... |
I need to execute several commands in a specific order but before I excute the main command, another command needs to be executed first and in some situations there are more commands that also need to be executed last.
To achieve this I build an extended chain of resposibility. It does not only have a post-command but ... |
Before I tried this, my impression was that (bottom up) merge sort would be memory (actual RAM) bound, and not affected much by multithreading, but a 4 thread sort is about 3.0 times as fast as a single thread sort, and an 8 thread sort is about 3.9 times as fast. This is on a 4 core Intel 3770k (3.5 ghz), Win 7, 64 bi... |
This is my first time working with Java exceptions. I have made a program that works to specifications, but I am wondering if there is anything I've done which is unconventional or not recommended. The application program does specify that there be line breaks between each message.
My driver is:
import java.util.Scann... |
I am a beginner Java programmer. I have just finished up an assignment and would appreciate some advice and/or constructive criticism on my program. For context, I have the assignment details, followed by the full code below:
The Shape interface is as follows:
public interface Shape {
public double area();
... |
This is a little program I put together to help people learn the phonetic alphabet. Feel free to query the code.
import random
phonetic = { 'a' : 'alpha', 'b' : 'bravo', 'c' : 'charlie', 'd' : 'delta', 'e' : 'echo', 'f' : 'foxtrot', 'g' : 'golf', 'h' : 'hotel', 'i' : 'india', 'j' : 'juile... |
I have a library function that returns a pair of two numbers like this
def library_function(x0, x1):
return x0**2 + x1**2, 10*x0*x1 + 1
(Actually, it is a function that returns predicted probabilities of two classes for some object, but it doesn't matter, so I created an artificial one.) I want to draw contours wh... |
I'm searching for all the unique possible permutations of nucleotide given a defined length. By unique, I mean the reverse complement would not be counted.
ACGT
For example, permutations of length 1 would be:
A:T
C:G
G:C
T:A
But the last two wouldn't be included because they would already be seen.
Length 2 would be... |
I have a below Singleton class where in my getStatement method, I populate a CHM by doing if check.
public class CacheHolder {
private static final Map<String, PreparedStatement> holder = new ConcurrentHashMap<>();
private static class Holder {
private static final CacheHolder INSTANCE = new CacheHolder();
}... |
Triggered by Finding overlaps between two lists of axis-aligned rectangles, I tried to code "rectilinear" intersection using line sweep - in python.
I'm not keen on discussing (2D) line sweep in general here (which is why this isn't tagged algorithm).
The code looks small enough to stay a single module.
I didn't take t... |
I have different strings that will return different integers, though some strings have the same value (usually 4 per code).
I used a Dictionary first, and still have them, but it's kinda messy. I also tried using switch, which is basically the same to me in this case.
Here are two examples:
public static int PPCFloatCa... |
I solved this problem from LeetCode:
Given a pattern and a string str, find if str follows the same
pattern.
Here follow means a full match, such that there is a bijection between
a letter in pattern and a non-empty word in str
Examples:
pattern = "abba", str = "dog cat cat dog" should return true.
pattern = "abba... |
I want to find character sequence count in a given string.
Sample Input: aaaabbbbaaacccbbb
Output: a4b4a3c3b3
My below function is working great and giving me the same result. but can this be optimized?
function getCharCount(str) {
var result = str.charAt(0);
var count = 1;
if (str.length == 1) {
re... |
The code along with the utils module is also at github. If you'd also have any advice on how the whole crate is structured I'd love to hear it. :)
use std::ascii::AsciiExt;
use std::str;
use utils::hex_to_bytes;
use s1c2::fixed_xor;
/// Scores ASCII test represented by byte array. The higher the score, the more commo... |
I have this view vw_RFQPartVendor that's based on these two views vw_requestVendor and vw_vendorEmail and various other tables in SQL 2005.
I find that view vw_RFQPartVendor is a little slow, anyway to improve it?
vw_RFQPartVendor 83250 rows.
SELECT TOP (100) PERCENT
dbo.SubconJobQ.Regno,
CASE
WHEN user... |
I've been working on optimizing such as loop unrolling, is there anything I can do to optimize this code to make it run faster/in less cycles?
void compute_ranks(float *F, int N, int *R, float *avg, float *passing_avg, int *num_passed) {
int i, j;
*num_passed = 0;
*avg = 0.0;
*passing_avg = 0.0;
//... |
Just for learning purpose I thought to write a simple and useful dependency injection service which would just do dependency injection but also it should expose its core too which would let the client code to do some advance stuffs.
I took inspiration from here but I think it does too much apart from that I think that ... |
Currently I'm having a big form, with steps and a lot of complex fields. To make sure the user fills the required inputs and don't make them crazy pushing down the button submit when one required field on step 3 of 6 is no filled in, I decided to disable the button so they can see fast something is not right and check ... |
The purpose of this custom TableRowSorter is to provide me with a different sort order of the columns. It changes the sort order fromSortOrder.UNSORTED => SortOrder.ASCENDING => SortOrder.DESCENDING => SortOrder.ASCENDING => SortOrder.DESCENDING => ...toSortOrder.UNSORTED => SortOrder.ASCENDING => SortOrder.DESCENDING ... |
I want to explain to beginners what a Map is in Java, with the assumption that beginners do not understand what a hashcode is.
As I developed games (Tarot, Belote, President, Pokemon), I know Java pretty well and I do not understand why overriding hashcode considering that I developed a Map class that looks like the st... |
I have a service with these methods:
Observable<User> getUsers();
Observable<Role> getUserRoles(String userId);
For each user, I want to get her roles and set them.
I have this method working:
private Observable<User> getUsersWithRoles() {
return service.getUsers().flatMap(new Func1<User, Observable<User>>() {... |
Let's say that I have the following methods
def name(value)
if value
attribute['name'] = value
end
return attribute['name']
end
def surname(value)
if value
attribute['surname'] = value
end
return attribute['surname']
end
def age(value)
if value
attribute['age'] = ... |
Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j].
If there is no solution possible, return 0.
Example :
A : [3 5 4 2]
Output : 2
for the pair (3, 4)
My Code :
def maximumGap(self, A):
if len(A)==1: return 0
a_list = sorted(([Val,indeX] for indeX,Val in enumer... |
I'm parsing an XML file that is structured like this:
<root>
<entry>
<elem1> key </elem1>
<elem2> value </elem2>
</entry>
<entry>
....
</entry>
</root>
</root>
My first code was using .parse() and .getRoot() but I had memory issues (1.5G memory use for 350M file). I solved my problem using an iterat... |
It is my second attempt to make a math expression evaluator.
To evaluate an expression, I created a class that works like this:
-it removes all the blank spaces
-if brackets are present, it processes them by creating another evaluator with the expression inside those brackets
-it gets all the numbers and does first all... |
I have written a module, which should only be used by means of import, then call the functions as required.
I do not want this module to do anything when ran interactively, other than printing out the docstrings of all the functions, which have docstrings, and which are not starting with '_'
I am looking for tips/trick... |
The following code is a python script that removes duplicate files in a given directory. At first I considered the most basic thing: relying on identical names, but you might have 2 different files with the same name in 2 different directories. So I decided to rely on md5checksum, since any 2 files that yield the same ... |
I wrote a responsive mixin for Less when I couldn't find a full featured one. Curious what other developers have done to solve this problem and hoping to improve/reduce my code since I'm very new to Less:
It would be invoked like:
element {
overflow: visible;
.responsive(768px, 0, min, {
overflow: hidd... |
SELECT Title
FROM Film F, Award A
WHERE F.Film = a.FilmID
AND Award_Category = "Best Documentary"
AND Award_Ceremony = "Galway Film Fleadh"
AND F.Year = 2008;
SELECt Title,Year,Genre
FROM Film F, Director D
WHERE D.DirectorID = F.DirectorID
AND D.Forename = "Neil"
AND D.Surname = "Jordan";
SELECT A.Forename, A.Surnam... |
I created the following program that transforms a numerical month into the corresponding textual month. I initially calculated the starPoint and endPoint in the class constructor; then I changed that calculation to the getName method. Which is a better option? Calculating in the class constructor, or in a separate meth... |
I have a project template and like to usually work with the following setup (grossly simplified, but that's the gist of it).
CompanyName.ProjectName.Business.Entities
I define my business objects. I am not going after DDD, so having [Key] is definitely not an issue for me. Nevertheless, the classes are true business ob... |
I fill out random values in two sheets (Testfall-Input_Vorschlag) and (Testfall-Input_Antrag) out of another sheet (ADMIN_ARB11).
I have 371 rows in sheet (Testfall-Input_Vorschlag) and I have 488 rows in sheet (Testfall-Input_Antrag). I have 859 columns in sheet (ADMIN_ARB11).
I pick a random value from each of the 1s... |
I implemented the Vigenere cipher in haskell as a part of exercises for Haskell programming from first principles.
Though the code isn't all that long, I feel it could use some refactoring to simplify things (I feel the code I wrote is ugly). One caveat: string inputs should all be in uppercase.
The vigenere function ... |
BitEx is a Python module I've been working on for a little over 9 months now, as a side project. It was published 6 months ago on GitHub, and as I edge closer to my 1.0 release, I wanted to take the opportunity to present my code on here, in order to straighten it out.
What it solves and offers
It's designed to elimina... |
I've done the shakesort algorithm win \$O(N^2)\$ but it doesn't seem that \$O(N^2)\$ is correct because it takes 6-9 steps in the while loop for a list of 4 integers and \$4^2\$ is 8. ~1975 steps for 80 entries. I think that should be original. Do you have any tips and improvements for me?
# -*- coding: utf-8 -*-
"""
C... |
I am a beginner Java programmer. I have just finished up an assignment and would appreciate some advice and/or constructive criticism on my program. I am trying to ensure I do not advance my knowledge using bad practices. For context, I have the assignment details, followed by the full code below:
Part 1: Write an abs... |
The biggest question is if it's worth it to use a useless if statement to make the x and y variables local away from the main statement.
//Unconventional part, make it so that x and y are local variables
if(true){
int x,y;
//set x and y to be the width + height of the terminal
getmaxyx(stdsc... |
This code is meant to compute the height for the tallest stack of boxes out of a given collection of boxes. A box has width, height, and depth dimensions. The height of a stack of boxes is the sum of all of the heights of the boxes in the stack. The boxes cannot be rotated. A box can only be stacked on top of another b... |
I'm a mechanical engineer/amateur programmer trying to learn modern C++. I'm working on a personal project where I'm building a library that uses PortAudio to abstract some basic audio processing, specifically pitch and volume extraction from microphone input as a way to facilitate that learning. I'm as interested in... |
This is my first Clojure program. If you want to run it locally please check out https://github.com/achikin/game2048-clj
core.clj
(ns game2048.core
(:require [nightlight.core :refer [start]])
(:require [game2048.ui :as ui])
(:require [lanterna.screen :as s])
(:require [game2048.game :as g])
(:gen-class))
(de... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.