instruction stringlengths 71 71.9k |
|---|
Basically, I made a function which switches between stages (see the Switch class below).
The way I call it is seen in the Controller below. I wanted to ask if this code (in the Switch class) is good practice or not.
Login class:
public class Login extends Application{
@Override
public void start(Stage primaryS... |
I have coded up the variable length integer encoding aka VLQ in Java. It works with any base in (1, 128]. I've implemented the usual encode/decode methods and also the addition and multiplication for this encoding. Single byte multiplication uses shift-and-add and multi-byte ones uses Karatsuba algorithm.
I've tested t... |
I've been trying to learn Java for the last day or two. This is the first project I am working on, so please bear with me. I worked on a multithreaded web crawler. It is fairly simple but I'd like to ask for some advice.
Purpose / Running
The program starts at one web address (in this code, http://google.com) and looks... |
This is a follow-up to SICP exercise 1.28 - miller-rabin primality test.
Exercise 1.28:
One variant of the Fermat test that cannot be fooled is
called the Miller-Rabin test (Miller 1976; Rabin 1980). This starts
from an alternate form of Fermat’s Little Theorem, which states that
if \$n\$ is a prime number and ... |
I have written the following control which allows loading a GIF from embedded resource, file, or raw Image. It allows for more granular control over the direction and frames per second of animated image types.
The problem I face, is it is quite laggy during the frame switching (unlike the PictureBox control which does... |
Over the last year I have been programming on my own, mostly in Python. I haven't had any formal education, though I have followed some online instructions, and have been making things that interest me.
One of those things is my Vigenère encrypter. I've made a few versions of it, and I would appreciate feedback on my l... |
Unreal Engine 1 nowadays is slightly useless, but it still is (kinda) flexible and allows for modifications of extensive kinds, including many sorts of maps.
However, one of it's editor, Unreal Editor (2 in this case) 's biggest limitations is the small number of possibilities when trying to do complex brushes. The 2D ... |
I've been following along with CS50 online and tried my first shot at making a program from scratch and without guidelines. I hope you may be able to rip it to shreds for me.
//
// this program determines how many hours you slept last night.
// it assumes that:
// you're using a 12 hour clock
// you sleep for a maxim... |
Recently, I have been using the Wolfram LibraryLink wrapper. By that technique, I could call the function written in C from Wolfram Mathematica.
Here are two C wrapper functions, BSplineCurveKnotsRemoveAll() and BSplineSurfaceKnotsRemoveAll():
BSplineCurveKnotsRemoveAll(P,U,p,TOL) removes as many knots as possible of ... |
Please review these string checking functions. This is the whole module
which is actually written here. It supports buffer, array, and
string by checking the char code.
const charCode = chr => typeof chr === 'number' ? chr : chr.charCodeAt(0)
const every = (fn) => (list) => {
for (let i = 0; i < list.length; ++i)
... |
I was practicing for the upcoming zco in CodeChef, where I came across this problem:
Given some number \$K\$ and a list of \$N\$ numbers, count the number of pairs (\$i\$, \$j\$) such that \$1 \le i \lt j \le N\$ and \$|a_i − a_j | \ge K\$.
\$1 \le N \le 65000\$
\$1 \le K \le 10^8\$
\$0 \le a_i \le 10^8\$
I got the... |
Please tell me anything that comes to mind. However, I am most interested in ways to make my code more idiomatic (modern) C++.
tsp.h:
// File: tsp.h
// Author: Rodion "rodde" Efremov; Aug 21, 2016
// License: there is no such, you can use it freely in your projects. However,
// if the code in this file... |
I have downloaded the latest version of the Linux kernel and I want to perform thorough analysis on it. I want to start by eliminating comments from all the source and header files that belong to it. I am using a code I wrote sometime ago and I want to use it recursively. In the past I tested it on my code and it worke... |
In MS Paint, if we choose paint bucket and fill click on a certain spot, it gets filled with a new chosen color along with its neighboring pixels that are the same color until it reaches certain limitations such as a different color. This program, using recursion, does the same thing except to a flat ASCII surface:
xxx... |
Earlier today, I encountered an Access Violation error when opening the VBE for SolidWorks 2006, while Rubberduck VBA was initializing.
I traced the Access Violation back to an attempt to set the Picture property of a CommandBarButton, and then posted on SO
Initially, I suspected that SolidWorks might have implemented ... |
console.clear();
function cons(inorder, preorder) {
if (isEmpty(inorder) || isEmpty(preorder)) return null
if (size(inorder) === 1 && size(preorder) === 1)
return {val: inorder[0], l: null, r: null};
var leftSize = inorder.indexOf(head(preorder));
return {
val: preorder[0],
l: cons(take(inorder,... |
Since I had not found exactly what I was looking for I wrote some simple workqueue-based job system myself that is based on boost's lock-free queue. It is supposed to be used in some GUI application where calculation jobs should run in the background. At the moment, results are not conveyed and there is no signaling, w... |
I have two tables. Table 1 has sets of EXPORT conditions: e.g., SET 1 has FOOD, GARMENT, and TECHNOLOGY, and SET 2 contains GARMENT and TECHNOLOGY.
TABLE 1
SETID EXPORT
-----------------------
1 FOOD
1 GARMENT
1 TECHNOLOGY
-----------------------
2 GARMENT
2 TECH... |
I have a method that validates a user-written IP address in an Android application. If it's invalid, I need to know why and notify the user using a Toast.
I created an enum for this called Status that has a list of reasons for an IP address to be invalid and a value for when it's valid. The method isValid will return a... |
I wrote a script that pulls all the cards in my food expenses list that are separated by months. I then extract all the numbers and log the sum to a file. Later I plan on graphing my monthly expenses and the names.
#!/usr/bin/python
from trollop import TrelloConnection
import logging
# Lots of issues with Python3. Lo... |
C++11's range-based loops allow convenient and easy iteration over containers, but what about more complicated iterations such as tree traversal? Usually this involves a lot of boilerplate code and potential errors since we need to write complicated iterator classes as well as some wrapper class proving begin() and end... |
For reference: L-system
I'm mostly looking for general style stuff here and in particular:
if my type parameters are too crazy — I wanted two parameters so that variables and constants could have their own types.
if I could be using some library features that I don't know about.
if there might be some type based way t... |
This is our first attempt at building an unbalanced k-dimensional tree with nearest neighbor (1NN) lookup to process multi-dimensional data. In particular, the "suspect region" in the NN() function is where we are having the most questions:
Is a distance calculation (distCheck) necessary on every element in the subtre... |
I made a settings class for my own C# application. My main goal was to reach this class from every other class (this is why I choose the Singleton pattern). I also wanted to distinguish the different type of settings, so I added GeneralSettings and made it public. Do you know any other ways which I can tell apart the d... |
I have implemented a breadth-first search and I'm more or less looking for suggestions on how I can improve on what I've done here.
How to use:
search(queue, "Musician");
The logs from the search:
Lansana is not a Musician. Lansana is a Software Engineer.
Zack is not a Musician. Zack is a Software Architect.
John is ... |
In Python the Extended Euclidean Algorithm (egcd) could be written as follows:
def egcd(a, b):
if b == 0:
return (a, 1, 0)
else:
(d, tmp, s) = egcd(b, a%b)
return (d, s, tmp - (a//b) * s)
I want to write a native and modern C++ version of the egcd. This is what I have so far:
template<typename A, typen... |
I wrote this quicksort implementation in C++
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
void myquicksort(std::vector<int>& A, const int left, const int right)
{
int i = left;
int j = right;
int pivot = A[left + ((right - left) / 2)];
while(i < j)
{
while(A[i] < pivot) ... |
I'm just looking for constructive criticism of my Ruby implementation of a bubble sort algorithm.
class BubbleSorter < Object
def bubble_sort(list)
swaps = 0
# parse the list until it is sorted
until @sorted == true
# run the comparison of adjacent elements
for i in 0...(list.length - 1)
... |
Question:
You're in a hotel and you forgot what room number you were in but remember that the sum of it's divisors is greater than the number, yet there is no subset of those divisors that add up to the number itself. There are 100 rooms in the Hotel, what's your room number?
My Answer in CoffeeScript:
Looking for cons... |
I'm looking for some advice in how well this gulp file is written out and any suggestions on improving it. Any insight is appreciated
/* ================================================================
Plugins
================================================================ */
// Base plugins
const gulp = requir... |
I'm looking to get some feedback on my attempted string implementation. The code is just meant for me to play around with and work on some C++ to try and improve. A lot of the things done here (rule of 4 and 1/2, auto return values, const methods, etc) are features of C++ I don't have a lot or any experience with and I... |
Description
The code captures keypress events that do not occur in a text field and dispatches on the properties of a $command object in the application execution context. I have provided a sketch of the execution context in order to assist your review of the code of interest.
Execution Context Sketch
This is a sketch ... |
I am using the following function to receive XML data from a URL.
Is there a more efficient method for retrieving this XML data?
Public Function UserLocation() As String
Try
Dim XML As Object = Server.CreateObject("MSXML2.DOMDocument.6.0")
Dim getXML As String = "<URL>"
XML.async = "false"... |
This program calculates up and downspeed of a given connection for as long as it is running.
#upspeed/downspeed indicator
#written by Chubak -> aurlito@riseup.net
import requests
import time
import os
def get_seconds(datetime):
time = datetime.split(' ')[3].split(':')
time_hours = int(time[0])
time_minu... |
I've created a simple pathfinder programme that receives its input from a very small .png file.
Example file here:
Here's a link to the file (note that the green pixel represents the start, the red pixel represents the end and black pixels represent walls). Also, the file needs to be saved as map.png, in the same fold... |
Problem:
There are \$n\$ pigeons and \$m\$ grains. Pigeon \$i\$ eats a single grain every \$x_i\$ seconds. Find the time until all the grain is eaten.
Input:
A line with the integer \$m\$ giving the number of grains, followed by a line with \$n\$ integers \$x_1, x_2, \ldots, x_n\$ giving the time taken by each pigeo... |
The purpose is to attach a tooltip-element to arbitrary HTML-elements.
The tooltip appears when the user hovers an element. Follows the mouse-pointer while moving over the element.
/**
* Attaches a tooltip to every element in the result-set.
* @param { string } selector - An CSS-selector.
* @param { number } hor... |
The code's purpose is to call to some function async given some condition was true. I've using the following code which is working as expected. Is there a way to write it better, maybe by not using the promise push array?
var _run = (req, res, oModule, oConfig, urlPath,action) => {
var aPromises = [];
//reques... |
I have created a rationalnumber class and used operator overloading function of C++.
My questions are:
Have I implemented the class and < operator correctly?
Objects of class can now inserted in map and set. Is that part done correctly?
#include <bits/stdc++.h>
using namespace std;
class RationalNumber {
int nu... |
Write a program to implement stack which implements min a method
which gives the minimum element below the top element in the stack.
const items = Symbol('Stack items');
class Stack {
constructor() {
this[items] = [];
}
pop() {
return this[items].pop();
}
push(data) {
this[items].push(dat... |
I've been developing a small screen sharing project for the last months, it's a desktop application, pct protocol based. I'm going to show the logic and the code and I hope to get reviews. I would like to hear every suggestion.
First of all, I'm using a service called Desktop Duplication API. Here's the C# implementati... |
I wrote a method that will confirm email with token send to user emails. It will also send different email depending on the condition for the registered user. If anyone would write the same method, how would you write this code snippet?
[AllowAnonymous, Route("confirm-email", Name = AccountControllerRoute.GetConfirmEma... |
Please let me know your feedback around handling ADO.NET connection and transaction, especially when it comes the catch block. Any way I could improve?
public static bool FileBulkLoad(string filePath, string tableName, string fieldSeparator, int numberOfSourceColumns)
{
using (var connection = new SqlConnection(Get... |
I'm currently trying to learn the idiomatic way to write F# code. The code simulates a basic calculator with only binary plus, minus and unary minus.
I'd like to know if there is a better way to group union cases than the way I did it. Should the Add/Sub/MinusExpression be cases in the Expression union? Is there a bett... |
I need to shorten/simplify this code:
require "time"
def parse(timings)
validdays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
hours = {}
if timings.include?("Open everyday from")
validdays.each do |day|
open_close = timings.gsub(/.*everyday\s*from\s*(.*)... |
I've started learning C and as an exercise I decided to implement some basic functionality for a bloom filter. This is my first C project, so I wanted to see if I was doing things appropriately (project structure/organization wise). Also, I was wondering how to turn this into a shared/static library, since I tried ini... |
I have this program on Excel VBA, that implements a userform in order to simplify input and to create control charts from the data input analyze the data and send emails if certain conditions are met.
My problem is that everything works properly but after running line by line I noticed that when filling up the correspo... |
I recently started to learn Haskell in order to write some small tools for me. Currently I'm working on a program which calculates how much steam a (railcraft) boiler of a given size outputs per tick.
In the console the user inputs a string of the following format: S | L | BL-Size | BH-Size, example BH-3x3x4
I then use... |
These couple of functions solve (or attempt to solve) an arbitrary Euler square. In this case I will refer to it as the colored tower puzzle and explain it that way:
Given an n by n grid of tower bases of different heights (0 to n-1) which each base height occurring once in each row and column as well as n sets of n t... |
I had to jump through some hoops to get a localized enum working. I went through dozens of SO articles that never actually answered the relevant conundrum with a working solution. So I made my own:
I have two resource files: LocalizedStrings.resx and LocalizedStrings.es-MX.resx
With two corresponding lines:
GENDER_FEMA... |
I have a data scraping script that runs and scrapes records, saves into the following table:
For the records already existing in DB, I need to update the old records if it is not updated for the past 2 days.
My table has fields scraper_run_inserted (DATETIME value when record is inserted) and scraper_run_updated (DATE... |
actualarray = {
'single_open_cost_1':{
'cost_matrix': [
{'a': 24,'b': 56,'c': 78},
{'a': 3,'b': 98},
{'a': 121,'b': 12121,'c': 12989121,'d':16171},
]
},
'single_open_cost_2':{
'cost_matrix': [
{'a': 123,'b': 1312,'c': 1231},
... |
I am writing a program in an environment that makes use of cgroups to identify and group processes together. I want to parse the CPU utilization of each cgroup by sampling /sys/fs/cgroup/cpuacct/.../cpuacct.stat over a 1 second interval a few times and then averaging them. It also calculates the overall CPU utilization... |
I've been working on an ANTLR grammar that defines some tokens in terms of Unicode character categories (fileformat.info page). The Unicode Consortium makes a full data tab-separated-values .txt available at http://www.unicode.org/notes/tn36/Categories.txt.
The below scripts work together to take Categories.txt and tu... |
I have made one architecture on my project and want to know. Is it good or bad?
events = {
init: function() {
for (var callback in this.events){
this.bind(this.events[callback].selector, this.events[callback].event, this[callback], this.events[callback].params || {})
}
},
eve... |
I've written the following codes in Scala and Java to solve cryptarithmatic problems.
E.g. For SEND+SOME=MONEY, assign the digits 0 to 9 such that the equation holds true.
The algorithm I've used is backtracking without pruning.
Scala Implementation:
package recursion.flavors.decisions
import scala.language.dynamics
i... |
I'm very much used to enumerations a la Java, where each value in an enum is a distinct object. You can call functions on these objects, and they're generally treated as most normal objects.
Except ActionScript 3 doesn't have enumerations. So... I had to create my own.
My hard requirements:
Compile time type-safety ch... |
I want to return an iterable collection of all q-grams of a provided string. This means all sub-words of length Q. Let Q be 3 for example:
normalized as an already whitespace-stripped and upcased word or string. PREFIX3 and SUFFIX3 are constant strings ^^ and$$ that are put surrounding the string before splitting. That... |
The puzzler:
This was sent in by a fellow named Dan O'Leary. He came upon a common
one-syllable, five-letter word recently that has the following unique
property. When you remove the first letter, the remaining letters form
a homophone of the original word, that is a word that sounds exactly
the same. Replace ... |
I implemented a function that prints all the numbers from the Fibonacci sequence until max_num. The minimum value allowed is 0 (so, fib(0) prints 1). It works until 92, and I want to know how to improve the code, in general.
void fib(unsigned int max_num)
{
unsigned long fib_num = 1;
unsigned long fib_temp = 0;... |
I have a Django site where users upload and have the option to delete files. There will be a lot of files that will have the same logical name so I append numbers to them:
foo/bar/file.mp3 foo/bar/file2.mp3...
I needed a method that would return the lowest file number not currently being used. I have a working examp... |
Suppose my milestone is this:
milestones = [ {state: 'unavailable'}, {state: 'arrived'}, {state: 'completed'} ]
I want to remove all the unavailable state from the list of hashes except the last one. My function works pretty well but I need some help to re factor it even further, and will appreciate any comments you c... |
Can the following function be improved in terms of performance?
I am calculating millions of such hashes.
The long array represents a record from data table where all values are encoded as long values. Usually in one calculation stream all arrays are of the same length but in some rare cases this rule does not apply.
T... |
This is a small function I have written to equalise the height of groups of elements. Useful for when titles or content will end up being odd length and throw out the visual flow.
To use it you just add the data-equalize attr to two or more element you would like equalised. Can have multiple groups working on one page.... |
After dipping my toes in PowerShell for over a year i think it is time for creating a real cmdlet. My first mission was creating a regular PS script to take in a .csv and create a wifi account using the Aerohive REST api.
Although it works, i find the script bloated and ugly, and want to swap large code block for prope... |
I implemented a tcp socket server using the Microsoft IO Completion Port Model, which is basically an asynchronous model where WSAXXX function return immediately and you use a worker thread to handle actual completion of the operation and handle data received or sent.
There is quite a bit of code in tcpserver but not m... |
This is for heapsort and am wondering about the heapifyDown method. Here it is for review. I included relevant helper methods.
The heap is stored in array starting at index 1.
/*swaps node at i with biggest child if larger*/
private void heapifyDown(final int i) {
while(!isLeaf(i)) {
//find biggest child
... |
Today I wanted to find a program that I wrote a while ago. I knew that it contained a certain regex, but I couldn't for the life of me remember the file name I saved it under. I knew I could use Windows search, but it takes more time then it would for me to write a Python program to do the same.
The main two things I u... |
I wrote a recursive function to uncheck all menu nodes. It works well, but I need to know if it is right to leave empty block inside if (nodes[i].children.length === 0) base case.
Is there a better design choice?
The function:
function uncheck_all_tree (nodes) {
var i, n, n_dom_el;
for (i = 0; i < nodes.length; i... |
I am new to the whole Data Structures thing and I want to get better at writing efficient code. So, I have been practicing some problem sets. The questions is - Replace characters in a string using iteration and recursion approach. I am still learning the whole recursion approach. But I tried to design an algorithm usi... |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Youtube Iframe load on thumb click</title>
<style>
.youtube {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
max-width: 100%;
}
... |
I've recently wanted to make a "Loading..." display in C where the dots print one at a time in order and then reset:
Suprisingly, there isn't much on the internet for doing this well, so I figured I would make a simple program for it.
#include <stdio.h>
#include <time.h>
int main(void)
{
int msec = 0;
const i... |
Let's say I have a struct…
struct Person {
let isMale: Bool
let name: String
}
and an array of Person structs. I want to trim all the men (isMale == true) from the start and end of the array (similarly to how you'd trim whitespace from the start & end of a string)…
func trimMen(people: [Person]) -> [Person]
... |
I created a class that is able to generate a Sudoku board.
The following board generation steps are made:
Create a valid board with numbers on all squares, row by row
Basically I always generate the sequence 1 to 9 and I shift the elements on the cells. The shift amount depends on the row index.
Shuffle the board
Nothi... |
Update: Based on Mike's inputs, a better version of my code can be found below (search for "better version", to skip the ugly version)
The dataset I obtain after performing a table join in the database is this:
RestaurantID RestaurantName OutletID OutletName Address Phone Latitude Lo... |
I solve this problem in Swift. I am looking for a code review, thanks!
Given a non negative integer number num. For every numbers i in the
range 0 ≤ i ≤ num calculate the number of 1's in their binary
representation and return them as an array.
class Solution {
func countBits(num: Int) -> [Int] {
var ... |
Although C11 introduced aligned_alloc( alignment, size ), there is no support for aligned reallocation (AFAIK). The memory_resource structure that follows and its related functions provide such functionality.
I wanted to provide something with as little overhead as possible, which is why there's close to no error check... |
I've made this extension but I'm touchy around NSAttributedStrings, keenly aware that Swift refuses to use the traditional notion of integer lengths on Unicode Strings, what with their graphemes that can compose and overlap. Also, it feels odd to convert to String to check for the newline. I'm not worried about \r beca... |
I managed to send video feed over tcp socket using code and decode of string64. My problem is that the video feed is kinda laggy, and it's probably because of this time between coding and decoding.
Is there a simple way to improve this?
C#
private void enviar_data()
{
string data = "";
stri... |
I have the following C# code for deleting files from a folder (and from its sub folders) excluding a list of files specified in an Excel file. The code works fine.
The deletion is happening one-by-one in a for loop. Is there a way to improve its performance by reducing the time taken for deletion?
class Program
{
... |
The task is to create a website which allows the admin to create classes, students and teachers. He/She should be able to assign students to classes and one teacher. The admin should also be able to register students attendance using a register. Classes should have specified dates as to when they are running.
The teach... |
This code implements an FTPManager class and is designed to be a place to insert file data to be sent later, without having the program wait for a potentially very slow file operation to finish.
This code is designed to work around some issues that I've been noticing when having multiple threads use FTPWebRequest simu... |
Background and Example
This code simulates the Enigma machine, minus the plugboard. Here's some test code that illustrates how the machine's construction and use:
>>> r1 = Rotor("VEADTQRWUFZNLHYPXOGKJIMCSB", 1)
>>> r2 = Rotor("WNYPVJXTOAMQIZKSRFUHGCEDBL", 2)
>>> r3 = Rotor("DJYPKQNOZLMGIHFETRVCBXSWAU", 3)
>>> reflector... |
I am certain there is a better way to flatten the array with an optimized approach for the solution.
Example:
[[1,2,24],[12,1241,122],[3,2],[7]] => 1 12 3 7 2 1241 2 24 122
public class flattenArray {
public static void main(String args[]) {
int inputLists[][] = {{1,2,24},{12,1241,122},{3,2},{7}};
flatten... |
The goal is to write a generic doubly linked list program to handle.
Header:
#include <stdio.h>
#include <stdlib.h>
struct list {
struct node *head;
struct node *tail;
size_t element_size;
int element_count;
void (*printFunc)(struct node *);
};
struct node {
struct node *next;
struct node *previous;
... |
Uuencoding is historically used to encode emails. Instructions for creating a Uuencoder are:
Start with 3 bytes from the source, 24 bits in total.
Split into 4 6-bit groupings, each representing a value in the range 0 to 63: bits (00-05), (06-11), (12-17) and (18-23).
Add 32 to each of the values. With the addition of... |
I tried to refactor my code with entity framework configuration, splitting in multiple private methods, one per entity, each responsible for configuring things related to that entity and only that entity. But I feel like Version 2 can still be improved.
What do you think?
Version 1:
protected override void OnModelCreat... |
I wrote a small piece of code for observing changes on JSON object. Whenever there is a change in Object, it should trigger all the handlers with simplistic information about data change.
I am looking for improvements in the code. As I am struck with this pattern, could not think of better ideas of it. Please help.
How... |
I was refactoring a quite large WPF project and I found some pieces of code where it can leads to error.
Ive got some services in the form
public sealed class CurrenciesService : ContainerServiceBase<Currency>, ICurrenciesService
{
public override Currency GetItem(int id)
{
return GetItemInternal(x =>... |
I have written a script that turns an asn file into a hpp file, but it look very dirty even though I have made changes based on pylint.
I think I make use of too many lists, for-loops and try except blocks.
I would like to get a review of my code, and I am particularly interested in making my code look more organized ... |
Recently I was going through this codechef problem while practicing for the upcoming zoc.
The problem asks to calculate number of combinations of the given numbers where the sum is less than another given number.
Previously I had a bruteforce algorithm which gave the correct answer but took a lot of time, in some cases... |
I wrote this function for string concatenation some time ago.
Jo() stands for "Join". The name is shortened on purpose, because this function is used very often.
It offers a stream-like functionality: Jo("i = ", i) = cout << "i = " << i
and returns a const char * to internal buffer.
const char * is used instead of std:... |
I've done a practice session on cyber-dojo and would like someone to review it.
Main question - is my solution too complex for such a simple task?
For example, I decided to split out printing and generating logic into ChainPrinter and NumberGenerator classes. This in my opinion conforms better with Single Responsibili... |
Given a 2D matrix find the largest area of identical elements.
Here is my first implementation:
using System;
using System.Collections.Generic;
namespace ProgrammingBasics
{
class MaxArrayArea
{
static void Main()
{
// target matrix
int[,] matrix = new int[,] { { 1, 3, 2, 2, 2, 4 },
... |
I was wondering if there was a way I could shorten this code that gets input from the user about the state of their 2×2×2 Rubik's Cube to solve it. I want it to still be informative so any user knows what to do, the thing is the method is pretty long.
static public int[][] scanCube(){
int counter0 = 0;
Scann... |
How can I improve upon this code to apply logic based on the user's response to a SaveAs Dialog Box 'do you want to overwrite existing file' question:
Sub SaveFile(fName As String)
cancelSave = False
Retry:
saveAsFileName = Application.GetSaveAsFilename(InitialFileName:=fName, FileFilter:="Excel Files (*.xlsx), *.xlsx... |
I just finished working on a coding challenge for learning Python 2.7. Essentially, I'm a function that if it is fed a string such as:
"The man drank the drink and ate the bread and forgot the drink"
I get in return:
{'and': {'ate': 1, 'forgot': 1},
'ate': {'the': 1},
'bread': {'and': 1},
'drank': {'the': 1},
'dri... |
I'm trying to implement a heap using list data structure. I'd also like to keep track of the position of elements in the list in order to enable easy deletion. My implementation involves looping through the entire list to update the positions after an insert/delete combo. I'm afraid this raises the time complexity from... |
I have written a basic binary file handling program and have used goto, so I want to know how to improve this program by replacing goto with another function
#include<fstream>
#include<process>
#include<string>
#include<stdio>
#include<conio>
using namespace std;
int opt;
class housing
{
int hno,income;
char nam... |
jQuery plugin for a form. Looking for constructive criticism on my code. Thanks in advance!
// form.js
// splashinn
var Form = function(options) {
options = options || {};
this.url = options.url;
this.$fields = $(options.fields);
this.$status = $(options.status);
this.$submit = $(options.submit)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.