Big Integer redux

9

I started a project that will include Big Integer math implementation (common Delphi&FPC codebase) based on interfaces without objects. Right now the project reached the stage where I am able to compile (and run!) code like that:

{
  Usage example: BinomCoff 120 42
  Demonstrates how to use BigCardinal type
  see also:
    http://rosettacode.org/wiki/Evaluate_binomial_coefficients#Delphi
}
program BinomCoff;

{$APPTYPE CONSOLE}

uses
  SysUtils, tfNumerics;

function BinomialCoff(N, K: Cardinal): BigCardinal;
var
  L: Cardinal;

begin
  if N < K then
    Result:= 0      // Error
  else begin
    if K > N - K then
      K:= N - K;    // Optimization
    Result:= 1;
    L:= 0;
    while L < K do begin
      Result:= Result * (N - L);
      Inc(L);
      Result:= Result div L;
    end;
  end;
end;

var
  A: BigCardinal;
  M, N: Cardinal;

begin
  ReportMemoryLeaksOnShutdown:= True;
  try
    if ParamCount <> 2 then begin
      Writeln('Usage example: BinomCoff 120 42');
      ReadLn;
      Exit;
    end;
    N:= StrToInt(ParamStr(1));
    M:= StrToInt(ParamStr(2));
    A:= BinomialCoff(N, M);
    Writeln('C(', N, ', ', M, ') = ', A.AsString);
    A:= BigCardinal(nil);   // A is global var and should be freed explicitely
                            //   to prevent memory leak on shutdown
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  ReadLn;
end.

Output:

A lot still yet to be done, but it works! 🙂

Why StackOverflow sucks

743

StackOverflow is a monster Q&A machine. If you have a programming question, StackOverflow is probably the best place to ask – you have a better chance to get an answer on SO than anywhere else.
The paradox is that SO is not interested in users getting answers to their questions. Usually Q&A sites want their questioners to be happy, but not SO. SO wants great questions and great answers. Hence the reputation system and an army of Nazi retards moderating everything they can see.
If a question is considered poor by the user with moderating privileges, it will be downvoted, closed and finally deleted. But that is not all – SO has an automatic ban system. Users providing questions & answers that received low marks can be banned by robots.
One of the first questions I answered on SO more that 2 years ago was:

Here is a task:
“3 brothers have to transfer 9 boxes from one place to another.
These boxes weigh 1, 2, 4, 5, 6, 8, 9, 11, 14 kilos.
Every brother takes 3 boxes.
So, how to make a program that would count the most optimal way to take boxes?
The difference between one brother’s carrying boxes weight and other’s has to be as small as it can be.”
Can you just give me an idea or write a code with any programming language you want ( php or pascal if possible? ).
Thanks.

I thought the question was interesting and after spending some time found a solution based on checking all permutations of 9 weight numbers, it appeared to be blazingly fast. I posted an answer, and my answer was accepted by the questioner.
Sure that was not a great question. Also the question was not properly tagged – with ‘php’ and ‘pascal’. I guess ‘php’ tag was a mistake; the questioner got a whole army of moderating idiots attacking his question.
The question received 17 downvotes. The question got the comment `Smells like homework to me` and the comment got 14 upvotes; the presumption of innocence does not work on SO, and a guy with the editing privileges tagged the question as ‘homework’. Later on it was closed by the moderator called Bill the Lizard with the following resolution:

It’s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form.

Strange resolution, isn’t it? The question was answered…
The strange guy Bill the Lizard did not stop after closing the question. More than 1.5 year (!) after the question was answered he returned to it and deleted both the question and my answer (my answer probably because it contradicted his resolution).
If you think your post was not well accepted on SO, just think of the whole picture.

[Updated]

I was saying in this post “If you have a programming question, StackOverflow is probably the best place to ask”. It was when SO started some years ago; not now.

Today your chances to get a useful answer to your question on SO are close to zero. Instead you get a lot of comments arguing for example that your question does not fit SO or wrongly worded or else and nothing useful.

SO today is yet another trolls&noobs zoo.

Nice feature of Lazarus IDE

4

Lazarus treats include files (*.inc) as a part of a project. That means you should not bother where you store include files in a project – just

{$I Smth.inc}

is enough.

Not so in Delphi (Delphi XE to be exact). You can add *.inc file to a Delphi project, but it does not matter for Delphi, you still need to write paths to include files like that

{$I ..\..\Source\Common\Smth.inc}

and sure the paths are different for units in different project folders.