Friday Programming Quiz
-
@echo off set /a count=1 :: Load all the numbers :loop echo %1 > _%count%.var set /a count=count+1 shift if "%1" == "" goto :startSort goto loop :startSort set /a total=count-1 :RestartSort set /a count=1 :sortLoop set /a next=%count%+1 call :swap %count% %next% set /a count=count+1 if "%swapped%" == "true" goto :RestartSort if "%count%" == "%total%" goto :output goto :sortLoop :swap set /P var1="" < _%1.var set /P var2="" < _%2.var if /I %var1% LEQ %var2% goto noSwap ren _%1.var _temp.var ren _%2.var _%1.var ren _temp.var _%2.var set swapped=true goto :eof :noSwap set swapped= goto :eof :output set /A offset=((%total%-5)/2)+1 set /A limit=%offset%+4 for /L %%i in (%offset%,1,%limit%) do call :showval %%i :cleanup erase *.var set next= set offset= set total= set count= set var= set var1= set var2= goto :eof
Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page
Hot damn, somebody who likes to do perverted things with batch files as much as I do! :cool: :-D
Software Zen:
delete this;
-
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
print join "\n", @{[sort {$a <=> $b} @ARGV]}[$#ARGV/2-2 .. $#ARGV/2+2];
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish
| CP SearchBar v3.0 | C++ Forum FAQ Hungarian notation FTW
-
@echo off set /a count=1 :: Load all the numbers :loop echo %1 > _%count%.var set /a count=count+1 shift if "%1" == "" goto :startSort goto loop :startSort set /a total=count-1 :RestartSort set /a count=1 :sortLoop set /a next=%count%+1 call :swap %count% %next% set /a count=count+1 if "%swapped%" == "true" goto :RestartSort if "%count%" == "%total%" goto :output goto :sortLoop :swap set /P var1="" < _%1.var set /P var2="" < _%2.var if /I %var1% LEQ %var2% goto noSwap ren _%1.var _temp.var ren _%2.var _%1.var ren _temp.var _%2.var set swapped=true goto :eof :noSwap set swapped= goto :eof :output set /A offset=((%total%-5)/2)+1 set /A limit=%offset%+4 for /L %%i in (%offset%,1,%limit%) do call :showval %%i :cleanup erase *.var set next= set offset= set total= set count= set var= set var1= set var2= goto :eof
Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page
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^**
-
Hot damn, somebody who likes to do perverted things with batch files as much as I do! :cool: :-D
Software Zen:
delete this;
Wearing your black waders I hope.
-
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
Care to enlighten us as to why you've had to do that?
-
Care to enlighten us as to why you've had to do that?
After completing a LINQ book (which I was reviewing), I found out that LINQ in VB has more features than in C# (query expression wise). I was thinking about a simple example that can be used to demo LINQ in VB and that was it.
Co-Author ASP.NET AJAX in Action
-
After completing a LINQ book (which I was reviewing), I found out that LINQ in VB has more features than in C# (query expression wise). I was thinking about a simple example that can be used to demo LINQ in VB and that was it.
Co-Author ASP.NET AJAX in Action
Yeah, but that's still in beta, right? :-D
-
Yeah, but that's still in beta, right? :-D
-
PIEBALDconsult wrote:
Yeah, but that's still in beta, right? :-D
VB9 = Visual Beta 9 X|:-D
For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.(John 3:16) :badger:
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#.
-
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.