By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can
see that the 6th prime is 13.
What is the 10 001st prime number?
public class Problem7 {
public static void main(String[] args) {
// a prime factor is something that can divide by only 1 and itself eve...
Because you don't lose any information going from int to double: all values that an int can have, a double can have as well
But a double can, for example, have a fraction. An int cannot. That's why this is not allowed without explicitly doing so. You can write int y = (int) Math.Sqrt(5); and it will work because you're using an explicit cast now which, in effect, will truncate the fraction if there exists one
And a Square Root function most definitely can have a fraction
I have a login method in my controller:
def login(conn, %{"login" => %{"password" => password}}) do
conn = conn |> fetch_session
count_attempt_login = conn |> get_session(:count_attempt_login) || 1
if count_attempt_login <= 10 do
if @password_login == password do
...
CRitter Collaboration
Choose a previous community challenge and work with someone(s) to complete it.
The only stipulation is that it must be something none of you have already submitted. Though interest in challenges may be high time can be scarce so this is a way to get more participation!
D...
Task is create Binary Search Tree from inorder and preoreder arrays and print them in level by level fashion(one level per one line) and below is my implementation
*****I am getting index of bound exception as below .
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at...
First of all, it's not really a virus that is used to spy, or steal bank accounts. I don't even know if its a virus at all... I only made it to troll friends/people I know, and practice my programming skills. I will show you the code, than I will try to explain it a bit;
package pracatice;
impo...
@Eddie many of us spend time writing programs that do useful things or solve interesting problems, maybe you should try that instead of writing "prank" programs, to practice your programming skills. — Phrancis2 mins ago
@JeroenVannevel I notice that a lot of code I see on SO that has to deal with lists/collections (more than just very basic stuff) seems to use LINQ, would you say that LINQ is very good at working with list-like structures, more-so than core C#?
Here, better explained graphically, I'm trying to get C:
var A = new List<int>() {2,3,5,7};
var B = new List<int>() {2,2};
//I want to compare B to A, to remove N elements from B that are in A N times
//for instance above would return C: {2}
//A: {2 _ 3 5 7}
// | | | | |
//B: {2 2 _ _ _}
//C: {_ 2 _ _ _}
It's kind of like Except but with a twist that will preserve additional occurrences of an element in B that is in A
So I am learning Objective C and iOS development. I started a tutorial online to get a little bit more knowledge about views. But after I did the basic I decided to finish the game.
The game is a little "I spy" game where the user tries to guess the item loaded in a picture on the scree. They ar...
Original Problem: HackerRank
I am trying to count the number of inversions using Binary Indexed Tree in an array. I've tried to optimise my code as much as I can. However, I still got TLE for the last 3 test cases. Any ideas that I can further optimise my code?
# Enter your code here. Read inpu...
I'm doing an exercise, and would like to know if what I'm doing is correct and follows the correct structure for rollbacking in case a transaction fails. I would like to know as well if my try...catch statements are well implemented. Here is my code:
create procedure spTeste2(
@tit1 bigint =...
// Source: stackoverflow.com/a/5012027/3626537
var factorsLookup = EmptyLookup<int, int>.Instance;
factorsLookup = primeFactors.ToLookup(F => F);
remainingFactors =
(
from groupA in factors.GroupBy(A => A)
let groupB = factorsLookup[groupA.Key]
from A in (groupA.Count() < groupB.Count() ? groupA : groupB)
select A
).ToList();
remainingFactors.Dump();
@EBrown Yes they are sorted
Problem with above is that, well, it outputs something like this (there's a bit more code than above)
var a = new List<int> { 2, 3, 4, 5};
var b = new List<int> { 2, 2 };
var c = new List<int>();
foreach (var n in b)
{
if (a.Contains(n))
{
a.RemoveAt(a.IndexOf(n));
}
else
{
c.Add(n);
}
}
a.ForEach(x => Console.WriteLine("A: " + x));
b.ForEach(x => Console.WriteLine("B: " + x));
c.ForEach(x => Console.WriteLine("C: " + x));
public static List<T> ExceptExact<T>(this List<T> source, List<T> exceptions)
{
var result = new List<T>();
foreach (var el in source)
{
if (exceptions.Contains(el))
{
exceptions.RemoveAt(exceptions.IndexOf(el));
}
else
{
result.Add(el);
}
}
return result;
}
var a = new List<int> { 2, 2, 3, 4, 5};
var b = new List<int> { 2, 2, 2 };
var c = b.ExceptExact(a);
a.ForEach(x => Console.WriteLine("A: " + x));
b.ForEach(x => Console.WriteLine("B: " + x));
c.ForEach(x => Console.WriteLine("C: " + x));
Basically, here's the problem statement:
Given a List<T> source and List<T> exceptions, create a List<T> result which contains all of source, without exceptions, only omitting exact instances of a value. I.e.: if a value appears twice in source, but once in exceptions, then result will have t...
@HarryJohnston I'm sorry what is moderator? It doesn't seem like another sub community of stackoverflow such as supersuper, codereview etc.... — the190040 secs ago
I'm writing an online classifieds website similar to craigslist. I use semantic-UI for the insert form. I'm still working on improved functionality such as dynamic options where the sub-category will expand to number of rooms and area for an apartment etc. But the code is live and you may look an...
@microbuster It may or may not be. The "script" tag on History is very small. Perhaps you should go to their Chat or their Meta and ask about your proposal, and how much overlap there is
I have written this to practice Test Driven Development. I would like to know if the process is right and how it could be improved.
Problem Statement : A wizard can cast spell on goblin and make his size big, normal or small. He can also make the goblin visible or invisible. In addition to this,...
There is luckily enough a Pokestop close enough to my workplace to check-in every few minutes. This yields me the necessary Pokeballs and experience, but my bag is getting full. I am only allowed to have 350 items. Are there rare items (so no Pokeballs) that I would miss out on with a full bag? I...
@Phrancis it's a tool to be used like any other. If your issue is solved with LINQ (and it typically is) then there's a good chance you can just use that
Once you start having something more complicated then it might be worth it to just write it out with traditional loops though
to preserve clarity
it depends on the situation. I personally would write an algorithm like that out in full, otherwise it'd be hard to read in a few months
As @tkausl recommended: if you have a working code and you just want to know how it could be done better and/or faster, the question is better suited for codereview. — icza11 secs ago
I have written a decimal to binary code that creates a list of 0 and 1s and reverses them to get the precise order of the binary digits. However the code, as follows, is very crass and verbose. It uses recursion which I believe it shouldn't. Please review it and tell me how I can improve it:
cla...
Please do not delete my Question. If it is in a wrong section, just tell me. I will move it to the other section.
First I am learning Haskell with the book Marco Block and Adrian Neumann. This is not a school lesson or something. So there are exercises, but not necessary. I hope i can receive h...
I've written a Ledger class for a daemon process, which is supposed to keep track of an exchange's orderbook. My main concern is the way I keep track of the orders - more precisely, the containers I use to store them: a combination of set() and dict() appeared like the most feasible solution.
Ho...
I use the gem act_as_votable to allow users to select categories they like. To get the categories a user likes:
current_user.get_voted(Category)
These categories have children categories, and I need to find the posts in those children categories.
I use this line to do it:
@categories_posts...
I'm a Go (and programming in general) newbie and the task was to program a Go server that would accept incoming messages, take each line, reverse its order and case and send it back. Besides doing that I also wrote a client (just for the hell of it and to help me test my server). I wonder if some...
I was reading this code where author claims that its the fastest implementation which I doubt, hence I decided to write my version of the same problem.
'use strict';
module.exports = function unique(arr) {
if (!Array.isArray(arr)) {
throw new TypeError('array-unique expects an array.');
...
Well correctness can be opinion based in this case. You have a working solution, so whats wrong with it? If you want a code review you are here at the wrong place. — Sir Rufo14 secs ago
My code given below will produce the correct output but it tends to take way too much time with larger data thus timing out for some of the test cases. I've linked to the problem description here
Given below is my code. Any help/advice/suggestion is welcome
#!/bin/python3
import sys
inp0 = ...
This is the problem statement: https://open.kattis.com/problems/parking
I have submitted successfully a O(n^2) solution and I would like to know if there is a way to improve the running time to, maybe, O(nlgn).
Current solution (Please note that I use custom IO which I haven't included):
public...
I'm learning Ruby 2.3 and I've tried to implement a function which performs the Luhn credit card verification algorithm on an input string, returning true if it matches and false if it doesn't.
def luhn(card_no)
card_no.split("") # Break into individual digits
.reverse # Start f...
things like swap, begin, size... should be called unqualified, with std:: version brought in current scope with using-declaration. Qualified call to those should be threated as bug on any code review. — Revolver_Ocelot40 secs ago
i need code review for my first jQuery plugin. Maybe it's a lot of code)
I want to hear something about my plugin code structure and more. Thanks.
;
(function($) {
'use strict';
$.fn.mpopup = function(options) {
//Default settings
var defaults = {
overlayClass: 'mpopup-o...
I'm voting to close this question as off-topic because the OP is essentially asking for a code review, so the question would be better placed at codereview.stackexchange.com. — nnnnnn53 secs ago
I just got asked if I was a robot by CR and it was hard to say no.
@N3buchadnezzar I have a feeling this will happen to me, too.
I have a £570 deposit for this place and my landlord is a bit shady. I mean, the sink has been giving me an electric shock on and off for the past 18 months and he hasn't bothered to fix it despite me telling him as soon as I moved in
login page with session using PDO
index.php,general message.php, logout.php, site life.php (this page for session and put it in the other pages by required )
connection.php
<?php
$dsn = "mysql:host=localhost;dbname=mg";
$username = "root";
$password = "";
$options = array(
PDO::MYSQL_ATTR_I...
@Shepmaster Sorry, I don't know what I was thinking. Thank you for pointing me to code review. I'm willing to delete this question and repost there, if that's the appropriate thing to do? — Stephen Lazaro53 secs ago
I'm working through Cracking the Coding Interview. The first challenge is to implement an algorithm to determine if a string has all unique characters.
I've gone through several iterations, but here's my "final" solution. I've made several assumptions:
We are considering case-insensitive strin...
This is my first Python project, so:
create a pot with dimensions (radius, thickness of wall, thickness of base, height), fill it with food (to a specific height). Determine the ratio between the volume of the food and the volume of the (metal in the) pot.
I am aware that this code does not tak...
I am creating a php app in MVC (no framework).
I am having a difficult time understanding how the Model and the Controller communicate in an optimal manner.
Let me first give you the code:
User.php
<?php
/**
* Created by PhpStorm.
* User: antony
* Date: 7/7/16
* Time: 1:17 PM
*/
namespac...
I've been experimenting with how to pass my managed object context throughout my application in Core Data and I came across an approach that I'd like reviewed.
I've been creating a protocol for all of my View Controllers that need a managed object context to implement.
protocol ManagedObjectCon...
I already have two versions of this code reviewed (thanks @Bobby).
They can be found here and here.
The question is still the same.
The goal is maintainability and following best practices.
Jar.java
package com.tn.jar;
import java.util.Random;
public class Jar {
private String itemNam...
And then she's like, "It's perfectly safe!" "No, it's not. You're going out, at 11PM at night, to find a widely sought after Pokemon, which is completely known to all of the public."
It's a predators dream.
All these young kids will be on Pokemon GO, trying to find all these cool Pokemon, and now predators have exactly what they need to find them.
@EBrown To think I used to vie for the day where a) Pokemon would be a popular discussion point and b) people would go OUTSIDE and play it. WITH EACH OTHER.
I also strongly disagree with giving young kids the option to go into any important buildings, like a police station, etc. They are too young to make the decision if they should do that or not
I have the following snippet code which, within a loop, creates a JavaScript object where some of the properties maybe undefined:
reader.on('record', function(record) {
let p = record.children;
let player = {};
// below we create a dy...
I have a class (Patient) with many instances.. I need a way to share the instances with other users, so I thought of converting the instance into a string and sharing it, then reconverting it into an instance
From instance to string
func ToString(pt: Patient) -> String {
let myarray: [Strin...
@N3buchadnezzar Well, at least now you know to take them. Photograph everything when you move in. Photograph everything when you move out. Won't stop some landlords, but does make it more likely you can successfully sue them over it.
@Zak Yeah. Luckily I move in with some friends for about a year. They are pretty laidback so everything should be fine. However I will for sure take pictures next time I move.
It's alive, it's alive!
I feel like Frankenstein now. My code looks like a monster, but it compiles and is alive! Muhahaha
> The XNA Framework encapsulates low-level technological details involved in coding a game, making sure that the framework itself takes care of the difference between platforms when games are ported from one compatible platform to another, and thereby allowing game developers to focus more on the content and gaming experience.
Overall your code looks okay, nothing much to comment on it as a whole. I'd like to add the following comments though:
The variables in your Jar class should be final where possible, I would change them to the following:
private final String itemName;
private final int numberOfItems;
private f...
I guess my answer isn't going to get simpler than this
This question appears to be off-topic because it is a code review request. This is better suited to the Code Review Stack Exchange site. Before posting there be sure to read their FAQ to ensure that your question meets their guidelines. — John Conde39 secs ago