instruction
stringlengths
71
95.1k
First, this is my first post on this stack exchange site. So please be patient with me. If there is something wrong or you miss something, please let me know. I will add it asap. I am currently working with the SOLID principles and trying to achieve a practical implementation. I have seen Tim Corey's practical videos o...
Here's an RPG I'm working on that uses only standard C++ libraries. I'm having trouble conceptualizing a coordinate system for characters spawned in a map, and the inventory/item system is only a shell at the moment. However, I've created a small demo including some of the features that will be present in the full prod...
I am a beginner coder and was wondering how to improve my c# console code. It makes a tic-tac-toe game. using System; namespace TicTacToe { class Program { static string[] options = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; //stores the variables to change static bool Playing = true;...
I love the "projections" introduced by the ranges library, and I would like to use them in algorithms that haven't been rangeyfied yet. I had the idea of using them through a function like this: #include <utility> #include <functional> template<typename TFn, typename TProj = std::identity> auto constexpr proj(TFn &&Fn...
Similar Word Finder I created this similar word finder for fun. (word.txt are words from http://www.mieliestronk.com/corncob_lowercase.txt) Is there any way to make this better or more accurate? import java.util.*; import java.io.*; class Main { public static void print(String text, int times) { for (int i...
I put a backtracking algorithm around the Farmer, Wolf, Goat and Cabbage problem - to see if there are any interesting branches, besides the (two) 7-step solutions. WGC Problem: A Farmer with a wolf, a goat and a giant cabbage has to cross a river on a tiny boat that can only carry him plus one of the three cargo loads...
My first client-server application. It's a simple Python script that gets a list of running processes from Server_1 and writes it to a datetime-named file on Server_2, every 5 seconds. I am planning on refactoring this code into one or two functions, maybe one for securing the connection and one for implementing the lo...
I have a simple task. Array of people object comes in, up to a thousand. Need to iterate over it, and create a custom payload for external service. I have created a working solution, but I would like to see if I am totally off course, and what changes should I make. I have reduced non-important details from the code ...
The program transfers a data array from a Zynq-7000 PS DDR to a BRAM IP (block RAM) memory in a PL part of a FPGA due to a PL AXI DMA IP. Inferring a xilinx axi dma driver (not scatter-gather mode), an interrupt controller and the vendor's printf function the data array is carried from the DDR to the BRAM. main.c #incl...
Problem Write a command line application or script which parses a cron string and expands each field to show the times at which it will run. ~$ your-program "*/15 0 1,15 * 1-5 /usr/bin/find" minute 0 15 30 45 hour 0 day of month 1 15 month 1 2 3 4 5 6 7 8 9 10 11 12 day of week 1 2 3 4 5 command /usr/bin/find Code /...
In order to learn Rust I'm going through The Rust Book and did the implemented a program for the following exercise: Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” taking advantage of the repetition in the song. I have decided to use lookup tables for the repeating lines of the song and ordin...
I have been working on a function which I call report. What it does is that whenever I call the report function. I can give it a payload of my dict with some data and as well as reason where I can have custom message or the exception errors of whatever can happened. For now I have created something simple where I creat...
I've just started doing programming problems. https://icpcarchive.ecs.baylor.edu/external/58/p5880.pdf The code below works fine, but my run time is 2.715 seconds and the time limit is 3 seconds. How can I improve speed of this code? I've already started to use sys.stdin instead of input(). import string import sys w...
What do you think about this assignment "idiom"? template <typename ...A> constexpr auto assign(A& ...a) noexcept { return [&](auto&& ...v) // noexcept(noexcept(((a = std::forward<decltype(v)>(v)), ...))) { ((a = std::forward<decltype(v)>(v)), ...); }; } It seems a better alternative to me than the st...
I have a simple service class here which import csv or xml file into database using .NET Standard library C#. Do you have any comments? Are there any recommended techniques to use instead of the switch statement in the method ProcessPaymentFile? public class AbcPaymentService : IAbcPaymentService { private readonly...
I implemented an ExpireLRUCache class, which will clear the data when it times out. There are two ways to achieve this: Use a timer to clear the expire data Call the clean function in Add and Get If I use a struct in class, and it use the template typename, how to deal with this? I put the declaration of Node at the ...
Preamble This is an Alarm Clock app. The way it works is pretty simple: you change the time by pressing the +/- buttons and set the time by pressing the play button. When the time is up, the alarm will ring at which point you can stop it by pressing the pause button. This question is already long as it is so I won't be...
According to https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 an HTML 5 attribute name is defined like this: Attribute names must consist of one or more characters other than controls, U+0020 SPACE, U+0022 ("), U+0027 ('), U+003E (>), U+002F (/), U+003D (=), and noncharacters. In the HTML syntax, attrib...
I've been asked to create some code to help automate the loading of data into a system based on employee data in a spreadsheet. However, the data isn't clean, so some people may have no manager, some may be their own manager, some have managers who already exist in the system, so aren't included in the export, and oth...
const generateFibonnaciSequence = (n) => { return [ (arr = new Array(n).fill(1).reduce((arr, _, i) => { arr.push(i <= 1 ? 1 : arr[i - 2] + arr[i - 1]); return arr; }, [])), arr[n - 1], ]; }; const [fibonacciSequence, fibonacciNthNumber] = generateFibonnaciSequenc...
Example of usage with header: public class AccountBalanceConfig : IExcelTypeConfiguration<AccountBalanceFile> { public void Configure(IExcelTypeBuilder<AccountBalanceFile> builder) { builder .WithHeader(3, file => file.Balance) .Property("Kontobenämning", ab => ab.AccountName) ...
I am working on designing a simple version of a Connect 4 game. Here is my first draft code. I would like some feedback on it, and also required modification for these follow up questions: Add some intelligence in the players to select the column optimally. How will you make the game generic so that it can check for 1...
Hello I have written a multi-threaded implementation of the K-means clustering algorithm. The main goals are correctness and scalable performance on multi-core CPUs. I expect to code to not have race conditions and no data races, and to scale good with more CPU cores. package bg.unisofia.fmi.rsa; import java.util.Arra...
I am using .Net 5, and I am making game server using SignalR core. Ther're 2 ways to inject service to my classes. 1- Constructor injection: where I must separate functions and data, even if it's stored in memory not database. For example: Instead of Room class that contains data and functions, I will be RoomManager se...
I'm implementing a generic (ie. void *) queue in C. I believe I have a working version but I'm looking for two things: Do any subtle bugs pop out to the experienced reader? Can I implement this in a better way (perhaps using void ** pointers? queue.h #ifndef QUEUE_H #define QUEUE_H #include <stdbool.h> #include <st...
I am trying to perform the basic operations + with CUDA for GPU computation. The function vectorIncreaseOne is the instance for the operation details and gpuIncreaseOne function is the structure for applying the operation to each element in the parameter data_for_calculation. The experimental implementation The experim...
First of all I must thank for the help given in the previous post: Class showing a format similar to var_dump RC5 Version I have it deployed in a early versio v1.0.5: https://github.com/arcanisgk/BOH-Basic-Output-Handler As they should imagine; Thanks to your help, the main code has had serious changes; both of logic a...
I am working on a simple to do list and i was hoping if a experienced person could review my code in hope for feedback. I don't use any libraries as i haven't taken time to look about them. I decided to stick with plain js. Thank you for your time. Edit: Thank you for the reply, now i'm looking into the semantics in h...
So this is a project I have been working on for the last few weeks. Just started learning Python. Started out with bash scripting and got the itch to learn more. Anyway code fetches covid-19 data from the internet, assembles data the way I need it to, plots it on graphs that are saved as .png files, writes all the data...
I'm new to Rust and am learning by implementing my own version of cut. This is a snippet that parses the <list> of ranges required for the -f, -b, or -c options. The relevant section of the spec states: The application shall ensure that the option-argument list (see options -b, -c, and -f below) is a -separated list o...
I have some classes with properties, wich could only have numeric values in a given range (e.g. 0 to 8). This should be validated and wrong values prevented with an exception. The given behavior may be implemented without duplicating the given code. There are some ValidatorAttributes in C# but I can't get them to runni...
I'm writing a little library for some undocumented file formats. The original program uses a path string to find files in an archive and this function tries to do the same. The archive contains a magic string, an offset into the file list, the data in the files and the file list itself. A entry in the filelist consists...
This is one of my first attempts at querying the WordPress database for data, and some my first PHP code ever, so please bear that in mind when commenting. It is supposed find data between two dates, and show it as HTML in a for each loop. How can this be made better? What is the correct way to query a WordPress databa...
I am working on a simple CRUD app as a personal project using Flask. I am currently working on the user blueprint and trying to use as less as libraries as I could and no ORM (for learning purposes). On my blueprints, I have multiple folders including a user folder. I wrote 2 classes in blueprints/user/models.py: User:...
The comments in the code kind of explain it. Backspace characters only move cursor back and don't erase output so I need to overwrite them with ' ' to delete them. #include <iostream> #include <string> using namespace std; const string PASSWORD = "PASSWORD"; int main(int argc, char** argv) { string userkey = ""; char ...
a rust exercise in initalizing a 12x12 array based on the algorithm for twelve tone matrix described here: https://www.instructables.com/Create-a-Twelve-Tone-melody-with-a-Twelve-Tone-Mat/ i copy pasted description from there into a comment but the post has pictures which may help you understand. the code doesn't actua...
I found out the hard way, when utilizing pandas is better to use pandas.Series than lists data type to manipulate data. Even if I understood how pandas stores different data types, I did not realize the ramification of using lists of strings instead of pandas.Series of objects. Pandas dtype Like the pic above shows, p...
Just wondering how my code looks, consider it a "professors input" since I'm not taking classes this semester. Also I'd like to note that this will soon be transitioning to a database approach where I use a MySQL database to get the InventoryItems. Inventory.h #pragma once #include <vector> #include <iostream> #incl...
I've written an implementation of setjmp and longjmp in MMIX (assuming no name mangling). I also hand-assembled it. Are there any mistakes anyone can spot? // Memory stack pointer is stored in $254. // jmp_buf is rO, next address after setjmp call, memory stack pointer, // frame pointer, then possibly other...
I've written a script which creates a new database, a table within the database, insert some values into it and fetch the values in one go. The way I've created the script below to achieve what I just said seems not to be an ideal way as there are too many repetitions in there. To be specific this two functions create_...
Using GetEnumerator extensions added in C# 9 I was able to do the following: public static class Extensions { public static IEnumerator<int> GetEnumerator(this Range range) { var start = range.Start.Value; var end = range.End.Value; var current...
I made very simple interpreter in C and now, I want to make my code better. Here is my code: #define size_t unsigned long long int printf(const char *format, ...); int scanf(const char *format, ...); void *memmove(void *str1, const void *str2, size_t n); size_t strlen(const char *str); int main() { char ch[50]; ...
I'm new to coding and have been directed here from Stack Overflow. As I'm new to coding, I'm not entirely sure if my program works completely, but I think it does. I'm looking for suggestions on how to improve my code, particularly the format, as well as the code itself please. Rather than output FizzBuzz for the first...
I have a TCP Listener with NetworkStream that reads 530 bytes from the Client once a second. Within the TCP Listener BackgroundWorker, I write those bytes into a MemoryStream, and invoke a method that breaks down the MemoryStream into smaller arrays. Then, I have another BackgroundWorker that constantly compares those ...
I am trying to implement a tiny image tagger with customized tag options in C#. The main window is as follows. The left block is a picture box MainPictureBox and there are two buttons, PreviousButton and NextButton. Furthermore, there are some tags in a group box AttributeGroupBox. A save button SaveButton is used for...
I am working on a simple CRUD app as a personal project using Flask. I am currently working on the user service and I just finished the registration process. I am also trying to use as less as libraries as I could, this is why you won't see any ORM or Flask-wtf (for learning purposes). models.py: contains 1 class - Us...
I have made most of the review changes based on feedback I have got from here. Now I am back here for a second review to further better my code. Before posting the changes, somethings I haven't changed are the following. I have left the print statements as-is for now. The reason for this is, at times if something goes...
I have a valid code in C-style int arr[10][10] = {0}; // all elements of array are 0 What is the optimal way to do the same for C++ style array? My idea is #include <array> std::array<std::array<int, 10>, 10> arr = {0}; // is it correct?
This is a very simple FFT, I am wondering what I can do to make this faster and more memory efficient from the programming side (better data types, and maybe some tricks like unrolling loops or using the preprocessor if that is useful here), and not by using a more efficient mathematical algorithm. Obviously I would ap...
I'm trying to build an extension method that will allow me to subdivide a huge array into much smaller ones. My current code is the following but it still takes about 2s to generate with an array of size 512x512x512 and the size of the sub cubes set to 32x32x32 public static T[][][][] Divide<T>(this T[][][] array, int ...
Wondering about efficiency here - I have a bit of code that does what I want; but it is terribly slow. I structured the code in a way that made sense to me logically, but I'm wondering if someone else could take a look at the code and find a shortcut or two that might make it faster. I'm guessing that I am referencing ...
I made a multithreaded logger years ago when I was still a total newbie. It "worked" (when it didn't deadlock). Now that I'm slightly less newbie I'd like to get some criticism on this new version. The logger spawns an internal thread on its own method writer(), whose purpose is writing (to console and to file) the log...
I try to solve a kata on codewars which let you write a skyscraper solver for skyscrapers up to size 11x11. Basic Example what is a skyscraper puzzle (here with 4by4 but the principle stays the same): In a grid of 4 by 4 squares you want to place a skyscraper in each square with only some clues: -The height of the skys...
So I have a solution for this which uses a for loop and calculates distance between the main point and other points. I found the code for distance between two points online, changed it to my needs and wrote the rest of the code. While this code works pretty well, I'm just curious if there's a better and more efficient ...
How can I decrease the time complexity and increase efficiency, without writing a new algorithm. My solution solves the majority of puzzles in a fast time, but for some difficult ones it can take over a minute! I have added some of the difficult puzzles below the code. import numpy as np from skimage.util import view_a...
Below is my code for the problem: ItoR = { 1: 'I', 4: 'IV', 5: 'V', 9: 'IX', 10: 'X', 40: 'XL', 50: 'L', 90: 'XC', 100: 'C', 400: 'CD', 500: 'D', 900: 'CM', 1000: 'M' } def convertItoR(number): number_str = str(number) number_len = len(number_str) rom_str = '' for i in range(number_len): # Ex...
A problem from Coderbyte. Find the longest word in a sentence after removing the punctuations and if two or more words are of same length return the first word Below is my solution: def cleanWord(word): # To remove punctuations punctuations = ['!','.','\'','"',',','&'] new_word = '' for c in word: if c in ...
I have recently been in a situation where multiple developers worked on a shared local git repository under the same Linux user¹. As one can imagine, it can easily become a bit annoying not to commit changes as someone else if you don't check the values of git config user.name and git config user.email carefully and th...
https://leetcode.com/problems/sort-the-matrix-diagonally/ A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a...
I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features of customers such as gender and age. The problem is the code takes 200 seconds to just create the network and as I am tun...
I have made the review changes based on feedback I have got from here which was based on the feedback I got from this one. I am almost done and now looking for a final review with respect to any minor or obvious improvements/fixes that can be done quickly. In regard to supporting multiple instances, I have included tha...
This is my code: def add_to_destination_array(destination_arr, src1, iSrc1, src2, iSrc2): temp_array_length = len(destination_arr) while len(destination_arr) - temp_array_length < len(src1) + len(src2): if iSrc1 < len(src1): if iSrc2 == len(src2): destination_arr.append(src1[...
import pandas as pd import pandas_read_xml as pdx from lxml import etree url2='http:' url='http:' tree=etree.parse(url) st=etree.tostring(tree.getroot()) # The list "all_leaves" includes every node and leaf in the tree from io import StringIO, BytesIO #st above is encoded as binary all_leaves=[] events = ("start", "...
This is my second project since I started with Python, this time I learned a little bit of SQL that is so useful and beautifully simple. Starting idea: Generate a program that will store information in DataBase(SQL). Goal: Learn SQL basics and expand my knowledge in Python. After project thoughts: The more basic it loo...
I am simply implementing a filter function for one my forms. I'd like to hear some reviews where I can improve in my code or my functionality :) Summary I have 1 textbox and 2 comboboxes (See image below): Category options Status options Code public MainView() { InitializeComponent(); categoryText.SelectedI...
The question comes from How to separate a list of serial numbers into multiple lists with matched prefix? on Stack Overflow. Input: sn = ['bike-001', 'bike-002', 'car/001', 'bus/for/001', 'car/002', 'bus/for/002'] Intended output: # string with same prefix will be in the same list, e.g.: sn1 = ['bike-001', 'bike-0...
Right now I have a snake game that is working but I need a way to make my code look better and work better. A method I named GameSense is very long and I need a way to make it more object-oriented. I want to use enums. This is what my teacher sent back to me: The game is very nice and nicely working tail! The test you...
I just implemented my memcpy function without any previous lookup. #include <stdio.h> #include <stdlib.h> #include <string.h> void * copy ( void * destination, const void * source, size_t num ) { if ((destination != NULL) && (source != NULL)) { unsigned int *dst = destination; const unsigned in...
I am trying to create a dictionary with a file containing text based on a matched pattern. Lines containing key_str should become keys and subsequent lines not matching key_str should become values and get associated with keys in the dictionary. so i have below code working: But I need help and getting the best practi...
I created a function yes.seq that takes two arguments, a pattern pat and data dat, the function looks for the presence of a pattern in the data and in the same sequence. For example: dat <- letters[1:10] dat [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" pat <- c('a',"c","g") yes.seq(pat = pat,dat = dat) [1] TRUE bec...
I have been building a weather app that changes the background colour depending on the weather temperature and description. This is the code I have to get it to work. const body = document.querySelector('body'); const colorList = [ {weather: 'Clear', color1: '#7AE7C7', color2: '#72C1E1'}, {weather: 'Clouds', color...
I'm just learning the ropes to programming, so bear with me here. I wanted a simple command-line program to quickly convert decimal numbers into either binary or hexadecimal. This is what I came up with, but I know it can be improved. while True: while True: conv_type = input("Hexadecimal or Binary?: ").low...
This is a follow up for C++ Fast Fourier transform . I did end up changing the algorithm slightly to reduce the memory usage. #include <vector> #include <iostream> #include <complex> #include <cmath> #include <algorithm> #define N 1048576 // Problem size, must be a power of 2 #define PI 3.14159265358979323846 typedef...
Dice "Game" So, just started python a weeks time ago, so I'm looking for feedback/critique on things i can do to improve my code. I wrote a little user/pc dice rolling game. Any feedback at all is appreciated! def dice(n: int) -> tuple: """ Simple function to roll 'n' number of dices. Returns numbers of e...
I wanted to know if i have used abstraction and encapsulation effectively here, and if not where can i improve thank you. (follow up from my unworking previous version) MAIN using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Vo...
I have written the following code to achieve the following: Regularly scrape all live matches on the betting site oddsportal.com Pull odds data into data frame Evaluate data frame for two odd providers (Asianodds, Pinnacle) and compare actual data against pre-defined patterns Send a telegram message if a pattern was i...
The problem I'm solving is a more complex version of pairing up opening and closing brackets. Instead of matching only on ([{}]), I additionally need to match arbitrary opening sequences of arbitrary length to closing sequences of arbitrary length, such as '(' which is mapped to ')'. While only the top-level matches sh...
dynamic_pointer_cast is only implemented for std::shared_ptr. I need the same functionality for unique pointers. The wrinkle is that dynamic_casting a pointer could fail (yield nullptr), so what do we want to happen then? I decided that in that case I would like the original pointer to remain unchanged. I have implemen...
I tackled a beginners' exercise: "asks the user for a number and then prints out a list of all the divisors of that number." The workflow I established is: input an integer number, say x; add a variable which value is x/2, say y; declare a divisors list. If x is greater than 4 iterate between 2 and y+1; if the remainde...
This is my first question on Code Review, so please let me know if I botched anything. After working for quite a while on my CS50 calculator, it has finally reached the point where I am completely satisfied with how it works. However, since it is hosted on Google Sites, I'm slightly worried about security issues; I con...
What I have here is a relatively simple endpoint for a small site I'm making. Idea is to take: title content tags and create an entry in the database. It works properly. I threw this together as something that should work and tried to make it clean (like with the error list that gets returned) but clearly I'm doing t...
I've just finished writing a program to help track Pokemon across Soul Links. The goal of the program is to take in the names of the two Pokemon alongside the route that they were caught on. The Pokemon is then added to a table for the user to keep track of whether or not the Pokemon has died. import java.awt.Color; im...
This iterator is designed with one purpose in mind. If before you had an iterator where you could do int x = *it; now you do int x = **make_wrap_iterator(it); This is useful for example if you want to use a range-based for loop to produce iterators to each element rather than values. You could do std::vector<int> sou...
I have two python scripts (or one bash script + one python script) which are working independently from another, one script puts data into a folder, the other one reads from it. Since I don't want to accidentally read from the folder at the same time it's updated, I created this simple folder lock using a dummy file. I...
I have a lot of redundancy here, but I am not sure how could I make it look shorter. namespace Notan { public class EquipmentSystem : ScriptableObject { public UnityEvent onUpdate = new UnityEvent(); [SerializeField] private Weapon weapon1; public Weapon Weapon1 { ge...
I've implemented a dynamic queue with a random-access iterator. iterator: #pragma once #include <iterator> namespace con { template <class T> class rnd_iterator { T *m_Ptr; public: /* * type aliases */ using value_type = T; using iterator_type = rnd_iterator<value_type>; using iterator_category = std:...
Hi I've finished my code but I want to make it shorter and more OOP. Can anyone help me out? The question The cost to become a member of a fitness center is as follows: a. the Senior citizens discount is 30%; b. if the membership is bought and paid for 12 or more months in advance, the discount is 15%; c. if more than ...
"Find minimum path sum" in a 2D grid, is a very popular question which is solved by dynamic programming. But what if instead of the minimum sum value, we return all the actual paths that lead to the minimum sum path? This was an interview question which has been puzzling me. The original problem is : Given a m x n grid...
I've written a function that takes a list of extensions and recursively finds files of those types, and logs their paths to a text file. Usage example (finding image files in a home directory): // set up filestream for unicode const std::locale utf8_locale = std::locale(std::locale(), new std::codecvt_utf8<wchar_t>());...
I am trying to create a program where a user inputs two numbers - a base and an exponent, while exponent is a binary number. Then prints out the last two digits of the result. My code is working well, but according to the time execution it is not the fastest way to do it. I read a little about using Horner's method, is...
Here are ~100 lines of code implementing three classes (ZipRef, ZipIter, Zip) which should satisfy the zip iterator pattern in a STL-compatible way. This means that, unlike boost::zip_iterator, ZipIter can be safely (I hope!) used in various algorithms like std::rotate and std::sort. I tried to embrace the power of C++...
Hey there guys, I have just completed an exercise for uni and I would really like some feedback as I'm pretty new to using java. Areas that I could especially use some input in this instance: readability of the code, the names of the variables, the javaDoc comments, correct use of error statements AND MOST IMPORTANTLY ...
Hello and thanks for clicking! I'm currently studying the relationship between a database and user objects. This is a very simple program and the "database" itself is a dictionary. This will be used in a website (after studying a lot, of course, as I am fairly new to the "programming world", if you will), but I've abst...
I wrote a function to generate a complicated version of the pascal triangle. The generated triangle should look like that: ┌─────────┬───┬───┬────┬────┬────┬────┬────┬───┬───┐ │ (index) │ 0 │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ ├─────────┼───┼───┼────┼────┼────┼────┼────┼───┼───┤ │ 0 │ 1 │ │ │ │ │ ...
I'm brand new and been going through some beginner code problems on checkIO. I finished this one today and am posting because I'm sure there is a much more elegant way to accomplish this, and I think this particular problem has a lot of useful applications. I would like to know what are the 'clean and efficient' ways t...
To summarize what I've been trying to do, I basically tried to make a safe narrow_cast operator, which casts to the Target type if and only if the value is unchanged (not narrowed) in the process, and throws an exception if the conversation will cause the value to change. So I implemented this by making two templates, ...
I want to create a collection (in this case a map due to the extended function 'groupBy') that maps an IntRange to a list of a data class, which members are determined whether an int inside the data class is within the IntRange. The IntRanges are 0..9, 10..19, 20..29, etc. Concrete example: data class Trip( val (.....
I'm new to C++ and I'm writting some kind of chat server and client who talk to each other through commands for learning purposes. I serialize and deserialize these commands using a JSON library. My first approach has been to create a base class called Command and have a derived class for each command. The use case wo...
I'm trying to write a program where computer attempts to guess a number entered by user. Computer should keep asking until guessed number will be equal to user number. If you know what can be improved to make this code more readable, if implementation of the binary search algorithm is efficient, let me know! #include <...
Left limit, right limit and the digit to be counted is entered. This code works only for whole numbers i. e. from 0 to n. This code returns the number of occurence of the digit n in the given range. Please review this code and suggest improvements. #include <iostream> int count_n(int l, int r, int n) { if (r <= l)...