instruction
stringlengths
71
71.9k
This code is for a simple 2D tile-based game. x1 and y1 are the mouse coordinates in the world. entity->x1 and entity->y1 is the point where the player is, the shot origin. I would like to know how to keep the current output while simplifying the code and improving performance. void shoot(Map *map, Entity *entity, int ...
The Greed game, from Ruby Koans, where you roll up to 5 dice: A set of three ones is 1000 points. A set of three numbers (other than ones) is worth 100 times the number. A one (that is not part of a set of three) is worth 100 points. A five (that is not part of a set of three) is worth 50 points. Everything else is wo...
I'm trying to display data from Keen.io we're collecting from an iOS app where we report what devices of ours the app is used to communicate with. In particular I'm trying to find where there are more than one of our device. An entry from the Keen collection looks like: { "iOS_OpenUDID": "hexadecimal", "iOS_Country...
I have a private method that is called from the constructor to instantiate a bunch of objects. I can do it two ways. private Monster[,] createMonsters() { Monster[,] myMonsterArray = new Monster[8, 6]; for (int i = 0; i < 8; i++) { myMonsterArray[0, i] = new Monster(SpriteFa...
I need to implement some functionality of the otherwise monolithic application via DLL that is loaded at runtime. (Think about a customized DLL -- different for each customer.) The Visual C++ from VS 2013 is used. The application gets the full name name of the DLL. The function to be called has a fixed name (convert i...
Let's say you want to increment the cells around the position (x,y) in a square matrix m of size T. I've written the same code in a few languages. Here's the JS syntax version : if (x>0) { if (y>0) m[x-1][y-1]++; m[x-1][y]++; if (y<T-1) m[x-1][y+1]++; } if (y>0) m[x][y-1]++; if (y<T-1) m[x][y+1]++; if (x<T-...
I'm using MVP pattern for a payroll system as my final year project. There are about 16 entity classes (like employee, client, salary etc.) in the analyzed problem and I have designed the solution as follows… Number of UIs (Views) – 18 Separate Presenters and Models for each UI ( 18+18) One Data Service (repository) ...
I have some code: $matchingEvents = []; foreach( $this->recurringEvents as $event ){ if( $event['RCE_Type'] === 'Month' && $event['RCE_Day'] === $dayOfMonth ){ array_push( $matchingEvents, $event ); } else if( $event['RCE_Type'] === 'Week' && $event['RCE_Day'] === $dayOfWeek ){ array_push( $matc...
I wrote a solution to the popularized FizzBuzz problem in Haskell to see how a functional solution looks. I'm more or less happy with my solution, except for the definition of list. It just looks sort of contorted. Are there any language features in Haskell which can improve the readability of this code, especially t...
I coded a php chat that stores the text in a txt file and retrieves it, and I want to know if XSS can get past it or if someone can replace xhr.open("POST","uhh.php"); with something that contains the same php code but without htmlspecialchars or something like that. What are the vulnerabilities? (More specifically, I...
As many may know, I am developing a Trading Card Game for the Coding Challenge. I have just completed the Field class and have not used it in practice yet, so all theoretical and looking for a review. Using Java 8 and all custom classes will be included in this post as well, if you wish you can see all source on GitHub...
Problem 33 in Project Euler asks: The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by canceling the 9s. We shall consider fractions like, 30/50 = 3/5, to be trivial examples. There are ex...
Lately, I've been, I've been losing sleep Dreaming about the things that we could be But baby, I've been, I've been praying hard, Said, no more counting dollars We'll be counting stars, yeah we'll be counting stars (One Republic - Counting Stars) The 2nd Monitor is known to be a quite star-happy chat room, but exactly ...
Please, have a look at the previous (bad) implementation and the review here. After reading the suggested article at HowTo: Export C++ classes from a DLL, I have decided to use a plain C function approach. However, I want to use C++ code inside the DLL later. Anyway, the exported one will be a plain C function with the...
I'm new at Caliburn Micro and the MVVM pattern. I have 3 views (with its corresponding viewmodels): AppView ClientsView EditClientView AppView is my main page with a TabControl inside. The child views (WPF UserControls) are loaded in new tabs. In ClientsView I have a grid with filtered clients. I select one, and when...
I just started learning about the MVC architecture. And I started to create my own MVC framework to how I like it the most. Here I've got the index.php, indexcontroller.php and view.php. I'm not too sure if what I am doing is right, or with best practices. So I would like to know if there is anything I missed so far, o...
(Method signature is given with parameters) Try to visualize me writing this code at an interview, and please be brutal while judging it. Problem: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. Fo...
I'm writing a simple xHTML parser which parses a data without nested tags. Example input code will look like: <h2>Header</h2> <p> atsatat </p> <h2>asdsaad</2><p>s32532235</p> I've wrote the following code: #include <node.h> #include <vector> #include <string> #include <sstream> #include <iostream> using namespace v...
I was doing this easy challenge "Counting Minutes I" from Coderbyte.com where you just calculate the number of minutes between two given times. The second time is always after the first, although it may look to be before but mean it's during the next day. The format of their test cases is "hour1:minute1-hour2:minute2...
I'm trying to improve my understanding of recursive and iterative processes. I've started with SICP, but have branched off to try and find a few exercises when I started having difficulty. Currently I've been looking at a series of posts on the subject by Tom Moertel. Tom's code defines a node object for binary search ...
I have an Excel sheet with lot of rows with data. I am separating it into 2 sheets with some condition satisfies. This is taking too much time. How can I improve the speed? Please suggest any changes to my code. Dim bmver As Object(,) = New Object(i20, 36) {} Dim bmhor As Object(,) = New Object(i20, 36) {} Dim ik As...
Given set of words that are lexicographically sorted, return lexicographic order. E.g: abc acd bcc bed bdc dab The order of letters for the given example would be a->b->c->e->d Time: Part-1: Complexity of constructing graph: \$O(n * m)\$, where \$n\$ is number of words and \$m\$ is max length of any word. Part-2...
Let's say that I have a view, whose purpose is to show a table with some information about a person entity. The view contains a form with an input element that the user can use to add a new person to the table by entering its name. My question is: In this scenario, is there a convention about where to put hidden field...
I have snapshots (photos) that I load off my camera's memory card, and store in a folder. Sometimes I have videos, and occasionally plain audio too (the camera can record just sound). Additionally, my wife, and kids have their point-and-shoots too. I have a workflow where I dump the photos on to a designated folder on ...
I've the following code: protected Dictionary<NpInfoHelper, object> Informer; protected override void OnInit(EventArgs e) { if (Session.Keys.Count == 1) { Session.Abandon(); Response.RedirectPermanent("~/Pages/Login?e=true", true); } else { ...
I have a form that requires the user to select photos to be included in their portfolio before they can proceed to use the app for the first time. I don't want to spend the rest of my life implementing a custom file browser, so I've decided to just use the FolderBrowserDialog to allow them to select a folder containing...
I have been attempting to learn Scala lately and so have produced a couple of different sorting algorithms to build up my basics. I think I have been lucky with the methods returning exactly what I have wanted, but for MergeSort I have implemented recursive methods that could return one of two different values and coul...
Can you please verify my approach? using System; /* * In Factory pattern, we create object without exposing the creation logic. * In this pattern, an interface is used for creating an object, * but let subclass decide which class to instantiate. * */ namespace FactoryMethod { Product (abstract)...
I'm working through Yet Another Haskell Tutorial. One of the exercises is to prompt the user to enters numbers, entering a 0 to quit. The program should then both sum and multiply all the given numbers, and then display the factorial of each. It works, but it's obviously sloppy, with some functions doing more than wha...
public class DataBaseHandler extends SQLiteOpenHelper { private static String DATABASE_NAME = "UnitDatabase"; private static String MEASUREMENT_TYPE_TABLE = "measurement_types"; private static String idCol = "id"; private static String typeCol = "type"; private static int DATABASE_VERSION = 1; ...
HTTP Strict Transport Security (HSTS) is an opt-in security enhancement that is specified by a web application through the use of a special response header. Once a supported browser receives this header that browser will prevent any communications from being sent over HTTP to the specified domain and will instead send...
Recently I have given an interview to a widely well-known technology firm. The first interview was general and it went well but they rejected based on some technical things. They did not mention it so I expect may be due to my Coding Exercise that I submitted is not well designed. It would be great if someone point out...
Below is the code for the problem at Codechef. I have made use of the String method .equals in my solution which is working fine for all the test inputs. However, I am getting a Time Limit Exceeded when I submit to the Judge. I need your ideas on optimizing the code. import java.io.BufferedReader; import java.io.IOExce...
I'm writing a driver in C for a WiFi module attached to a PIC18 microcontroller. I want to implement some functions that I'm familiar with in computer application level programming like Window's API recv function for WinSock. The module itself already implements the WiFi communication protocol and the TCP/IP stack, and...
Aim is to provide total head movement in different disk scheduling algorithms namely FCFS, SSTF, LOOK, C-LOOK, SCAN, C-SCAN. #include <iostream> #include <cstdlib> #include <conio.h> #include <math.h> using namespace std; int compare (const void * a, const void * b) { if ( *(int*)a < *(int*)b ) return -1; if ( *...
After coding my divisor code which I did as a practice for my GCSE stuff which I have to take soon, I have decided to ask the community if there are any bugs or ways I can improve my code. import time, math from array import * def programme(): num = input("Enter your Number: ") try: intnum = int(num) ...
Learn You a Haskell shows the intersperse function: ghci> intersperse '.' "MONKEY" "M.O.N.K.E.Y" ghci> intersperse 0 [1,2,3,4,5,6] [1,0,2,0,3,0,4,0,5,0,6] Note that the interspersed element only appears inside of the elements. list elem ... item ... list elem ..... item .. list elem Originally, I tried to wr...
This is a teaching sample intended to illustrate use of mutability and list consing in F#. The structure is intended to be a thread-safe stack structure, which multiple threads can push to/pop from concurrently. Concerns: Will this actually be thread safe? Are the locks necessary? Is there an immutable way to do the...
<edit: There's a major problem in the code. It is basically the one in the comment regarding backpressure. I'll rework the code within a a few days... It's time for a quick code review, good points, examples, handholding if anyone has time to spare for commenting and, yes, even nitpicking too. I wrote a short piece of ...
This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some pretty non-trivial piece of code that I decided to post here as a new question for review. Basically, this is quite close ...
I am writing the Cloud function for Parse whose purpose is to update my database with a provided array of data objects. The main problem are the nested promises, which doesn't look right. Any help to refactor this code or any other critiques? /** * Updating multiple object arrays: * Look for object with the same ...
I'm writing a Perl program to take a set of clauses and a conclusion literal and produce a resolution-refutation proof (if possible) using a breadth-first set of support (SOS) search algorithm. The actual searching part of the program runs extremely slow, because I have many nested loops. I imagine it may also have to ...
I want to create a container that has an AutoList object list. I wonder if my container is correct. class Auto{ string model; int co2; public: Auto (); Auto(string m, int c); ~Auto(){}; string GetModel(){return model;} void SetModel(string s){model = s;} int GetCo2(){return co2;} voi...
I have made 2 scripts in Ruby. The first program creates an .rtf file with cards (file with colored table with persons) from a list of people in text file. The second program does the same, but in an HTML file. In the first, I can use the gem library, but I'm not allowed to do so in the second. My teacher said that i...
A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me that I should ask for advice online from more experienced Python programmers. He said that "the issues were algorithm de...
Given a set T of characters and a string S, find the minimum window in S which will contain all the characters in T in complexity O(n). eg, S = “ADOBECODEBANC” T = “ABC” Minimum window size is 4 - “BANC”. public final class MinSubstringWindow { private MinSubstringWindow() {} private static void addCharCount(...
I'm writing some code which needs to take a generic java.util.List from another source and adapt to the available functions; eg. does it support add(), set(), etc. I'm currently just calling the functions on the list and creating a set of available operations, but I'm wondering if there's a better way than try-catch. C...
Here is the link to the jsFiddle and below is the code: JS: $(function() { var hours = minutes = seconds = milliseconds = 0; var prev_hours = prev_minutes = prev_seconds = prev_milliseconds = undefined; var timeUpdate; // Start/Pause/Resume button onClick $("#start_pause_resume").button().click(fu...
The class routes URLs based on the domain.com/class/method/param/.. format. It also checks the request type (GET or POST) and calls the method name GET or POST from the identified class. class Router { private $_routes, $_path, $_method, $_found; public function __construct(...
from random import random def to_color(obj=None): """Determine a color (string 000000-ffffff) from the hash of any object If no argument is passed, a random color is returned. Args: obj: any hashable object; string, tuple, ... Returns: a color string in range '000000' to 'ffffff' ...
Answer is the Parent table and AnswerDetail is the child. Below works, but I'm wondering if there is a better way to do this using EF? My Method Signature is this: [HttpPost] public ActionResult Evaluator(EvaluationVM evaluation, string command) It is coming from a MVC 4 application. Answer AnswerRecord; Answ...
I've written the following query for SQL server: SELECT YEAR(Meeting_Date) year, MONTH(Meeting_Date) month, COUNT(project) meetings FROM meetings WHERE Meeting_Date BETWEEN CAST(DATEPART(year,DATEADD(m,-6,GETDATE())) as varchar(4)) + '-' + CAST(DATEPART(month,DATEADD(m,-6,GETDATE())) as varchar(2)) + '-01' AND DATEADD...
This is part of one of my projects called largetext, which actually stemmed from a question on Stack Overflow. The goal is to provide access to a very large text file as a CharSequence so that it be usable with not only java.util.regex but also grappa. In the next version, I want to provide a thread safe version of the...
So I wrote this code a while ago as a way of seeing how many times it could compute a simple sum in a second (one tick). I was wondering if this gives me valid results or is in fact giving me bogus ones. from datetime import datetime from datetime import timedelta start_time = datetime.now() def millis(): dt = da...
I was wondering which time.time() of from datetime import timedelta was the quickest and best way to find how long a programme had been running for example. import time start = time.time() #do stuff print(start - time.time()) or (although longer) from datetime import datetime from datetime import timedelta start_ti...
After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses a separate list for each char list but I am sure it is using a very long-winded method! import random, sys letters = ["a...
I wrote a fizz buzz variation method in Python which prints "fizz", "bang", and "buzz" for 3, 7, and 11 respectively. def FizzBang(): string = '' for n in range(1,101): msg = "" if not n % 3: msg += "Fizz" if not n % 7: msg += "Bang" if not n % 11: ...
I'm new to design patterns and specifically the Service Layer implementation. I need some clarification on where to use Service Layer calls. Below is an example of what I'm dealing with. I have data from 2 different repositories so I'm not quite certain when/where I'm supposed to call up any additional information t...
I have few years of experience with web and I recently started learning C++ and I feel a bit lost, so I would like to ask to for some tips how to improve my code overall. This text summarizer should get the sentences with the highest weight (most important ones). Header file: #include <iostream> #include <string> #inc...
I am trying to use the following form to enter new info into a database. I am trying to use the entity framework. I have the following classes of Interest: public class InventoryContext : DbContext { public DbSet<Item> Items { get; set; } ....Other DbSets follow... } [Table("Items")] public class Item { ...
I was thinking in a way to improve the following query if possible: SELECT CONCAT(DATE_FORMAT(start_date, '%Y'), ',', (MONTH(start_date) -1), ',', DATE_FORMAT(start_date, '%d')) as start_date FROM PROJECTS I need start_date in this format: dd/mm-1/yyyy. Note: I am using an API that use month from 0 to 11, and ...
I want to implement the following function: // Return true if and only if 's' is numeric including // leading positive/negative sign, decimal point. bool isnumeric( const char * s ); It is somewhat similar to strtol() but I don't need to return the number. My approach is to count various things unless I can bail out: ...
I have written the same code in Python (NumPy) and in Matlab, and I tried to use the same structure for both language and follow the same procedure. Now my problem is that when I run my code in Python it's very very slow but it runs fast in Matlab. How can I improve my Python code? I want to work on the Python version...
I am trying to implement lock by which I don't want to have reads from happening whenever I am doing a write. Here is my ClientData class in which I am using CountDownLatch: public class ClientData { private static final AtomicReference<Map<String, Map<Integer, String>>> primaryMapping = new AtomicReference<>(); ...
I had a task to create a responsive HTML5/CSS3 page based on PSD layout. I got rejected and when asked for details I got these comments: semantically incorrect HTML incorrect use of ID selectors in CSS incorrect general way of solving given CSS problems The link is here HTML: <!doctype html> <html lang="hr"> <head> ...
So I am working through a few different game ideas as I learn programming, and I could definitely use some feedback on my latest project. This is a simple SimCity clone. So far I have created a City made up of City Tiles objects, and a number of Person objects as well. The Persons are passed from the City Tiles to th...
This is a follow-up to this question, which resulted in major confusion on my side regarding forwarding of arguments. Advice regarding that should probably be given in my question on SO. Overview The classes below implement the observer pattern for use in an embedded system. My main need is to be able to connect source...
I'm implementing transpose in Haskell. -- transpose [[1,2,3],[4,5,6],[7,8,9]] -- [[1,4,7],[2,5,8],[3,6,9]] Please give it a look. Note that I'm trying not to use any built-in functions (excluding map and ++): transpose' :: [[a]] -> [[a]] transpose' ys | null $ filter (not . null) ys = [] | otherwise = [flatten...
Below is working code of a semi complete program. Its purpose is to take an input string of any type and modify it based on rules defined for each type. So in this example I pass it a string in CSV format and modify some of the fields. My questions are Can the use of interfaces be improved? How can I handle diffe...
I've been trying several styles of validation code for a form. I was wondering if this is good or needs some improvement or just trash it and use jQuery validator code? $("#registration-form").on("submit", function(e) { e.preventDefault(); var error_field = ""; $(this).find(".input-field").each(function(...
This is a follow-up to: Lock for preventing concurrent access in client data I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three maps. My requirements are: Reads block until all three maps have been set for the first time. Now second time, If I am updatin...
I am learning data structures, and have written an algorithm for insertion sort after learning from some sources. But I am confused which implementation is more correct or appropriate. Code #1 This implementation takes an element and sorts itself with all the elements to its left, one by one, like bubble sort I think. ...
Building on the older building block, Trading Card Game's Hand class and tests, I decided it was time to implement a HandView, which can be implemented by a GUI for example. The view need only be notified if a structural change happens in the "parent" class. I have taken the following facts into consideration: Loose c...
Initial problem For a project I found myself in the need to search for elements in a container that are the closest neighbours to another precise element I have. In my case it was points in any dimension, but it can apply to various other things that we are not used to compute "distance" for. So I decided to write a ge...
I tried to write my own variant class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from boost::static_visitor or to contain typedefed result_type. The result type of the visitor deduced by means of std::result_of and also can be prvalue, rref,...
I need comments on the below code: Thread.new {EM.run do IpamAgent::Amqp.run end} module IpamAgent class Amqp class << self def run begin $connection = AMQP.connect(RMQ_CONFIGURATIONS) $connection.on_tcp_connection_loss do |conn, settings| ...
I want to inform the Receivers about new contracts we have this week. After I sent the Emails, the Information about sent contracts are stored in MS SQL Database. To avoid that someone become the same Email about contract more than one time I perform this steps: I have the Collection with new contracts as the input I ...
I need to generate a minimum and maximum value for a range of speeds (slow, medium, fast), the user can specify any combination of the 3 values, and receive a range that encompasses all. Given any combination of "slow", "medium", "fast", getRange() will return a [min, max] range. The function can be called in the follo...
What do you think of this piece of code ? This is an implementation of quick sort in C, but I'm not sure about the quality and correctness. #include <stdio.h> void swap(int tab[], int a, int b) { int temp = tab[a]; tab[a] = tab[b]; tab[b] = temp; } void quickSort(int tab[], int begin, int end) { int left = be...
I am very new to Ruby and building my first game. To be honest I did it this way because I was lazy to type so much. My friend told me that the correct way was to do this with case statement i.e. for scissor we have three cases, for rock we have three cases and similarly for paper. puts "Rock, paper or scissor" w = 0 a...
I wrote this code where I trap InterruptedException's in a blocking queue and try again to consume from the same queue thinking of spurious wakeups. I don't know if in this case I should be thinking of spurious wakeups since I am not calling wait() directly. Basically, the worry that someone raised is that if the take ...
I'm new to HTML coding and have created a basic webpage structure for a basic website with 5 pages. Can anyone suggest any improvements that could help with the structure, layout and design for the pages? Code for one of the pages is below (all the same except for the names): <!DOCTYPE html> <html lang="en-GB"> <Head> ...
I have the need to search a directory containing 1000+ files on remote servers where I only have access to SQL Server Management Studio and Explorer. I have written the below SQL statement which does what I need, only incredibly slowly. I fear using this many temp tables and the cursor is the main issue. Any ideas on h...
I want to find the corresponding hash in an array from a string that contains a criterion defined in a hash of the array. I do something like that : types = [ {key: 'type_1', criteria: ['type_1a', 'type_1b']}, {key: 'type_2', criteria: ['type_2a', 'type_2b']}, ... ] def find_type(str) types.each do |type| typ...
I'm changing the inner implementation of a project. In order to do so, I've created an interface that will be implemented in 2 different ways. One of this ways is by class A, which is a wrapper for an outside class (class "B") from a .dll file (a product of other team). Class B is a private a member of class A. Class...
Following code is supposed generate a new ID (PID) for a new client based on the client name's first letter and the existing IDs in the range which are stored in a database. For ex lets say if the new client's name is "Abc" and if last ID in the database starting from letter A, is A200. Then the new ID should be A201...
Not sure if this is the right board for this topic but since it will affect my SEO i guess it's not that wrong to ask about this in here. I just took on a website that lists some stores around your location. You can enter some conditions and it will return a list of nearby stores. I noticed that the List of stores will...
This question continues on my previous implementations of the Hand class of a Trading Card Game, earlier questions can be found here: Earlier model: Trading Card Game's Hand class and tests Older model having similar functionality as this one, likely deprecated for current one: Trading Card Game's Hand and HandView im...
Is there a more elegant and Pythonic way to handle counters in this solution to an exercise from the NLTK book? The exercise asks to print out the context (one word forward and one word back) for every verb of a particular type (tagged VN). import nltk wsj = nltk.corpus.treebank.tagged_words(simplify_tags=True) cdf = ...
In my method I have something like this: returnValue = null; if (!string.IsNullOrEmpty(pa.Phone)) { if (pa.Length != 10 && member == Schema.Phone.Name) { returnValue = new stuff; } } if (!string.IsNullOrEmpty(pa.OtherPhone)) { if (pa.OtherPhone.Length != 10 && member == Schema.OtherPhone.Name)...
I've been working to create a game in Python similar to Plague Inc. and instead of just writing one big clump of code and then getting it reviewed, I wanted to do it stage-by-stage and make it a little easier. Also, reviews might possibly help me later on in the development process. import datetime import random coun...
I've implemented DFS and BFS implementations. I want to check if the code is readable, contains any issues, and can be improved. GraphImplementation package graphs; import java.util.*; import graphs.State; public class GraphImplementation { public void dfs(Node root) { //Avoid infinite loops ...
The problem is presented here as follows: You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+a[j] ; x ≤ i ≤ j ≤ y }. Given \$M\$ queries, your program must output the results of these queries. Input The first l...
I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three maps. Requirements: Reads block until all three maps have been set for the first time. Now second time, If I am updating the maps, I can still return all the three old maps value(before the updates are d...
I have the below MySQL query that does exactly what I need, but I am sure there are better queries that do the same thing. If you see something very ugly or bad and have any suggestions, I will be very glad to hear them. SELECT c.`ID_COURIER`, c.`NAME`, c.`NICKNAME`, c.`AREA_CODE`, c.`PHONE_NUMBER`, d.`ID_DELI...
This code works fine, but I believe it has optimization problems. Please review this. Also, please keep in mind that it stops after each iteration of the loop foreach($mascow_sub_area as $subway). <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <?php set_time_limit(0); ini_set('memory_l...
I'm working on a framework that will be used to create simple 2D grid based games. It is using an Entity-Component-System pattern with corresponding manager classes used to control the lifespan of objects and construct them polymorphically based on an ID. In addition to general improvements to my code, I'm asking for f...
Problem: \$n!\$ means \$n × (n − 1) × ... × 3 × 2 × 1\$ For example, \$10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800\$, and the sum of the digits in the number \$10!\$ is \$3 + 6 + 2 + 8 + 8 + 0 + 0 = 27\$. Find the sum of the digits in the number \$100!\$. My solution in Clojure: (reduce + (map (fn[x](Integer. (str x))) ...
I have a class called Piece, and many many subclasses of Piece. I want to add an instance of every single subclass of Piece (under the pieces package) to my JTree. Currently, I have this class with a huge function (well, 57 lines, but still) that increases in size every time I add functionality to my program. My initi...
I recently began learning Clojure. In order to get better acquainted with it, I've been tackling Project Euler challenges. Problem 14 is not really a difficult one. It asks for the number that results in the longest Collatz sequence. The following iterative sequence is defined for the set of positive integers: n → n...