instruction
stringlengths
71
71.9k
I have been learning common lisp and am a newbie, using the great book Practical Common Lisp. There is a once-only macro in the book that I spent a lot of time figuring out how it works. Even after I figured out how it works, I still have to look at it and think for a while every time I come across it. I tried to write...
I have some buttons in my class that show or hide two views (by setting their alpha property to either 0 or 1) when the user taps on them. I have written a function that uses the tag property of the sender of the button (which is passed to the function by default) to identify which view to show or hide: @IBAction func ...
The number is ranging from 1 to 999999999. public class ConvertIntegertoEnglish { private String getCountSuffix(int value){ String word = ""; switch(value){ case 3: word = "Hundred "; return word; case 4: word = "Thousand "; return word; case 5: ...
Whether based on MVar or TVar, async implementation are always based on operation on some underlying monad IO and STM. Making Async a monad on its own, as in F# async computation builder, if done in a naïve way require littering with unsafePerformIO which does not feel very haskellish. module Async2(Async, async, wait)...
I am a beginner in Python and I wanted to see if I could get some feedback on my simple Rock, Paper, Scissors game. I do have previous experience in programming, as I started learning a few years ago but got happy feet and moved through the "basics" for a lot of different languages. With that said, I plan on sticking w...
GitHub repo. main.c #include <stdio.h> #include "level.h" static void flush_stdin(void); int main() { int level; puts("Enter a negative integer to exit."); for (;;) { printf("Enter level: "); if (scanf("%d", &level) != 1) { puts("Please try again."); f...
I started learning C++ a few days ago, and this is my first full program. It takes in words until an end-of-file character prompt is given, and then outputs which of those words are palindromes and the longest palindrome of those words. I want to know if my evaluation for whether each string is a palindrome is acceptab...
Many implementations of Sieve of Eratosthenes (used to find prime numbers up to a given n) use a temporary mutable array to keep track of which numbers are composites. I'm looking to write a purely functional version that has the same runtime complexity: (define (primes-up-to n) (cons 2 (unfold null? ...
Since I've never done any performance programming (Aside from the better choices such as array vs list etc. The real basics.), I should probably read up on it. But I had to start somewhere, so, someone I know - which is a much better programmer than I am - tasked me with making this "assignment": You are given the tot...
I have created an Electron Application with a JavaScript/NodeJS Backdoor and a Ruby command-line listener. I created this program for remote administration of my home computer securely using a new technology (WebSockets) which I found very interesting. The program has two parts: The Electron application written in Ja...
I am working on a Ruby gem to pull data from the Wikidata API. The data is deeply nested, as it contains a lot of repetition. I have written a piece of Ruby (sans Rails) code that enables an array of hashes to be merged together, with any duplicate key-value pairs being stored as an array under the same key. For examp...
I'm a newbie to F# and so I've written a small extension method library to practice the language. The extension method attempts to determine if a url string is for an image. I wrote the code as an extension method so that it can be used as an extension or static method in other .net languages, namely C#. The code...
I'm making a neural network that comprises five populations of feature-selective neurons and one population of non-selective neurons. Each neuron in this network receives connections from c * f * N_E randomly selected neurons from each of the selective populations c * (1 - f * p) * N_E randomly selected non-selective...
In this example, I am only looking for the first duplicate - curious if this logic in for loop (take from the top, evaluate, put on the bottom) pattern has a standard form function findOneDupe(input){ var b = input.split(/\s|\n/).map(Number); b.shift(); for (var i=0;i<b.length;i++){ var e = b.shift(); if ...
The following Bash script takes a single parameter (the PAN) and exits with 1 if the PAN does not satisfy a LUHN check. #!/bin/bash pan=$1 panlen=${#pan} for i in $(seq $((panlen - 1)) -1 0); do digit=${pan:$i:1} if [ $(((panlen-i) % 2)) -eq 0 ]; then #even ((digit*=2)) [ ${#digit} -eq 2 ] && digi...
The problem is that I had an interview for a gaming company and I had to write a prototype of a Match Three style game. The time line was 3 days. I made the code in about 2 days and sent it to them. Then I had a rejection and a comment that my code has "many problems with performance, basic programmers mistakes and pos...
I am trying to prototype a simple structure for a Web crawler in Java. Until now the prototype is just trying to do the below: Initialize a Queue with list of starting URLs Take out a URL from Queue and submit to a new Thread Do some work and then add that URL to a Set of already visited URLs For the Queue of startin...
A couple of weeks ago a company sent me this coding challenge: Please write a PHP web application and send it back to me as zip file: Which waits for a user action, like clicking buttons. According to these actions some data (see further below) should be: either shown nicely formatted on the screen or downloaded as ...
Requirements A function is needed, that is able to parse a list of symbols with the following rules: Symbols may be associated with numbers or not. Numbers are defined by a comma separed list behind the symbol. Numbers may be defined as range (e.g. 3-7 or also 7-3). Whitespaces and invalid tokens should be ignored a...
To get familiar with the Rust language I've decided to implement the method of Sieve of Eratosthenes to find primes up to a number N. I have created the following code that both prints the prime number and whether it is prime in tabular format and prints a vector consisting of the prime numbers. As additional library I...
If I have this simple structure: $ tree . └── project ├── __init__.py └── my_script.py where I want to define __version__ in __init__.py (this allows setup.py, in the parent directory, to import project.__version__): $ cat __init__.py # -*- coding: utf-8 -*- __version__ = "0.1" Now, I also want to use the va...
I have this menu in jQuery that works perfectly, but I think it would be better if, instead of using class="btn-accordion" for each li, I just had a single class="accordion-menu". Is that possible or is the code OK? my html: <div class="accordion-menu"> <ul class="" role="tabpanel"> <li class="btn-accordion i...
This is a Windows Forms application that adds JavaScripts to PDF files. It supports multiple files at the same time. Right now, the only supported script is a "time-stamp on print" script, but any others I add in the future would work exactly the same in principle. My company uses the "time-stamp on print" script for t...
I have following problem: My server (ASP.MVC WebAPI) is tracking, when client application ("Agent") is on-line. It's storing this inf on following table: +-------+-------------------------------+-----+ |AgentId| Date |State| +-------+-------------------------------+-----+ | 1 | 30 may 2016 ...
I am trying to fill a hashtable with LicenseID and FullName when user first logs in. I don't have access to the Licenses database right now. So "Context" is a place holder. I am at loss if what I am doing is kosher. On load of first MVC C# View: MySingleton.GetInstance().BuildAllGrowers(); Here is MySingleton class ...
There are two methods, hash1 and hash2, that return hashes or nil. The hashes have the same keys. I want to merge them with their mean value only if both methods have hashes. (I added Array#mean to calculate the average value of an array). def merged_hashes return if hash1.nil? && hash2.nil? return hash2 if has...
I recently discovered a hugely inefficient portion of code in my program, and have gone about rewriting it. I am however, not quite sure if the rewritten program actually does exactly what I want, due to its (relative) mathematical complexity. I am especially uncertain about how this new code will handle changes of the...
I have a very long sequence of letters (>20000 elements long). I want to permute them so that I have another sequence using the same letters but in a different order but still with the property of no repeats. e.g. ABABABA does not have repeats, but ABCDEEABCDE does as E is repeating itself in the middle. I cannot acc...
I'm reading the K&R book and I'm interested in a program which finds the longest line on the input. I've written the same code as in the book, but I wanted to do it myself. I tried to write my own code to do same thing. I think it's working, but my question is whether my code is "good" or if it's written in a "bad way"...
Here are two implementation of a stack that does Push, Pop and Median in O(1). Invite comments on complexity and betterment. Option - 1 public class MedianStack { private Deque<Integer> stack; private PriorityQueue<Integer> minHeap; private PriorityQueue<Integer> maxHeap; public MedianStack(){ ...
I need some suggestions on my reimplementation of a doubly linked list with smart pointers since I'm new to smart pointers in C++. I read some docs on smart pointers and found out there are shared_ptr<Obj>, unique_ptr<Obj> and weak_ptr<Obj>. I only use shared_ptr<Obj> in my current code, but I'm not sure how to use uni...
This a solution to the shortest bitonic tour using dynamic programming. Bitonic tour starts at the leftmost point then goes strictly rightward to the rightmost point and finally strictly leftward to the starting point. The complexity of this algorithm is . I also use sfml to draw it (Just started using it, this part is...
I am a self - taught coder, and have been learning Java / C# for the last 2 1/2 years (inconsistently). I have recently created a snake game in Java with the help of an online tutorial. I have rearranged the program into separate classes & methods. I am skeptical on how good of a programmer I am, and I code messy. I do...
Wrote a practice code for reversing a string say. Input = "This is funny" Expected output = "ynnuf si siht" This code works for me. Want to know your comments and a better optimised way to perform this. void reverse_string(std::string input) { int N = input.length(); char buffer[100]; char* ptr1; ...
I had previously submitted a tic tac toe code. I followed some of the changes suggested. This is my new code. var playerSym; var computerSym; var turnCount = 0; var playerWin = 0; var compWin = 0; var whoseTurn; var grid = []; var winFlag = false; var playerScore = 0; var compScore = 0; var winningLine; var emptyBoxes...
I wrote the following function to find the longest increasing sub-sequence in an array (tuple, it doesn't work for a list since a list is mutable and it stores the results in a dictionary.). It uses Top Down dynamic programming approach. def LIS(seq, memo={}): if len(seq) == 1: return seq elif seq ...
I know this is a long code and hard to read but when i started working on this it was just a few if-s, and as time passed i added more and more and came to this. Tried refactoring it by my self and anything i tried to do had no effect on code. Switch statements don't work here( doesn't lower amount of lines needed for ...
The past few weeks I've been trying to grasp on nearly any Design Pattern ever invented, but the repository pattern is one I could understand and implement it myself in my project. My application uses the MVC pattern where I've got the "V" and the "C" part covered in a very basic way, and I want to get rid of a single ...
Recently I did an exercise for a interview pre-screening, but was not selected. They did not give much detailed feedback apart from "the code was not up to what they wanted". It would be really helpful to understand as to whether the code written is up to production standards and what is it that I could be missing. He...
I'm getting an array and I needed to find a duplicate ID inside: var aDuplicateId = []; //get the duplicated configuration indexs for (var i = 0; i < aConfigurations.length; i++) { //in case the index is the duplicate array skip if (aDuplicateId.indexOf(i) >= 0) {...
Is it possible to make this cleaner / more efficient? I know that this is probably not the best way to do this and probably could be made better but I cannot figure out how I do that. Basically, a number is given which is then compared to the numbers in Num[] and then returns a color based on that comparison. private C...
Basically, all I have to do is read some xml from a file. And I have a working solution, although I am not sure that it is the best way of going about doing things, as I have only recently started working with xml. Any advice on how I could improve the following? [XmlRoot("iosLayout")] public class iosLayoutXml { [...
This is the problem: Calculate $$\sum_{i=2}^{10^8} s(i)$$ where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$. Quite mathematical, I've found a better way than brute force by using largest prime factor and greatest common divisor. It works fine when n = 100 but still very slow when n gets larger and f...
I was advised by a Reddit user to get my code reviewed on this site. The complete code is on GitHub. # Monopoly Simulator # http://img.thesun.co.uk/aidemitlum/archive/01771/Monopoly2_1771742a.jpg from random import randint piece = 0 jail = 0 iteration = 0 brown1 = 0 brown2 = 0 light_blue1 = 0 light_blue2 = 0 light_...
I am implementing a music player for Windows 10, and I am in a bit of a pickle at the library phase. I am scanning for all the files in a music library (plus optional folders the user selects) and I need to get their tags (only need the title and artist; don't need complex details). The problem is performance. Getting ...
I wrote the following code: var xmlArray = from m in (from row in data select row.Mitarbeiter).Distinct() select "<Value Type='Text'>" + m + "</Value>"; var xml = string.Join("",xmlArray); Then I noticed there are two iteration (two from) and also the Distinct() and I rewrote it using a foreach: var mit...
I have just finished working on a problem on hackerrank dealing with time conversion in C++. I'm still fairly new to programming as I only have a few semesters of programming classes under my belt and had a pretty challenging time with this program. Below is a link to the problem itself and my code. I solved the prob...
I want to find common items between two collection, and set values from one collection to another collection. I am aware of similar posts on the web, but they are different from this post. I want to know if there is a better algorithm or method than my current code below class Job { public Job(int id) { ...
The Ruby on Rails framework doesn't allow you to validate enums submitted through a form in any sane manner. Evidently, enums are meant to be used to maintain internal application state, and are not supposed to be user-facing. Well, in my case it doesn't matter too much, but I still want validations *just in case*. Her...
This is the first time I've tried this. I'd like some feedback on how I did, including any bad practice warnings. For example is it a really bad idea to allow the code to recreate the table if it doesn't "think" it exists? Would it be better to simply create the table once in a different file? <?php /* Database and ma...
I'm trying to get better in Python and decided to rewrite my dice roller in Perl into Python. #!/usr/bin/env python """roll D&D dice""" from sys import argv from random import randrange import re if len(argv) < 2: raise ValueError("args are dice in D&D format like 2d6") for roll in argv[1:]: matched = re.mat...
I've created a simple hangman solver and although I'd consider myself proficient in webdev I am by no means an expert. The trick with this is that since HTTP is stateless, I can't really think of a better way to look words up than to start from scratch each time (and lookup is performed with ajax EVERY time the input c...
I would like to hear feedback from an interviewer's perspective on how to improve the following code: from collections import Counter def word_map(string): word_dict = {} stop_word_file=open("stopwords.txt", "r") stop_words =stop_word_file.read().split() for word in string.split(): word = filte...
I already know how to merge two linked list, but I needed to code a function that'll merge three already sorted linked lists into one. I wrote a code and it is working fine, it takes care of null lists and so. I just don't know if it's efficient enough. What do you think? How can I improve this code? typedef struct cli...
I have written [PHP code][ to upload image/s to server. (To see the result, open the JavaScript console of your browser, look at the Network tab or the Console tab.) The code is also available and runnable on paste.ofcode.org. (Upload images) I would like to know if this code is secure for uploading valid images. <?php...
I'm trying to speed this code up for larger values of N. Any suggestions? I'd like to stick to this implementation and not move on to something more complex like numpy or sieves. Is there any low hanging performance I'm missing? import time start = time.clock() def prime(num, divs): prev = 1 if divs: ...
I watched this video from The Unqualified Engineer on YouTube and tried out the challenge. The challenge (or interview question) is to build a generator that returns all the permutations of the positive integers up to \$n\$ (that is, \$1,2,3,\ldots,n\$). I know about itertools.permutations but want to implement it myse...
Edit: After reading Gareth's answer I have pushed an updated version of the code to github. I needed to shuffle cells from specific columns in several CSV files. One of the requirements was to be able to do derangement (shuffling that leaves no element in its original place), I read about Sattolo's algorithm. So I sta...
I'm just starting out with code. I created a very basic JavaScript calculator. While writing, I couldn't help but think that there must be easier, faster and less redundant ways to write this. For example, when I have to update the display, I have to call the refreshScreen function, which then takes the previous HTML,...
Just looking for some constructive (harsh) criticism of a project I've completed and handed in. This is a theoretical implementation of the system, specifically has a simplified registration number and a simplified driving licence number generator. I've added in the other classes for clarity (and criticism is welcome f...
I'm looking for a structure to store large amounts of strings (5k to 100k) and then test for existence of new strings against the previous inserted data, in the least possible amount of time (memory is mostly irrelevant). The structure would first be fully loaded at the program start, without any queries. After the bui...
A friend and I watched most of the thenewboston syntax videos for Python 3 and spent 2 hours attempting to piece together our first program / generic text adventure. First experience with coding. I'm looking for feedback on silly code and poor conventions. Pastebin class Erdrick(): exp = 0 level = 1 levelu...
After learning about linked list implementations of a queue I was asked to try a resizing array implementation. I'm looking for constructive criticism. import java.util.NoSuchElementException; /** * ResizingQueue - Resizing Array Implementation. * * @author Rocky * @version 2016-05-31 */ public class ResizingQue...
This code checks value's type and cast it into appropriate type, then puts it into a javax.jcr.Node. The checking looks long and boring. Is there a way to refactor it? I'm using Java 7. /** * Set node's property. */ public static void setProperty(Node node, String propertyName, Object propertyValue) throws Repositor...
The Longest Palindromic Substring challenge from InterviewBit: Given a string S, find the longest palindromic substring in S. where a "substring" must be contiguous, and in case of ties the first such substring should be returned. Example: Input : "aaaabaaa" Output : "aaabaaa" My code: class Solution: # @param...
I'm new to jQuery but have managed to get it working the way I want. The problem is, it's a bit convoluted and could easily get out of hand if I add more options. I am trying to show and hide divs based on a user's dropdown selection. I've made a JSFiddle with where I am so far, but I think it could do with some stream...
I implemented type (UserRuleManager) that will apply list of rules to entity User. I need your code review and your advices. Here is usage of that type private void ProcessUser(User user) { if (!_userRuleManager.ApplyGeneralRules(user)) { SetWarning(); } else if (!_userRuleManager.ApplySpecificR...
As I am a novice, I was keen to solve the task, so now I want to optimize the code. Sub AddOlEObject() Dim mainWorkBook As Workbook Set mainWorkBook = ActiveWorkbook Sheets("SingleProfile").Activate Folderpath = "C:\Users\sandeep.hc\Pics" Set fso = CreateObject("Scripting.FileSystemObject") No...
I seem to be in a love-hate relationship with C++. It can make some parts of your code elegant and easy to grasp, and some others become an inconceivable mess. And it's not the language itself causing the problem, but the allure of some language constructs which can lead to many headaches in the long run. I have a coll...
I recently started picking up the Haskell programming language. I've managed to learn other languages rather quickly, but I'm still having a difficult time grasping some of the basics of Haskell. I decided to practice and wrote a program that calculates the Fibonacci Sequence (original, I know) a certain amount of time...
Challenge URL: http://acm.scu.edu.cn/soj/problem.action?id=3330 Windy has a matrix A with size N*M which only contains 0 or 1. The distance between Axy and Apq is: |x-p| + |y-q| Can you help Windy to find the minimum distance between Aij and 1? Output the sum of the minimum distance of all Aij. Input The first line o...
I've been reading the Chapter 8 of this book. Here's the view I'm currently coding. It list all characters/guilds according to the type of URL. /ranking -> List Top 50 Characters /ranking/guild -> List top guilds /ranking/pvp -> list top killers def ranking(request, type): if type=='': queryset_list = ...
I am a computational chemist working with the program Gaussian 09. After I manually check the output(s) I want to create a summary for easier processing of the obtained values. Also avoid opening all the files again and again. The script searches for the last line of the energy statement. A portion of the output will b...
I have an userform that has check boxes where user can decide which worksheets to print. Code in userform: Sub PrintOK_Click() PrintSelection = Summary.value + _ CCSummary.value + _ DivSalaries.value + _ CCSalaries.value + _ PrintAll.value _ ' Displays warning box if no report is selected If PrintSelection = 0 Then ...
This is related to my (unanswered) question here, but the code has changed considerably since I asked that question. I have a method that takes the filename of a PDF file and a Script object, and applies the Script to the PDF. If you are not familiar, PDFs support JavaScript to perform various tasks such as changing th...
The function below is designed to return a UTC offset string, in the form used widely by timestamps, of the user's current time for when only naive date time objects are available (no time zone information). I've tested it on two systems, which are in different time zones, and it works perfectly. However I'd like confi...
This is related to here and here. These two methods are used to programatically add a text field to a PDF document. The field can be of any user determined size and have any user determined title, and will be on the pages specified by an enum value. private void AddFieldToPdf(Field field, iTextSharp.text.pdf.PdfSta...
I was just writing some code the other day, and I found myself writing something I am not sure whether it is OK to do it like this, or not. Let me give an example of what this is: I have this Method: public static string STOLENVersion() { string version = string.Empty; try { ...
This js was written strictly for a visualization of a graph redesign included in a stats report within our game systems. It all works properly, but I know there has to be a much neater way to organize this. I have some ideas, but I don't quite know how to approach it. Any guidance would be greatly appreciated. var ...
I have written my first rock, paper, scissors project recently. I had to use a lot of if statements and System.out.println(); commands in the program. I am wondering what ways I could optimize my program to contain less lines of code/run faster. Are there ways to get the job done using more practical coding techniques ...
I am a beginner with only about 2 months under my belt. I'm learning Python 3 using the Automate the Boring Stuff with Python manual. In the chapter on reading and writing files one of the exercises is to make a program that would fill in a mad lib that was read from a file. It works, but it's not very elegant. Can any...
I'm seeking code review comments for the following implementation. jsFiddle /** * You need to run a number of async tasks, but you're being rate limited. * Run as many concurrent tasks as you can, queueing the rest for when the * tasks are complete. */ /** * @param concurrency: number of concurrent tasks that can be r...
Challenged by Sandy Metz's newsletter, I've tried to implement this kata from exercism. However, my solution, which passes the tests, is quite a lot simpler than Sandy's solution. Ok, so she's using refinements and also supports the inverse, but still... As she's probably smarter than me, do I miss something? class Fix...
Task I have a large spreadsheet where each line should include: The URL of a social media account A field indicating whether the account is "active" A name and UID number for each account I have to find if the activity field is accurate for every account on the list, and fix any mismatches. Code ##### IMPORTS impor...
My code has a nasty smell that looks like this: @RequestMapping(value = { "/updateGraph" }, method = RequestMethod.POST) public ResponseEntity<ArrowsGraph> updateGraph(@RequestBody ArrowsGraph g){ try{ g = arrowsBo.updateGraph(g); return new ResponseEntity<ArrowsGraph>(g, HttpStatus.OK);...
I made a simple program in which I compare two images pixel by pixel and determine if the pictures are the same. I'm trying to adapt it to MPI, but I'm afraid that the communications are taking too long, making it way more inefficient than its sequential counterpart. I have tried with images of very big resolution and ...
Original post here: MIST - auto-implemented, attribute-driven .NET notification mechanism I've developed (and use) an IL "weaving" solution for auto-implementing property change notification in .NET applications, but I'm considering using a different tactic for making the IL modifications. I can replace the InsertNoti...
In C# I wrote a method to move a folder into another existing folder: public void MoveFolder(string folderToMove, string destination) { String destinationFolder = Path.Combine( destination, Path.GetFileName(folderToMove)); Directory.Move(folderToMove, destinationFolder); } Usage: MoveFolder(@"D:\myfol...
I want to convert strings with the iso date format (2015-08-02) to the default format of our app (2 Aug 2015) in ClojureScript. As I don't need anything else, I don't want to pull in libs like cljs-time. I'm quite new to Clojure & ClojureScript, so I want to ask for some feedback on this small snippet. Thanks! (defn fo...
I have recently started writing a userscript for Mozilla Firefox to tighten security and make it more private, but before I want to start publishing it, I would like to have some experts take a look at it to see if I made any mistakes, I am by no means a experienced coder, and this is my first little project. Things I ...
Can anyone here please review my PHP code which preserves line break by splitting the line into as many line break as it have? class PerserveLineBreak { //Preserves line break in HTML element content while stripping by splitting the html element content into two items protected $text; protected $pattern; ...
Both ways work: os.path.join(os.path.dirname(__file__), '../../../testdata')) or os.path.join(os.path.dirname(__file__), '..', '..', '..', 'testdata')) First is shorter. Is there any reason to use 2nd syntax?
As a follow-up to this SO question, I implemented, for my Prolog-based language Brachylog, my own labeling predicate brachylog_equals/2 which is not guaranteed to terminate but works for infinite domains: brachylog_equals(Z,Z) :- brachylog_equals_('init',10,Z). brachylog_equals_(I,J,'integer':Z) :- fd_inf(Z,'i...
I am building an API where the client can send a url and some comma-delimited tags: { "url": "https://www.youtube.com/watch?v=pquxHIBx8ks", "tags": "JavaScript, Sequelize" } Before processing this data, I want to validate the input. To do that, I wrote a middleware function called validateSubmitScreencastReq: i...
I'm trying to cover the following 4 scenarios: No parameters DB param DB param and 1 option No DB param and 1 option So far I have the program working for all scenarios. However, I'm not happy with the way it's implemented. Is it possible to change this to a cleaner solution, rather than checking if there's only 1 pa...
I started taking the Algorithm design class from Coursera. So into the third week they talk about Greedy algorithms and walks through a sample problem. This is the Problem Statement that I could find which was close. Professor Midas drives an automobile from Newark to Reno along Interstate 80. His car’s gas tank, wh...
In web api controller: I am a newer in parallel and Async&Task programming. Need someone help me code review. public async Task<IHttpActionResult> DoWork() { List<string> listTask = await Helper.GetBlockBlock(); userIds = listTask; this.ParallelTaskWork();//step 1,must be finished,but I an not sure when.. ...
I'm solving some online puzzles and I had this problem: Given a vector, write code to find the indices of TWO values which sum to a given number N so if I'm given [2, 5, 6] and N = 8, I should output the 0-based indices [0, 2]. I wrote the following code to do this in O(N) vector<int> twoSum(vector<int>& nums, int ta...
Here is a snakes and ladders game I made using an Arduino using a serial terminal, a set of addressable LED's to create a physical game board, a 7 segment display, and a piezoelectric to create sound. I'd love to get some feed back on this regarding what I did right, what I did wrong, and any improvements that can be m...
I was asked the following question: Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen so far as a list of disjoint intervals. For example, suppose the integers from the data stream are 1, 3, 7, 2, 6, ..., then the summary will be: [1, 1] [1, 1], [3, 3] [1, 1],...