Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue.
The idea is to be able to invoke the program like this:
./longline 10 < /usr/share/dict/linux.words
And get it to print the 10 longest lines in the linux.wor...
I have been working on the following kata from CodeWars. It's basically a modification script for encryption -- see the test cases below my solution code.
Any comments/feedback appreciated!
def encryptor(key, message):
new = ""
for letter in message:
if letter.isalpha():
...
This is my attempt to answer my own equally named question on SO. In this case, I need a method comparing two strings so that the running time is input independent.
// Not private in order to prevent optimizations.
static class Blackhole {
private static void eat(long n) {
dummy += n...
Keep state same if the doesn't fall in following conditions:
Change to 2 if there are exactly 2 ones in the neighbors
Change to 3 if there are more than 2 ones in the neighbors
Also it is wrapping around so neighbors can be cyclic
Wrote a basic structure and modularized it to individual func...
First here is my settings object below. insight, spike and momentum are binded to 3 checkboxes in the markup. The objective here is to prevent the user from deselecting all choices, 1 choice must remain selected.
var settings = {
user_id : 0,
insight : true,
s...
Implemented this solution for the problem. Feedback and review if this can be improved in an way. Appreciate your help.
public class queueUsingStack {
static Stack<Integer> s1 = new Stack();
static Stack<Integer> s2 = new Stack();
public static void enqueue(int element){
s1.push(element);
...
I'm looking for a critique of this audio management system I wrote for Unity games. It references a JSON file to trigger the clips by events.
The main AudioController.cs class is pasted below. The full codebase can be found here: https://github.com/GlowLimeGames/audio-system-unity
/*
* Authors)...
I am trying to understand how the props and states comes and goes. I am commenting the pieces of code that I understand, but there are some others that I can't because I didn't get what is happening.
This is the code: https://jsbin.com/mazubenaxa/1/edit?js,output
Or here you might see the code...
Here is my own predicate class; it is equipped with some operators. Demo:
using static BusinessObjects;
using static Console;
class Program
{
static void Main(string[] args)
{
WriteLine(Sell("John Doe", "[email protected]", 10000));
WriteLine(Sell("John Doe", "test@exampl...
I have following code. Header file is myView.moc.h and c++ file myView.cc
// header file myView.moc.h
#ifndef MYVIEW_H
#define MYVIEW_H
include <QTextEdit>
class QContextMenuEvent;
class QShortcut;
class myView : public QTextEdit {
Q_OBJECT
protected:
virtual void contextM...
So it turns out when we are recording dates, this happens:
var start = kendo.parseDate($scope.DataItem.Start, $scope.ShareSvc.UserPreferences.DateFormat + " HH:mm:ss");
var utcStart = Date.UTC(start.getFullYear(), start.getMonth(), start.getDate(), start.getHours(), start.getMinutes());
Which converts the date object to UTC, but does not actually convert the time to UTC.. so if you enter 12pm in GMT+1, you send to the server 12pm in UTC
aka instead of sending 2016-06-14T12:00:00+1 you send 2016-06-14T12:00:00Z
we haven't noticed this because the calendar is only displaying dates in UTC without converting them to a timezone... which means that all of the countres in differing timezones have incorrect data
I'm new to Python! Kindly suggest me improvements!
Problem statement :
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect n...
What the hell man, how do you even consider this an answer ? The idea is to help and learn here, not hire people for free code review. — Zil34 secs ago
I am new Python user, who decided to use Python to create simple application that allows for converting json files into flat table and saving the output in cvs format. I was wondering if you could give me some advice how I could improve my code to make it work in more efficient way. I am asking s...
This belongs in code review. Your code doesn't seem to have any problems, your simply asking if it's the best approach. — InBetween30 secs ago
I'm voting to close this question as off-topic because the OP is asking for a code review. The code works, there is no specific problem to solve. — InBetween50 secs ago
My apologies, I wasn't aware there was a code review section. — Eritey25 secs ago
I want to to run a trigger on the db.
This trigger looks in the 'inserted' table for rows to further manipulate.
My question: If I'm using Entity Framework and have excluded ALL columns, marked an entity as modified and then call SaveChanges(), will I still end up with a row for that entity (ass...
Quick Q. Say I have a collection of items gradually getting added into a list. Is it faster to start with a set, or convert the list into a set at the end of the code?
Take the following example, I have multiple 'Integration' classes that inherit from the same 'IChannelIntegration' interface.
public interface IChannelIntegration
{
}
public class IntegrationA : IChannelIntegration
{
}
public class IntegrationB : IChannelIntegration
{
}
public IChannelInte...
You can get rid of the lets and even the binding of getLine to input in main.
First, let's identify what exactly you're doing to the input before printing it. First you call strToUpper on it and then pass the result to stringMapReplace lolcatDictionary, using function composition, we can easily ...
> I'd suggest you pick up a book about Haskell first and see how things are done in it and why they are done that way before writing too much code that deals with IO.
Problem. My naive version now is too slow. I think setting/accessing concurrent atomic bit is way slower comparing to access/modify an array of boolean. Second, the parallel execution only happen on the beginning of the process. For bigger numbers, thread-pool is not really active.
public class...
In order to leave remarks like that that are "friendly" you have to structure your entire review around being a "friend" to OP, rather than just giving neutral feedback
IOW, you can't leave a load of points about why his code isn't working X Y Z without trying to engage with him further before leaving that note
I'm sure that could appear friendly, but the tone of your answer does not reflect that. Your answer is very matter-of-fact, which is fine, but you can't leave remarks that have to be read in a jovial tone in that case.
If you dive in so far that you can't see shore and have no idea how you'd get back, then you're just fumbling around in the dark and not *really* learning in a way that is useful.
I made that mistake with VBA. Started out just "trying to get stuff to work" without having the first clue about programming. About a week in, I bought a textbook, read the whole thing iand *then* I had a basic framework to build off of.
@200_success If there is a comment thread that I think has reached the end of it's usefulness do I flag it? If so just one comment or all of them? (I'm not used to this flagging business)
I just wanted to make clear that I don't mean to dismiss the effort you've put into your code and learning Haskell or criticize the way you're learning it.
And if you feel like diving in the deep end is the right way for you, or if I am wrong about thinking that that's what you're doing, feel free to ignore that part.
@MichaelBrandonMorris Cool, glad I could help you
@MichaelBrandonMorris I was glad to see a lowball question honestly, Haskell is very new to me too and it was cool to be able to write up an answer.
@200_success It's just as there is two 'discussions' going on at the same time. I left my comment to make it more understandable, and don't know if you can see deleted ones. IMO the entire tuple thread can go as it's in the answer now.
Simple extension method for Kotlin. Should perform an action on every element in a 2d array. i.e. An array of arrays.
I have made the assumption that because the receiver type is defined as an array of arrays of type T, that I do not need to do any checks or casts.
fun <T> Array<Array<T>>.forEa...
> Clojure is a functional programming language. It provides the tools to avoid mutable state, provides functions as first-class objects, and emphasizes recursive iteration instead of side-effect based looping. Clojure is impure, in that it doesn’t force your program to be referentially transparent, and doesn’t strive for 'provable' programs.
Basically, in Haskell, everything is strongly typed. In particular, any function that does I/O will have a type signature where the type is "tainted" with IO.
This project is intended to be a platform for bot contests within simple 2d game environment such as loderunner, tanks, bomberman etc. Bot should connect to server's web socket, get current game board message, figure out it's action/move and send it though web socket back to server
https://github...
generally speaking executing a function without using its result is a side effect in other languages
though I guess in Haskell if you can prove that that branch does nothing and you discard the result, then it isn't a sidef effect because you know it's pure so it gets optimised away
@overactor Yes, that's my point, if you were to execute a function but not use its result ,would that not be counted as a side effect unless the result you got was from a pure function?
@Gluttton: I disagree - optimisation questions are perfectly on-topic here - codereview is more for working code that can be improved idiomatically or stylistically. — Paul R10 secs ago
This is my attempt at a basic implementation of GOL. The user can add and remove cells with the mouse and some basic stats are printed to console. Any feedback is welcome, but I have a couple of specific questions:
In Cell::get_neighbours() it seems a bit inefficient to keep constructing vecto...
I have still another version of my validation extensions. I've reworked it and added some new features. It doesn't relay on expression trees any more but as a compensation the same extensions can be used for unit testing.
The base class is still the ValidationContext:
public class ValidationC...
@Phrancis in a pure functional language, every function is like that, if you pass the same arguments to a function, you are guaranteed to get the same result back
@Phrancis if you start looking into languages like Rust, JavaScript (the good stuff), Flowtype, and other similar languages youl'l start to pick up on it quickly
@PaulR Non-specific optimization questions are on-topic on Code Review. However, there is a specific question in the title of this question, so I think it's a fine Stack Overflow question. — 200_success52 secs ago