instruction
stringlengths
71
71.9k
I got my game working for so far, however, I would like the game to run faster. It's running at approximately 26 FPS when most of the blocks come in; my FPS goal would be about 60 FPS. import pygame, random, sys from pygame.locals import * TEXTCOLOR = (0, 0, 0) FPS = 60 BADDIEMINSIZE = 10 BADDIEMAXSIZE = 75 BADDIEMIN...
Previously, I had written this program in C++ and asked about it here on Code Review. After spending some time with C++, I desired to become more familiar with its namesake. This is my first C program. The purpose of the program is to help with remembering complex bash commands. It's invoked with arguments describing t...
I am working on a UserScript that displays total flag counts and other information on the Flag Summary page. Example: Everything is working correctly but this bit of code seems rather repetitive and I'm sure it could be improved upon. The following code pulls the total count of each flag type from the flag summary pa...
I have the following functions and accompanying script. The purpose of these is is to extract XML data from one CSV column (one XML document for each row), and then transform it into a dictionary (where the tags are the keys and the text are the values). Then I update the headers in the original CSV with the keys and t...
I am attempting to build my own website, based off Google's Material Design principles, to better my design/UX skills. I am currently working on effects for my navigation, I wondered what would be best to lower browser resource usage when viewing my web page. Quick Example: When scrolling, without wrapping certain p...
With the recent craziness of the Powerball in the US, I got interested in building a little lotto simulator to see how frequently I could win with purchasing large amounts of tickets. For those not familiar with the game and its odds and ways of winning, a Powerball ticket consists of 5 white balls between 1 and 69 and...
Is there a more efficient way to run this? I am especially interested in a way which perhaps does not require a for loop... shopt -s nullglob file= declare -a ARRAY1 ARRAY1=( ~lettus_*.sh ) for file in ${ARRAY1[@]} do ## ## Get <name> from /some/path/lettus_name.sh ## # remove .sh extension file=$...
I created a quick calculator in Javascript and I was wondering if there was a way to make the code look prettier or make it simpler. To me, it looks really cramped and messy and I'm not sure how change that. function calc() { var height = (document.getElementById('height').value) / 100; var weight = document.ge...
Which option is better? In the first case, I use a universal repository that can work with any entities. The methods of this repository have many parameters, such as string queries, table names, entity mappers, etc. Another option is to use for each entity separate repository (which is probably a good practice). Advan...
We are given two list on integer arrays, and the objective is to retrieve another list which contains the duplicates in both lists. The code developed is the following: public List<int[]> GetDuplicates(List<int[]> pInputList1, List<int[]> pInputList2) { var outputList = new List<int[]>(); pInputList2.ForEach(x...
I have written command line chess in Python 3.4.3 and the code is included here. The chessboard is printed to standard output as a 2-D array; for now I only have CLI and the output in the command line is as below: ['Rb' '0 ' 'Bb' 'Qb' 'Kb' 'Bb' 'Nb' 'Rb'] ['Pb' 'Pb' 'Pb' 'Pb' '0 ' 'Pb' 'Pb' 'Pb'] ['0 ' '0 ' 'Nb' '0 ' ...
Do you have in mind a way to compute the following sum $$R_{i,j,k} = \sum_{l=0}^{2} J_{i,j,l+3k} v_{i,j,l}$$ obviously in a vectorised fashion? This may sound like an equivalent of: c = np.einsum('ij(l + 3k),ijl->ijk', j, v) where of course the notation 'ij(l + 3k),ijl->ijk' is not accepted by einsum. I tried with the...
I have a single page application where the resources sit on the classpath. Any request for a resource that doesn't exist should redirect to the index.html page. Resources should be mapped to memory on first request and then all subsequent requests should load from memory. Have I made any mistakes with how I should be u...
This uses a linked list to store the data. I used a linked list as it's the only type of data structure that I know currently. Using chrono, I can get microseconds into my timer and <random> for a completely random scramble. A main goal of this program is to be fast in the sense of less keystrokes to get scramble and s...
Here is my scenario: Every user checks in every five minutes. If some user doesn't check in after 5 minutes, I should be able to keep track of it. If some user doesn't check in N number of times, an alert should be generated , like send email or SMS. Here is what I have implemented so far: var Report = function(atte...
For test cases I need a unique way to set any structure to zero. For openCV I wrote this: // Fill every basic structure of openCV with zero. template < typename Tp > void zero( cv::Point_<Tp>& p ) { p.x = p.y = 0; } template < typename Tp > void zero( cv::Point3_<Tp>& p ) { p.x = p.y = p.z = 0; } ...
Scenario: Count the total number of times a char occurs in a word. For instance, "aaabbcccdddaaaa" should print out "a7b2c3d3". Can you please critique my code? import java.util.HashMap; import java.util.Map; public class Demo { public static void main(final String[] args) { final Demo d = new Demo(); ...
I have a number of XML files containing data I would like to analyse. Each XML contains data in a format similar to this: <?xml version='1.0' encoding='UTF-8'?> <build> <actions> ... </actions> <queueId>1276</queueId> <timestamp>1447062398490</timestamp> <startTime>1447062398538</startTime> <result>ABOR...
I am trying to get this code running as fast as possible when traversing through my stack of my DFS currently the input files are like so: 0 2 2 1 1 4 4 5 5 6 10 8 8 9 9 6 7 6 3 4 0 1 3 9 0 4 Where my Maze class will tie the numbers together and create a graph for me. After the graph is created my DFS class runs thr...
I'm writing code to find the available ports on 127.0.0.1. I'd like it to be faster, but it's functional now. def find_open_ports(): for port in xrange(1,8081): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) res = sock.connect_ex(('localhost', port)) if res == 0: yield ...
In the beginning of my methods that handle the calls from outside, I run this method to make sure that everything's OK, or let the caller know what's wrong: private static void Validate(Guid userId, EntityState state, object data) { if (userId == Guid.Empty) throw new Exception("Token unrecognized!"); if (state...
This is a script that accesses the SE impromptu APIs to receive the fkey, a variable need for connection to chatrooms, and uses it to build a websockets connection which is handled by Node.js. This is also available on GitHub. It requires your username and password in the ws.js file and looks like this once executed: ...
private void moveViewToScreenCenter(final ImageView img, int x) { DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); img.animate() .translationX(0) .withEndAction(new Runnable() { @Override public vo...
This program is meant to ease making mods for a game. A mod is made with XML. I used the lxml library to handle making the XML. I used PyQt for the GUI and this code is the functionality of the GUI. Most functions do just what their name says: open file opens a file, save saves, addFunction makes sure that button that ...
I have implemented the "Find the N longest lines in a file" problem from CodeEval quoted below. I got a full 100 score and 182ms execution time of their data set on the site so I consider the code to be working and effective. What I'm wondering is, is there something I can do to make this faster than it already is? Di...
I need to read databases which contain 44-50 tables, with around 5 million entries in total (~ 100k entries per table). The data consists of positional tracking data in sports (players, refs and the ball) and match-events (shots, plays, tackles, ...): Match-events are negligible regarding performance. Table: PlayerXYZ...
I'm trying to refamiliarize myself with Java and working with it, so I've implemented my own version of a BitArray. Basically, it's an array of integers that maps 32 boolean values to each integer. This means an array of 32 boolean values only takes 4 bytes of space. I was attempting to implement a Sieve of Eratosthene...
I feel that I have done as much as my knowledge base allows me to on developing this tic tac toe program. I would love for anyone to critique it and tell me of any good/bad points. Includes two players, optional AI, optional first turn and a scoring system. The two things that I am unsure about are the 'GameLogic' cla...
Question: Is there a way to more efficiently or more readably write a loop that creates multiple types of controls? Background I've been trying to learn C# by converting some of my older VB.Net programs over. This is a method I use after the main form loads to populate a TableLayoutPanel with controls. Eventually looki...
I have a "manager" class that returns objects when requested. The if the required object already exists in the object collection it is returned, else a new one is created, added to the collection, and returned. I also need to periodically remove the objects from the collection when they're no longer required. This is d...
I have made the decision to move the storing of session data from the filesystem to the database. Our application is growing at pace and we are having issues with the load balancer breaking the sessions (even with sticky sessions on). Whilst obviously the idea here is to have my code reviewed, I have a few questions/ar...
I currently use a data structure like this: (def sample-board [[{:mine true} {:warn 2 } {:warn 1} { }] [{:warn 2 } {:mine true} {:warn 1} { }] [{:warn 1 } {:warn 1 } {:warn 2} {:warn 1 }] [{ } { } {:warn 1} {:mine true}]]) Now I want to create a copy of the fi...
I am creating a util module that I'm using to communicate with a MS-SQL database. I want each public method to return a promise. I started with a private function that executes a DB query and returns a promise. The function establishes a connection to the DB then it executes the query. My current code just lets all err...
I am creating a simple program that will do three things: add up the prime numbers found within the range set by the user, print out the entire list of prime numbers, and print how many prime numbers were found. # Starting number lower = int(input("Enter lower range: ")) # Final number upper = int(input("Enter upper r...
I'm working with TCP Sockets and I've build a simple packet struct that turns it into a datagram protocol. I've created a class which returns "promise" Tasks for Packets. Packets are very simple, they consist of: struct TCPPacket { unsigned short size; // contains size-1 // such that size r...
I have started a project on my free time were I'm writing a 2D game engine in Java. One of the more challenging and interesting aspects of such a project is collision detection between sprites on the screen. I have previously written a game engine in C++ were the more naive approach (O(n2)) of using a list of all sprit...
I wrote a jQuery function to show a popup that can be draggable have multiple buttons etc. Demo How can I improve this code? I want to try keeping it light and simple but at the same time make it as versatile as possible for all the sorts of popups I might need in future projects. /*Popup function*/ function popup(conf...
Node's HTTP library provides a handy shorthand function for GET requests. Something similar doesn't exist for POST requests. I'm trying to write one in ClojureScript that compiles to node-readable JavaScript. In JavaScript (+ underscore.js) it would look like so: var _ = require("underscore"); var url = require("url")...
I am beginning to use generics and would like feedback on the following set of classes that will serve as the basis for an app that contains a large number of basic CRUD-y entities. I have used Car and Person classes as examples, but there will be a whole bunch of basic classes like these, perhaps 50 +. My aim is to ...
I've just started out writing an app that will visualize genomic data for anybody to understand. When you get your genome sequenced the raw data usually comes in the form of a VCF file. I started out by drafting parser below that essentially creates a JavaScript object out of a VCF text file. Next I think want to write...
I'm looking to add a module to one of my utility classes that functions as a countdown timer for tools that execute tasks after a certain amount of time. The code below is what I have working for PoC, but when I went to make this and check out existing examples, none really seemed this slim/simple without going all-out...
I have completed an exercise where there are 4 different color boxes and 1 main box below them that is blank, when you click on one of the colored boxes, the main box changes to the color of the box you just clicked on. Also there should be working undo and redo buttons. Am I doing this the "Angular" way by using $even...
On Linux, the file /proc/cpuinfo returns a set of key-value pairs, where the key and value are separated by a colon and each pair has its own line. It's a bit more complicated than that in reality, but for my needs that's as complicated as it needs to be. (I have only one processor core.) My goal is to write a function...
I wrote this script in order to generate a hosts.txt file with the IP addresses of the laptops in my school. Each laptop is assigned a number, and their IP addresses are assigned to them with the template "192.168.0.x". X being the computer's number + 10. All these computers are running Arch Linux with XFCE4, custom ta...
This is regards to one of my answers: Linq Expression Calling Combines. The question wasn't very well received, but it proved to be an interesting task that I enjoyed working on. I ended up with the following: public static class ExpressionHelpers { public static TExpressionType InlineInvokes<TExpressionType>(this ...
I'm learning Ruby and I would like to know if I have used the good syntax. My script works, but can I simplify it and make it more elegant. puts "Hello, what is youre name?" name = gets.chomp puts "Are you a boy? (yes/no)" genre = gets.chomp if genre == ("yes") puts "Do you like soccer #{name}? (yes/no)" foot...
I've asked a question receiving excessive (in a good sense) feedback. After I've incorporated it into the code, it changed substantially and I felt that I'd need opinion on the new version. Posting revised code is against the rules, so I'm asking a new, follow-up question. Choice of exception names. Are those informat...
Let's consider a method like this: public bool IsWordABeforeWordB(string Text, string WordA, string WordB) { ... } By Word I mean a string composed of more than one character. Test cases: [TestMethod] public void IsWordABeforeWordB_ShouldBeTrue() { string Text = "CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED ([IDT...
I'm currently working on a Tic Tac Toe project to improve my programming skills, and I'm simultaneously learning Git. This is my GitHub page for my Tic Tac Toe project. I will post the code below so you don't have to go to GitHub. But if you could give me some small feedback whether I have pushed/committed things in th...
The following code snippet is causing me a performance problem in my application. The first 5 db queries are not high time consuming, the real problem lays on the foreach loop. I considered to use Dictionary structures instead of List to improve the lookups, but improving the loop will make the real difference. public ...
As of now, instead of the previous 4 or 5 out of 10 (relative to my C# programming skill), I'd say I'm a solid 6, and some of that is thanks to the advice I got from the last revision. I realize the code is very long, and I tried to condense it all down to what was necessary (referenced in these main files). The full p...
I have a script which I use to delete rows from a Excel Sheet, dependent on the Column C cell of that row being blank. I believe deleting a range might be quicker than deleting individual rows, but I'm unsure. Sub Shorter() '47ms to remove blanks rows of 80 rows 'Searches the designated Column and checks for a Blank ...
Introduction: I have a website where customers can configure and checkout glass products like for example: Shower doors, Mirrors, Kitchen splashbacks, Table tops etc. What I am trying to do: I am trying to create a class for calculating the price of this kind of configurable products. All the products have in common th...
I have been an Angular developer for more than 5-6 months and mostly I learned with my experience. However, recently after submitting code to some competition, I got a feedback that AgularJS best practices were not followed. I need some help understanding irregularities in my code. Controller crossover.controller("roo...
I recently found myself in need of an IDictionary<TKey,TValue> implementation that was observable from a WPF UI. Since the .Net framework does not provide one, I rolled my own, but borrowed very heavily from what ObservableCollection<T> does on its own. And since there is not generic implementation of OrderedDictionar...
I am doing a lot of stuff with JavaScript and jQuery lately, but am not heading for clean code too much, as I am usually writing userscripts or small applications for myself. Recently, a community I am part of announced that it will change their supported BB-Codes, as the tabmenu BB-Code had a possible safety issue. By...
I'm creating a Q&A website, Something like SO. Now I need to print a "check" icon (to specify accepted answer) next to every answer. Now there are some conditions: Is the current user logged? Is the current user the author of the question? Is there any accepted answer? And some other cases. Actually, I implemented th...
The following code calls Parse. And uses its API to create two functions: post.create and post.find. As the names imply, one is for creating posts and the other for fetching them. Example: import Parse from 'parse' Parse.initialize('APP_ID', 'CLIENT_KEY') const post = {} post.create = json => { const Post = Parse....
On my way to learn OOP, I am developing a little CMS using the MVC pattern. I would like to have some feedback about my router class, mostly about if I am correctly using OOP. Right now, I have a .htaccess file redirecting requests to an index.php file, both of them in the root directory of the project. .htaccess <IfMo...
I have completed a coding challenge from Free Code Camp. The challenge's user stories are as follows: I can create recipes that have names and ingredients. I can see an index view where the names of all the recipes are visible. I can click into any of those recipes to view it. I can edit these recipes. I can delete t...
I'm learning some Python with my kids, and we're making a program to generate D & D characters from user input. One portion of the code is to generate stats, which are a set of six numbers where each number is the sum of three random values from 1-6. We're total softies, though, so for each value, we're generating four...
I have a function that returns size of an image IO (Maybe (Int, Int)) It would be nice to convert it to float tuple beautifully. I am sure there must be a better way than what I currently have: data Vec2D = Vec2D Float Float getImageSize :: FilePath -> IO (Maybe (Int, Int)) getImageSize path = do img <- readImage ...
I am trying to optimize my code when downloading around 50 pdf files from a website. All of the pdf are big in size (average 25mb). Is there any way to optimize further to download the pdf faster? for (String pdfUrl : pdfUrls) { URLConnection request; request = new URL(pdfUrl).openConnection(); InputStream ...
The Rubberduck code inspections have just seen yet another structural change, hopefully for the better. The IInspectionModel interface was originally named IInspection; it only exposes the bare-bones inspection properties, those needed by the CodeInspectionSetting class: public interface IInspectionModel { /// <sum...
I'm actually doing my whole shell in C from scratch from a Linux computer. The thing is that I think we all do our best from creating the simplest things that can be explained easily. And I'm not sure my shell has these qualities. All command I tried worked but command 1 | command 2 | command 3 or command 1 | command 2...
I am learning to code by making a todo app in pure javascript. My first attempt can be seen here. It's all cosmetic, meaning it stores no information, generates no objects or arrays, though it was sure fun to learn how to manipulate DOM elements in pure JavaScript and building my first "program"! I am rebuilding it in ...
If one enters, say, "2, j" then it prints: j jj If there is no second it should be *, so if it's just 2, it's * **. #include <iostream> #include <string> #include <vector> using std::string; using std::cin; using std::cout; using std::endl; using std::ostream; using std::vector; class tree { public: friend ostre...
I have a subroutine which re-formats cells after a heading is inserted into the document. Most cells are 12.75 points high, whereas the headings are 15 points high. When a heading (single line) is inserted, it pushes all of the other cells down, however the formatting does not move with them, so any headings below the ...
I've started learning Clojure, after many years of Java. As one of a series of exercises, I'm writing a simple card game, and the overhand-shuffle function is shown below. My main concerns are: Most of my code appears inside the let, and to me it looks more procedural than functional, is this the best way to do this? ...
Here's my implementation of sorting a stack in ascending order. The problem statement is as follows : Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you may not copy the elements into any other data structure (such as an a...
This code was created for a game project in which 10 houses need to be populated with 16 people. I wanted the distribution to be random, with no more than 3 and no less than 1 person per house and no remaining people or houses. JSbin link function getRandomPartitionsFromNumber(number, parts, min, max) { var result = ...
I have a large function that performs a search over a data set given a set of parameters. This function goes through multiple databases which all hold data that would comprise one final entry from the search. def perform(self): #Go through each year and each DB in that year for year, yearInfo in data["preproces...
For ease of Reference, Sample Data Set which needs to be pasted into Column C from row 20. You can paste the text below into word and then copy from word into Excel with the Cell format set to Custom: yyyy/mm/dd hh:mm:ss.000 2015/08/01 12:53:03.000 2015/08/01 12:56:31.101 2015/08/01 12:56:37.499 2015/08/01 13:0...
In my project I need to send emails. Emails will have different credentials and senders. I'm thinking about "abstract factory", but will it be good solution? public abstract class Mail { public string Body { get; protected set; } public string Subject { get; private set; } public string Emai...
This is of one the interesting problems I've solved: An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on arrival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will re...
This small utility class is my solution for a more convenient way for checking against null. I also wanted to have more informative NullReferenceExceptions but I didn't want to pollute my code with null checks everywhere. static class NullGuard { public static T Check<T>(Expression<Func<T>> expr) where T : class ...
I am implementing a smart pointer class template and I want to overload operator ->* (even if it’s rarely done). I came across Scott Meyer’s article Implementing operator ->* for Smart Pointers. The article is from 1999 so I decided to try to adapt the code for C++ 14 (using parameter packs and perfect forwarding) and ...
Given a complex object (with nested objects at any depth) I need to be able to quickly retrieve a value for a given property name. I have designed the following code, I would like to know: How to tune my code for maximum performance considering passing a big object? Am I missing some case in data.a.x? Any other improv...
I have the following enum extension method: public static IList<SelectListItem> SelectListFor<T>() { Type enumType = typeof(T); if (enumType.IsEnum) { return Enum.GetValues(enumType) .Cast<int>() .Where(i => !i.Equals(0)) .Select(e => new SelectListItem() { Value = e.ToStr...
How can I Pythonize/Djangoize/DRY my Django code? views.py class AccountDetail(DetailView): model = BankAccount template_name = 'bank/account_detail.html' def get(self, *args, **kwargs): self.object = self.get_object() if self.object.is_owner(self.request.user.citizen): return ...
This takes in an array of data built from a source workbook, builds a set of "flags" based on the data in each row of the array. Then it creates a new finalRng array that will, based on a set of logic from the business, create new rows based on the data. I think there are a ton of ways to accomplish what I am looking ...
Wallace the Weightlifting Walrus is training for a contest where it will have to lift 1000 kg. Wallace has some weight plates lying around, possibly of different weights, and its goal is to add some of the plates to a bar so that it can train with a weight as close as possible to 1000 kg. In case there exist two such ...
I got inspired by Doorknob's blog post What’s the largest MD5 hash you can find? to get my hands dirty and learn some Python. After playing around with the code from that post, I decided to rewrite the whole thing and to make it more flexible (to get some practice). This is what the code does: It generates a random st...
Hey so I have written some code out in jQuery, but it seems to violate DRY. I'm not too familiar with JavaScript or jQuery, so I was just asking for some advice on how to optimize this code: $("#twitter").rotate({ bind: { mouseover : function() { $(this).rotate({animateTo:360}); $("#twitter").fadeTo(fu...
I am learning Node.js and I would like to see if I'm using it correctly: var mysql = require('mysql'); var fs = require('fs'); var connectionProps = JSON.parse(fs.readFileSync('connection.json', 'utf8')); var connection = mysql.createConnection({ host: connectionProps.host, user: connectionProps.user, password:...
A very long time ago, I started development of a code generator for HTML. And some time ago I rewrote it and published it under LGPL v3.0 on Sourceforge.net. It is very universal because one of its classes ([ElementListSetting][1]) reads DTD files and extracts elements from them. Currently, this class creates only a si...
I wanted to write a function that would take a long long int argument as well as a base and it would convert that number into an equivalent number in a different base, and return the result as a string (er, char array). For example, the call, convertBase(9, 5) should return "14\0". For negative values, the returned st...
Motivation I do a lot of graph-theoretic code, and, by now, I feel substantial need for data structures that can represent weighted graphs, both directed and undirected. Up till now, I was in a habit of writing a graph node type along with the weight function (in my prior posts, something like DirectedGraphNode and Dir...
The reason I'm posting this piece of code is because I want to know how I'm supposed to properly handle the change in requirements/specifications and how I should accommodate it in unit testing. /** * Create an Affiliate */ public function createUser($username, $password, $email, $firstName, $lastName, $ip, $notifica...
Given a string and an array of words, return all indexes in string for which a concatenation of all words in the array, in any order (so ["eensie", "weensy", "spider"] has six orderings) can be matched. All words will be the same length. I am new to programming so please tell me where my big slow down points are. I...
I am using a <form> to send various input parameters as a GET to retrieve data from a very simple two table MySQL db. After filtering the inputs (resulting in $inputs), I'm using the following code to build the WHERE clause which I've adapted from a MATLAB function we use to build XQueries. It works fine, but I'm just...
I want to nest a for loop to cycle through the Range.Value but ("B4") throws me off and this can't be avoided. I was considering using an array to do this but can't seem to get the format correct. "Q3" is a spreadsheet and "Bac Form" is the attached table imported from a PDF that must be kept. This code works wonder...
I was having a discussion with my coworker about a function that returns either an empty string, or a string of a css class. The function is passed an object which has an HTTP status code, and then depending on that statusCode, it returns a value. We couldn't agree which is cleaner. He wanted the function written as so...
I have class with some basic string operations. Any suggestion to improve the class class StringHelpers { function replace_between($str, $needle_start, $needle_end, $replacement) { $pos = strpos($str, $needle_start); $start = $pos === false ? 0 : $pos + strlen($needle_start); ...
I completed Assignment 2 for MIT OpenCourseWare 6.092, titled "Foo Corp". The code I wrote below calculates a an employee's total pay: package fooCorp; class Employee{ private double payPerHour; //regular hourly wage private double overTimePayPerHour; //regular hourly wage * 1.5 private double basePayHour...
I find that I am often writing files where the names either: Need to be incremented (rather than overwriting a file that already exists in the directory with the same name) Need to be timestamped And, so, I've created the following methods to do so: public static string CreateDatedFileName(string directory, string fi...
I am just picking up C++11 and decided to try some algorithmic problems to get better at it. One such problem is the fractional knapsack problem which can be solved by a greedy approach. The idea is to find the most valuable item and fill it in and move on to the next one till the knapsack is filled. Partial items are ...
Given an array a, check to see if z numbers inside a total up to n. If a = [1,2,3], n=3 and z=2, then this function should return true, since z numbers in that array combine to equal n. I recently took a test for a job to fill out this function, and this was my answer. It was presumably rejected by the robots for bei...
I'm getting started with Docker, and I've set up a very simple image built from a Dockerfile. It's based FROM the ubuntu image, and I'm downloading and building apache from source. I'm just curious if I'm on the right tracks, if there's a more "Docker" way of doing what I'm doing, or any other things that I could be do...
In this exercise, I'm supposed to sum up elements from 2 arrays, then display the answer on one line with spaces in between. I did it and my answer got accepted as correct, but I'm wondering if there is a better way to do this since I feel my way was more complicated than it needed to be. import java.util.ArrayList; im...