instruction
stringlengths
71
71.9k
I recently found a static C function on Stack Overflow which returns a UIViewController reference from a containing subview using the responder chain: static UIViewController *viewControllerForView(UIView *view) { UIResponder *responder = view; do { responder = [responder nextResponder]; } whil...
I am new to python so I decided to write a script that parses a json array and writes data in a file. I wrote the code that does that but I think it can be done way better, So I was hoping to get feedback on how this code can be enhanced and more inline with python best practices. from urllib2 import urlopen import jso...
I recently came across this problem that asks you to print the number of leaves not eaten by the caterpillars: As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, eats as much of it as it can (or wants), then stretches out to its full length to reach a new leaf with its front end, ...
This is now an Iterative Review. Next Iteration Nowhere near a full game yet. Just a basic overview and initialisation of a Snake() class. Thoughts? Snake.py import numpy ''' Game Board: X by Y array of numbers Derived from Snake Object and base parameters (height, width, obstacles?) Board Values: 0 - E...
I want to check a string by using multiple search patterns and split the string at every occurrence. I'm using RegEx and it works fine. But I'm worrying about efficiency and performance. struct StringPart { let text : String var matched : Int // index of pattern let pos : Int init(searchText: ...
I am in the process of creating a brain-computer interface, and one task is to stream electroencephalograph (EEG) data into a Python script for real-time analysis. Included in this question are two Python scripts: (1) to generate and stream fake EEG data (32 random floating points for testing purposes), and (2) to rece...
I wrote code to determinate ranges of char,short int and long variables,both signed and unsigned.Please help me to improve my code :) Here is the code: #include <stdio.h> //function declerations... long power(int base, int power); int main(void) { //From 2^(N-1) to 2^(N-1)-1 (Two's complement) int intmin = po...
I needed to create a basic JDBC helper class for our JDBC connection and wanted to know if my design is appropriate or needs cleans up? Just a basic JDBC utility class which helps reduce the boilerplate code that JDBC has. public class JDBCUtils { /** * Retrieves a connection from the given pool. * ...
I have a spreadsheet where I control my shift hours. In such spreadsheet I input the date, the start time, time left for lunch, time back to work, end time and sometimes the overtime. After that I have created a couple of functions to calculate the amount of time worked, the difference against the 8-hour shift expected...
I'm writing a console blackjack game. To hold all the possible moves a player can make, I have a map that maps a keyboard key to a move keyword: (def move-map {\s :stand \h :hit \p :split \d :double}) Splitting and doubling are only available options during the first move t...
I just now got around to implementing a full snake game in Pygame. The player can move his snake with the arrow keys and as in the original, the snake continues to move in the direction of the last key pressed. Dark Green : Snake Head Light Green : Snake Body Red : Fruit The player can adjust the snake speed based o...
I have a moderate size sub-procedure where I am calling multiple functions to feed values into other functions. I feel there may be a better or more concise way to present and run this module, but have refactored the code as far as I can see. Public Sub CompareArrays() Dim matchCell As Range Set matchCell = Th...
I have a 9-dimensional signal (as a csv from this Gist) that looks like this: A signal peaks every 30 steps. I want to get the maximum values of the peaks in that 30 second window. Here's what I've hacked together so far, where sig is the signal loaded from the csv file and max_res is the desired result: trial_num = 8...
I'm currently using a PHP shopping cart, and finally decided to implement a search suggestion feature. There are some already available solutions out there, but I wanted to gain control over how mine is implemented and how it functions. I'm asking for some assistance here and code review on two things: Can anyone spot...
For a given binary tree and a sum, I have written the following function to check whether there is a root to leaf path in that tree with the given sum. /* //A binary tree node struct Node { int data; struct Node* left, * right; }; */ bool hasPathSum(Node *node, int sum) { if(!node) return sum==0;...
I am only a beginner when it comes to programming, but after reading tons of tutorials on and offline, I have been able to create this simple math quiz. It does work as intended, and I'm really just fishing for someone to yell at me for doing something glaringly bad practice in the code below. using System; namespace ...
Link to original question: Successful use of strtol() in C After getting excellent feedback from the code review community I attempted to redo my string to long conversion program! I believe I enhanced it significantly(Most ideas from answers on my last post) but I did add my own 'style' to it and am looking to see if ...
Recently I came across this problem , A despotic king decided that his kingdom needed to be rid of corruption and disparity. He called his prime minister and ordered that all corrupt citizens be put to death. Moreover, he wanted this done quickly. The wily prime minister realised that investigating every citizen...
The following function computes a the last element in a Fibonacci sequence in Go language. package main import ( "fmt" ) type Element struct { Next *Element Value interface{} } type Stack struct { Top *Element Count int } func (stack *Stack) Push(value interface{}) { el := Element{ ...
I'm not sure if this is the right subsite of stackexchange because it's not only about code review but a bit about design eihter. I'm currently developing a network application. I need to connect a (java) server with a tcp socket. I implemented two different variants of my client. One uses a blocking socket with thread...
The function of this program is repeatedly prompting a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. Suppose all input is proper, so we do not need to check whether the input value is illegal or not. largest = None smallest = None whil...
hey guys how you all doing, I built a spider that crawls through a house price website and stores houses address and transactions on it, through a bunch of functions, and I was wondering if anyone could help me refactor it, possibly pointing me in the direction of an OOP spider, so it would be easier for me to make an...
(See also the next iteration.) I have implemented NBA* (New Bidirectional A*) in Java and compared it against conventional A* and Dijkstra algorithms. The results may be as optimistic as this: Seed = 8900460676230 Created the graph data structures in 2989 milliseconds. Source: 80939 Target: 72799 A* in 120 millisec...
Task: Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water, Sprite, ... , Whatever). Then allow the user to choose a beverage by entering a number 1-5. Output which beverage they chose. ★ If you program uses if statements instead of a switch statement, modify it to use a...
I'm new to computer vision and numpy. I wrote a simple script to seperate red, green and blue colors from the original image by using the kNN algorithm. After reading through some numpy tutorials, I'm under the impression that the performance of my script can be improved heavily. So here are my questions: Is there a ...
I've written a very revised and developed version of the game of Runes. The major changes are listed: Convert runes to use curses. Add color-coding to the pieces. Change the board to use the alternate character set (box-drawing characters) Use a struct to hold game data Enforce all rules (can only move a certain piece...
I have built a single header-only memory class (just a C++ wrapper around a dynamically-allocated pointer and a size) that supports copy and move semantics (I hope I implemented them correctly) for a game I'm building. Its use case is to wrap the raw contents of assets imported (from any source) before processing them....
I have been working on a project for some time and have let one Python file grow into a huge file that tries to do everything. The structure is pretty flat and I don't like it. I've used other programming languages like Java and C# and have had pretty structured code, but for some reason in Python I always let it turn ...
Zeckendorf's theorem states that all positive integers can be represented uniquely as the sum of one or more distinct Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers. So given the input 10, the Zeckendorf set would be [8,2]. This is my working code that was for Reddit...
I thought this question was particularly interesting DailyProgrammer 284: Wandering Fingers so thought I'd have a pop at it myself. See the other question for the nitty gritty but the brief problem statement is: You'll be given a string of characters representing the letters the user has dragged their finger over. For...
This script checks if parentheses are balanced. I wonder if there is something that can be improved here including ES6 features. function isBalanced(str) { var stack = []; const allowedSymbols = '()[]<>'; for(let i = 0, l = str.length; i < l; i++) { var c = str[i]; var isOpen; var s...
This collects user's guesses for the word. The user has 8 guesses, a correct guess and a repeated guess does not affect the guess count. def getAvailableLetters(lettersGuessed): ''' lettersGuessed: list, what letters have been guessed so far returns: string, comprised of letters that represents what letters...
I would like to get the current user's timezone name so it can be used with the PHP date_default_timezone_set(). After looking up a few things I've finally managed to come up with a solution for this. I'm not great with code though so any code checks/help will be appreciated. As long as it is a fair guess of the user's...
I am a bit new to programming. I have some edits on my form, and for each edit completed it will have to do a procedure. Currently, I use this code that works perfectly, but I am looking for a better way to accomplish this task. If I add another edit not have to repeat all the code. string rgxExpr = @"(\w+)\s([\w\s]*)"...
I made a Perl script to analyze CSV files. However, it is running a little slow. Is there anything that I can change to make it more efficient? #!/usr/bin/perl -w use strict; use warnings; use Time::Piece; use List::Util qw( min max ); use List::MoreUtils qw(first_index); use Tk; use CGI; my $current_file=(); my $mw...
I had previously written a very simple CMS in PHP, but it wasn't very good looking so I decided to rewrite and improve it using the PHP standards. Have I done this well, and what areas can be improved? <?php class ContentManager { private $db; public $websiteInfo = array(); public $pageInfo = array(); p...
This is my attempted solution to cracking the coding interview exercise 3.5. Looking for any feedback on coding style or the algorithm anywhere I can improve really. The problem specification is as follows. Write a program to sort a stack such that the smallest items are on the top. You can use an additional temp st...
The intent is to update an existing Drupal web page with content based on text entered into a textbox. The existing page displays data from a database in a table. This code gets JSON formatted data, compares it to data in the table, and appends pertinent data in a hidden "td". After doing this, the user may enter text ...
Here is the formula for the deBroglie wavelength of an electron versus its kinetic energy: $$ \lambda(E_k) = h\left/\sqrt{\frac{(E_k+m_eC^2)^2-m_e^2C^4}{C^2}}\right.$$ and here is simple script that prints a CSV with plot data: #!/usr/bin/python import csv from scipy import constants as spc import numpy as np vev = n...
Overall logic: determine number of days in a month. Loop through table (wsUploadTable) and increment value if condition is met. Loop to next day in month and repeat. For example: 10/1/2016, loops through table for date match and increment value. Next date, 10/2/2016 loop table for match... until last day of month 10/31...
I've written a server in Node.js that listens to http requests via Express.js and forwards requests to a Neo4j server. It's my first time working with Neo4j and Express.js. The code runs as intended but is an eyesore to read. The Database has the following Nodes and Relationships: (:User)-[:RANTED]->(:Rant) (:User)-[:U...
I am currently learning C++ and have learnt about inline functions and how they can give a performance benefit. How could this be improved? #include <iostream> #include <chrono> #include <ctime> long fibonacci(unsigned n) { if (n < 2) return n; return fibonacci(n - 1) + fibonacci(n - 2); } inline long fib(un...
I'm wondering if there is more I can do to incorporate more idiomatic scala and functional programming principles. I know the maze itself is mutable but i didn't see an easy solution to making it immutable. Also, if there is anything I can do to improve my algorithm, that would be great too. The reason I have the trait...
I am currently in the process of creating a website which requires it to work with and without JavaScript enabled. All callbacks to the server with JavaScript enabled will be made through Ajax callbacks. In order to keep my code very DRY, I wanted to reduce the amount of views that was required to be created. For that ...
I recently came across this problem: It is Lavanya's birthday and several families have been invited for the birthday party. As is customary, all of them have brought gifts for Lavanya as well as her brother Nikhil. Since their friends are all of the erudite kind, everyone has brought a pair of books. Unfortun...
I need to return private collection and avoid calling code modifying them avoiding copying overhead if possible So I thought of returning copy-on-write arrays, hashes, and sets. I couldn't find any implementations of these, so I tried my own. require 'delegate' require 'set' module Cow end class Cow::Base < SimpleD...
I wrote this sparse linked list insert function, and there are nine return statements. Is this a code smell? Is this badly implemented? I fear that it's hard to read, or hard to maintain. /* NOT BUGS, TESTED AND WORKS CORRECTLY * insert an element into a list * list is ordered using pos * if position pos is already ...
I'm hoping to get some feedback on a function with variadic templates that parses a format string and fills in some parameters whose order and types are based on the characters in the format string. Kind of like scanf(). (For the curious, I am trying to make a typesafe version of this function, documentation here.) I'm...
Question: The old system stored a list of letters per score: 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T", 2 points: "D", "G", 3 points: "B", "C", "M", "P", 4 points: "F", "H", "V", "W", "Y", 5 points: "K", 8 points: "J", "X", 10 points: "Q", "Z", The shiny new scrabble system instead stores the score per...
private String sort(String word) { char[] content = word.toCharArray(); Arrays.sort(content); return new String(content); } private boolean isPermutation(String s1, String s2) { s2 = s2.toLowerCase(); if (s1.length() != s2.length()) { return false; } if (s1.equals(s2)) { r...
Here is my crappy clone of Atomas, a puzzle game where you combine small atoms into more valuable ones. # Pytomas (an Atomas build for Python) # Author: Qwerp-Derp from random import randint # Initial variables element_table = [] atom_range = [1, 3] specials_list = ["+"] * 6 + ["-"] * 3 + ["B", "C"] carry_over = " " ...
The exercise I wanted to solve is from here. Copying from that page: public static int dayOfYear(int month, int dayOfMonth, int year) { if (month == 2) { dayOfMonth += 31; } else if (month == 3) { dayOfMonth += 59; } else if (month == 4) { dayOfMonth += 90; } else if (month == 5...
Here's a very small and basic script that sends commands over SSH to another computer on my network: #!/bin/python import sys, os commands = "" for i in sys.argv[1:]: commands += " " + i; if len(sys.argv) <= 1: os.system("sshpass -p VerySecrectPassword ssh pi@172.16.0.141") else: os.system("ss...
Question: http://qa.geeksforgeeks.org/9744/vinay-queried-interesting-problem-optimization Input The first line contains N denoting the length of Target String. This line is followed by the Target String. The Target String is followed by an integer Q denoting the number of queries asked. After this Q lines follow...
I've recently released my first ever Qt application, and would be glad if someone will look into it and tell me if there are some flagrant anti-patterns and likes. This grabs some screenshots (paths) from the user and copies them to respective Steam directories, converting them to JPEG if necessary. After the copying i...
This is my take on this problem. I don't pre determine the distances, it's not suitable for the application I'll use it for. I'll use it in shool to determine some a mean total distance and how to setup a the poles of a power grid. from random import sample from random import random from random import uniform from ra...
This is more of an exercise for me to get use to Pandas and its dataframes. For those who didn't hear of it: Pandas is a Python package providing fast, flexible, and expressive data structures designed to make working with structured (tabular, multidimensional, potentially heterogeneous) and time series data both...
I've been working on a class(2 actually) that wraps around the array data structure of PHP. It doesn't bring anything new to the table, it simple makes the function somewhat more abstracted with the possibility of method chaining. It's made mostly for fun and practice purposes, I don't expect(nor encourage) anybody to ...
I just started doing the Project Euler challenges and right now I'm on Challenge #3 - The largest prime factor of 600851475143. I wrote some code and tried to optimize it based on some other Stack Overflow users' advice. What I got is this code which does its job, but I think it takes longer than it should - calculatin...
I wrote a function in Clojure to solve quadratic equations using the quadratic formula The function (defn solvequadeq [a b c] (let [D (- (* b b) (* 4 a c))] (if (< D 0) #{} (let [sqrtD (Math/sqrt D) x1 (/ (+ (- b) sqrtD) (* 2 a)) x2 (/ (- (- b) sqrtD) (* 2 a))] (...
Goal My goal is to merge directories. Whenever a file has the same name in two or more directories, then only the one that has the highest number of lines should be kept. If both files have the same number of files and differ then an error message should be thrown. Note that files having more lines are also bigger (in ...
I recently wrote a small INI parsing library. The code is also on GitHub, with documentation. I would like to have opinions, suggestions, and critiques. confini.h /** @file confini.h @brief libconfini header @author Stefano Gioffr&eacute; @copyright GNU Public License v3 @date ...
This code is for a Telegram bot I created. Basically if the user types in Whats the news,Whats the technology news,Whats going on in Syria, Whats happening in New York City, etc it will retrieve 4 articles from google news related to the users query. This uses CoreNLP to analyze the sentence. Just by the way I am only ...
So this is my very first time in this site. I have written this very basic Python code with PyQt5 to create a Memory Game. As I am not very familiar with OOP (but I'm trying to be!), I hope somebody could point me to where I could improve my game. As it stands, the whole thing is working but it lacks of a pretty templa...
I'm trying to understand the strtod() function, and how I can handle any user input given to the function. I assume I tested for everything, however I am hoping for a review to make sure and to catch anything I missed. (I know I should separate everything into functions, however, I am just trying to understand the natu...
Here is the problem on HackerRank. I want to know how I can improve this code. I am mainly trying to improve the following skills: Documentation, functional programming (top-down approach), accurately estimating Big O Complexity, Space Complexity, doc-testing, and readable code. Sometimes I feel that my code is simply ...
I am trying to write a simplify the algorithm of finding the number of nodes in a binary tree by using good object oriented design. I have been into good OOP style recently and found it really compelling in way that it can simplify the mental load by proper polymorphism. Having said that, I don't know if it's a right s...
Recently I came across this problem which instructs me to find the longest substring which is a palindrome: As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma. We consider any sequence consisting of the letters of the English alphabet t...
I have the following backbone function to read a JSON schema and draw the tree structure (as in the screenshot below). I want to make sure if checking against the type as object/array is alright or if there is a better way to do it. traverseJSONSchema: function (root, rootName, level, rank, resultPane) { var height...
I've have make this animation on the weekend as a "just for fun" thing. And for to play with various techniques I've seen in others code. I think it works quite alright. Nevertheless I would appreciate comments about: How to structure / shorten the JavaScript- and Sass-code better? How could the animation be improved?...
I have written the following code in order to: Find begin and end of FTP user and password from a given URL (ftp://[user[:password]@]host[:port]/url-path) Allocate memory to hold this string Copy the sub-string into the allocated memory Here is the code for your review: static char * swd_parseUsrPass(void) { char...
I'm writing a "crypto library" and gradually adding algortihms. Now it's just ancient cryptography, but I'm going to expand the library. It doesn't depend on any external libraries. class Crypto(): def __init__(self, rotInt=3, letters=list("abcdefghijklmnopqrstuvwxyz")): self.letters = letters self....
Recently I came across this problem , here is an excerpt of it, It is well known that the routing algorithm used on the Internet is highly non-optimal. A "hop", in Internet jargon, is a pair of nodes that are directly connected - by a cable or a microwave link or whatever. The number of hops that a packet may ta...
I assume there can be space in between and I have ignored that. Also, there will be only lower case characters in the string. My logic: There can be only one occurrence of odd number of character in palindrome string. #include <iostream> #include <algorithm> #include <unordered_map> using std::cout; using std::end...
I have this small program in PHP implementing merge sort. I used one rather simple run time optimisation via using one additional array which allows faster merge operations: function merge_impl(&$source, &$target, $source_offset, $target_offset, ...
Often, I find myself folding over a range object if I need to repeatedly transform something. This, to me though, feels like an abuse of fold since I never even use the numbers that I'm folding with. Almost perfect example: (ns shuffle-example (:import [java.util Collection Collections])) (defn shuffle [^Collectio...
I recently came across this problem: Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with their hands and teeth and so on. A perceptive follower of such movies would have noticed that there are limits to wha...
This is working pretty well right now: var p=''; if(typeof parameters!=='undefined'){p='&p='+parameters;} var t=''; var l='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for(var i=0;i<64;i++){t+=l.charAt(Math.floor(Math.random()*62));} if(!sessionStorage.t){sessionStorage.t=t;} if(!localStorage.t){loc...
The problem is instead of doing what is stated in the if statements, does the else line like the if statement is false. However, when printed the variables i am working with, seems i have managed to get the desired expressions. I can't see a problem with the code either so if you experienced coders can please help me. ...
I wrote a DSL for defining a finite state machine. My robotics team wants to use a state machine to manage the state of the subsystems on our robot, like the arms, drive train, lifter, etc. Each subsystem is implemented as a FSM and subscribes to events published by buttons and sensors. I'm using an event bus as the mi...
I was given an assignment to write a mini-shell: To write your own shell, you will need to start with a C program that will prompt the user for input and accept in a number of arguments from a command line. The commands entered will be accepted into your shell and then processed to understand if it is a built in...
This code is part of the Construct library. Docstrings explain what the code is supposed to do. @singleton class VarInt(Construct): r""" Varint encoded integer. Each 7 bits of the number are encoded in one byte in the stream, having leftmost bit not set when byte is terminal. Scheme defined at Google's sit...
This code is part of the Construct library. Docstrings explain what the code is supposed to do. from construct.lib.py3compat import byte2int, int2byte, bytes2str, iteratebytes, iterateints # Map an integer in the inclusive range 0-255 to its string byte representation _printable = dict((i, ".") for i in range(256)) _...
I was tasked with implementing Conway's Game of Life. It seems to work fine but the implementation is lacking as I find that it takes a long time to generate the next generation of the grid. I'm looking for flaws and tips to speed up the process. Currently, I can only refresh the display twice a second. The grid class ...
The idea behind this problem is to represent a configuration of 8 queens with a one-dimensional array. So a[0] represents the first row, a[1] the second row etc. and a[row]=column position, where column position represents the "row position" of the queen. Is there anything I can improve? #include <iostream> #include <m...
This is a program to calculate the largest prime number. Are there any possible improvements in style/speed/accuracy? public static int? LargestPrime(int max) { if (max < 0) return null; int largestPrime = 0; for (int i = 0; i <= max; i++) { bool? isPrime = IsPrime(i); ...
Here is my go at understanding generics, Comparables and Comparators, as well as type bounds. I believe I made it as close to Collections.sort as possible in terms of interface. Please review. import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Random; public class QuickS...
I am just into redux. I am developing a dashboard using ReactJS redux and material-ui for components. It's a large app as my dashboard contains various features like add/edit/delete device, add/edit/delete tab, create card etc etc. It's growing very large and I am just into redux, so I am not sure how I can refactor my...
Using modern C++ feature template argument deduction for class templates and folding expressions it is possible to implement "multi" scope guard utility, which have right order of functor calls: #include <utility> template< std::size_t I, typename F > struct wrapper { F f; }; template< std::size_t I, typename F > con...
I'm relatively new to C++ (learned it years ago, but never used it much until now), and I needed an exercise to get a better handle on the language. I also needed a good way of handling events, and while there are plenty of libraries that have good event systems, I didn't like the client code for any of them. It felt u...
I have code which works pretty well. I just need some of your opinions on how to write it better with fewer line of code. I want to use a ternary operator but I couldn't make it work so I did an if else instead. Basically, I want to insert a price on my database. The price column is a nullable decimal. Even in my C# co...
Can somebody help me with optimizing this code? I'd like to have some control about placement. Masonry doesn't do the job in that way. What I have done now is to create some sets of columns. For different screen width one of the column sets will be active. Big screens have 3 columns middle screens 2 and small screens o...
Description: I am trying to solve algorithmic problems mixing them with Object oriented design as part of my interview preparation. So, the question is given an array of integers find the pair of index which satisfy the given sum hence, given: arr = [1, 2, 3, 4, 5] , sum = 6, answer = (2, 4) or (1, 5) Code: class Sol...
Here is my class that handle all MarshMallow Permissions I prefer separate it class as I will call its methods in all my apps. At first I get used to check permission by this way: private void CheckPermissionGranted() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (ActivityCompat.checkSelfPermis...
I'm working on my own "MVC" framework for learning purposes and for personal use. I use the "MVC" expression as a concept not a concrete design pattern. So I refer to MVC as a "separation concept" not a concrete thing since (mainly in the world of web) the implementation can be different in every framework. Main The ht...
I've a static method which parses a String (from the App.config) to a Int32. I need to have a valid (since the parsing would fail of course^^), positive and not zero integer. I've done it like this: public static int uiScale () { int retint = 0; try { retint = Int32.Parse...
This is an iterative review. Previous Iteration My snake now moves and grows and successfully kills itself. Eventually, the game board will handle state and things like the list of fatal coordinates and telling a snake whether it's dead, but for now that's just a function called fatal_board_positions paired with is_fa...
I m making a script to store date information in the smallest size in bits (I don't mind of the actually memory use in the program / runtime) #!/usr/bin/env python import random import datetime MAGIC = "DAT" def extract(data, size): return (((data >> size) << size) ^ data) def compress_date(year, month, day, hou...
I need to compare 2 xml strings where the formatting may be different. The approach is to use the XmlWriterSettings to format both strings and compare the formatted result: public static class XmlHelper { public static string FormatXml(string xml) { try { var stringBuilder = new Stri...
I am taking on this challenge on CodeWars. You have to create a function that takes a positive integer number and returns the next bigger number formed by the same digits: next_bigger(12)==21 next_bigger(513)==531 next_bigger(2017)==2071 This is my solution: def next_bigger(s) s.to_s.split("").permutation.to_a....