instruction
stringlengths
71
71.9k
My word search goes through and searches for the first letter in the word slowly. I am looking for a way to optimize the program to search faster and efficiently. I want to find a way to search faster by using a single loop instead of nested loops in my findWords method. I think it would be better to use the appropriat...
Implementation for a relatively basic programming challenge: Find the first unique character in a string So evaluating the string ABCA would return B. My implementation does the following: Initialize a boolean array that is the size of the input string - note that the default initialization value is false The boole...
I wrote this Caesar cipher and decipher just for the sake of practising OOP (previous answers to my java questions all seem to point to OOPness). What it is: The Caesar cipher is one of the earliest known and simplest ciphers. It is a type of substitution cipher in which each letter in the plaintext is 'shifted' a...
This synchronizes the document’s vertical scrollbar and a DIV’s horizontal scrollbar so they can work in unison controlling the content simultaneously. The code is operable and behaves how I want. I want to know whether or not this code can be optimized any further. Heads-up: the jsScroll0 and jsScroll1 flags stop eith...
I am building a Rails marketplace application using TDD. I would like to get advice on the way in which I have built the User associated Profile associations and way in which these are then handled in the controllers. User model class User < ActiveRecord::Base has_one :profile, dependent: :destroy has_many :listing...
I have created a bit of path-finding code in response to this code golf question. Since this is one of my first large bits of code in Groovy that I have written, I would like to see how I could improve it. def invalid() { println "Invalid map." System.exit(1) } def map = """01001E 010110 000P00 1100J1 ...
I am using a one-byte bitmap to control four relays. I am writing a function which will take the bitmap stored as uint8_t, look to see which bits are set/cleared, then turn on/off the relays appropriately. The input value to my function could be anything from 0 to 15. This is in a controls application, so I'd like this...
This is a basic AI that I created. It has a teach function that creates a .txt file with user inputed info for future use. If you type teachme you have the option to type in something that you have already taught it and it will tell you what you taught it. Any tips to make this better are appreciated. (I'm OK if you...
I am working through a udemy course on Python, this is the first real program I've written. I am new to Python and to programming. I'd like to replace the main function below with something more efficient and less repetitive but I'm not sure what or how. The most I could think to do is write a function for adding hours...
In PHP exists a function array_diff (http://php.net/manual/de/function.array-diff.php) which returns the difference of two arrays. I have tried the implement my own version in JavaScript. Any feedback is welcome. :) function getArrayDiff(a, b) { var ret = [], merged = []; merged = a.concat(b); for (var i...
I use bluebird promises. I want to promisify my requests from communication layer: Utils.js //Question: is there more beautiful way to do that? promisifyXMLHttpRequest(xhr, timeout = 0, timeoutCallback = _.noop, responseHandler = response => JSON.parse(response).data) { const requestPromise = new Promise((resolve, ...
I have this program that solves a \$(n^2 - 1)\$-puzzles for general \$n\$. I have three solvers: BidirectionalBFSPathFinder AStarPathFinder DialAStarPathFinder AStarPathFinder relies on java.util.PriorityQueue and DialAStarPathFinder uses so called Dial's heap which is a very natural choice in this setting: all prio...
Apparently it is possible to implement enumerate so it produces a sequence when given a sequence, and produces an iterable otherwise. Sequence can be safely reversed. This works by replacing the builtin function. Other similar functions could be made this way, too. class EnumeratedSequence: def __init__(self, items...
I have a variable List. Its declaration is like : List<HashMap<String, Object>> Sample data in it: [{total-expense=228, company=HiHard, year=2009}, {total-expense=2936, company=POTENT, year=2009}, {total-expense=1362412.65, company=HiHard, year=2010}, {total-expense=9007.96, company=POTENT, year=2010}, {total-expen...
Whenever I need to use a Promise interface in my NodeJs code and I don't have a promise to start off with, I do this: var someResultPromise = Q.resolve() .then(function () { var something = 'value'; var anotherPromise = callFunctionThatReturnsPromise(something) .then(function (result) {...
I need validation for all DTO objects using System.ComponentModel.DataAnnotations. You can see how I implemented. Idea is to have one abstract class that will be inherited in all dto classes. This abstract class have check if object is valid and get all validation results. Is this good approach? What do you think? dt...
This was a basic anagram problem. Take an input word, find all its permutations, then check a dictionary file to see what if any of those are real words. Dictionary file My input data: 8 lasting lameness severer lapse alerting medical tasking crates My answer: 3 3 3 5 4 4 3 6 The code works slowly, as in, it took ma...
I am trying to merge two pdfs - one from a razor view and one from a file on the server. To create the pdf from the razor view I have used the following nuget package: MVCRazorToPDF. Unfortunately this didn't allow me to merge an existing file with the pdf so I have downloaded the project and changed the PdfActionResu...
I don't know regex. I want to learn regex, but learning regex just for the sake of regex would be quite boring. So I decided to learn Ruby as well (which so far looks a lot like Python, which I'm familiar with). My first program attempts to speak with a combination of both Daffy Duck's lisp and Elmer Fudd's verbal apra...
I needed a clean, simple and robust piece of code to retrieve the date of publication of the latest release of a given GitHub Project. My constraints were that it needed to be written in the C++11 subset supported by Visual Studio 2012, and that it would require as few dependencies as possible. Here is what I came up w...
Here I am parsing a JSON array and inserting it into a MySQL database. The JSON Array comes from my android code. This is how my JSON array looks like: ["{custInfo=Ujwal 9975022560, rate=24000, weight=21.00000, desc=GENTS ANGTHI 22k NO STONE, makingAmt=200, vat=RS.3064.38, itemTotal=51073, sum_total=RS.156283.38, barc...
I am using PHP to create a file structure in which to store XLSX files, for this I have created this class: <?php class XLSX { /** @var resource */ private $handle; /** @var array */ private $data; /** @var array */ private $headings; /** @var bool */ private $finished = true; /** @v...
I'm writing my own FTPclient for downloading files from my FTPserver as a project. So far I can download and go backwards/forwards in the folders using this code. How does it look? What could be done better? etc. Should I remove the interface and just create one class ftpItem instead of an interface and a file and fold...
I have a swift method that I'm using to update Parse in the backend when the button is tapped. Votes are being updated: The method acts as a voting system, incrementing a label every time it's tapped. This action is happening in a Custom Cell: @IBOutlet weak var votesLabel: UILabel! var parseObject:PFObject? ...
I'm working on a port of NLTK to Rust. I am fairly new to Rust, so I wanted to post a small file to check if I was writing idiomatic Rust. I've included the original Python. The Python has docstrings that describes usage, so I didn't include comments for brevity in the Rust. This file passes all of the tests we've writ...
Normally the game speed with pygame is locked with the fps, so I attempted making a simple two classes that'd be super easy to use, to allow for the same game speed no matter what the fps is. For each frame, it calculates the difference between the amount of ticks that have passed, and how many should have passed (I ge...
Python has that range: >>> range(10, -20, -3) [10, 7, 4, 1, -2, -5, -8, -11, -14, -17] I have this C++ implementation of exactly the same facility: range.h: /* * File: range.h * Author: Rodion "rodde" Efremov * Version: (Nov 30, 2015) */ #ifndef RANGE_H #define RANGE_H #include <stdexcept> namespace codero...
How would you improve this code? Particularly the check and check_all functions? The time complexity of the algorithm of mlcs is \$O(|\Sigma|MN)\$, where \$\Sigma\$ is the alphabet, M is the number of strings and N is the length of the strings. Is that right? My analysis: candidates() performs \$O(|\Sigma|M)\$ operatio...
I've written a userscript that pops up a dialog before you take a moderation action (closing, deleting) with some pro-forma comments, so that you can add one of those before you cast your vote. I'm pretty happy with how I wrote it, but what's clear to me is unlikely to be so to others. Is there anything in this that I ...
I recently posted a program I made to unlock spreadsheet files( see also ), I've taken all of your advice and made it more Ruby like, it has no shell commands in it, and uses FileUtils I personally think it looks a whole lot cleaner and a whole lot more Ruby like. I would like a critique on my work so far, and would li...
This is my implementation of the (open) Knight's Tour on a 5v5 board. My original assignment for CS was to solve the Knight's Tour from any startings position (0,0 -> 4,4). The goal for myself was to make this class as clean as it could be. I would like some feedback (and constructive criticism!) on the code and its pe...
In a prototype 4X space game that I am working on recently, I have two different scroll panes to show the ships and the stars of the player. The ships are displayed in a vertical scroll pane on the right side of the screen, and the stars are displayed in a horizontal scroll pane running along the bottom. Here is a pic...
The code below takes a video as input (a drop onto a fabric surface) and I want it to return the area of the drop. Currently the code works, but I'm no Matlab expert, and wrote it entirely through google/hack&slashing my way into a successful form. Unfortunately it's slow, and it's probably not written with good style...
The code works as it is written, however; I was wondering if there are any easier or more effective ways to merge two lists. import java.util.*; public class MergeTwoSortedLists { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); // Enter values for...
I call this animateElements function as part of an animation loop (inspired via Dave Gamache). Everything works as expected, but I would love to try and improve/optimize if possible. var animation, translate, translateY, translateX, scale, rotate, opacity, display; animateElements = function() { //var anima...
I'm working on an HTML text-based game (think like OGame and other browser games of the genre). I've tried worked on a grid controller to display a map of points that you can move around when you have an entity to move yourself from point to point. The basic concept that I used is to grab a sub-grid of the total map po...
I would like a quick review on my method to delete a node from a singly linked list. I'm fairly certain that this is not near optimally done, and would love to get feedback. It uses a SinglyLinkedNode element as the node: public class SinglyLinkedNode { private SinglyLinkedNode next = null; int data; public...
The function tests whether or not the provided string is a palindrome, and the main function just times how quick it is (after all, C's supposed to be quick, right?). header.h bool palindrome(char *text); main.c #include <stdio.h> #include <time.h> #include <stdbool.h> #include <string.h> #include "header.h" int main...
I've been following a Python programming book and reached the Regex chapter where I encountered this challenge: Write a password strength checker that checks if a password is: At least 8 character long Contains at least one uppercase and lowercase letter. And contains at least one digit. I managed to do so, but fra...
Type Driven Development with Idris demonstrates how Idris can be used to build a Finite State Machine for a vending machine. Please critique my implementation. I'm new to dependent types, so I'm not sure if dependent types would enhance this implementation. In other words, if path-dependent types would significantly im...
This code consistently executes commands with a given priority. How can I to improve it? public class PriorizatableCommandQueue<T> : IDisposable { private readonly object _lock; private readonly Action<T> _action; private ConcurrentQueue<T> _forLowestPriority; private ConcurrentQueue<T> _forBelowNormal...
I want to declare string Arrayinside a class and then access it by a method. What I want is to run random inside method and catch the value, but I don't know if I'm doing it right. namespace Animals { class Animals { static private string animal1 { set; get; } static private string animal2 {...
I face a problem I think I am not approaching appropiately. I have two independent enumerators that both will contain the same members, the only difference being the values given. I have to be able to parse from one enum type to the other on the fly and I've seen the following code works as intended: (enumType)Enum.Par...
I'm sure I can optimise this code, but I can't find how in order to be generic. I'm not sure that .parent and .child combination is good in the long term here. $(document).ready(function() { var lengthInit = $("#lengthSession").text(); $("#timer").text(lengthInit); $("#dimBreak").click(function() { dimLengt...
I'm implementing a Producer/Consumer but the generic interface doesn't require any knowledge of blocking collections or tasks. public interface IReader { IEnumerable<Data> Read(); } Is it okay if my implementation of the IReader launches a task asynchronously and returns the consuming enumerable? public IEnumera...
Idea: In C++, often a straightforward implementation of comparison operators is needed. In C++11, they can be conveniently implemented using std::tie. The following mixin class automatically enables comparison operators by deriving a class T from Comparable<T>. Implementation: (please review this part, requires C++14) ...
I made a solution to this problem from HackerRank : You are given a list of N people who are attending ACM-ICPC World Finals. Each of them are either well versed in a topic or they are not. Find out the maximum number of topics a 2-person team can know. And also find out how many teams can know that maximum numb...
I'm seeking style pointers, bugs, memory leaks, incorrect usage etc. #include <pebble.h> static Window *s_main_window; static AppTimer *app_timer; time_t now; struct tm disp_time; // Time to display. // Slot on-screen layout: // 0 1 // 2 3 #define TOTAL_IMAGE_SLOTS 4 #define NUMBER_OF_IMAGES 10 // These imag...
I've written a python program that is responsible for making sure that all elements in one data set (let's call it the source) exists in another (let's call it the target). Constraints beyond my control: Retrieving unique element identifiers from the source is extremely costly (~7-8 minutes), whereas counting the numb...
while practicing Promises, I ended up with a simple weather application which works on the command line. I would highly appreciate it if you can point out any flaws in my code. They can be related to the efficiency, etc. I'm looking for anything you can provide in the review. package.json: { "name": "weather-app", ...
So I was checking out the courses on InteractivePython, and I came across this example to demonstrate inheritance. My focus is on the Connector class and how it interacts with BinaryGate and UnaryGate via the setNextPin method. class LogicGate: def __init__(self,n): self.name = n self.output = None...
Yesterday I read a fascinating article on Wikipedia about sorting networks. Comparator networks are abstract devices built up of a fixed number of "wires" carrying values, and comparator modules that connect pairs of wires, swapping the values on the wires if they are not in a desired order. Sorting networks differ fr...
The idea is to create a function that gets a number passed in and ouputs a multiplication grid. For example the desired output for grid(10) would be : 1,2,3,4,5,6,7,8,9,10 2,4,6,8,10,12,14,16,18,20 3,6,9,12,15,18,21,24,27,30 4,8,12,16,20,24,28,32,36,40 5,10,15,20,25,30,35,40,45,50 6,12,18,24,30,36,42,48,54,60 7,14,21,...
You are given an array of N integers, find the Max Difference where the index of largest number is greater than the index of the smallest number. If not find the next smallest number, so on and so forth. If this condition cannot be met, return -1 Sample Input Sample Output values = [1, 2...
I have console application that sends and process XML data. I have created a fault mechanism that the connection drops. I go in a "fault" mode. And try to reconnect to my server. I'm sending keepalives and so is the server. When I'm not receiving any keepalives and any others messages in a timespan of 2 minutes the pro...
Introduction After getting stuck with a Pythonish integer range in C++, I rewrote the facility in Java. In Python you can say: >>> range(38, 0, -3) [38, 35, 32, 29, 26, 23, 20, 17, 14, 11, 8, 5, 2] In Java you can say: for (int i : range(10)) { ... } or, if need be: List<Integer> list = new ArrayList<>(range...
I just released a book with a deadline. My first job with LaTeX, very messy. I wondered if there is anybody out there, who would be so kind and take a look at the code and see, what optimizations can be done. I am releasing the same book in Danish/Latin (as you see, the code is in English/Latin) and I would like to hav...
This is part of a two-part post (Part 2). Here, I have two recent projects that parse a file. The first uses a loop that's kind of hard to follow, and the second uses "modes" to decide what to do. Project 1: A "bookmark manager" for managing URLs easier than a text editor. The data structures: typedef struct { cha...
This is part of a two-part post (Part 1). Here, I have two recent projects that parse a file. The first uses a loop that's kind of hard to follow, and the second uses "modes" to decide what to do. Project 2: A working map renderer that I plan to implement the game of Picross with. This one uses "modes" to control the ...
I have an MCU (TI Tiva TM4C) that operates a GSM modem, LCD display, keypad, ADC inputs, and four relays for microgrid control/operation. To date I have about 2000 lines of code, mostly for supporting peripherals. Now the hard work of creating an algorithm begins. Before I do that, I am hoping a few embedded C experts...
For this project I'm targeting .NET 4.6 with Prism 6 as a toolkit to implement correct MVVM patterns. The code below allows me to raise a dialog box with Yes, No, Cancel buttons. If the user clicks 'Yes' the content is saved then the tab item closed. If 'No' the tab item is only closed, and if 'Cancelled' then return, ...
I would like to know how I can improve this CakePHP 3.0 Component (inside folder controller) 1st: to use external libs (stored on vendor folder) I'm using the require keyword and include the class using use keyword, like this: require_once(ROOT . DS . 'vendor' . DS . 'CakePHP-ImageTool-Component' . DS . 'ImageTool.php...
As part of a school project for ICT lessons, our class has been required to write a quiz program following certain criteria that has been set. The first part of this is a program that handles the registration process by asking the user for details such as player name, age, email and gender. import getpass import os imp...
One of the URL in my application is vulnerable to XSS attack, so I am handling it in the below way. I created a util class: import java.util.regex.Pattern; public class HtmlUtils { public final static String tagStart = "\\<\\w+((\\s+\\w+(\\s*\\=\\s*(?:\".*?\"|'.*?'|[^'\"\\>\\s]+))?)+\\s*|\\s*)\\>"; public fin...
I have some questions on how I can improve this "action" (method) in "controller": My template has a navbar with dynamic content (if the user is logged in a special button appears, his name appears in the navbar among other custumizações) also the integration of modes is dynamic based on whether the user is logged in ...
This is my implementation of the bell() function to calculate the n-th bell number in C. Along with it I made the factorial() and binomial() functions. I have serious doubts about their efficiency, in particular whether my implementation of the factorial() function should be correctly optimized for tail-recursion, and ...
I wrote this for use internally at work and have never worked with encrypted data before, so can you please critique? It's written in VB.NET which I have decent experience in, just not the encryption portion of it. I have written a simple internal messaging client. Basically a home grown email program but it uses file ...
Given a two-dimensional list, say some_list = ["ABCD", "EFGH", "IJ"], I am supposed to encrypt it by reading each column top to bottom, thus: A B C D E F G H I J Would become: AEI BFJ CG DH My initial try had “index out of range” problem so I did this: def encrypt_list(some_list): encrpted_list = [] fo...
I recently created a license manager for my publicly released project and I just wondered how I could improve it. using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace Kiwi.Application.Base.License { sealed class LicenseManag...
I'm getting address (physical address, not digital) input that's obfuscated, and looks like the following: The plaintext version: '39 Jerrabomberra Ave. Narrabundah Canberra 2604 Australia' The obfuscated version: ['39 Jerrabomberra Ave., Narrabundah', 'Canberra', ' ', '2604', ', ', 'Australia', '39 Jerrabomberra Ave...
Given the following CreditCard object, how would you get a count of unexpired credit cards? What are the pros/cons of using each method? Or is there a better/optimal way? public class CreditCard { public int Year { get; set; } public int Month { get; set; } public int Day { get; set; } } public class User {...
During Jonathan Blow's video where he muses about a games-focused programming language, he presents C++ code that allocates a single big block of memory and has N pointers into that block. The purpose being to avoid heap allocating N blocks of memory for N arrays. That code looked to me like it could use some genericit...
Simple tool to save a web page's source. A result of trying to learn and apply an MVC approach. The FXML is generated via Scene Builder, but included for completion. I welcome any general feedback on how to improve anything but in particular: There are many exceptions, current impression is that current handling is no...
I have implemented a Trie-based concurrent key/value store using hashcode similar to HashMap. It is something like, if your hashcode is 50 (110010) then create a TRIE with array size of 4 (two binary bits), the first value is 10 which is 2,10- [][][X][] --> 00- [X][][][] --> 11- [][][][X] will be represented. HERE Th...
I need a class representing a parsed Range HTTP header value. I've done it like this: namespace net { namespace http { class DataRange { public: static const uint64_t UnspecifiedBytePos; static const DataRange Full; explicit DataRange(uint64_t firstBytePos, uint64_t lastBytePos); ...
I want to make a list of the last words on each line of a file that looks like this: casper@casper-PC ~/scripts -> cat /tmp/foo update PTMM_ARCHIVE.FASTTRACK_USER set user_name = 'monohajoxx' where user_name = 'monohajo' update PTMM_ARCHIVE.FASTTRACK_USER set user_name = 'wuemxx' where user_name = 'wuem' update PTMM_A...
It took some time to make Conway's Game of Life in HTML, CSS, JavaScript and jQuery. I'd like suggestions, criticisms, and discussions on how it can be done better. JSFiddle link /* * Conway's - Game of Life. * Any live cell with fewer than two live neighbours dies, as if caused by under-population. * Any live cell ...
I was talking to a coworker about over engineering things, which somehow lead to me over engineering the hell out of fizzbuzz. I went for a functional recursive solution in JavaScript. What do you think? Full disclosure: my knowledge of functional programming begins and ends at "functions are king" and "no side effects...
This is basically a non-recursive std::tuple_element implementation. Note To make this non-recursive, you must replace std::make_index_sequence with a non-recursive implementation. I left it with std::make_index_sequence in order to reduce the amount of unrelated code. How it works deduct has a specialization of deduct...
I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the function). I originally had it like this (not this in the where clause of an outer query): skew.CalibrationDate.Date == ...
(See the previous iteration.) I have refactored the Range; now it looks like this: Range.java: package net.coderodde.util; import java.util.AbstractCollection; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; /** * Thi...
I had this idea today, but I don't have any practical usage for it right now. Any feedback or improvements welcome. Code is found at CodePen, and also presented here as a snippet: ul { list-style-type: none; width: 250px; border: 2px solid #a9a9a9; border-radius: 16px; margin: 0 auto; } .item { margin: 1...
Can someone tell me how to improve my following python code. Code: a = open('/home/Username/1st few programms/names.txt') for y in a: c = y.split(",") c.sort() dict = {'"':0, "A": 1, "B": 2,"C": 3,"D": 4, "E": 5,"F": 6,"G": 7,"H": 8,"I": 9,"J": 10,"K": 11,"L": 12,"M": 13,"N": 14,"O": 15,"P": 16,"Q": 17,"R": ...
This is a progression of the script I posted here: Zip the contents of subfolders, conditionally It does this: Determines all subfolders recursively Checks each subfolder for files older than 31 days which aren't .zip If such files found, creates a new folder within, labelled with the date Moves the files to the new f...
(See the next iteration.) The result looks like and my code is: \documentclass[10pt]{article} \usepackage{amsmath} \usepackage[ruled,vlined,linesnumbered]{algorithm2e} \begin{document} \begin{algorithm} \SetKw{Nil}{nil} \SetKw{Is}{is} \SetKw{Not}{not} \SetKw{Mapped}{mapped} \SetKw{In}{in} ...
Problem: You are given a randoms string containing only lowercase letters and you need to find if the string contains ALL the vowels. Input: First line contains N , the size of the string. Second line contains the letters (only lowercase). Output: Print "YES" (without the quotes) if all vowels are found in t...
I've been playing around in C for a few weeks and decided to write a program that somewhat simulates an ATM machine. I'll give you the code at the end of the post in case you're not interested in dealing with the question at all. Some facts: There are 2 languages in the program, the 2nd is Slovak. The code for it is th...
I have some questions on how I can improve this "add action" (method) in "controller": I'm using the add action only if post request. Is it correct? This action doesn't have views ($this->autoRender = false;). Is it correct? I set a response .json file to this action but I didn't change on routes to routing .json file...
We have an exercise to design a simple library, which can calculate some length with different unit, e.g. 2m*2 + 20cm/2 - 5mm and the result can be any of: 4.095m 409.5cm 4095mm I want to design it in Object-oriented, and have a solution like this: public class Length { private final double value; private fi...
I have some questions on how I can improve this "add" action method in a controller. Using a single form, the user can upload a product to be displayed on the site. A Product is composed of three entities: Product, ProductFeatures and ProductMedias (stored in three database tables). To prepare data for insertion and u...
I was asked a weighted probability question in a technical interview a few months ago that went something like this: Given an input of colors and an integer "weight" value, randomly return a color based on its weight. The sample input would be something like this: [("Red", 20), ("Blue", 50), ("Green", 70)] The proba...
I recently started following the James M Kernel Dev tutorials and was able to create an operating system in C++. Here is the source on GitHub. I have a couple of questions: Is my coding style ok? Is it wrong to write bash scripts for building the project? JOSMake.sh # # Build File for JOS # # To Build # bash build...
I wrote this to scrape album review data from AOTY into a spreadsheet. Check it out and let me know what I could've done better. Option Explicit Const classAlbum As String = "listLargeTitle" Const classScore As String = "listScoreContainer" Const classRating As String = "listScoreValueContainer" Const classReview As S...
I have created a Backbone Movie app as part of a learning exercise, the app is hosted on codepen although I actually have it built on my local but thought this approach would be handier for code review. I have some dummy JSON containing some movies that are stored in a Movie Collection and then another collection to st...
I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with NULL terminators and the like. Not only that, but it should be efficient. #include <stdio.h> #include <stdlib.h> #include <strin...
My method searches through an list of accounts which have the property "Name". class Accounts { static internal List<Account> accounts = new List<Account>(); static internal bool findAccount(string name, ref int account) { for (int i = 0; i < accounts.Count; i++) { if (accounts[...
The calculator evaluates a mathematical expression with binary operators +, -, *, / and ^ in C. I store numbers and operators into two different arrays and process them according to precedence. Please review my code and suggest me on changes on approaches to make it scalable to add unary operators and parenthesis. #i...
I've just solved this challenge, though I feel that there is a problem with stack growth or something because the 5th testcase has a runtime error import Control.Monad import Data.Sequence hiding (replicateM, replicate, take, drop) import Data.List main :: IO () main = do n <- getLine input <- getLine ...
I'm having problems solving this problem within the time limit. Alternative Thinking http://codeforces.com/contest/603/problem/A Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represent...
I recently started "coding" and this is one of my first "projects". It is supposed to be an SI converter where you can type a value, its unit and the unit to which you want it to be converted. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ...