Hi,
Given a point (pX, pY) and a circle with a known center (cX,cY) and radius (r), what is the shortest amount of code you can come up with to find the point on the circle closest to (pX, pY) ?
I've got some code kind of working but it involves converting the circle to an equation of the form (x - cX)^2 + (y - cY)^2 = r^2 (where r is ...
Hello all, I have a language-agnostic question about an algorithm.
This comes from a (probably simple) programming challenge I read. The problem is, I'm too stupid to figure it out, and curious enough that it is bugging me.
The goal is to sort a list of integers to ascending order by swapping the positions of numbers in the list. Each ...
I have a bunch of objects in my application (Organisations, Individuals, Orders, etC) and I need a nice clean way to decide which users can and can't view/edit these objects. User have a range of permissions such as 'Can edit own contacts' and 'Can view team's contacts' and can also be members of groups such as 'Account Manager' so vario...
I see the phrase "programming idiom" thrown around as if it is commonly understood. Yet, in search results and stackoverflow I see everything...
From micro:
Incrementing a variable
Representing an infinite loop
Swapping variable values
To medium:
PIMPL
RAII
Format, comments, style...
To macro:
Programming paradigm or common li...
Can anyone recommend a website, book, or simply a list of refactoring strategies for procedural languages as opposed to object oriented languages?
Everything I was able to find contained some strategies that could apply, most were useful only if working in an OO language.
...
I've been thinking lately about a few practices that I have kind of adopted. Not things you see listed all the times, but patterns that you've looked back and said "I'm glad I did that", then adopted for yourself.
I'm not really thinking of the ones you hear all the time, like "Refactoring" or any design patterns listed in common books...
What do you guys think? Should constants be capitalized? Or is that an archaic practice? So...
const int MY_CONSTANT = 5;
vs.
const int myConstant = 5;
...
"Tell me, and I'll forget. Show me,
and I'll remember. Involve me, and
I'll learn."
We all have participated to some experiments with a teacher, a pro or a friend who wanted to make his point and involved you in the demonstration.
For example:
My communication teacher asked me to sit back to back with a friend. He gave him a s...
I have a small project that basically a Python wrapper to a websites API.
It's fairly well tested, but there are some conditions I cannot work out how to easily test: when the remote API is unreachable, or otherwise broken.
More specifically, I would quite like a test for each of the following:
When the site is unreachable (connectio...
I need to create a site map/list,but I need the link-name to show up as well.
What I mean by that is given , say , www.google.com , I need the following list to be created.
Google - www.google.com
Images - http://images.google.com/imghp?hl=en&tab=wi
...
My Account - http://images.google.com/imghp?hl=en&tab=wi
Personal Infor...
I have a following object model:
- Book
-- Chapter 1
--- Page 1
---- Image 1
---- Image 2
---- Text 1
--- Page 2
...
Resources are way down at the page level. But, I need to know the full path to resources, from the resources' point of view.
One way, is to have resources be aware of their parents.
So my Image object could have...
I'm preparing documentation for an open source project. My target audience are developers.
Right now, I'm working on the API, porting and code design sections.
Anyone has any tips on making documentation for developers?
...
Ok as programmers we all follow programming standards (as in W3 standards, or C++ standard, etc...), and many of us consider these standards "sacred" and also many seasoned programmers can recite their choice of standards by heart when asked about a question in their field of expertise. You can see this last case a lot here on SO by the ...
Upon reading a blog post about a minimalist story-generating python program, I was asking myself - and you - which are the most successful attempts at such programs. I remember seeing something using generating grammars, for instance. And which are the best attempts that, like this one, are extremely compact, either self-contained or abl...
What are good ways to handle user input concurrency?
As the answers to this question already rule out database locking, how do you handle concurrent user inputs in general?
Is locking always a bad idea, even if it is not implemented by row locking? Are there best practices which are not use case dependant?
What were your experiences wi...
Does anyone have any good references for equations which can be implemented relatively easily for how to compute the transfer of angular momentum between two rigid bodies?
I've been searching for this sort of thing for a while, and I haven't found any particularly comprehensible explanations of the problem.
To be precise, the question ...
I want to design a class that will parse a string into tokens that are meaningful to my application.
How do I design it?
Provide a ctor that accepts a string, provide a Parse method and provide methods (let's call them "minor") that return individual tokens, count of tokens etc. OR
Provide a ctor that accepts nothing, provide a Parse ...
The code golf series seem to be fairly popular. I ran across some code that converts a number to its word representation. Some examples would be (powers of 2 for programming fun):
2 -> Two
1024 -> One Thousand Twenty Four
1048576 -> One Million Forty Eight Thousand Five Hundred Seventy Six
The algorithm my co-worker came up was alm...
I have an array (arr) of elements, and a function (f) that takes 2 elements and returns a number.
I need a permutation of the array, such that f(arr[i], arr[i+1]) is as little as possible for each i in arr. (and it should loop, ie. it should also minimize f(arr[arr.length - 1], arr[0]))
Also, f works sort of like a distance, so f(a,b) ...
This is pretty trivial, but I noticed on SO that instead of an offset they are using page numbers. I know the difference is minor (multiply the page number by rows on a page or divide offset by rows on a page), but I'm wondering if one is recommended over the other.
Some sites, like Google, of course use a more complicated system becaus...