instruction
stringlengths
71
71.9k
I posted the original question here, but I think it would be nice to have someone else's eye on this code for improving it. public override void Update(UserProfileDto item) { base.Update(item); var memberIntersestIds = _memberInterestService.GetAllPlusDeleted(); var dbIds = memberIntersestIds.Select(p => ...
I have a function that takes an unsigned value and transforms it into a std::vector<std::uint8_t>. The requirements (and post conditions) are as follows: The code must utilize "modern C++" up to C++14 The focus is on readability/maintainability first, performance second The most significant byte must be at index 0. Th...
I'm learning Elixir. while building a trivial cli application (as seen here http://asquera.de/blog/2015-04-10/writing-a-commandline-app-in-elixir/) I'm defining a module that implements a main/1 function that accepts a List as an argument. My question is: What is the best way to pattern match a method against a non-emp...
package com.company; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import static com.company.Person.id; public class Main { private static Scanner in = new Scanner(System.in); private static File file = new File("Addresses.txt"); static List<Person> peopl...
I wrote code for determining the push button state whether it is long pressed or not. This function is called by timer interrupt routine every 1ms. But it seems really dumb. How can I make it shorter and more efficient according to both readability and professional rules? What should I add or change to get double Tap p...
In Swift, should I be posting notifications to the iOS notification center from the device sending a text message or from the device receiving it? I'm using OneSignal, so my code to send a notification from the sender device to the receiver device looks like this: OneSignal.postNotification(["contents": ["en": "You've ...
I am implementing a Request class in my MVC framework that stores all the required information from a page request. It surely does it's job, but I was wondering if this is secure enough. I see alot of people advising against the use of $_SERVER['REQUEST_URI'], since this can be manipulated by the end user. Have I made ...
In this class, the order of the last 3 statements in the constructor is important. If you call OrderedCards = OrderCards(cards, wildcardsCount); last, it will crash with NRE. Is this a bad idea? If so, how should I fix it? /// <summary> /// The abstract result of analysis describing the combination of cards /// </summa...
See here: https://gitlab.com/linted/linted/blob/162b5e9fba53a90b3c6d78e214776e069c3c722b/src/ada-core/src/linted-queues.adb The code implements a concurrent queue. It can't allocate memory or use many other niceties because memory allocations are difficult to reason about with formal methods. So the package has to use ...
Problem: In a grid of nodes pick a starting node(has mode2), and using Breadth-First search, find one with a ending node (has mode1). You can make walls so it's harder for the search. And that inspired me to make an algorithm which creates mazes, so my search will have something interesting to solve. I want to know h...
I have a custom logger which logs all messages at WARNING level and above to a Slack channel. Certain error messages occur so frequently that they make it hard to see actual errors in the channel, so I would like to be able to disable Slack logging for a specific message, using something like logger.error("This is a co...
I'm writing a small custom DSL and interpreter as an exercise in understanding how the language stack (lexer/parser/(interpreter/compiler)) works. Because I want to be able to report the location of semantic errors, the AST needs to retain information about where the elements were in the source. For this purpose I wrot...
Please critique to help me learn: int getNextInt(int* number) { int value = *number; (*number)++; if (*number > 3)*number = 1; return value; } I want a function that will increment an external number by one, when it goes over than 3, then reset it to 1. essentially when I repeatedly call this function ...
I am a system admin, not a developer, so this might be pretty horrible code. This is a password generator. The point of the attempt was to become more familiar with Django at a lower level. I current host Django sites other developers write and sometimes it would help to have a better understanding of how the sites wor...
Problem: Given a picture of square with a bunch of horizontal and vertical lines in it (lines are not necessarily spanning the full square length, in other words think of a fine grid with many holes in it), design data structure(s) representing the data and a function that returns a number of squares pictured. My ide...
I was recently doing a challenge on Codewars and this is what challenge said: There are no explanations. You have to create the code that gives the following results: oneTwoThree(0) → ['0', '0'] oneTwoThree(1) → ['1', '1'] oneTwoThree(3) → ['3', '111'] oneTwoThree(19) → ['991', '1111111111111111111'] I have solved...
Assume a binary tree with a data structure like this: typedef struct binary_node BINARY_NODE; #define BINARY_NODE BINARY_NODE struct binary_node { BINARY_NODE *next[2]; /* 0 -> left */ }; Assume insertions maintain a relevant order, but there is no balancing criteria. removeBinaryNode() takes a node and its paren...
I have a folder which contains lots of files. I need to write C# code that will open and read and display the content of it. Is this efficient code or should something be changed? using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Security; using System.Threading; us...
I am an experienced Python developer learning C. I solved this assignement: Write a program that reads a word and some sentences from stdin. The word is separated by space from a sentences. The sentences are separated by one of the following characters: .!?. Words in sentences are separated by any char for which one o...
I wrote a simple calculator program. How can it be improved? #include <iostream> // get a double value from user double getDoubleValue () { while (1) { std::cout << "Enter a double number: "; double d; std::cin >> d; if (std::cin.fail()) { std::cin.clear(); ...
I am studying computer science and just for the sake of practise I thought of implementing an object pool. This is my first implementation, it is simple and works correctly, but I would love any thoughts on it. Currently, the memory is allocated on the stack, but I am thinking of using policy based design to allow heap...
About half year ago, I derived a integral of a piecewise polynomial, which was a complex formula. Below is one of that formula: Obviously, the above formula has relationship with four varibles \$u_i,\cdots u_{i+3}\$. In the begining, I implement it in Wolfram Mathematica with the help of Compile[] technique and corres...
I have a bit of EF Lambda code which returns a list of data from the db table, then orders by a field called IsDefault At first, the code was var listOfData = Db .TableName .Where(u => u.UserId == userId) .OrderBy(u => u.IsDefault) .ToList(); Which when writing down, sounds correct. However is wrong as...
Currently I'm trying to redo this code to avoid the breaking line because of the 80 characters rule: def decompress_all(directory_path, remove_after): """ """ try: if 0 in [ decompress(file_path, remove_after) \ for file_path in files_within(directory_path) ]: decompres...
I've developed a simple application to grab golfer index scores from a website that has no API. The application works but is very slow, with 6 users that require updating takes 60 seconds. I've tried to make my web requests asyncronous to offset some of this lag but it only resulted in a 15% increase in performance. De...
I'm trying to determine if this code could be a memory hog with huge files. Can anyone tell me if there is anything I can do to make this more memory efficient, or is this how java.crypto works? private byte[] symmetricDecryptAttachment(byte[] encryptedAttachmentBytes, byte[] keyBytes) throws IOException, GeneralSecuri...
please review my code on selection sort algorithm: selectionSort(); function selectionSort(){ var numArray = [4,34,2,5,12]; var MIN = 0; var totalNum = numArray.length, temp = 0, next_position = 0 for(var i = 0; i < totalNum; i++){ MIN = numArray[i]; next_position = i ...
Previously in the Settings JAVA_HOME with batch post, I had created a script in bash to change my JAVA_HOME env variable. Since then, I have been trying to use more and more PowerShell so I recreated the script with PowerShell. The script has several options that provide different functionalities: e or echo : output t...
I am using a global class (like a global model) that acts like a sql abstraction layer for my application. I am using it without problems now, but since the application I am creating is getting bigger, I would like this class to be reviewed if this is really a fine abstrraction layer. I cannot use a proper ORM or frame...
A binary relation \$R\$ on a set \$A\$ is called reflexive if and only if \$R(a, a)\$ for every element \$a \in A\$. I want to know if there can be any improvements made on the function below to make it more efficient. def reflexive(R): ''' @param R : set containing homogenous elements ''' result = [] ...
I recently added Pool Checkers to my Checkers game. My main concerns are about how I manage calling the correct variant in my PublicAPI functions. Because this is a library, any public-facing method in PublicAPI can be the starting point, and because I use pure functions, I have to get the information in every functi...
Here is my recursive implementation of a power set function in C++. One thing that concerns me is that I am iterating over the set of sets while modifying its size. The code nevertheless functions as desired. Any feedback would be highly appreciated. #include <iostream> #include <set> #include <vector> template <type...
I would like to improve the following code: result = database.execute(script, fetch="0") # (6, 2016) for example month = str(result[0]) year = str(result[1]) if len(month) == 1: month = "0" + month return "%s/%s" % (month, year) I'm feeling that my code is dumb, and could be more intelligen...
My script goes through sub folders in my main directory and based on a wildcard checks if a tiff file exists or not, if it exists then the file path is appended to the corresponding list. For example, all the tiff files with "*CRP.tif" wildcard, in all the sub folders, go into CRP_List = []. My current code is partiall...
In terms of performance, what is the best way to bind mouseover/mouseout event on dynamically created elements? This is what I have but I'm not sure it is ok for performance: document.addEventListener('mouseover', (e) => { if (e.target.getAttribute('data-tooltip')) { // Show } }); document.addEventListe...
A thought exercise on my part as I'm relatively new to Haskell. I wanted an interesting project to work on so I decided to implement the Hashcash Algorithm, which is most commonly used as the basis of Bitcoin Proof of Work scheme. I am implementing the original specification that utilizes SHA1 and the description of t...
Using constexpr and preprocessor magic it is possible to cook a struct which have a minimal size between all possible sizes, keeping all the data members properly aligned. #include <boost/preprocessor/seq/for_each_i.hpp> #include <boost/preprocessor/repetition/enum.hpp> #include <utility> #include <cstddef> namespac...
I am filtering out a List<Car> based on the brand. Since each car is made by one brand, I want to make sure my method getCar() is called and just a single car is returned. If it returns more than one car, throw an exception. This is a simplified example, my current implementation is as follows: I have a list of cars st...
I am a Python beginner learning Python 3. I have written two small functions that parse the lsblk output and return Linux physical and logical disks. Here is the first function: from subprocess import run, PIPE def physical_drives(): """ Gets all physical drive names. Gets all physical drive names on a L...
I am learning java and would like to create a very simple application but which uses SOLID principles. The required functionality is: generate the alphabet with a possibility to select specific letters. For now there must be an option to select only even/odd letters but the project must be open for extra functionalitie...
I wrote a very minimal spreadsheet program in Python with tkinter. Here I present the help text: You can use this program to calculate neatly in table format. SPACES ARE MANDATORY: 5 + B1 = # Is correct 5+B1= # Is wrong In order to perform the calculation please end the formula with an eq...
I am currently working on refactoring two methods that exist in directives into a service. This is method one: scope.computeStyle = (component) -> elementHash = {} if component.element.type == 'table' elementHash.height = 600 if component.height? elementHash.height = component.height * 50 else if c...
I'm not very familiar with webpack, and I was very afraid that what I implemented for cache busting would break something. What I have seems to work. When I open up the built folder, under pub, I see 3 files: main.someHashHere.js index.html manifest.someOtherHashHere.js Previously, before I implemented cache-busting,...
I am using asp.net core entitiy framework. The page displays the customers. The user can add new customers or delete existing ones. I am looking for ways to improve my code. Here is my cshtml page @Html.Partial("Index") @model ecommerce.Models.Users <h6>Add a new customer</h6> <form asp-controller="Customer" asp-act...
This is a simple program that I wrote. It takes a 64-bit unsigned int as input and returns its English name. #include <iostream> #include <string> #include <cmath> #include <stdint-gcc.h> using namespace std; int container[7]; /// every element contains a number between 0 and 999 string conv0to19(...
Some days ago, in the middle of a flight, in one hour or so, I've written this basic music player using Python3 and PyQt4. I needed some easy to use music player, so I decided to write this piece of code that just works. This little guy is called Frederic. It uses, besides PyQt for the GUI, a library called mutagen to ...
I have written a class to encapsulate pointers for a platform, where the STL is not available. The idea is to have something similar to std::shared_ptr. However, I don't want to delete the encapsulated object automatically, once the last reference is gone. Instead, I force the application code to do so by asserting. te...
I wanted to create an extension method to enable left outer joins in linq/lambda IQueryables, and I have come up with the following, but I am still not sure it's completely correct. public static IQueryable<TResult> LeftOuterJoin<TOuter, TInner, TKey, TResult>( this IQueryable<TOuter> outer, IQueryable<TInner>...
In this SO question I provided two answers for the batch conversion of more than 100K txt to xlsx files I suspect any automation of Excel is too slow, but would appreciate if there is a superior (i.e. faster) approach using powershell. $files = Get-ChildItem C:\Temp\*.txt Write "Loading Files..." $Excel = New-Object ...
I have a video which I read in a loop frame by frame. For every frame, I want to do temporal kernel filtering, the coefficients of which come from the input variable model (a dictionary). The temporal kernel is an array that has size of 15. So, basically, for every frame we apply this function. The variables scale, cli...
I'm working on the backend of a community radio station website, and fancied trying my hand at writing a drag and drop scheduler. It's working, but I feel I've made a mess with the drag and drop maths. What's the best way to handle an elements position in JavaScript? I've used a combination of offsets from .pageX, .ge...
Spoilers!! (duh..) This code manipulates two HTML number input controls and multiplies them. I am trying my luck on implementing MVC in JavaScript by example. This is a very minimal and useless code! What I am doing is achievable directly; by listening to the "change" or "input" event number-input fires. And here...
I am trying to write an algorithm to solve a variation of the N queens problem. There are only 2 queens on an N x N board. I simply need to find the number of solutions, don't need to know what the solutions are. Below is the code I have so far, and it works fine for N < 100000. However I need to solve it for N > 13045...
Essentially, we must be able to get from one side of the grid to the opposite side of the grid. My code tests for up to down and left to right. However, this is painfully slow and I'm wondering if there's some way to optimize it. I think the recursion makes sense, and it seems to be working properly based on some of th...
Below is my code for generating a random string of random length. I am using it in integration tests. Currently I have almost 2000 tests running each time a commit is made to master and a few of those tests are using this class. I would like to make sure the code is optimized so that the tests complete as quickly as po...
This code creates a text file and writes a given number of characters to it. Is this a good method, or is there a faster method? #include <fstream> #include <iostream> std::ofstream file; int main() { int size = 10000000; //~10MB file.open("text_file.txt"); for (int i = 0; i < size; i++) { file <<...
I have written some Flex and Bison code for parsing a file. The following is a simplified example of the input file as well as the code used for parsing. There are a few things I am not satisfied with: The way keywords are recognized (Marked with [1] in tokenizer.lex), because the rules also recognize the following wh...
I implemented a binary search tree with methods of insert, search, size and print using the << operator. All the methods works with template. main is a simple demonstration of the methods and templates working correctly. Please also review the code formatting. Node.h #pragma once #ifndef Node_h #define Node_h template...
Having a look at my code, is there a way to be losing elements? import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.util.Map; import java.util.Set; import java.util.UUID; public class Main { private final static Map<String, Set<String>> data = Maps.newConcurrentMap(); public...
For practicing/learning object orientation, I made a Card class and am practicing doing stuff with it such as shuffling decks and dealing hands etc... I have a method that receives a list item which essentially is a hand of 5 cards then tells the user how about the hand such as pairs and three of a kind however it feel...
I have written a thread-safe list which can be used as a drop-in replacement for a regular list. This has been tested and used internally without issue, but "The absence of evidence is not evidence of absence" so even though I have had no issues with using this, do you folks see anything wrong with the code? Stepping b...
Right now i have a WPF application supposed to display some media into a WPF Window, from actions in another WPF Window ( for example : you write text in a textbox, you click on a button, and the text is displayed in a textblock in the second Window ). It's working even tho it is completely not optimized, and i would l...
I have the following structure: { "name": "Client Name", "title": "Test Client", "text": "Client Name : Test Client", "client_id": "1", "children": [{ "name": "Customer Name", "title": "Test Customer", "text": "Customer Name : Test Customer", "customer_id": "2", ...
Inspired by this post I looked up A* on wikipedia and went on with my own implementation as seen below where I try to mimic the pseudocode on Wikipedia but in a recursive manner. I would like any comment on functional style, recursion, workflow, event handler etc. My idea is to maintain the current state of progress i...
Anyone following Eric Lippert's blog will know that he has an on going series where he is building a ZMachine in OCaml. C# 7 is another step forward in adding features normally found in functional languages, native tuple support, pattern matching, local functions, etc., so I decided to port Eric's implementation to sta...
This is my first attempt at multithreading in C#. This entire program does several things with prime numbers, but the part I'm going to post is mainly focused with printing out all prime numbers starting at a high number all the way until it reaches 1. This was not originally intended to be a multi-threaded program, bu...
The purpose of the ChunkBuffer code below is to designate a "chunk" from a given input file and to loop that chunk (if needed). Its operation is similar to the following pseudocode, with the important difference that the real code uses a heap-allocated buffer for performance: chunk c; chunk_init(&c, input_file, begin_...
I'm trying to create a logical and scalable many to many relationship data structure in Firebase. A user can authenticate with Facebook/Google, upload 3 photos, and a video. Users can also "star" another user's profile. I've created the following JSON schema, but I'm struggling with keeping flexibility with photos and ...
For a special writing and/or worldbuilding project I have, I created a special program. In the story, different factions have different ideas on what should be considered the first year of their calendar system. For the sake of simplicity, the years are equally long, but the "first year" declarations are different. Thi...
This code is an excerpt from an infinite platformer I'm working on for fun. It belongs to the class GameObject from which every object i.e platforms, player, collectables extends and it primarily handles collision and movement. On each game tick, the collision function is called. It grabs a list of all the GameObjects ...
This block of code is one of my first C header files I have made; it's ported from a Python program I made a few months ago for a project. I was just looking for advice on how to increase the efficiency of the program. I tried to make everything as efficient as possible, but am I missing anything? Also, any suggestions...
This code is very, very simple, but I was wondering how it could be improved: #include <iostream> int main() { std::string input; std::getline(std::cin, input); for(int i = 1; i <= input.length(); i++){ std::cout << input[input.length() - i]; } std::cout << '\n'; return 0; } This cod...
I have an algorithm which generates some cars (quote unquote) and displays them using Graphics. I would like to know if my code is using Random correctly, and if it has any memory leaks. Or if there is anything I did wrong and I should improve. using System; using System.Collections.Generic; using System.ComponentModel...
I'm making some small REST API, which I have never done before. I've got some basic stuff working. Now my job is to add new entities to this, but all my work is reduced to copy-pasting code I have written before with changed schema and entity name. Can I make it more "generic"? Also it's my first haskell program, pleas...
I have created my first project on the github. It is Redis client protocol implementation (request-responce part only). I would like to make my sources more Kotlin style. Please, check my sources and give me some advices. KRedis. Redis protocol implementation by Kotlin Reply.kt package redis.protocol.reply import java...
Based on this Code Review answer, I have created a noughts and crosses game in Python, which asks for an index (1 to 9) and updates the grid, and displays it on the screen. I have done some very untidy programming in places, and would please like some help on how to make it more readable, and avoid repeating statements...
I have made a Python program that can perform some prime number functions. For example, it can produce an endless output of sequential primes. I am looking for ways to make it faster and cleaner. When I was making it, I had a huge amount of trouble using generators, I don't know why, and what the problems were, because...
I am beginner and I want some tips on this code i have written. How can i make it better, shorter cleaner. And the isMobile() Function is borrowed from the internet. It's a Weather App That gets Data from a Weather API and shows it on a Page. You can see a live demo here. // Getting Location of Mobile Client using G...
For a function to determine which element has been removed from a shuffled array, I came up with: def finder(arr1, arr2): l = len(arr1) - 1 result = list(arr1) for i in range(l): current = arr1[i] if current in arr2: result.remove(current) arr2.remove(current) return result[0] In the solut...
I have the following function that takes out the rotation values from a css string and returns them as an array. var extractRotationValues = function(code) { var getAllIndexes = function(arr, val) { var indexes = [], i = -1; //To understand the second parameter of indexOf function //have a look at...
I've two snippets below, the first one output all the keys of a piano and the second one give me a scale when given a starting note. For those who don't know how a piano is structured here is an image of a piano. Basically I want to put each notes, in an ordered array. As you can see the black notes have two names, one...
I have this plain JavaScript library for typesetting pseudocode in HTML documents. (See the documentation for details.) (See the GitHub repository - broken as of now.) Source code algotype.js //// ////////////////////////////////////////////////////// //// // Algotype.js, version 1.6 by Rodion "(code)rodde" Efremov /...
I have a linq query that combines three tables: Users, Products, and User_Has_Products I am retrieving the user.name, product.name, user_has_product.quantity, and user_has_product.time _ ViewBag.User_Has_Products = (from user_products in _context.Users_Has_Products join user in _context.Users on user_produ...
I'm updating a solution that I wrote a while ago. I've got a WinForm that does Update/Insert/Delete on a particular database table. I've got all of the database access code in the form. Is this bad practise? On the one hand, I know you should separate presentation and data access. Also, it would make unit testing easie...
I've been learning java for over a year and I'm looking for better ways to learn and I'm trying to get a better idea of where I am as a programmer. I honestly have no clue if my code is good or bad. I'd really appreciate it if you could have a look at my code and point out anything that's wrong with it. The calculator ...
A Wilson prime is a prime number p such that p² divides (p−1)!+1. The first three Wilson Primes are 5, 13 and 563 and the fourth is larger than \$2×10^{13}\$. I was curious as to how much memory/processing power it would take to calculate the Wilson Primes using a brute force type method. When I was coding this I kept ...
Goal: I am attempting to create a script that would automatically establish a PSSession to a Windows server for implicit remoting. Problem: Export-PSSession : Proxy creation has been skipped for the '%' command, because Windows PowerShell could not verify the safety of the command name. At Z:Somewhere\aScript.ps1:12 ch...
The affine cipher is a simple mathematical substitution cipher. If you're interested in the details behind how it works, this page goes further into detail. After writing a program to encrypt and decrypt text using the affine cipher, I felt that it seemed needlessly cluttered. I have also noticed that there are no ques...
I'm try to get the public IP address from my FreeBSD machine and use it for the rest of my code. Is this implementation good? Can it be optimized more? Can you see some gaps here? Something that maybe sometimes will throw an error? GET.CPP char g_szPublicIP[16] = "0"; char g_szInternalIP[16] = "0"; bool GetIPI...
I am looking for some review of a Minesweeper game that I made as my first JavaScript program. What I have here is simply the prototype for the minesweeper game while I handle the actual grid in a separate section, and I could care less about that. I'm just looking for a few pointers in the right direction in case I am...
I'm relatively new to react and attempted to create a simple Tic-Tac-Toe game. Would be great if i could get some feedback on this. Again, at this point using only React (no Redux). main.js - main file which adds our App component to the DOM import React from 'react'; import ReactDOM from 'react-dom'; import App from '...
I would appreciate feedback on the linked list implementation and usage below for question 2.6 from Cracking the coding interview book. struct Node { char value; shared_ptr<Node> next; Node(char v) : value(v) {}; }; shared_ptr<Node> head; void createSampleList(string str) { auto ptr = head; for (c...
I have made a beginner program using C that uses file handling and formats the given file. Formatting includes removing trailing blank spaces, replacing one or more blanks by a single blank and also wrapping lines. It would be extremely helpful if you could point out the mistakes I have made and also if I add any othe...
I created this using C++ and this gives the largest prime factor of a number.But my problem is if I try to find the largest prime factor of a very large number (12 digit number) it gives an error or it doesn't give an answer. I'm new to programming so please be kind enough to help :) #include <iostream> #include <cmath...
I use the following code in Javascript to get the difference between two Date objects. I want the result to return the difference in: seconds if the result is less than 60 secs minutes if the result is less than 60 mins hours if the result is less than 24 hours days otherwise The code is very long and I see lots of c...
I have implemented insertion sort using C++. Is there any way to improve my code and is it CppCoreGuideline compliant? As I passed the vector as const in print method, do I need to specify const in range for loop? /* * Insertion Sort */ #include <iostream> #include <vector> void insertionSort(std::vector<int> &v);...
I have implemented the Repository pattern in my Web APi 2 + Entity Framework 6.1 + Angular 1.4 SPA site. The application allows management of a martial arts club. One of its functionalities is to allow to handle belt promotions. This involves some validations i.e. You can't add a promotion to a higher belt with a date ...
This is pretty much the first actual (not "hello world") program I'm writing. It's a rewrite of this app and my aim was to increase the fetch speed, and increase the cache storage efficency. I've more or less done this through multiple simultaneous fetches and stripping and compressing the game data. document.getElemen...
Hint: This question is a follow-up to my Code Review question from 09.01.2017: Class sort with BubbleSort algorithm After been showed Mergesort and QuickSort as pseudo-code this week in lecture I had to re-implement my class Sort (which formerly used the BubbleSort algorithm). So that it now uses QuickSort as the sor...
I have a 2-player game of Battleship written in Python, but I've reused a lot of code for the second player's decisions (particularly in the play_game function). I'm not sure if my question is specific enough for this website, but if so would appreciate some guidance on how this redundancy could be minimised. __author_...