instruction
stringlengths
71
71.9k
This post improves upon my Java implementation of the Huffman algorithm for data compression. I did the following improvements: The map mapping each byte value to its frequency does not rely on float values, but rather on integers representing absolute counts. I am not quite sure, but it seems like a more robust way o...
I've been trying to write a simplified Google Maps program. My programming experience is limited. I have come up with a solution but I'm looking to make it more user friendly by splitting it up into various classes. import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import jav...
So I tried the brute force method after visiting https://www.programiz.com/python-programming/examples/palindrome on palindromes. Any comment on how I can improve my coding will be much appreciated. t=[] def is_palindrome(x) if list(str(x)) == list(reversed(str(x))): t.append(x) else: pass for i...
I have written code to calculate the area of different shapes using polymorphism (virtual and override methods) and it is working as expected. Can anyone please review this and let me know how I can make it better? class Program { static void Main(string[] args) { double side = 0; double length ...
I built this toggle nav that switches a banner section between the slider and a map. All works well but I would like to know how I could improve my JavaScript as I am quite new to it. $(document).ready(function() { // Banners Toggle var bannerSlider = $('#banner_slider'); var bannerMap = $('#banner_map'); $('.thm-ban...
From a deck of 50 need to get sets of 5 as random as possible and as fast as possible. The thought here is to shuffle to get 10 sets of five at a time with no collisions. Int1 and Int2 will not change during a run. If they do other bad stuff would happen. public MainWindow() { InitializeComponent();...
I solved this problem: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same ch...
I've written an itty bitty tcp server, for educational purposes. The program outputs a file if you input the correct hash (or whatever you set the environment variable to). I've performed tests on the application through netcat ( nc localhost 9000 ) and everything is fine, the application works as intended, both in m...
I'm trying to expand my use of classes and better understand how/when to use them. Please review the code and let me know if I'm on the right track or where I need to make improvements. For example, should I remove the database call from the class, why or why not? <?php class Model{ private $_db; private $fir...
I've just implemented counting sort in C and would like to hear your opinions on it. As I'm usually being rather picky when rating other people's code, please go ahead and be picky, too -- I will try and justify my decisions but I'm thankful for any hints :) #include <stdlib.h> #include <stdio.h> #include <assert.h> /...
I'm implementing a search for a deep array. It applies the search/filter to the deepest level of children below, i.e. { name: 'foo' }, { name: 'bar' }. If all children are filtered from the parent object, the parent is removed from the list too. Since I want to leave the original object intact, I copy each container ob...
I've made this code to extract a conversation from a Skype database file with a certain user ID, all this being specified as a command line argument. Since Skype uses SQLite to store the messages I can use the sqlite3 Python module to retrieve the messages. The code first checks for the database file, opens it if it ex...
I've designed a userform in Excel and it has many comboboxes and textbox inputs, once the user is done it puts ticks in appropriate columns depending on the ComboBox selection and also writes the value of the TextBox to the sheet. At the moment I feel as though the sub could be refined but am unsure how to proceed as t...
I'm developing my first legitimate jQuery plugin, and I'm trying to keep it very modular. To do this, I'm writing many individual functions, which is fine, but I need a clean way to determine what functions to fire based on the plugin options provided by the user. Right now, I'm using a .on('click',...) event with a sw...
I wrote this code to filter a list of names based on certain conditions, and wanted to see if I can reduce this further and eliminate redundancy in code. names1 = ["Jane", "Jake", "Bradley", "Bill", "Betty", "Kara", "Kris", "Jil"] names2 = ["George", "Kate", "Karen", "Kurt", "Greg", "Gary"] selection_criteria = ["full...
I have returned to programming after a year without practice and this is also my first time using Java. I know there is a more efficient way to do this so any suggestions would be appreciated. I am trying to distribute stats randomly to a character in my game. However, I can't just go through each stat and increase/dec...
I recently finished the Using Databases with Python course. To figure out whether I really understood what was being taught, I build an application which does roughly the same but uses a different formatting. The idea is to have a list with addresses, look up the corresponding coordinates using the Google Maps API, sto...
#pragma once #include <atomic> #include <memory> template <typename T> class RingBuffer { public: explicit RingBuffer(std::size_t capactiy) : _buffer_capacity(capactiy){ std::unique_ptr <T[], RingBufferFree> buffer_ptr(new T[capactiy]); _ring_buffer_array = std::move(buffer_ptr); } ~Ring...
In the prior obsolete implementation of std::deque, I used two std::vectors to contain the elements. But the standard guarantees that pointers and references to elements aren't invalidated when an element at either end is erased or when an element is inserted into either end, which the prior implementation doesn't: To...
I am extracting data from .txt files and writing needed data to Excel. My problem is that my code is very very slow and at one point even slower (+35k txt files). How should I rethink this problem? Microsoft.Office.Interop.Excel.Application excelapp = new Microsoft.Office.Interop.Excel.Application(); exce...
I am working on the problem of removing comments from C-like source code. Here is my code in Python 2.7, and if anyone could advise improvement areas (especially performance), or any functional bugs which I do not discover, it will be great. Problem statement Given a file path represented as string, take this input str...
I started learning Haskell a couple of days ago and decided to build a Caesar shift in it. import Data.Char shift_str :: Int -> ([Char] -> [Char]) shift_str num | num > 1 = \str -> shift_str_forwards (shift_str (num-1) str) | num == 1 = shift_str_forwards | num == 0 = no_shift | nu...
Coming from high-level languages like PHP and JavaScript, I'm doing an Assembly course on Udemy. Yesterday I tried to implement the following task: Write a program that takes a number m as input, and prints back 1 to the console if m is a prime number. Otherwise, it prints 0. Original text can be found here (Exerc...
My web application can take URL-encoded strings and return a JSON that contains information, like API calls. My main concerns are with security. I need a cheap and easy (but secure) way to do certain commands. This part is handled by the adminhandle section of the code. My code is currently designed to be able to be de...
I have a method liked_by and it doesn't seem like appropriate as per Ruby style. I need to do it as less as possible. def liked_by if !object.likes.nil? like = Like.where(bonus_id: bonus.id) users = [] like.each do |likes| liked_user = User.find_by(id: likes.user_id) users.push(l...
I am trying to implement multiplication of two numbers without using the * operator, as a practice for programming interviews. I have written two functions. 1) Using Long Multiplication static int MultiplyTwoNumbers(int num1,int num2) { List<int> leftnumber = new List<int>(); do { ...
I want to optimize the below code, I have asked a similar question here. I know this approach is better than my last code but I feel there are ways to optimize this too.This code is used in almost every project and I am not satisfied with this answer. There are not even using last filter results and traversing whole l...
I'm really new with Django and I would like to get your minds, advices, ... in order to improve the first part of my project. For the moment, I created a model form which is named Identity and users can fill the form, get a preview with modification before to submit data. As I said, I'm beginning to use Django and I'm ...
I am a relative newbie to C++. I recently finished a command line program which cracks Vigenere encoded messages from a file by testing each word in the dictionary. I have never had a tutor/teacher for C++, so I wanted to make sure that I don't develop any bad habits. Main.cpp: #include <iostream> #include <fstream> #i...
will you please give your thoughts (code review) on these two way of solving orientation. About the app: We have a universal App. The main purpose of the app is to watch the videos. The app has four screens. Shows the list of shows show the list of episodes in the show details of an episode Player screen The way ...
This is my first program in Swift/Xcode. The full source code and xcode project is available in GitHub. The part I would like reviewed is IOKeyEventMonitor.swift. //Copyright [2016] Jean Helou // //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the ...
After I got this answer, I edited my code after that answer, but the code still seems kind of slow. Can I make any other improvements? And why does the code seem to get slower with every minute? It seems to start great and continue slow. Am I missing something here? using System; using System.Windows.Forms; using Micro...
I have an application which uses SQLite. In that database I have several tables that I need to be able to read and update in my application. Often I need to 'cross-reference' these tables to get the correct values. For instance, I load an interview with answers someone has previously selected. To do so, I have a Result...
I have been learning to code for nearly a month now. Any tips on how I can improve with indenting to help future readers? Snippet body /* font & back clr */ { font-family: verdana; background:whitesmoke ; color:black; } .menu { background: black; width:100%;} ...
I made this AngularJS 1.x filter, to search using a the same SQL LIKE syntax. Right now only the percentage symbol (%) is supported, the underscore symbol (_) is not. Under the hood I'm simply building a RegExp from a format string passed as a parameter (ie. the search string), then I'm looping over all the object prop...
Rather than checking if my angle is in the range of 0 to 2pi every time it gets set, I got the idea to store it as an unsigned short with 0xFFFF being +2pi, thus the standard overflow behavior for unsigned numbers should keep it bound to the desired range. Is it a good idea to do it this way, or is there something I'm ...
After some feedback on my last Ruby Code I decided to start another one with two big concerns in mind: Trying to adequate my coding to the OOP paradigm Trying to follow the Ruby Style-Guideliness I started a small Asteroids remake, trying to make it as simple as I could so I would focus on those things rather than so...
I recently had an interesting requirement in a test environment where I needed to simulate actions at varied (random) intervals in a node back-end. They needed to be sequentially executed, but queued so I could fire and move on. Using a typical timeout/interval here wouldn't work, since if I set a timeout for fn1 to ex...
Lately I've been working on a practice project using JS ES6 to understand it better, therefore I've read a lot about JS design patterns and JS coding strategy. My question is about splitting the functionality of the project so I have to briefly explain to what I'm trying to do in this project. I have an input that gets...
I have a Rails helper that swaps out some text for certain icons. Example: Helper Sample ... '+1' => '<i class="ms ms-loyalty-up ms-loyalty-1"></i>', '+2' => '<i class="ms ms-loyalty-up ms-loyalty-2"></i>', '−1' => '<i class="ms ms-loyalty-down ms-loyalty-1"></i>', '−2' =...
I had an interview yesterday where I had to write an algorithm on the whiteboard for working out if a value is a Palindrome in C#. The pressure got to me a bit but I've written my version of it in Visual Studio this evening. private bool Ispalindrome(string args) { var index = 0; var re...
RetrieveData is a 3rd party API that takes 3 parameters: a buffer, number of bytes to retrieve, and actual bytes required for the buffer. The buffer returned is a non-null terminated unicode string 99% of the time, the buffer is less than 256 bytes, but may be larger and needs to handle this scenario RetrieveData(data...
This is just the server part of a chat program. The user of the server can receive and send messages to all the clients connected to the server. Everything works fine but since I'm a beginner I don't know if I should avoid something or not, what I should improve, etc.. The server class of the app: import java.io.Buffer...
Here is the code for a two-letter word dictionary (example: aa) using array indexing: /* dictionary.h */ #include<stdlib.h> #include<string.h> #include<stddef.h> #define WORDSIZE 2 #define LETTERS 26 #define WORDS LETTERS*LETTERS #define EOS '\0' #define MAXDEFINITIONSIZE 512 typedef struct { char word[WOR...
I've created a Node class and a Graph class class Node: def __init__(self, val): self.val = val self.edges = [] class Graph: def __init__(self, nodes=[]): self.nodes = nodes def add_node(self, val): newNode = Node(val) self.nodes.append(newNode) def add_edge(se...
I have a CSV with around 10,000,000 lines. Each line looks like: keyword1, keyword2, ....keywordn keyword1, keyword2, ....keywordn keyword1, keyword2, ....keywordn keyword1, keyword2, ....keywordn The script which does a frequency count and outputs to another text file: from collections import Counter import csv impor...
Problem statement First version: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BearAndSteadyGene2 { class BearAndSteadyGene2 { /* * Nov. 28, 2016 * */ static void Main(string[] args) { in...
I've just got into Haskell a few days ago and I love it. I'm looking for some pointers and best practices on how to organise and write Haskell code specifically when it comes to managing errors, which I have done using Maybe. The following is an implementation of "select a list from a 2D list, take the last item from i...
My goal is to read complete contact information on an Android application. This is very slow and my understanding is that since the contacts are stored locally in a phone database, it shouldn't take long to fetch complete contact details. public void readContacts() { Log.d("TAG", " -> Into readContacts"); // Ge...
For fun, I decided to inspect the obfuscated source code on TypingTest and figure out how to write an auto typer for it. I came up with the following UserScript. A couple of notes: The site's code simply checks for focus on the .test-edit-area element, and handles each keydown and keypress event that occurs on the ele...
I need to expand logical patterns to list of strings. For example I have the following definition: (expand-pattern '(and "xy" (or "1" "2") (or (and "ab0" (or "1" "2" "3")) "cd01"))) Which evaluates to the following lis...
The program idea is take normal PNG with colour type 2 (Truecolour), decode it to grayscale and perform edge detection operator. I have rewritten code asked here before. Now my mainly concerns are: Style Reasoning errors (algorithms, "Why did you put it there", etc.) Is it ok to have CAPS attributes e.g. IDAT or shoul...
I am new to python from R. They are quite different. I wrote a python code to deal with Excel file. The code was running well, but I think it's kind of the style of R. I want somebody to show me writing the code in python way. The data structure looks like: Name Details 1 AAA first(100%-8) 2 BBB ...
Please review my game. I am learning Python now, so any suggestions are welcome. I am running this on a Linux machine, in Komodo and terminal. #!/usr/bin/python #encoding=utf8 import random # init global variables used for game player = [] dealer = [] class Deck(object): def __init__(self,rank=[], suit=[], whol...
I am trying to create a validation class that can be used to validate many forms of my webpage in general. It makes use of the database as well to verify records. The problem with it is that it looks bad and somewhat inefficient. I couldn't find any alternatives and I have used too many if-else if statements. And also...
I was messing around online at work the other day when our phone systems went down. I came across the R programming language. Now I'm not guru with programming by any means but I like to mess around with different languages here and there, I believe it helps me to become a better programmer. So I decided that I would t...
Here is a simple hex color fetcher and analyzer in javafx that i wrote to understand multi-threading in javafx. Questions: Is my regex ok ? or if it can be improve? I am not much familiar with javafx multi-threading so need know that i am doing it properly or not. Need special attention on prepareTask() method. Is my...
Long story short, the other day I discovered the site LeetCode and started solving some of its problems until I stumbled onto this one. I'll paste the description here: Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementin...
I'm currently working on a website which provides content to users based on their region. As a result the website has subdirectories for the appropriate regions. For example, a pricing page would look something like this: http://mydomain.com/ie/pricing http://mydomain.com/gb/pricing http://mydomain.com/fr/pricing In ...
I have a loop in my main sub routine which creates multiple graphs. This is run across a number of sheets, creating the same graphs for each sheet, but with different ranges and other variables. I have a separate subroutine for each graph (two are shown below, others are similar and can be posted if necessary), however...
For a university assignment I had to plot different polynomial functions depending on one single parameter. That parameter gave the number of supporting points to interpolate a given function in the domain \$\lbrack -1.0, 1.0 \rbrack \$. The supporting points were to be calculated in two different fashions. Either the...
Following your suggestions, I updated my expression evaluator with a Shunting-Yard algorithm. I've created two classes, a Shunting-yard class and a RPNsolver class. The first I mentioned converts from infix to postfix notation and the other solves the postfix expression. I'm open to suggestions of any type. Shunting_ya...
I'm currently working on a WPF application, making calls to various web APIs. Thus, I'm looking after a special observable tasks queue: Progress value must be available Tasks (API calls)/seconds must be limited Failed tasks must be restarted (API calls may unexpectedly raise exceptions) Since the API calls are not v...
I work with an API which answers really slowly. I created a module which constantly asks the API and update some cached value. The code is degraded for study purposes: // module cache.js const Promise = require('bluebird') let results function setter(_results) { results = _results } function recusriveUpdate() { ...
I recently had a requirement to export data to CSV in a different culture & hit an issue (see https://stackoverflow.com/a/40871162/361842). Here's my workaround: function ConvertTo-SpecifiedCulture { [CmdletBinding()] param ( [Parameter(Mandatory,ValueFromPipeline)] [PSObject]$InputObject ...
I have a React/Flux web app and want to follow the architecture best practices: I will focus on one view for my question, the component used to insert/update an entity (a User in occurrence). Everything is working with this code, but the core of my question is about the onUserDetailChanged function in my AdminUserDeta...
Here I am trying to delete a parent node but only if it doesn't have any child node. Please review this code. PostController.php /** * Delete the given post. * * @param int $post_id * @return void * * @throws \App\Exceptions\RelationExistsException */ public function deletePost($post_id) { $relations = ['t...
I am working with Cassandra and using the Datastax Java driver for it. Here is my singleton class where it makes a connection to Cassandra: public class CassUtil { private static final Logger LOGGER = Logger.getInstance(CassUtil.class); private Session session; private Cluster cluster; private static class Ho...
Based on the value of what is in column B (column A is hidden) it groups/colors/removes the corresponding node(s). "R - " values are nodes that need to be grouped. The rows are 6 cells apart before a new node starts. It also adds a formula below the value. I wrote this code and it of course looks messy. I just want to ...
I am trying to write a generic Python script that do the following types of tasks: Load .npy file (the .npy file is of shape (m_samples, channels, row, column), which corresponds to m_samples images, and here the channels are always 1 Check whether a given path exists Iterate against the .npy file, and save each image...
I learned Python and Pygame and now have coded a few games. For the last few months I have been working on this "luck free" pokemon battle simulator. I feel my program runs well in the current state and at the same time is being semi spaghetti-coded because as I try to improve the game I find it more challenging than i...
There are many sorting algorithms, so how about unsorting algorithms? But how could one go about creating a random list of unique elements while not using shuffle, NumPy or any other ready made tools to do it? def get_un_sorted(limit): numbers = list(range(limit)) shuffled = [0] * limit for i in range(limit...
I'm working on a linked list to save the information of students. I can insert anywhere on the list, delete and sort it. Now i'm reviewing the code to try to simplify it somehow. I don't know if the .c's and the .h's of the project are correctly arranged. The program complies and runs as it should. Do you think the me...
I have this JSON schema: { "name":{ "first":{ "attributeValue":"firstName", "attributeType":1, "dataType":1 }, "last":{ "attributeValue":"lastName", "attributeType":1, "dataType":1 } }, "age":{ "attributeValue":"age", "attributeType":...
This program takes a simple nucleotide sequence and finds the most common "k-mers" in the sequence, as determined by the supplied dataset (see below). The goal of the program is to find the origin of replication of a DNA sequence, as it is presumably the most common sequence, or in other words, the substring with the m...
Last time I posted my code of Tant Fant Game. I got some really good advice and I have implemented all the suggested changes to my code. I was wondering if there were any other revisions that would be good to implement? Thanks! =) class board: def __init__(self) : self.loc = ['B', 'B', 'B', '', '', '', 'W'...
I'm creating a C# application that produces unique lines of data. The main purpose of the application is for me to learn C#. The secondary purpose is to have available lines of (dummy) data when testing database development. For this particular question I'm concerned with the most efficient algorithm for incrementing c...
I want to determine whether or not the selected element exists in the list. This is the current procedure that I'm using for finding the element exist in a list or array. Is there any fast procedure for finding an element with any of these? int[] array = { 1,2,9,3,5,6,7,8,10}; boolean isFound = false; for(int i =0; i<...
For the last couple of months I've been working on a python script that pulls data from a specific Trello list and sums up the numeric values by list (lists are split up into months). I've worked on making my code pythonic, basic functionality, separating functionality into distinct functions. It currently only works w...
For a homework assignment I've been given the task of parsing out information from an 32-bit MIPS instruction. (For more information on the instruction formats, see here). The instructor has provided us with a header file enumerating all of the functions required, and it's my job to implement them. Currently, this is w...
Lauren has a chart of projected prices for a house over the next n years, where the price of the house in the i-th year is P_i. She wants to purchase and resell the house at a minimal loss according to the following rules: The house cannot be sold at a price greater than or equal to the price it was purchased a...
Can I please get some reviews and suggestions? This is what this app does: It picks user login from Users table and compare it with the post in the login function. Then it logs in. You can query the payments table for payments in the database and also can update records using the add_rec() function. It's a simple paym...
I am trying to test my first functional tests. I would like to know if my functional test is well done, or if the structure of it is not optimal. Any advice will be useful to me. As I said, I just started writing functional tests, so I have major doubts about my test method which regroups all of a sudden or should it s...
I had to do some maintenance programming on a legacy software recently. Most of the system's logic is done with Java and PL SQL. The Java creates some special kind of XML. These XML is then displayed in the browser. JavaScript is used as a link between does XML-views and the backend Java. The views consist of large f...
This is my first foray into multi-threading, and I'm keen to know if I have fallen into any traps or have room for optimisation/improvement. Example usage: var success = new ConcurrentBag<CourseParticipant>(); var fail = new ConcurrentBag<CourseParticipant>(); using (var parallelEmails = new ParallelSmtpEmails()) { ...
The problem is: Given two strings, write a method to decide if one is a permutation of the other. I wrote the following code in scala, may I know any other optimization one? def checkpermutation(str1:String, str2:String): Boolean=(str1, str2) match { case (a,b) if a==b => true case (a,b) if a.length() !=b.length(...
I have these classes: public class BaseSearchFilter { public int IssueCount { get; set; } public bool IsSelected { get; set; } public string FilterDescription { get; set; } } public class IssueTypeSearchFilter : BaseSearchFilter { public StandardIssueTypeDTO IssueType { get; set; } public bool IsVi...
I'm writing a communications library for a class. Part of the requirements is that semi-reliable communications, which leads me to this monstrosity: unit UDP.Communicator; {$mode objfpc}{$H+} interface uses Classes, SysUtils, DateUtils, SyncObjs, blcksock, fgl, SimpleThread, Common.Types, UDP.Shared; type { TU...
I developed a simple deck shuffle and drawing system, as a test on how to use collections and learn from it. However, I think my code is a bit wonky, and I think here is the best place to get new tips on what to improve. Public deck As New Collection Public face As New Collection Public symbols As New Collection Sub a...
I have some files that I want to process, and I know how to do it in sed/awk (for each one): awk '{if (index($0,"#")!=1) {line++; if (line%3==1) {print $2,$3}}}' q.post > q or grep -v "#" q.post | awk '{if (NR%3==1) {print $2,$3}}' It's one line, and rather beautiful and clear. Now, my main program is in python (...
Time for the most original question of the year: writing a FizzBuzz in Haskell! So here is what I came up with: fizzBuzz :: [Int] -> [String] fizzBuzz xs = [fizz x | x <- xs] fizz :: Int -> String fizz x | mod x 15 == 0 = "FizzBuzz" | mod x 3 == 0 = "Fizz" | mod x 5 == 0 = "Buzz" | otherwise ...
I had a file with 2 hash functions (DJB2, NMEA0183), written in C-like way, e.g. something like this: uint8_t NMEA0183Hash(const char *s, size_t const size){ uint8_t hash = 0; for(const char *c = s; c < s + size; ++c) hash = hash ^ (uint) c; return hash; } Everything looked nice. However, I neede...
I have a problem where I need to replace every base part of URLs in a body of text. However, I only want to replace it in specific URLs. Only URLs that go to "resource.aspx" that have the "source" query string parameter need to get the replacement. Other URLs could have the target base part and we don't want to touc...
This class has the responsibility of parsing a string to one of the primitive types: int, double, float, decimal... While creating it, I have noticed that it'll be terribly ugly. It basically should perform a TryParse of each primitive type and return the first that returns true, along with the parsed value. public s...
I made an autocomplete input box of every town, city and village in the UK. Yes, every single one. The load times are painful so is there a way to reduce that? Here is a sample: <input type="text" id="location" name="locations" placeholder="Edinburgh, Belfast, Cardiff, London"> $( function() { var availableTags = [...
I have written a small program to query the Stack Exchange API, specifically for badges. The main idea of the program is to return the new list of Tumbleweed posts on Stack Overflow, every 10 minutes. The motivation for this bot was the Weed Eater hat. The program queries the API every 10 mins. If there are new tumble...
Exposing Inherited Members I have a WPF Custom Control library (ContentToggleButton) and an app (spec) to test it. The Custom Controls, which derive from Presentation Framework elements, expose inherited properties as well as new properties to the consumer. This means that the consuming app depends on the Framework Ele...
In my code, I use fast method of reading input and a custom model of list. After reading the input into my 'list'. The problem is that, when I test my code, most answers are correct, but for some INPUT my algorithm works slow. I unfortunately don't know the input data, but 6 from 12 tests finished with the wrong time. ...
A magic square adds up the values in each vertical, horizontal, and diagonal row to the same value. In this case, that value is 34. I have changed different indices values and the program returns false. It seems to work just fine. But I'm just learning 2d arrays. Please let me know if you see something wrong, much appr...
I'm trying to write the Josephus algorithm as a project for school, however, I think that there is a better way than what I already have. public static int[] StartTheGame(int prisoners, int count) { var position = count - 1; int[] list = new int[prisoners]; for (int i = 0; i < prisoners; i++) { ...