[BATCH] challenges.

Discussion in 'Scripting' started by nephi12, Jul 3, 2013.

  1. nephi12

    nephi12 MDL Novice

    Jul 3, 2013
    4
    0
    0
    #1 nephi12, Jul 3, 2013
    Last edited by a moderator: Apr 20, 2017
    I was thinking it would be cool to have an area where people could post batch challenges, and see if people could do them. if it doesn't catch on that's okay, but I thought it would be fun.
    here is a starting one:

    Write a batch file that takes one argument to display a diamond in numbers
    The single argument should be number.
    Eg. diamond.bat 5 will give the following output
    Code:
         
           0                                                                                                                                                         
          0 1                                                                                                                                                        
         0 1 2                                                                                                                                                     
        0 1 2 3                                                                                                                                                     
       0 1 2 3 4                                                                                                                                                   
      0 1 2 3 4 5                                                                                                                                                 
      0 1 2 3 4 5                                                                                                                                                 
       0 1 2 3 4                                                                                                                                                   
        0 1 2 3                                                                                                                                                     
         0 1 2                                                                                                                                                      
          0 1                                                                                                                                                        
           0                                                                                                                                                         
    
    I found this on another thread, and here's my solution.
    Code:
    @echo off&setlocal enabledelayedexpansion
    if '%1'=='' (echo missing parameter&pause>nul&exit /b)
    for /l %%i in (%1,-1,0) do for /l %%j in (%%i,1,%1) do set %%i=!%%i! 
    for /l %%i in (0,1,%1) do (for /l %%j in (0,1,%%i) do set nums=!nums! %%j)&echo !%%i!!nums!&set nums=
    for /l %%i in (%1,-1,0) do (for /l %%j in (0,1,%%i) do set nums=!nums! %%j)&echo !%%i!!nums!&set nums=
    
    please post other challenges.--'_'
     
  2. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #2 Compo, Jul 10, 2013
    Last edited: Jul 10, 2013
    Here's the solution I provided in that Topic, with a NoBrainer version for those who don't know how to use a Command Prompt.

    For a little fun what about trying to create a pure batch simple lottery number generator.
     
  3. Humphrey

    Humphrey MDL Expert

    Dec 13, 2011
    1,466
    990
    60
    Cool story bro, tell it again..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Krutonium

    Krutonium MDL Senior Member

    Aug 27, 2013
    409
    285
    10
    Ok, here's a challenge:

    Single argument should be a word, and the output would be that word made of text, for an example, see below

    CORE

    CCCCCCCCCCC OOOOOOOOOOO RRRRRRRRRRRR EEEEEEEEEEEEE
    CCC OOO OOO RRR RRR EEE
    CCC OOO OOO RRR RRR EEE
    CCC OOO OOO RRRRRRRRRRRR EEEEEEEEEEE
    CCC OOO OOO RRR RRR EEE
    CCCCCCCCCCC OOOOOOOOOOO RRR RRR EEEEEEEEEEEEE

    Edit

    So the example got messed up, so I hope its easy enough to understand.
     
  5. deloppoled

    deloppoled MDL Novice

    Sep 3, 2013
    5
    0
    0
    #5 deloppoled, Sep 27, 2013
    Last edited by a moderator: Apr 20, 2017
    I just posted a solution to that challenge too but I can't link to it since I only have a couple of posts and I need to have 20 posts to be able to provide links. Sorry but I will repost it here for now, later when I have the magical 20 posts minimum I will come back and edit this to a linkage instead of a double post.

    Even though mine is very simplistic, I thionk that it passes the do it in a one line batch file challenge that was posed...I think!

    ******************
    My batch files name is diamond.bat and I have created a text file with the visually appealing, numerical diamond as it's contents--it is named simply "25" no extension or anything fancy pants like that. Maybe I cheated? I'm not really sure. Please feel free to call me all sorts of things if you think that I did, I will crawl under a rock, with a laptop and try again...maybe? But it was driving me nuts until I thought about it and well, it's the best that my brain could come up with! Thanks again for this thread!

    Code:
    Z:\>diamond 25
    
    Z:\>type 25
    
    
    
           0
          0 1
         0 1 2
        0 1 2 3
       0 1 2 3 4
      0 1 2 3 4 5
      0 1 2 3 4 5
       0 1 2 3 4
        0 1 2 3
         0 1 2
          0 1
           0
    
    
    
    Z:\>