Friday Programming Quiz
-
Not Vaporware Beta? :-D As VB is just a "prototyping language", it makes sense to use it as a test bed for Linq, before putting the final implementation in C#.
VB is the next MS dynamic language.
-
Rama Krishna Vavilala wrote:
Full marks to a VB.NET 9.0 solution.
Now, that's a challenge!! I haven't used VB for at least 5 years, but here we go...
Sub Main(ByVal args() As String)
For Each n In (From a In args Select r = Int32.Parse(a) Order By r Skip (args.Length - 5) / 2 Take 5)
Console.WriteLine(n)
Next
End SubHomepage: TomasP.net | Photo of the month: Calendar | C# and LINQ, F#, Phalanger: My Blog
Latest article: Phalanger, PHP for .NET: Introduction for .NET developers -
Given a set of numbers passed to the command line. The number of number is always odd. The program should sort them and output the 5 numbers in the middle. For example, if there are 9 numbers the output should be sorted numbers from indices 2 to 6. e.g.
c:> med5 67 89 12 1 8 1 3 5 7
3
5
7
8
12Full marks to a VB.NET 9.0 solution.;)
Co-Author ASP.NET AJAX in Action
vector<int> vec_num; for(int i=1;i<argc;i++){ vec_num.push_back(atoi((char*)argv[i])); } sort(vec_num.begin(),vec_num.end()); copy(vec_num.begin()+((vec_num.size()-5)/2), vec_num.end()-((vec_num.size()-5)/2), ostream_iterator<int>(cout, "\n"));
The Advantage in work-from-home is that... we can blame the dog -Mark Salsbery Best wishes to Rexx[^]
-
Hot damn, somebody who likes to do perverted things with batch files as much as I do! :cool: :-D
Software Zen:
delete this;
It is really amazing to see a charming quick cut batch file doing that marvellously. :)
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
And the GWBASIC one? ;P
**
xacc.ide-0.2.0.77 - now with C# 3.5 support and Navigation Bar!^
New xacc.ide release RSS feed^**
leppie wrote:
GWBASIC
Is it available for download somewhere? I got a copy of QBasic anyway from here: http://www.uv.tietgen.dk/staff/mlha/Download/DOS/microsoft/qbasic.exe[^]
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Given a set of numbers passed to the command line. The number of number is always odd. The program should sort them and output the 5 numbers in the middle. For example, if there are 9 numbers the output should be sorted numbers from indices 2 to 6. e.g.
c:> med5 67 89 12 1 8 1 3 5 7
3
5
7
8
12Full marks to a VB.NET 9.0 solution.;)
Co-Author ASP.NET AJAX in Action
Haskell
module Main where import Data.List import System main = do nums <- fmap (map (read :: String -> Integer)) getArgs (print.take 5.drop (((length nums)-5) `div` 2).sort) nums
-
vector<int> vec_num; for(int i=1;i<argc;i++){ vec_num.push_back(atoi((char*)argv[i])); } sort(vec_num.begin(),vec_num.end()); copy(vec_num.begin()+((vec_num.size()-5)/2), vec_num.end()-((vec_num.size()-5)/2), ostream_iterator<int>(cout, "\n"));
The Advantage in work-from-home is that... we can blame the dog -Mark Salsbery Best wishes to Rexx[^]
5 for using the ostream_iterator alone:)
Co-Author ASP.NET AJAX in Action
-
5 for using the ostream_iterator alone:)
Co-Author ASP.NET AJAX in Action
Anyway, a 5 is a 5 ;P. Btw I think I should learn a new language to reply to your Friday Question. Replies representing all other languages are just there in seconds you post your question.we can't make our replies unique unless I try for a deliberately different technique of the same language.:-D
The Advantage in work-from-home is that... we can blame the dog -Mark Salsbery Best wishes to Rexx[^]
-
Given a set of numbers passed to the command line. The number of number is always odd. The program should sort them and output the 5 numbers in the middle. For example, if there are 9 numbers the output should be sorted numbers from indices 2 to 6. e.g.
c:> med5 67 89 12 1 8 1 3 5 7
3
5
7
8
12Full marks to a VB.NET 9.0 solution.;)
Co-Author ASP.NET AJAX in Action
Here's some C#.
System.Collections.Generic.List<int> list = new System.Collections.Generic.List<int>
(
System.Array.ConvertAll<string,int>
(
args
,
delegate ( string s ) { return ( (int) System.Convert.ChangeType ( s , typeof(int) ) ) ; }
)
) ;list.Sort() ;
foreach
(
int i
in
list.GetRange
(
args.Length/2-2
,
5
)
)
{
System.Console.WriteLine ( i ) ;
}This points up two shortcomings of the current (V2) implementation of .net: 1) System.Array doesn't have a GetRange() method 2) Sort() returns void -- returning a reference to the object would be more flexible If these shortcomings were corrected, the above code could be:
foreach
(
int i
in
System.Array.ConvertAll<string,int>
(
args
,
delegate ( string s ) { return ( (int) System.Convert.ChangeType ( s , typeof(int) ) ) ; }
).Sort().GetRange
(
args.Length/2-2
,
5
)
)
{
System.Console.WriteLine ( i ) ;
}-- modified at 16:33 Saturday 1st September, 2007 Whoops, forgot to protect the angle-brackets -- modified at 16:34 Saturday 1st September, 2007 And then of course I put them backward
-
Not Vaporware Beta? :-D As VB is just a "prototyping language", it makes sense to use it as a test bed for Linq, before putting the final implementation in C#.
Do you now that the Silverlight Compiler is written in VB.Net???? You should think twice before you say that VB is used only for testing purposes.