In the thread
Syntax in Different Programming Languages, I quoted this:
One of my best classes in college was a class called The Organization of Programming Languages. It was taught by someone who was giving back time as a professional in the industry, rather than a professor. Many years later, it is one of the only ones that sticks in my mind and that I use. I've gone from and to many different languages - Pascal to VB to C to C++ to Delphi to C# (and I currently dabble in a few others). The syntax has never been the problem. You can always find syntax. It's the data structures and memory management and such that are always the sticking point. If you can get those, you can rapidly move from one language to another with a minimum of difficulty.
-wraith808
I came across that thread recently, and equated it to a thread on a different board, and figured I'd pose an exercise here.
- What was your first programming language?
- Can you remember a snippet from that language?
- What's your current language of choice?
- How would you rewrite that snippet in your current language?
My Answers are:
10 PRINT CHR(21): DIM CARDS(52),CHECK(52)
20 SUIT$ = "CDHS"
30 N$ = IA23456789TJQK"
40 FOR S = 0 TO 3: FOR C = 1 TO 13:CARD(C + S * 13) = MID$ (N$,C,1) + MID$ (SUIT$,S + 1,1): NEXT: NEXT
45 TEXT: HOME : NORMAL
50 FOR X = 1 TO 52
55 XX = X - 1: VTAB 1 + XX - INT (XX / 13) * 13: HTAB 1 + 10 * INT (XX / 13)
60 PRINT SPC( X < 10);X;I:";
70 N = INT ( RND (1) * 52) + 1
80 IF CHECK(N) THEN 70
90 CHECK(N) = 1
100 INVERSE: PRINT CARD$(N);
105 NORMAL: PRINT SPC( 5)
110 NEXT X
One of the interesting things about AppleBASIC is that you can have multiple commands on the same line. Trying to put this into c# wasn't as easy as I thought. There's still a bug somewhere in my code, and I know it looks messy, but I didn't want to put too much time into this.
"\n".Dump();
string[] cards
= new string[52]; int[] check
= new int[52]; const string SUIT = "CDHS";
string N = "IA23456789TJQK";
Random rnd
= new Random
();
for (int S = 0; S < 3; S ++)
{
for (int C = 1; C < 13; C++)
{
cards[C + S * 13] = Microsoft.VisualBasic.Strings.Mid (N,C,1) + Microsoft.VisualBasic.Strings.Mid (SUIT,S + 1,1);
}
}
for (int X = 1; X < 52; X++)
{
check[X] = 0;
}
for (int X = 1; X < 52; X++)
{
int cardPos;
while (1==1)
{
cardPos = rnd.Next(52);
if (check[cardPos] == 0)
{
check[cardPos] = 1;
cards[cardPos].Dump();
break;
}
}
}
It runs, and pulls the shuffled cards- but there are nulls in there for some reason. I also skipped over the formatting code, as I wasn't going to try to do that in the console.
Anyone else want to take a stab?