Converting Pascal to C#

  • Thread starter Thread starter Mark Scott
  • Start date Start date
M

Mark Scott

I have downloaded some code for a pascal program to generate permutations of
letters to solve anagrams:

program Anagramm;

{ Gibt alle möglichen Anagramme zu einem Wort aus.
Copyright (c) 8/99 by Bastisoft Int'l, Inc.
All rights reserved. Reproduction in part or in total
prohibited by Lower Saxonian and international law. }

var
w : String;

function RestWort(s : String; i : Integer) : String;
begin
RestWort := Copy(s,1,i-1) + Copy(s,i+1,Length(s)-i);
end;

procedure Perm(p, s : String);
var
i : Integer;
begin
if Length(s) = 1 then
Writeln(p,s)
else
for i := 1 to Length(s) do
Perm(p+s,RestWort(s,i));
end;

begin
if ParamCount = 0 then
begin
Write('Wort: ');
Readln(w);
end
else w := ParamStr(1);
Perm('',w);
end.

How would I do this in C#? I have desifned the interface, with an input
text box, and 3 putput buttons, screen, file (to a save as box, text) and
Printer. Any advice would be useful!

Regards

Mark
 
What part of "Reproduction in part or in total prohibited by Lower
Saxonian and international law" are we not supposed to pay
attention to?
 
LOL

Dumbass.

If you are stealing code, at least do it well.

BTW, stealing source is in no way different from stealing a couple of
manufacturingrobots. It is easier, true, but it still is theft.

Kind regards

Alexander

clintonG said:
What part of "Reproduction in part or in total prohibited by Lower
Saxonian and international law" are we not supposed to pay
attention to?

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET (e-mail address removed)
URL http://www.metromilwaukee.com/clintongallagher/




Mark Scott said:
I have downloaded some code for a pascal program to generate
permutations
of
letters to solve anagrams:

program Anagramm;

{ Gibt alle möglichen Anagramme zu einem Wort aus.
Copyright (c) 8/99 by Bastisoft Int'l, Inc.
All rights reserved. Reproduction in part or in total
prohibited by Lower Saxonian and international law. }

var
w : String;

function RestWort(s : String; i : Integer) : String;
begin
RestWort := Copy(s,1,i-1) + Copy(s,i+1,Length(s)-i);
end;

procedure Perm(p, s : String);
var
i : Integer;
begin
if Length(s) = 1 then
Writeln(p,s)
else
for i := 1 to Length(s) do
Perm(p+s,RestWort(s,i));
end;

begin
if ParamCount = 0 then
begin
Write('Wort: ');
Readln(w);
end
else w := ParamStr(1);
Perm('',w);
end.

How would I do this in C#? I have desifned the interface, with an input
text box, and 3 putput buttons, screen, file (to a save as box, text) and
Printer. Any advice would be useful!

Regards

Mark

 
This is a direct translation of the pascal as the equivalent c# Console program

using System;

namespace Anagram
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Anagram
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string w;
if (args.Length == 0)
{
Console.Write("Word: ");
w = Console.ReadLine();
}
else
w = args[0];
Perm("", w);
}
static void Perm(string p, string s)
{
if (s.Length == 1)
Console.WriteLine("{0}{1}", p, s);
else
for (int i = 0 ; i < s.Length; i++)
Perm(p + s.Substring(i, 1), RestWord(s, i));
}
static string RestWord(string s, int i)
{
return s.Substring(0, i) + s.Substring(i + 1, s.Length - i - 1);
}
}
}

If you want to make it gui that's up to you
 
Back
Top