Coding challenge for any interested parties
Posted: 23 Nov 2021 09:35
*Following PenPen's suggestions, some edits have been made to provide clarity *
Background:
I enjoy batch scripting and a bit of code golfing in my spare time, and generally enjoy activities that require a degree of problem solving. I find batch to be interesting simply because there's a multitude of ways to approach problems, some simple and some rather obscure.
Id like to propose a challenge, that for many of the experts here should be simple enough, but I hope might still provide a bit of a thought excercise.
I propose also that any code responses be posted to an external site that shows an upload / edit time, and linked to a week from now so that responses arent influenced by others answers and we might see a few different approaches to solving the problem.
The task:
*Edit Clarified. Note: The edits made are not breaking - IE: they do not change the rules of the challenge or invalidate attempts made using the previous explanation of the rules.
Without using any of the following in your script:
- The literal characters 0 1 2 3 4 5 6 7 8 9
- If statements
- For loops
- DelayedExpansion
> Take 2 Inputs of the following types:
- A string containing any combination of printable ASCII characters ( TAB + Characters in the Decimal range 32 - 126 See: https://www.asciitable.com/ )
- Your script must be able to process an input string of any length supported by the method of reading input
- Accceptable methods of Input to use:
- Command line arguments
- Set /p prompt or read from file/s - Note: If reading both inputs from a single file, remember that For loops are prohibited.
- Hardcoded, provided that the input number is not used to generate other numbers the script will utilise
- Any other method of input you can concieve of that does not breach other rules of this challenge.
- An Integer (LEQ 8191)
> Walk the length of the string, and if the index number of the characters position is LEQ than the 2nd input and the string is not empty at that index, output the index position (1 indexed) and the character occupying it on a new line in the format:
Additional notes: *EDIT Repositioned and clarified:
- Testing will be done using windows 10 cmd.exe using code page 850
- Outside of The prohibited commands "If" "For" and the "DelayedExpansion" Environment, and keeping in mind the literal characters 0 1 2 3 4 5 6 7 8 9 are not permitted in your script, any executeable included in a standard windows 10 installation may be utilised by your script to generate the output. This includes but is not limited to using other languages in batch hybrids.
- No output to the console other than a prompt such as set /p for input or the expected output is permitted
- The program must be able to cope with empty inputs ( terminate without output )
- Inputs if provided will always be provided in string / integer order
Example One:
Example Two:
Background:
I enjoy batch scripting and a bit of code golfing in my spare time, and generally enjoy activities that require a degree of problem solving. I find batch to be interesting simply because there's a multitude of ways to approach problems, some simple and some rather obscure.
Id like to propose a challenge, that for many of the experts here should be simple enough, but I hope might still provide a bit of a thought excercise.
I propose also that any code responses be posted to an external site that shows an upload / edit time, and linked to a week from now so that responses arent influenced by others answers and we might see a few different approaches to solving the problem.
The task:
*Edit Clarified. Note: The edits made are not breaking - IE: they do not change the rules of the challenge or invalidate attempts made using the previous explanation of the rules.
Without using any of the following in your script:
- The literal characters 0 1 2 3 4 5 6 7 8 9
- If statements
- For loops
- DelayedExpansion
> Take 2 Inputs of the following types:
- A string containing any combination of printable ASCII characters ( TAB + Characters in the Decimal range 32 - 126 See: https://www.asciitable.com/ )
- Your script must be able to process an input string of any length supported by the method of reading input
- Accceptable methods of Input to use:
- Command line arguments
- Set /p prompt or read from file/s - Note: If reading both inputs from a single file, remember that For loops are prohibited.
- Hardcoded, provided that the input number is not used to generate other numbers the script will utilise
- Any other method of input you can concieve of that does not breach other rules of this challenge.
- An Integer (LEQ 8191)
> Walk the length of the string, and if the index number of the characters position is LEQ than the 2nd input and the string is not empty at that index, output the index position (1 indexed) and the character occupying it on a new line in the format:
Code: Select all
Indexnumber:"Character"
Additional notes: *EDIT Repositioned and clarified:
- Testing will be done using windows 10 cmd.exe using code page 850
- Outside of The prohibited commands "If" "For" and the "DelayedExpansion" Environment, and keeping in mind the literal characters 0 1 2 3 4 5 6 7 8 9 are not permitted in your script, any executeable included in a standard windows 10 installation may be utilised by your script to generate the output. This includes but is not limited to using other languages in batch hybrids.
- No output to the console other than a prompt such as set /p for input or the expected output is permitted
- The program must be able to cope with empty inputs ( terminate without output )
- Inputs if provided will always be provided in string / integer order
Example One:
Code: Select all
rem input 1
string: This (!@#$%^&*() String
rem input 2
Stop at char #: 10
rem output
1:"T"
2:"h"
3:"i"
4:"s"
5:" "
6:"("
7:"!"
8:"@"
9:"#"
10:"$"
Code: Select all
rem input 1
string: <an>other example "
rem input 2
Stop at char #: 50
rem output
1:"<"
2:"a"
3:"n"
4:">"
5:"o"
6:"t"
7:"h"
8:"e"
9:"r"
10:" "
11:"e"
12:"x"
13:"a"
14:"m"
15:"p"
16:"l"
17:"e"
18:" "
19:"""
C:\Users\tcdou>