@MartinBüttner maybe I completely misunderstood the edit I approved, but I thought it was merely adding in the old byte count that had been dropped somehow
Yeah, I think I mentioned somewhere before that you could just generate floats from 0 to 4 and count how many are less than pi. technically it's Monte Carlo...
i think this still fits the spirit: it's a randomized algorithm based on picking many samples that does not use pi and gives an estimate that's near pi with high probability
I'm not sure why it was reopened in that ambiguous state.
But I don't think it makes sense to put it through another close-reopen cycle. Better to just take the interpretation which makes it a better question.
well... if the sqrt(1-x^2) approach is valid, I think I can beat GolfScript with Mathematica :D
yep, 30 bytes
@Peter also technically, the credit should be due to PhiNotPi, I think. his earlier message was what xnor was referring to.
@Sp3000 so I've been thinking about transposing with regex... I think it would be even worse than addition... I feel like it's possible with a single replacement in .NET (at least for square input), but I have no idea how to do it in multiple replacements in other flavours
And yeah single replacement in .NET does sound possible, if you push the next few non-newline chars in one group, then the newline chars that follow in another group, and work out the corresponding char from that
I think I should be looking for problems outside P
@Optimizer is there no way to shorten your code by using 4/(1+x^2) and skipping the last division?
@Optimizer actually, you can remove the comment on @Peter's answer. I didn't notice that xnor had suggested a different method. so crediting him was actually correct.
@randomra hm, yeah, but then I'd have to check up front if the rectangle is 2 wide or 2 tall and then flip everything if it's the wrong way around, which will cost a lot
@MartinBüttner might I ask if you reckon my sandbox post is in a sensible enough state to post to the main site now? I should have time to address any problems that arise today, but probably won't tomorrow
@Lembik but you are still using conflicting tags ;) ... fastest-code says "the code is scored by actual runtime", but code-challenge says "I made up my own winning criterion"
@MartinBüttner OK so those in the know think of them like that. Visitors like me see it as "this question is about writing fast code and about some other challenging aspects of coding too"
so people who want to find challenges that require you make things fast would find it
because that is part of the challenge
it would have been clearer with fastest-code and code-golf.. I interpret it as saying "this challenge is about fast code and short code"
so people who search on either criterion would find it
yeah, I guess that's a fair point, but not policy around here. I guess you could ask on meta how people would feel about relaxing the rules regarding challenge type tags
hmm, ok, having removed some partition in my solution, it's taking a while longer on Establishments - I don't want people to have to add more characters to make it faster, I just wanted a bound so that people can't be too brutal
I'm not using it at the moment... which kinda makes me sad because it's definitely the best birthday present my girlfriend ever got me, but I don't currently know what to do with it :D
Finding Collatz-like rules with many loops
code-challenge sequence math number
This code-challenge is closely related to the code-golf question Analyzing Collatz-like sequences but the goal is quite different here.
We define a Collatz-like rule with 3 positive integers:
d > 1 divisor
m > 1 ...
Here is what Wikipedia says is the definition of Monte Carlo:
"Monte Carlo methods vary, but tend to follow a particular pattern: Define a domain of possible inputs. Generate inputs randomly from a probability distribution over the domain. Perform a deterministic computation on the inputs. Aggregate the results."
hi, I have a challenge that's been sitting in the sandbox for a pretty long time, it has a +1 and a -1 and I think I addressed all the (two) comments I received so far, last one yesterday; can I post it or should I wait longer?
I made the comment last night because I thought maybe there was something non-obvious going on (it's been a few years since I've messed with C). I didn't expect the post to get two upvotes after pointing it out.
9,9,9,9,9?
You need some Pokemon quotes to go with those nines.
I'm trying to learn Java again, and I found some code with a comment that I don't understand; it's just one line. Anyone here willing to take a look and tell me if this comment is wrong or if I'm being stupid?
public final class Digraph<T> implements Iterable<T> { /* A map from nodes in the graph to sets of outgoing edges. Each * set of edges is represented by a map from edges to doubles. */ private final Map<T, Set<T>> mGraph = new HashMap<T, Set<T>>();
I don't understand the "Each set of edges..." line
it seems that adobe has trouble with that and thinks that all of those slides are now page number 3. which means, I can't print page 3.3 ... I can only print page 3. I need to find a way to either tell beamer to stop doing that (and just give them consecutive numbers, unrelated to the current frame), or adobe to let me print pages with numbers like that...
@EricTressler there are definitely some really sick JS presentations
@MartinBüttner I switched primarily because I wanted to have actual JS code running real animations. I use a really simple package that is dependent on an outdated version of Jquery, so I'm not really keeping up with the times
nah, looks like handout mode does exactly what I'm looking for and just uses page N (with handout mode I don't care about the numbering though, because I can just print the entire handout)
I recently discovered that we have a martin-gardner tag. Martin Gardner was a man who wrote about puzzles (of many different kinds), not a type of puzzle. What use is this tag? Does it tell people anything about the puzzle? He wrote about checkerboard, liars, chess, logic-puzzle, math, and many o...
Gerrymander a Map
Congratulations! You have been selected as the chairman of your state's redistricting commission. It is your job to propose a division of the state into electoral districts. Your true goal, however, is to make sure that your party wins. To avoid suspicion, your divisions sho...
it sounds like an interesting problem, but I'm afraid the best golfing approach will be generating random (or all possible) divisions and testing them for validity and optimality
The 4th Congressional District of Illinois includes part of Cook County, and has been represented by Democrat Luis Gutiérrez since January 1993.
It was featured by The Economist as one of the most strangely drawn and gerrymandered congressional districts in the country and has been nicknamed "earmuffs" due to its shape. It was created to pack two majority Hispanic parts of Chicago into one district.
This district covers two strips running east-west across the city of Chicago, Illinois on the west side continuing into smaller portions of some suburban areas in Cook County, surrounding Illinois'...
Regex (PCRE), 98 bytes
Just managed to avoid a horizontal scrollbar. :) I would have done this in Retina to avoid discussions about where regex is a programming language, but I don't think this will be as short using the .NET flavour.
^((?>0|1(((?(5)!)\))*+(?1))|2(?2){2}|3(?2){3}|4(?2){4}|"[^"\...
I'm not even sure any more if it's possible in PCRE. I need to find a way to determine if I'm inside a certain recursion. I did that by capturing an empty group () and test if that captured anything. but I'm not sure if there's a reliable way to get rid of that group again
I do understand now though why it works sometimes... maybe I can make use of that
I have another stupid java question. I want to use an enumerated type for the edges in my graph class. say, RED or BLUE. I want to be able to add an edge with a type RED or BLUE, so I want the enum type to be public. Is the only option really to make a separate file for the enum type?
other than something stupid like having a public method addEdge(..., String type) and check for "type == "RED""
i was trying that earlier with an inner TEST class that just had one member "int A", and I kept getting "variable may not have been instantiated" errors when I tried to declare TEST objects in main
I want to make a graph class that contains two enum classes and an Edge class and a Node class, and I've having trouble. If it's possible to do that, though, I can probably sort out my syntax problems
public class graphTest { public class TEST { public int A; TEST () { A = 0; } }
public static void main(String args[]){ TEST x; x.A = 5; } }
that
produces "error: variable x might not have been initialized" on the line x.A = 5;
oh. I think I understand. This file should have no main; another file should have a main method, instantiate a graphTest object, and then it will have a TEST member with an A member
okay, I think I'm fundamentally thinking about the logical organization in Java wrong. In C++, I have a Node struct, an Edge struct, a Graph struct that contains nodes and edges, and a main function that instantiates a Graph.