instruction stringlengths 71 71.9k |
|---|
You are a computer science professor at South Harmon Institute of
Technology, and are in dire need of automatic grading! The good news
is you have all of your student's assignments in an easy-to-read
format, making automation easy!
You will be given a list of unique student names, and then a list of
their assignment g... |
I am running through some traditional algorithms in Go, and I was hoping to get feedback on efficiency and optimization.
Below is a basic selection sort algorithm that takes a parameter to dictate increasing, or decreasing order.
// SelectionSort
// in: A = {31, 41, 59, 26 , 41, 58}
//
// Increasing order
// out: A = {... |
This is a solution to the CodeHhef problem FCTRL2 where we are supposed to find the factorial of numbers up to 100. I have tried several techniques but I am always exceeding their time limit (1 second). Please help me optimize this code to make it execute faster.
import java.math.BigInteger;
import java.io.*;
... |
Basically I need to order a list, so that an element is not the same as the element that comes after or before it. I searched for a solution but couldn't find one so I wrote this function myself.
For example, [1,2,2,3,1,3,3] should come out as [3,1,2,3,1,2,3], [3,2,3,1,2,3,1] or [2,1,3,1,3,2,3] and so on.
def unorder(a... |
There have been already many similar questions to this one (e.g. this and this, just to point two), but I did not find any for clojure.
The goal is to compress a string in a RLE-like way: i.e. each character "run" is replaced by the character and the count of the run. Some examples:
aaaabbccc --> a4b2c3
b ... |
The problem statement is :
Given a binary tree, design an algorithm which creates a linked list of all the
nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked
lists).
My Algorithm is to use 2 Queues and BFS to accomplish this. The code is a bit involved and I've tried to make it as si... |
I've got an IDictionary<SomeT, DateTime> that does not always contain the desired key-value pair. For that reason, a target method expects a DateTime? that the default TryGetValue method cannot provide a value for directly, because of the added ?.
I've written this generic extension with main emphasis on the parameter ... |
I wrote this script for a user who wants to toggle the minimized state of a window that minimizes to the tray. The user required a .bat script, so I wrote a bat + PowerShell hybrid script in order to import functions from user32.dll.
<# : minimize.bat
:: toggles minimized state of a window by its filename
:: minimize.... |
I have a slider with 3 images and left/right arrows. If you click on them, the image changes. You also have 3 bullets below the images and the image changes depending on what bullet you click.
I don't want to use buttons "arrows"; I want to use the tag "a." Any ideas on making it better? You'll need to add 3 images "be... |
Please mention anything that could help me.
from easygui import *
import random
choice = ["+", "-", "x"]
question_number = 1
correct = 0
msgbox("This program is to help you get better at doing maths, you will get given a random set of random questions including +, - and x , at the end the program will tell you how man... |
This code is a page scraper using HtmlAgilityPack that creates a DOM document upon construction and allows for node manipulation afterward.
HtmlAgilityPack uses XPath Selectors for selecting nodes.
An example use case would look like:
var me = new PageScraper("http://codereview.stackexchange.com/users/62429/quill", Con... |
Please review my implementation of the Minesweeper game Kata. Any and all feedback will be much appreciated. I would love to hear your feedback on readability, simplicity, performance, and any code smells. I even welcome nitpicking. Overall I want to know is the code clean (I know there is always room for improvement).... |
Next release of Rubberduck will introduce a very cool @Folder annotation system that the Code Explorer will use to organize modules into - you guessed it - folders:
...which is tremendously awesome, because VBA doesn't have any concept of namespace, and the VBE doesn't offer anything better than a "Classes" folder to ... |
I have built a program that handles the basic scheduling requests for CodinGame's Super Computer challenge.
Specifications (taken from CodinGame)
The Goal
In the Computer2000 data center, you are responsible for planning the usage of a supercomputer for scientists. Therefore you've decided to organize things a bit by... |
This is my first Spark Application. I am using "ALS.train" for training the model - Model Factorization. The total time that the Application takes is approx 45 mins.
Note: I think takeOrdered is the bottle neck. it takes 45ms per User for 60,000 Users.
What can I do further to increase its performance? (Decrease time... |
I'm trying to unit test how my class responds to a NEST 1.7 IElasticClient's return values, using NUnit 2.6.4 and Moq 4.2. I feel mocking the Get function requires very "heavy" It.IsAny calls, and am mainly looking for feedback on how to mock IElasticClient in a way that my tests remain readable.
My code is mostly 100%... |
I have two collections - Movies and Watchlist. Both of these have Views that output Movie and WatchlistMovie Views. If you click add on a movie you should see it appear in the Watchlist colum`. If you remove then the movie should be removed. When clicking the add and remove buttons the view should rerender to show the ... |
I have two functions which am currently running separately and would like them to run at once.
The cartMaxCalc calculates and populates column O, then minfinder function uses the calculated values of column O with values of column M to finally set the values of column O.
I am a novice on VBA and would like some pointer... |
I've created a program that will search our work server where Ghostscripts occur. How it accomplishes this is by first sshing to the server specified, running a bash command to search the server for Ghostscripts caused by our guy that uses them, most frequently. If it finds one, it e-mails somebody on my team. It will ... |
I've got this kind of data:
[
{ userId: 1, postId: 1, ... },
{ userId: 1, postId: 2, ... },
{ userId: 2, postId: 3, ... },
...
]
And I need to group them by postId and userId like this:
{
1: { 1: [{ ... }], 2: [{ ... }], ...},
2: { 3: [{ ... }], ...},
...
}
Here is what I've done so far:
var posts = {};... |
I'm re-writing my module of Standard Methods. Virtually every project I do begins with grabbing some number of Data Tables and putting them in arrays. So, this is my general "Get Worksheet Data" method(s).
As always, particularly interested in maintainability, but all feedback is welcome.
Public Function GetWsDataArra... |
I would like to enable application behaviour based on the presence of a custom annotation that marks the configuration class (normally named something like ApplicationConfig.class) in a Spring 4 application.
This feature functions in the same way as do @EnableCache, @EnableRepositories etc, in the sense that adding th... |
I explain everything on my current code but this question is more general "HOW TO" work correctly with this in this case but even next time.
I have 4 methods in my class, each does something but in general this code just takes data from some API and insert it to another database in the right format:
// Getting data fro... |
I created a program which collects all the word files from a folder which belongs to our SharePoint library of documents. The program will only grab the documents if they were submitted/are a part of the HR team.
These documents are saved in a temporary folder, and then merged together into one large pdf.
I thought thi... |
I am trying to create a basic angular template where all files are sorted into a modular structure and referenced using the browserify require method.
I am very new to browserify and the CommonJS-type import system.
Here is a look at the initial structure before I go into details of the file contents:
So to start I ha... |
I have implemented the "Sum All Numbers in a Range" challenge from Free Code Camp quoted below.
The code works like a charm, but I don't think it's idiomatic. The challenge hints imply I should be using Math.max(), Math.min() and Array.reduce(). In addition I used the spread operator from ES6 to simplify both Math call... |
I'm trying to learn Java, so I'm doing a few exercises from a programmer project idea book. This exercise requires that the program be able to convert a decimal number to binary and vice versa, like so:
Please enter the binary/decimal number to convert:9783569
100101010100100100010001
Please enter the binary/decimal ... |
An Super array is defined to be an array in which each element is greater than sum of all elements before that.
For example:
{2, 3, 6, 13} is a Super array. (2 < 3, 2+3 < 6, 2 + 3 + 6 < 13)
{2, 3, 5, 11} is a NOT a Super array. 2 + 3 < 5 is false.
I wrote following code to find the array is Super Array or not . ... |
Some days ago, I put up a question here for review about the best way to handle JDBC transactions in the context of an e-commerce Java web application.
After a kind suggestion from user @gardenhead, I decided to use the try-with-resources construct to automatically close my resources, namely the statement and the conne... |
I wanted to take a stab at implementing a binary search, and here's what I came up with. Is there anything I could have done better, from a code clarity perspective, or code optimization perspective? Any and all criticism would be appreciated:
import random
# implement a binary search
def binary_search(alist, item):
... |
I was writing a function in python to extract original values given a list containing cumulative sum values. For eg -
Given : cumulative_sum = [1, 3, 6, 10, 15, 21, 28, 36, 45]
Output : [1, 2, 3, 4, 5, 6, 7, 8, 9]
I came up with two functions A & B and am looking for feedback on them, especially using xrange() vs enu... |
I was reading about the elementary sorting algorithms like insertion Sort, selection sort and bubble Sort in Introduction to Algorithms by Cormen and I decided to try and implement it in C.
#include<stdio.h>
#define MAXSIZE 100 // Maximum number of elements permissible in array
void swap(int*,int*);
void print(int*,... |
I'm looking for feedback on the actual logic of this simple Python 2.7 script. The automated grader passed it, but I expect it could be make more 'pythonic'. It was written for homework, and some of the constraints included basic looping constructs only and no function declarations. This differs from a simple String... |
I have re-designed my robot walking code from feedback I received on previous question and would love to hear some feedback and pointers.
Main.py:
#!/usr/bin/env python
#
## launch start_robot_controller.launch before running this.
import roslib; roslib.load_manifest('my_dynamixel_tutorial')
import rospy
import math
... |
I wrote a simple 2D renderer in OpenGL that works pretty well. I can render about 16,000k sprites in 1 draw call if it uses the same texture. I wanted to refactor this code out and put it in its own module to make it easier to work with.
With this, I can only draw about 100 sprites before things get really slow:
mat4* ... |
I'm a novice programmer who is very new to JavaScript, and animation/graphics, and I have this breakout game on my flask website.
I tried to do as much as I could from scratch, and I'm unsure if my physics system and especially collision detection are done reasonably well. I get little collision bugs sometimes (a block... |
Is there a better way to check whether a number is a power of 10? This is what I've implemented:
public class PowersOfTen {
public static boolean isPowerOfTen(long input) {
if (input % 10 != 0 || input == 0) {
return false;
}
if (input == 10) {
return true;
... |
Please bear with me, I'm only about a week into Python.
This code is something that I wanted to do once I completed the chapters dealing with opening and reading files, and RegEx. I always feel like I'm over complicating the code. Please take a look and let me know if this is sound and where it can be improved. There a... |
This function is meant to be used for reading files. It returns all bytes asked unless EOF is reached. It handles interrupts and returns -1 on errors.
//safe function to read all bytes asked, only returns less bytes if EOF
static ssize_t read_all(int fdes, void *buffer, size_t size)
{
ssize_t ret;
ssize_t ret2;
... |
Write a method getExponent(n, p) that returns the largest exponent
x such that px evenly divides n. If p ≤ 1 the method should return -1.
getExponent(162, 3) returns 4 because 162 = 21∙ 34, therefore the value of x here is 4.
if n is 27 and p is 3, return 3 because 33 divides 27 evenly but 34 does not.
if n is 28 a... |
The method SaveGroupStepPermissions(...) is a database API class.
If an error occurs within the method the exception is trapped. Whether this is good design or not is not the scope of this question as I need to adhere to product guidelines.
I feel that this method is to complex and too lenghty. The obvious solution is ... |
I am new to Javascript and HTML. I have written code for a calculator, so review my code and points out pros and cons in it.
(function ($) {
var shiftflag = 0;
var fontreducer = 0;
$.fn.close = function () {
$("#dragging").remove();
};
$.fn.calc = function () {
this.remove();
... |
Restricting types not related through inheritance without using instanceOf by creating own class hierarchy. It needs to interact with a key value data store, will convert to object before putting, but needs to convert back to fields after getting from DB with Function<Object,Field>. Something about this with regards to... |
I need to delete all the orphaned SIDs in the ACLs of about 20 shares (between 100GB/6TB) and change full control of users groups to other permissions (modify or read/execute). I have done this script but I'm pretty sure it's easy to improve. Any advice?
$root = "\\192.168.1.1\folder"
$log = "C:\log.txt"
#log creation... |
This question is really similar to an existing one in Ruby. So the task is also the same: Day 8: Dictionaries and Maps!
The problem is that on Hackerrank my solution only passes the first and last testcases. All the other ones between them are timing out (>12s!). I tried to use map instead of dict and also read the que... |
I was given a practical task as part of an interview for a front-end developer position. There is a follow up interview and I'm looking for some constructive criticism / tough love to help me prepare.
The guidelines were:
Should work on IE8
Use CDN's for external libraries
Use whichever library(ies) you prefer
Should... |
I wanted to have a DialogService that can return an arbitrary result. The views to be displayed are implemented as UserControls, and UserControls cannot close themselves (nor directly the parent window), so I decided to do the closing of the window via the DialogService. The UserControls do not have a ViewModel.
So I c... |
An element in an array X is called a leader if it is greater than all
elements to the right of it in X. The best algorithm to find all
leaders in an array.
Solves it in linear time using a left to right pass of the array
Solves it in linear time using a right to left pass of the array
Solves it using divide and c... |
This code is python 3X code (in django).
It takes an instance of user entry, and process images: it creates a resized version of original image, 2 thumbs, saves all, and update instance fields to point to correct files so it's correctly saved.
Then it returns the updated instance.
I'm not sure this code object oriented... |
Is there any security threat here?
$con = mysqli_connect("***", "***", "***", "***");
mysqli_query($con, "set names 'utf8'");
$id = $_GET["id"];
$result = mysqli_query($con,"SELECT * FROM document_$id");
while($row = mysqli_fetch_array($result)) {// echo table }
I am curious about my use of the $_GET variable, since t... |
I'm working on reworking our website from a WYSIWYG editor to MVC. I'm all right with server side code, but complete rubbish when it comes to client side Javascript, so I'd appreciate any/all feedback.
The goal
Embed this rss feed from our blog into a page on our main website.
So that it looks like this:
Design choice... |
I'm trying to figure out whether I can speed up passing large int and float lists to my foreign function:
from ctypes import cdll, c_uint32, c_float, Structure, c_void_p, cast, c_size_t, POINTER
lib = cdll.LoadLibrary('whatever.dylib')
class _BNG_FFITuple(Structure):
_fields_ = [("a", c_uint32),
(... |
I came up with a validation design for my project and wanted to hear if there's anything I could improve.
Here's how it works. I have the models (code first)
public class Item : IEntity<Item>
{
public Item()
{
}
public int ID { get; set; }
public string StoreCode { get; set; }
public string UP... |
I'm creating a script to turn into a commandlet we can reuse as part of our custom PowerShell module. This works, but is very slow. I don't suspect it is anything to do with my code. I have to individually load each site to retrieve the title even though this property is visible off the $site object, it is always empty... |
I am doing a controlled assessment and one of the tasks is that we have to sort the saved pupils scores (numerically), and their names (alphabetically) in a .txt file. Any other improvements to the code would also be greatly appreciated.
import random
classcheck = False
while classcheck == False:
classnumber = inpu... |
One of my friends told me that my validate.php file has some problems with SQL injections. Please feel free to commit it on GitHub.
<?php
session_start();
error_reporting(0);
include("../config.php");
$conn = new mysqli($hostname, $username, $password, $db_name);
$query = mysqli_query($conn,"SELECT * FROM `Admini... |
I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's not optimal, in terms of computational complexity). After consulting #racket and reading the first half of Greg Hendershott's Fear of Macros, I was able to w... |
I use this database class in a CMS, just a project to learn OOP. Would like to have some review on how to improve it, what should I change, add, remove?
<?php
namespace Core;
if ( !class_exists( 'DB' ) ) {
class DB {
private $cxn;
public function __construct() {
$this->connect();
... |
I have a for loop implementation for merging documents and page re-numbering. But since I am modifying the collection while iterating, I suspect that the code might break. As foreach doesn't allow collection modification, I have implemented it with for.
Is there any better way to implement/optimize this part of code? A... |
I have written a scraper in Python 3 using Beautiful Soup 4 to retrieve the latest version of Plex Media Server from https://plex.tv, and I'd like some feedback on how to improve it.
The HTML the parser is to be used on can be found at here (the section of code that downloads the HTML itself is not included in the pars... |
I am working on a code project that checks if all the characters in str1 can be arranged to form another string (str2). If all the characters in str2 are present in str1 (including any repeated characters in str2, i.e. if str2 has two 'a' characters, str1 must correspondingly have two as well), then the function retur... |
I have been writing some code to add to our company's Bill of Materials template Excel file. Every project that we do has its own unique Bill of Materials. I am attempting to make it more dynamic and to add some functionality that it didn't previously have. I have created an add-in BOM MACROS.xlam that each user will a... |
This is a follow up to this question.
I have implemented changes to the code as they were suggested in the previous question and have made a few changes of my own.
But it has been mentioned that the code snippet posted in the previous question was not sufficient to considerably affect code performance. So here, I'm pos... |
I was asked to make a view which is a mix of HTML & ERB logic available in multiple views. At first this seemed pretty simple. However, some of these views required the output to be plaintext instead of HTML & ERB. The rational behind this was that the strings can be added to, removed and updated in one place rather th... |
I am working on a plugin for a Minecraft server. In it, I have a function that returns a ChatColor depending on what permission level you are.
Whenever I need reference the user with proper colors, I always get a color from the below function.
/**
* ChatColor
*
* @param Player
* @return ChatColor
*/
public ChatCol... |
I'm fixed on the save file format. There are only three types of data:
long (NumPy int32 array, independent of platform)
double (NumPy double array)
string (UTF-8, but ord(c) < 128 for all characters)
whereby the first two get saved in their binary representation. Strings get saved as string and are preceded with an ... |
I'm trying to implement a dot product using pyspark in order to learn pyspark's syntax.
I've currently implemented the dot product like so:
import operator as op
from functools import reduce
def inner(rdd, rdd2):
return (rdd.zip(rdd2)
.map(lambda x: reduce(op.mul, x))
.reduce(lambda x,y: x + y)
... |
This code is used to toggle some dropdowns. I've added the click event on the document to close the dropdown on click outside, but I'm not sure if I'm doing it the right way. I want it to be optimized for better performance.
Let me know if you have a better way to bind/unbind the events.
$('.header-top-bar .toggle').ea... |
let shuffley (numbers:int list) =
let rec loop numbers acc =
match numbers with
| head::tail -> loop (List.rev(tail)) (head::acc)
| [] -> List.rev(acc)
loop numbers []
shuffley [1;2;3;4;5;6;7;8]
I am trying to practice some F# and I was wondering if could be a good example of tail recu... |
I've been rewriting this same sort of thing off and on over the years, but finally here's the "perfected" monstrosity. Some kruft in the middle with attempting to predict the number of spaces that will be set on the final line. But since that figure is always wrong, the line data structure has to be scanned anyway. So ... |
Like other posters, I'm currently working on recreating Google's Homepage for The Odin Project.
I'm new to HTML and CSS but I'm eager to learn and have been looking around for an answer, testing different code, and pacing back & forth - I'm still stuck.
I'm having an issue with positioning things on my project. I've re... |
I am trying to speed up the runtime of my program as the API can make calls. However after adding the inserts to a database 3 mins turns in 7 mins after 180 API calls, which can be one a second. How can I further improve the inserts into the DB?
I am using mysql database, but potentially could change if it will incr... |
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared
are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors
is 2500 which is 50 * 50, a square!
Given two integers \$m\$, \$n\$ (\$1 \le m \le n\$) we want to find all integers between m and n whose sum of squared divisors is itself a... |
The problem statement is:
You have two very large binary trees: Tl , with millions of nodes, and T2, with
hundreds of nodes. Create an algorithm to decide if T2 is a subtree of Tl.
A tree T2 is a subtree of Tl if there exists a node n in Tl such that the subtree of n is identical to T2. That is, if you cut off the... |
I am having some major issues with scrolling in my active app "Amanda's Relationship Tips"
Under the User Advice tab:
I'm using the Parse Database as a backend to pull user data. This lag is presenting a huge problem with Overall User Experience and I want to solve it, but I'm coming up short. I think (90% sure) tha... |
Just wondering if this is okay to do? I have to store some PHP variable values into LocalStorage.
if($res->status == "success"){
echo '<script>alert("alrighty sparky! lets get you in...");</script>';
echo '<script>localStorage.setItem("token", JSON.stringify({"token": "'.$res->token.'" }))</sc... |
This is my code to populate a Class and later convert it to JSON object.
public List<CSATGraphJSON> convertListToCSATGraphJSON(List<Object[]> list) throws ParseException{
List<CSATGraphJSON> customers=new ArrayList<CSATGraphJSON>();
//going through each list of object
for (int i = 0; i < list.si... |
I've been studying Haskell for some time, but I have never used it for real. So, I started following the CIS 194 Course from UPenn. I resolved the second homework but I'm not fully satisfied with the parser I came up with. I think it's way too verbose and I don't like the way the message string is passed around. I am a... |
Any suggestion is more than welcome! I had to do a few tricks in rewrite rules (checks on ENV:REDIRECT_STATUS) to avoid infinite loops, but it works fine.
error.php
<?php
$code = 0;
if (isset($_GET['code']))
$code = (int)$_GET['code'];
else if (isset($_SERVER['REDIRECT_STATUS']))
$code = (int)$_SERVER['REDIRE... |
This question regards the C implementation of the python code posted in this other question of mine, hence the explanation of the task at hand will be the same:
The problem
I need to process the data contained in a (relatively) large binary file.
The file has the following structure:
40 bytes of initialization,
4 byte... |
I want to use something like Setting.RES_WIDTH in my code without the need for a getter function (i.e.: custom getter, enum's .name(), .toString() or .valueOf()).
Someone suggested using a final class, so I wrote this:
public final class Setting {
public final static String RES_WIDTH = "resolution_width";
... |
An array is defined to be maxmin equal if it contains at least two different elements and the number of times the maximum value occur is the same as the number of times the minimum value occur. So {11, 4, 9, 11, 8, 5 , 4, 10} is maxmin equal, because the max value 11 and min value 4 both appear two times in the array.
... |
I am currently doing projects in freecodecamp.com to brush up on my javascript skills and just finished a weather report widget. It does the following:
Gets api from openweathermap.org and displays the weather based on
user's latitude and longitude
Displays the city, weather description and wind speed
Can toggle bet... |
I want to know is it possible to re factor my code in such a way to remove duplication of almost identical statements, bar the variable name and what it is initialized to by using methods. Here is the code in question:
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.GridL... |
I'm an intern in an industrial company in Brazil and it happens that I'm using excel a lot. I just started playing with VBA couple of days ago, and I'm amused of how many things it can do for me!
I don't have a strong programming background, so I'm learning by doing. The code is working fine and it takes less than 15 s... |
I have php function that compares two different database table. Any suggestion on improving it.
public function comparePartyTableCandidates()
{
$electionCandidates = ElectionCandidate::all();
foreach($electionCandidates as $electionCandidate )
{
$candidateName = $electionCandidate->C... |
Having been informed that sp_MSforeachdb is undocumented and unsupported, I have been working on creating a replacement stored procedure based off the work done here.
Is it ok as it is? I'm concerned about:
Using cursors
That the error raising may not iterate through stored procedures or when executed via SQL agent
La... |
I have a method in which I am accepting a String clientId and that has below requirements:
clientId can be a positive number greater than zero. But if it is negative number or zero, then throw IllegalArgumentException with a message.
clientId cannot be a null or empty string. But if it is, then throw IllegalArgumentEx... |
If you have a given list of lists what's the best way to sort them proportionally? Is there a better way to do this?
The idea is that in a case of web scraping, you would want to avoid hitting google all the time and want to distribute calls so that they are as even as possible.
Is this a thing that can be done more ef... |
I've been trying my hand at some simple problems on the website topcoder.com. I've been able to solve most of the problems I've tried so far in the Easy/Medium section, but I'm scoring very low. The points are based on running time and the amount of memory used by the program AFAIK.
This is a quick piece of code that I... |
For development I'm using timer classes that are based on Win32 functions like QueryPerformanceCounter() or the time stamp counter of Intel-compatible CPUs. However, for self-contained little test programs that can be posted here (or put in a place like PasteBin and linked) I'm looking for a replacement that does not r... |
I recently started with object oriented programming in PHP and I am wondering if my database class is on the right track.
Am I doing something wrong? If so, how can I improve it?
Here is the class:
<?php
class PDOC extends PDO{
private $myselhost;
private $dbname;
private $myseluser;
... |
I recently learned about linked lists and here is my first try to write one in C. I know it's a lot of code, but I hope someone takes a look. Any tips memory allocation and improvements are welcome.
SinglyLinkedList.h
#ifndef SINGLYLINKEDLIST_
#define SINGLYLINKEDLIST_
#include <stdlib.h>
#include <stdio.h>
typedef s... |
I have to pass a bunch of inputs and outputs between two Angular controllers and I've come up with a way to do it using $broadcast. I'm using an "if" statement to make sure the inputs match the outputs, but there must be an easier way.
app.controller('Ctrl2', ['$scope', '$rootScope', function($scope, $rootScope) {
v... |
This code works and does exactly what I want it to, but I feel that it is inelegant. It seems like there should be a way to use get() and/or setdefault(), for example. All comments and suggestions are appreciated!
Here is a function that builds a dict. The dict's values are also dicts. Some of the values are empty ... |
My goal here is pretty simple, I want to turn a number like 12435987234 into an array of integers in reverse order. So that would look like:
[4,3,2,7,8,9,5,3,4,2,1]
I want to do this without changing the number to a string and back. Really, I don't want to convert it at all but I'm open to hearing ideas around this.... |
Any feedback encouraged. My checkForWinner function feels cumbersome to me.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var buttonOne: UIButton!
@IBOutlet weak var buttonTwo: UIButton!
@IBOutlet weak var buttonThree: UIButton!
@IBOutlet weak var buttonFour: UIButton!
@IBO... |
I made a simple 8 puzzle which is 3x3 grids unsorted. The user has to move only one number at any direction, which is next to an empty tile. If the user sorted numbers, he/she wins the game, otherwise he/she needs to restart the game.
The game seems to work fine, but I would like to know how I can improve it further.
#... |
Inspired by a tweet linked to me by a friend and a Haskell implementation by her for the same problem, I decided to try my hand at approximating the value of π using everything in the Haskell standard library I could find for the job. Here’s what I came up with:
module Pi where
import Data.List (genericLength)
import ... |
I made a simple program that uses OOP methods. Please tell me if I used the 4 methods right. And if not, please show me how.
class Encap{
private String name;
public void setName(String newValue){
name = "Hello, "+newValue+"!";
}
public String getName(){
return name;
}
}
abstract c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.