User talk:Ledrug: Difference between revisions

No edit summary
 
(15 intermediate revisions by 9 users not shown)
Line 1:
== Common Lisp Implementation ==
If as you say you want to reopen this discussion then please add somthing to it here. If you have nothing to add then neither have I.
 
== Levenshtein distance C code ==
 
Line 73 ⟶ 76:
 
Cudos for catching this! :) I remembered to fix the one thing but forgot about the other... Cheers. [[User:WillNess|WillNess]] 06:41, 3 December 2011 (UTC)
 
Is there any documentation for the version of the code that is written and runs as PERL? "[[User:Cacher|Cacher]] ([[User talk:Cacher|talk]]) 03:54, 5 August 2014 (UTC)"
 
The setting up of the "property names and values" is straight forward, but the "constraints" section is a bit difficult to figure out.
Confused by the required order of the constraints and what to do when the hint is stated as the separation of two houses.
 
Trying to set up the following variant of the puzzle:
 
Puzzle: Given the following, where does everybody live?
 
# There is one house between the person eating potatoes and the person eating pancakes.
# The fourth house is white.
# The German drinks water.
# The German lives directly to the right of the horses.
# The butterflies live directly next to the brown house.
# The person in house two eats eggs.
# The person in house one drinks icetea.
# The person smoking pipe lives directly to the right of the person eating pancakes.
# The person eating spaghetties lives directly to the right of the white house.
# The Swede does not live in house one.
# There are two houses between the house of the person drinking coffee and the black house on the right
# There are two houses between the Spanish and the Dunhill smoking person on the left
# The person smoking Chersterfields lives directly to the left of the person smoking Cubans.
# The person eating potatoes lives directly next to the blue house.
# The British lives directly to the left of the birds.
# There are two houses between the turtles and the person drinking milk on the right
# The first house is brown.
# The person smoking Cubans eats spaghetties.
 
Answer: Should be: Spanish (4), German (5), Swede (3), British (2), Greek (1)
 
== Amazon links ==
Line 82 ⟶ 115:
== Lisp in the style of the C++ generator ==
Please leave [http://rosettacode.org/wiki/Kaprekar_numbers#In_the_style_of_the_C.2B.2B_generator this code] alone until you can demonstrate an understanding of this problem. Your second attempt at this is an improvement over your first naive attempt, but still not as interesting as [http://rosettacode.org/wiki/Kaprekar_numbers#In_the_style_of_the_C.2B.2B_generator this]. Maybe I shall seperate the [http://rosettacode.org/wiki/Casting_out_nines Casting_out_nines] from the Kaprecar part: <lang clisp>(let ((kk (* N N))) (do ((B Base (* B Base))) ()(let (( nr (/ (* N (- B N)) (- B 1)))) (if (< 0 nr) (let ((q (floor (- N nr)))) (if (= kk (+ nr (* q B)))</lang>
 
== Glitch in "Cut a rectangle" / CommonLisp ==
In [[Cut_a_rectangle#Common_Lisp]] the fourth line reading
<lang lisp>(if (= w 1) (return-from cut-it h))</lang>
leads to shown output like
<pre>2 x 1: 2 4 x 1: 4</pre> etc.
where these rectangles obviously have only 1 symetric cut.
As I have no intention to change a language example I <s>cannot</s>do not intend to run, I just thought to give notice to the author instead. - [[User:PKai|pKai]] ([[User talk:PKai|talk]]) 20:44, 10 May 2013 (UTC)
 
== LZW compressor ==
 
I have translated your nice C LZW program to D language. I have tried to make it idiomatic D, but some of the C style is probably still present. The D code currently still requires five casts, and I have guarded them with asserts, like:
 
assert(tmp >> oBits <= ubyte.max);
result[outLen] = cast(ubyte)(tmp >> oBits);
 
Perhaps with some more semantic knowledge of the program it's possible to avoid one or two of those casts.
If you want you can tell me if you see something that could be improved in the D version of the code. In some cases it's nice to receive a little of code review on Rosettacode.
: Since LZW deals with bit streams of variable-length token, a few casts are probably inevitable. I know nothing about D language, so I can't honestly comment on the D code, but since the C code is so messy, anything you did there would likely be an improvement in terms of safety and readability. If I get the time, it'd probably be a better idea for me to rewrite the C code cleanly instead. --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 17:36, 16 May 2014 (UTC)
 
== Finding pi using MonteCarlo method C Implementation ==
 
I didn't know if you were tracking the discussion page so I decided to copy our conversation. I hope you don't mind:
 
: Randomly throwing a point in a square, and it has chance p of being in the circle, while (1-p) chance of otherwise. If you throw N points and count the number of times n that they landed in the circle, n would follow [[wp:binomial distribution]] (look up the variance formula there). Here we are taking p = n/N as the ratio between areas of circle and square, but n is subject to statistical fluctuation. Assuming that we had the senses to throw a large enough N so n/N wouldn't be a completely bogus estimate of p, but we'd still like to know how far off it could be from p's true value. This is where the variance comes in: it tells you, given N and a rough knowledge of p, how much uncertainty of n (and p) one should expect.
 
: If you want to use the stddev formula, then each <math>x_i</math> takes the value of either 1 (landing in circle) or 0 (not). The average is <math>\mu = p</math> as mentioned above; now <math>\sigma^2 = {1\over N} \sum (x_i - p)^2</math>. Note that there are going to be about <math>Np</math> of those <math>x_i</math>s with value <math>1</math>, and <math>N(1-p)</math> with value <math>0</math>, so <math>\sum(x_i - p)^2 \approx Np(1-p)^2 + N(1-p)(0-p)^2 = Np(1-p)</math>. See how it comes back to the same formula? --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 06:17, 5 May 2014 (UTC)
 
:: Thank you very much that explains the origin of the formula. Even though following your reasoning the formula should be:
:: <math> \sum(x_i - p)^2 \approx Np(1-p)</math>,
:: But because we have a factor of <math> {1\over N} </math> we must take into account, then the resulting stddev should be:
:: <math>\sigma^2 = p(1-p)</math>,
:: Meaning that the formula implemented has an extra factor of <math> {1\over N} </math> inside the square root and a factor of <math> p </math> outside of the square root, meaning:
:: error = val * sqrt(val * (1 - val) / sampled) * 4, when it should be:
:: error = sqrt(val * (1 - val)) * 4;
:: Am I missing something else here? Sorry for the intrigue I'm no expert in probability, but I'm curious as to the implementation.-[[User:Chibby0ne|Chibby0ne]] ([[User talk:Chibby0ne|talk]]) 17:18, 17 May 2014 (UTC)
:: --00:17, 18 May 2014 (UTC)
::: What I wrote above was only to demonstrate how <math>p(1-p)</math> comes about; it's not actually how variance is derived. For that you need to take the binomial distribution, and calculate the variance of observed <math>n</math> (see [[wp:Variance#Binomial_distribution]]). When you throw <math>N</math> events, and receive <math>n</math> positives, the variance of <math>n</math> is <math>\mathrm{Var}(n) = Np(1-p)</math>. Without getting into too much details, let's say your result really means <math>N{\pi\over 4} = n\pm \sqrt{Np(1-p)}</math>, which leads to <math>\pi = {4n\over N} \pm 4 \sqrt{p(1-p)\over N}</math>, i.e., <code>error = sqrt(val*(1 - val)/sampled)*4</code>. I must admit that the first <tt>val</tt> in the original code is spurious; I don't know what I was thinking. But that shouldn't give an error that's off by orders of magnitude.
::: As a rule of thumb, sum of random samples deviates from "true" value by <math>\sqrt{N}</math>, while mean of random samples deviates by <math>1/\sqrt{N}</math>, as long as the distribution is something reasonable. This is why repeating an experiment many times reduces statistical uncertainty, but repeating too many times might not be worth the effort (because of the square root). Now I should go fix the code. --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 08:14, 18 May 2014 (UTC)
 
== Topographical Sort ==
 
 
Hi - just wanted to say thanks for doing the C version of the topological sort. I found it to be easier to follow than even some of the other "higher-level" implementations. Also the additional compile levels or layering of dependencies was exactly what I was looking for. Thank you!
 
== Total Area Circle - analytical solution ==
 
Hello i am beginning programmer, and your Total Area Circle Analytical solution is exactly what i need to solve a current problem i am working on, but i am working in C++ and cannot follow the Haskell code at all. I would like to ask you for your help writing it in C++, please? This was the only way method i could find to contact you. I hope to hear from you. Thank you. - vballhermie007
 
== Pentagram ==
 
Your PostScript entry is short and sweet, but it's not entirely correct. It doesn't fill the pentagon. [[User:Fwend|Fwend]] ([[User talk:Fwend|talk]]) 21:32, 21 April 2015 (UTC)
: It depends on what "fill" means. The code before used even-odd winding rule, which may be slightly unusual but I wouldn't exactly call it incorrect. I changed it to produce three different looking stars now, including one that's more likely to meet common expectations. --[[User:Ledrug|Ledrug]] ([[User talk:Ledrug|talk]]) 08:13, 22 April 2015 (UTC)
Anonymous user