instruction stringlengths 71 71.9k |
|---|
I was tasked this in class today, so the teacher could judge where our skills are.
I am not an experienced C++ programmer, and I made a mistake on my sheet, so I came home and wrote this.
I saw other examples online, but this is the solution I came up with. It works from what I can see, and for these test values.
Did I... |
A twinoid is defined to be an array that has exactly two even values that are adjacent to one another. For example {3, 3, 2, 6, 7} is a twinoid array because it has exactly two even values (2 and 6) and they are adjacent to one another. The following arrays are not twinoid arrays.
{3, 3, 2, 6, 6, 7} because it has thr... |
My program simply accepts the name of a directory from the user, scans said directory and generates an HTML file that lists the contents.
Is there any way that this can be improved?
/*
Basically, take the path of a directory, get a list of all files in the directory
and output that list to an html document
*/
i... |
For fun, I have been working on this game I called Star Catcher. It's a very basic game where stars are falling and you try to catch as many of them in your bucket before you miss 10. It's a real mess of code that I just threw into one file, basically. The animations seem to be working fairly smooth for me on my comput... |
In my Rails app, I have two classes each with the same enum for status. Code climate is complaining about duplication.
class Enrolment < ActiveRecord::Base
has_many :enrolment_presentations
has_many :presentations, through: :enrolment_presentations
enum status: {
'Pending' => 1,
'Suspended' => 2,
'Ca... |
I have a few "given" things:
An SQL Server 2012 table with certain structure
Data provided as XML with certain structure
My code has to shred that XML into a row in the table. I'm looking to get feedback on how I'm getting the data for each column from the XML variable.
Here's a realistic yet minimal repro of my scen... |
Some of my tests require that I need to test the date time results (like time stamps etc.). In order to be able to test the date time string I created a simple DateTime abstraction that I'm going to use in other projects later. It should replace direct calls to DateTime.(Utc)Now. Or should I rather call it TestValue in... |
This class is extension of this. Now I have added support to serialize array of TLV objects to byte array and vice versa. I posted also someone may find it useful in future (together with other TLVObject class). Feel free to provide feedback.
Usage:
// Add various values to TLV parser
TLVParser a;
a.AddByteTlv("Bill",9... |
I'm implementing std::once_flag and std::call_once for a particular MinGW build where they are not available, using only stuff available in the rest of the standard. The required semantics would be easy to implement with something like:
struct once_flag {
private:
std::mutex _M_mutex;
std::atomic_bool _M_has_ru... |
FeatureMap contains features, derived classes have some mandatory features that the map should have, say keys (the mandatory part) are added and all the features are fetched from somewhere. Since clients interact with FeatureMap, a featuremap needs to be returned and the type is part of the actual object. Is there a be... |
Codacy is telling me this method has a complexity of 13. I need some tips on how to reduce it, more specifically inside the forEach loop.
I've already changed it from an if/else` if hell, but it seems it wasn't enough.
function addGenresAndThemesFromWork(work){
let workDetails = {workId: work.$.id, genres: [], them... |
Is there a way to rewrite this code to make it more laconic? I'm using Java 6.
Object value = methodOutOfMyControl();
Collection<LinkedHashSet<String>> values = ((Map) value).values();
Set<String> strings = new HashSet<String>();
for (LinkedHashSet<String> set : values) {
strings.addAll(set);
}
|
The code itself is divided into 3 logical parts:
Core modules (I call them Kernel modules, my love for Linux) - those are basic modules a web-developer would need, e.g. database wrapper class (PDO), User class that works with user session etc.
Developer modules - the modules a web-developer might write for themselves.... |
class CSList
{
public:
CSList()
{
::InitializeSListHead(&m_head);
}
USHORT Depth()
{
return ::QueryDepthSList(&m_head);
}
PSLIST_ENTRY Flush()
{
return ::InterlockedFlushSList(&m_head);
}
PSLIST_ENTRY First()
{
return ::RtlFirstEntrySList(&m... |
For a trivial word game, I wrote the following code for the player to choose one of the two choices of words that in turn were read from a sentence.
My question lies in first in the click-listener of the buttons of the choice.
The main code, in Java:
private void initAnswerButtons() {
//2. here
if (questionNum... |
I have this ugly function, and I feel that the entire strncpy should just be an strcpy:
void PackData(char*& cursor, const std::string& data) {
*(reinterpret_cast<int*>(cursor)) = static_cast<short>(data.length() + 1);
cursor += sizeof(int);
// copy the text to the buffer
::strncpy(cursor, data.c_str(),... |
A balanced array is defined to be an array where for every value n in the array, -n also is in the array.
{-2, 3, 2, -3} is a balanced array.
So is {-2, 2, 2, 2}. But {-5, 2, -2} is not because 5 is not in the array.
I wrote the following class BalancedArray which satisfied above condition.
public class BalancedArra... |
One of my issues with sp_who2 is that you need to be in the console to run it as it recalls spid twice and most reporting tools throw this as an error.
My question is, would using the code below to reformat sp_who2 be a more reliable approach than taking the definition for sp_who and removing the
--Handy extra for ri... |
In order to submit a login form using wget, I need to find the values for the hidden field that were added to the form recently. Grepping for the names gives the following:
$ grep csrf signin.php
<input type="hidden" name="csrf1" value="56a0ecec3f15c" />
<input type="hidden" name="csrf2" value="4a8cb442fc85a745c9c... |
I am making a sheet that adds up the total cost for a summer camp after registration. Each parent can register up to five children. I have already made my code and it works, but there must be a simpler way.
The code looks at the cell, and determines the cost of the program depending on whether the parent chooses after ... |
I've seen a couple GSL-like string_view-ish implementations on CR recently, but don't recall seeing anything like array_view yet (AKA span in the GSL), so I wrote one just for fun!
My implementation is a simplified array_view that doesn't support the bounds and indexing in the same way the GSL span does. I also didn't ... |
I'm currently doing the Javascript course at Codecademy, and decided to customize their dragon slayer game. I would appreciate any help/pointers that can help me optimize the code. There's a lot of repetition that I'm sure can be done in a smarter way.
var slaying = true;
var youHit = Math.floor(Math.random() * 2);
var... |
I wrote my first Android UI application for a test job, but it was declined as employer said that he did't like "the code quality". He didn't specify what he meant. But I'm very interesting to know what's wrong with the code.
Here is the link to the Android Studio project.
Here is the text of this test:
Design and bui... |
Disclaimer: While the code in this question looks extremely long, I'm really only interested in reviewing some small parts of it. While I would sure appreciate someone going crazy and reviewing it entirely, this is certainly not needed. I included the full code so it can be run and tested.
I've been studying lua for ... |
I'm working on a Django Twilio app, and I believe it's coming along well. I just want to improve my code writing skills. How can I improve the below code?
def save_number(request):
from_number = request.POST.get('From', '')
try:
obj = SaveNumber.objects.get(phone_number=from_number)
if obj == ob... |
I've created a program that will pull spreadsheets out of a large tarball.
First it specifies the file name through the "folio" number which is given as an argument when the program is called. From there it runs a bash command that will list a text file containing the information needed to find the tarball, the informa... |
This is my first attempt at refactoring - FindIngredients and I'm wondering where I can improve. The github link in the code directs to the project that still has the old code.
The user has data validated selections to make in cells B2 through H12 on Sheets("Plan"). Each type of meal has certain selections from the ing... |
Here is a code I developed some time ago. I wonder if there is anything I can do to improve it. It works for non-loopy mazes which was already my goal.
In the maze defined, True are the open ways and False are the walls.
The main subjects that I gladly accept suggestions can be listed like this:
Is the solution python... |
I've just started a new class learning Java, and since it's been a long time since I've programmed in it I thought I'd put up my first project to get back in the swing of things. Here is my first assignment:
Welcome to the Bridge Crossing Problem. Person Pn can cross the bridge
in n minutes. Only one or two persons... |
Below I have implemented a class that will generate HTML to build the structure for a navigation menu.
define('BASE_URL', 'http://localhost/site');
class Navigation
{
private $doc;
private $xpath;
private $rootNode;
/**
* Initialize navigation.
*/
public function __construct($menu)
... |
I am starting to get into OOP using PHP and MVC. I just want to know if this code is good practice. Is this how I should be using my controller and model, in its simplest form?
AppointmentsController:
public function index()
{
$appointmentsByLabel = Appointment::findAppointmentsByLabel('2');
$appointment... |
I have coded this Ruby code. Everything here works perfect as intended, however it is a real mess. What would be the best way to clean this up with best practices and such?
class new_class
attr_reader :shop_id
SECRET_API_KEY = "asdasdasQWRESFSDFVSDFASDFSADFASDF123123ASDASD$%$%"
def set_shop_id(shop_Id)... |
I have a table containing about 30k rows of data and there's several table associations. The problem is that there's like 18 columns, and each column requires 1 db query.
Here's an example of what I'm doing:
if col_num == 0
tmp_string_text = finding_phase
elsif col_num == 1
tmp_string_text = ""
elsif col_num ==... |
I am PHP programmer whom only recently started to play with a bit of JS/jQuery. Because of that my code is probably something that most of You hardocding JS programmers would see as disgrace (again I am far from being one of you).
I wanted to create simple but quite customizable "tab > content" player and so I did.
I w... |
I have made a program to take x number of die and rolls them y number of times, then stores the data into an array so that I may output a CSV file. Everything works as intended, but I am having trouble figuring out how to increase the number of die to anything substantial. Right now I am using a switch, but linearly ad... |
An integer m is defined to be an even subset of another integer n if every even factor of m is also a factor of n.
18 is an even subset of 12 because the even factors of 18 are 2 and 6 and these are both factors of 12.
But 18 is not an even subset of 32 because 6 is not a factor of 32.
I wrote the following code to c... |
I am an owner of a small industrial business startup and I am learning to write software in order to efficiently keep track of our inventory and finances, as our needs have outgrown the capabilities of Excel.
I was working on our perpetual FIFO inventory allocation method and I've inadvertently created a monster. This... |
So a friend happened to show me how odd and specific the general email syntax rules are. For instance, emails can have "comments". Basically you can put characters in parentheses that are just ignored. So not only is it valid, email(this seems extremely redundant)@email.com is the same email as email@email.com.
Now mos... |
I have the following code for currency formatting
boolean isNegative = probe.nl_price!=null && probe.nl_price.signum() == -1;
String str = "Price: " + (isNegative ? "-" :"") + "$" + FormatUtils.getFormatInstance().format(probe.nlr_price.abs())
Is there more elgant way to rewrite it?
|
I have attempted to make the classic game Connect Four in C++, and I would love some feedback on this project. I have done everything myself without using the help of a tutorial or guide, so sorry if there are some bad practices here.
Main.cpp
// Connect4V2.cpp : Defines the entry point for the console application.
//
... |
The challenge:
Suppose you are inhabitant of a planet where 1, 7, and 9 are lucky digits. A lucky number for you is a number that contains only your lucky digits in it. For ex: 1, 79, 911, 9917 etc., are lucky, where as 5, 172, 93, 170 are not. Given a integer N, count the number of lucky numbers in the range 1 to N.
... |
I am building a JS router and would like to have some help doing it. It will work like so:
A list of routes is given with a URL pattern attached in each one.
[
{ url : "/home"},
{ url : "/user/:id"}
]
I want a function that will find the appropriate pattern when we pass it a route URL and will return the object ... |
This is an update for this post.
I fixed all style-issues from the comments, but still have a few questions left:
Someone commented that my last post contained too many functions, which could be easily implemented by the user of the library himself. Is this a basic enough set of functions? Is anything missing? (I hid ... |
I have been playing around with OpenGL and created a fairly basic 2D animation was just hoping someone could take a look and give me some pointers.
Main.cpp:
#include "glut.h"
#include <math.h>
#include <stdio.h>
int bc = 0.4; //building color
int frame=0;
class points{
public:
float x, y;
};
points startLine[2... |
I'm replicating a scenario on a sample set for better understanding.
Database Table: Products
Report required from that table,
the query is working fine, and I'm able to get the required result. But, I believe it can be optimized. So, looking for help to improve it. Any help in simplifying this one would be great!
N... |
Allow me to provide some context. I have a UITableViewCell that contains an EditText and a Button. This cell is then inserted into the self.tableView.tableHeaderView property of the table to achieve the following result:
Below is my implementation for the view controller:
class ViewController: UITableViewController {
... |
This is the code I am using for a distributed system. The code will be used to allow the server to send parts of a (really big) document which will be processed by the connected clients. Please tell me what things would make it more efficient and if there are any security issues that I can correct without addition of a... |
I am currently studying c programming, but I'm at a very basic level. So for practice I made a program that reads a string and inverts it. I want to know if the code is readable and how I can improve it.
/*
* Goal: Given a string, invert it, then print the result.
* Author: Lúcio Cardoso
*/
#include <stdio.h>
#includ... |
I'm a C++ programmer and thought I'd revisit the roots, so I scribbled something really quickly. I would appreciate input on how my C code is looking!
slist.h
#ifndef SLIST_H
#define SLIST_H
#include <stddef.h>
#include <stdbool.h>
struct slist_s
{
int key;
struct slist_s* next;
};
typedef struct slist_s sl... |
Here is command line for playing two videos side by side in sync in FFmpeg (ffplay). It can be useful for comaring videos, for example.
ffplay -v warning -f rawvideo -s 800x400 -i /dev/zero -vf 'movie=video1.mkv,scale=400x400 [mv2] ; movie=video2.mkv,scale=400x400 [mv1]; [in][mv1] overlay=0:0 [tmp]; [tmp][mv2] overlay=... |
This code reads text from the web using a WebDriver element and writes data to a JSON file. I had to use if-else (to write only the last line to the JSON file) just because of the asynchronous behaviour of NodeJs, otherwise I was trying to add fs.appendFile(filepath,"}") in the end to close the JSON file.
I just want y... |
I have the following two methods that write to file various data line by line. Both methods differ from each other only by few lines what would be the best way to refactor them that when in future I want to add another method (for example, CreateXYZLegacyInFile) it would be least time consuming.
public string CreateCVT... |
I have two functions right now:
TUNNEL_COMMAND = "ssh -L 27017:localhost:27017 username@ip -f -N"
def kill_tunnel():
p = subprocess.Popen(["ps", "aux"], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if TUNNEL_COMMAND in line:
pid = int(line.split()[1])... |
I am having problems with my code because I am using a system called styleci. Can you please check it? How can I make it better and more secure?
<?php
/*
* Tecflare Corporation
* Copyright Tecflare Corporation
* Provided by the Tecflare Corporation System
* * Code has been scanned by styleci.io
*/
$host = $_POST['... |
I have a device I connect to on TCP socket. I send it a message with what I want and it sends back all sorts of useful information:
Header:
+---------------+----------+----------+
| MagicWord | 2 bytes | 0xCAFE |
| Version | 1 byte | 0x02 |
| Type | 1 byte | Variable |
| UTC offset | 1... |
This was a learning experience. I have looked around and found some better ways to write some things but wanted a second opinion to look at what I've written and kind of analyze it as well.
I just finished my first "Text based game" sort of deal. I believe that it's poorly written and is pretty long for the short amoun... |
I've been working on numerals conversion lately. Now the JavaScript course I'm following asked me to do something similar for Roman numerals.
To keep things fresh and given the amount of test-cases provided I decided to write this one Test-Driven Development style. That is, for as much as I understand it.
First I check... |
I have a function here and wondered how well this can be refactored.
I currently have this:
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${s... |
I am looking to build a list of words (three letters or more) that make up a large list of six-letter words. I was wondering if there was a cleaner or more efficient way to loop through the characters to build these subsets.
The top of this program (not posted) takes two .txt files - one containing the list of 6-letter... |
I have a Multivalued map (javax.ws.rs.core.MultivaluedMap<String, String>) which I want to convert to regular HashMap so I got below code:
private Map<String, String> convertMultiToRegularMap(MultivaluedMap<String, String> m) {
Map<String, String> map = new HashMap<String, String>();
if (m == null) {
re... |
In Python 3.4, a Counter object called cnt like this:
Counter({'0200': 3, '3000': 2, '3011': 2, '0210': 1, '4000': 1})
is to be written to a comma-separated file.
I first tried with CSV and DictWriter that I had not used before, but I kept getting misty errors and was pressed for time, so I decided to make this ... |
I wrote an abstract Configuration class, then an ConnectionConfiguration class and then an DatabaseConnection class.
ConnectionConfiguration extends Configuration
DatabaseConnection extends ConnectionConfiguration
My reason for doing this was to learn more about object-oriented design and better PHP programming the r... |
I've started building extension methods for my EF classes like below because it makes building queries so easy, and the intellisense provided helps keep people from writing a new Where() clause in code every time they do to do something.
Example Extensions to an EF User Class
public static class UserIQX
{
public ... |
I'm writing code to create a list of new areas for patches of conserved land within a watershed based on the current size distribution of conserved land patches that are in the watershed now.
I'm generating a new random area based on a normal probability density function fitted to the log-transformed distribution of t... |
Within our application I need to work a lot with simple IDs (just integers).
They are used to make queries against a database. For performance reasons I don't want to materialize them to Entities before the query.
Example:
// not really *that* static typed
public void DoQuery(int userId, int groupId)
{
}
Because I wa... |
I have a table that look like this
ID NIP SHIFT DATE
289305 01000267 M 2015-12-01 00:00:00.000
289306 01000267 P 2015-12-01 00:00:00.000
289307 01000267 S 2015-12-01 00:00:00.000
289127 01020358 M 2015-12-01 00:00:00.000
289128 01020358 P 2015-12-01 00:00:00.000
289129 01020358... |
I'm trying to learn linked lists so I can answer interview questions. Even though I've seen plenty of tutorials to understand how they supposedly work, I don't know if I am doing a good job because I have no one to get feedback from.
class Node(object):
def __init__(self, data, next_node = None):
self.data... |
Here's a program I made for estimating a double integral over a general region. It's pretty accurate, but it's VERY, VERY slow. (Getting an accurate enough result takes about 30 seconds)
Here's the code; the lines are indented just for readability.
ClrHome
Input "Surface: ",Str0
Str0→Y₈
Input "y-Bound 1: ",Str0
Str0→Y₉... |
I'm working on a programming challenge and the question is as follows:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-segment_display).
Max starts to type all the values from a to b... |
I receive a string with a lot of characters that I don't need and I am trying to remove them and replace them with characters that I am able to work with. My current structure has me redefining the var multiple times which I feel is not efficient and can probably be done better. Please let me know of a more effective w... |
Can you review the code?
#include <stdio.h>
#include <pthread.h>
#include <windows.h>
#include "bin/include/pthread.h"
#include "bin/include/sched.h"
#include "bin/include/semaphore.h"
#define TCOUNT 10
#define WATCH_COUNT 12
int count = 0;
pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cou... |
The code converts hexadecimal into octal. The function is working, but it takes more than a second to process the input. How can I optimize this?
import java.util.Scanner;
public class BasicTranformSixteenToEight {
public static void toBinaryTransform(int n, char[][] arry,
String[] arryBinaryStr) {
... |
I would like to refactor this code printing odd and even numbers with two threads considering agile practice:
public class EvenOddNumberPrinter {
private static class NumberPrinter {
// To check if even number is printed or not.
private boolean isEvenPrinted = true;
public void printOdd(i... |
Consider the following function:
def test_func(all_copies, checker):
bad_copies = set(c[0] for c in itertools.permutations(all_copies, 2) if not checker(*c))
all_copies = [c for c in all_copies if c not in bad_copies]
return all_copies
This function returns a list of elements that are not overshadowed by a... |
I'm working on several projects involving Telegram bots and I've decided to make a library that meets my needs. Basically, there is already a Python library for Telegram bots (import telegram in my code), but I wanted to wrap it to make it even more convenient to me.
In terms of functionality it works fine. But I'm a s... |
I recently made a post on Code Review entitled Writing lists to .csv file. I found the feedback extremely helpful, and wished to provide a continuation of that particular topic; of working with Python and .csv files.
I therefore set the somewhat more complex challenge of creating and populating a table within a .csv fi... |
I am making a permutation generator in c. Any ideas how I can make it faster?
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
char s[] = "abcdefghijklmnopqrstuvwxyz";
int n = 8, c[n], i, l = strlen(s);
char w[n];
for(i = 0; i < n; i++){
c[i] = 0;
w[i] = '\0';
... |
I have a service which takes a lot of key value parameters in a URL. Only a few are mandatory and others are optional. It's up to the customer whether they want to set those optional parameters or not.
The mandatory parameters are userid or flowid. They can be set together or independent of each other so below are the ... |
This question is connected to the previous one: Request handler based solely on reflections
I have edited the code, taking tim's answer in regard, editing the Kernel class cohesion.
<?php
namespace Qobox;
class Kernel
{
private $request;
private $module;
/**
* Kernel constructor.
*/
public ... |
I've written a simple interpreter with ANTLR for evaluating Roman numerals. Here's the contents of the grammar file (Roman.g4):
grammar Roman;
root : (oneThousand)* hundreds? tens? units?;
// --- I, II, III, IV, IX or V VI, VII, VIII
units : one ((one)* | five | ten) | five (one)*;
// --- X, XX, XXX, XL, XC or L,... |
I recently found an interesting series that describes the specifics of how interpreters and compilers work, explaining each step (with code) and encouraging the reader to do exercises.
My code is mostly based on the boilerplate provided in the first tutorial. The description didn't really seem clear enough to me, so I ... |
The task is pretty simple: implement a timer that executes tasks when the next event takes place. I created a task scheduler based on a priority queue.
A new thread is created for TaskTimerRunnable and sleeps during run() until the next task.
When a new task is added, it checks if the time for the new task is sooner t... |
This code add functionality to a GUI designed using PyQt. It cannot run alone, but I can provide the code. I am not asking for someone to provide criticism for every single function written here, but one or two tips would make me a happy camper. I would like to know if there is something I am making more complicated th... |
I have Tornado chat with export to Redis. Other scripts will export messages from Redis to MongoDB in the time. It works, but how is it written?
def tornadoredis_client():
client = tornadoredis.Client(*configuration.REDIS_CONFIG)
client.connect()
return client
class PlansqTornadoChat(SockJSConnection):
... |
What I'm wanting to do is create a String readFile(Path filePath, Charset encoding) method, that returns the entire contents of a given file.
I'm wanting the equivalent of Guava's Files.toString(file, encoding), but without calling the Path.getFile() method (as this method only works with the default filesystem provide... |
Now I am pretty crappy at software architecture. I think I was able to make this relatively concise. Please, any input is helpful!
var cheerio = require("cheerio"),
request = require("request"),
sqlite3 = require("sqlite3").verbose(),
colors = require("colors"),
fs = req... |
In an effort to make my code more testable, I'm trying to make use of constructors and prototypes.
Here is a working Google Apps Script (GAS) for creating a new submenu under the Addon main menu in a Google Spreadsheet. If a user clicks the 'Show' menu item, a sidebar will appear.
var UI = function (menuName, menuFunct... |
I started writing Rust by doing a simple program that will print all prime numbers until it reaches the upper bound that is provided through standard input. Here is my code
use std::io;
fn main() {
println!("Enter a number: ");
let mut limit = String::new();
io::stdin().read_line(&mut limit).expect("failed... |
I'm looking for a better way to make a background operation with abort/cancel support. Right now I use this approach:
Task.Factory.StartNew(() => {
var cts = new System.Threading.CancellationTokenSource();
var ct = cts.Token;
try
{
var t = System.Threading.Thread.CurrentThread;
usin... |
Handy wrapper for aggregates to use with emplace*() container's member functions:
#include <type_traits>
#include <utility>
template< typename type >
struct aggregate_wrapper
: type
{
aggregate_wrapper() = default;
template< typename ...arguments,
bool is_noexcept = noexcept(::new (std::dec... |
I have the following C code that finds numbers between 1 and 10000 whose sum of digits are prime and save then to a file.
#include<stdio.h>
#include<conio.h>
int sum_of_digits(int);
int check_prime(int);
void save_to_file(int);
int main()
{
int i, num, isPrime;
for(i=2; i<=10000; i++)
{
num = sum_o... |
I am currently in the process of learning C++ from C++ Primer. I have found the exercises in this book to be somewhat dull in that they only test syntax and not reasoning. As such, I have recently written a somewhat advanced C++ calculator. It is advanced in that it can interpret more complex ideas than a simple operat... |
I have implemented a class which implements a list of my custom DateObj. I have sorted the list in a peculiar manner based on the current month. I achieved my desired results, but I'm required to call Collections.sort() four times to achieve it. I feel this could be improved. Any thoughts?
//Custom Date Object
public c... |
I created a simple minesweeper game as I am trying to get my hands dirty in JavaScript. I have tried to use the oops while doing this.
I am posting 3 files:
index.html
minesweeper.js
minesweeper.css
Also:
It does not have 2 major features - timer and flagging.
You may find the UI not-so-pleasing.
I have hosted the ... |
A Sudoku puzzle is a 9 × 9 grid with some numbers between 1 and 9 in
it, that has to be filled in so that
every row,
every column, and
each of the nine 3 × 3 blocks
contain all the numbers from 1 to 9.
For example the following matrix is not a valid solution of a Sudoku
puzzle: the fourth column contains two 7'... |
Have you ever being implementing Option<T> functional type? It is discussed here. Basically, it is about using IEnumerable<T> with no or only one element instead of potentially nullable object reference in C#. We can empower LINQ functionality to streamline processing reducing cyclomatic complexity because of no if(nul... |
Based on the previous question, I have implemented all suggestions with slight modifications. The game seems fine, are there any further improvements needed in this game?
#include <iostream>
#include <cassert>
#include <random>
#include <algorithm>
#include <array>
#include <map>
#include <numeric>
#include <conio.h>
... |
I have the following code for the BST for the inorder, postorder, preorder, breadth first and depth first traversals. Can you review and let me know the optimisation points and issues, if any?
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
public class BST {
... |
Building on top of the classes in this question of mine, I've made this class to support the moving of the entities for my given assignment:
Welcome to the Bridge Crossing Problem. Person Pn can cross the bridge
in n minutes. Only one or two persons can cross at a time because it
is dark, and the flashlight must b... |
Given the following working code:
def get(self, key, default=None, type=None):
"""Return the default value if the requested data doesn't exist.
If `type` is provided and is a callable it should convert the value,
return it or raise a :exc:`ValueError` if that is not possible. In
this case the function ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.