Search found 1879 matches
- 31 May 2023 20:25
- Forum: DOS Batch Forum
- Topic: Dos Batch Math Library
- Replies: 69
- Views: 101746
Re: Dos Batch Math Library
The same, written in a slightly different (and simpler, I think) way: @echo off setlocal EnableDelayedExpansion set "clamp= (leq=((low-x)>>31)+1)*low + (geq=((x-high)>>31)+1)*high + ^^^!(leq+geq)*x " set /A low=10, high=20 for /L %%i in (0,1,30) do ( set /A "x=%%i, out=%clamp%" echo %%i- !out! ) In ...
- 29 May 2023 12:02
- Forum: DOS Batch Forum
- Topic: How to clear an array?
- Replies: 9
- Views: 5346
Re: How to clear an array?
I don't see any advantage in using your proposed notation to write arrays (and I do see several if the standard form is used). For example, if you want to use part of a susbcript, I think that set "value=!var[%index:~0,4%]!" ... is clearer than set "value=!__var%index:~0,4%!" ... because in the firs...
- 29 May 2023 00:14
- Forum: DOS Batch Forum
- Topic: How to clear an array?
- Replies: 9
- Views: 5346
Re: How to clear an array?
IMHO it is simpler and clearer to use the standard array notation to define arrays. For example: set var[1]=abc set var[2]=123 In this way you can delete such array in the "standard way": for /f "delims==" %%x in ('set var[') do set "%%x=" Otherwise someone may think, especially beginners, that arra...
- 28 May 2023 23:54
- Forum: DOS Batch Forum
- Topic: Notepad bug
- Replies: 10
- Views: 9755
Re: Notepad bug
. . . Or to add chcp 65001 >nul at its beginning Mmmm... No... You have a confusion in a couple concepts... The file (the disk Batch file, or any file for this case) is created by Notepad.exe with UTF-8 as default encoding always . This have no relation with the contents of the file. The UTF-8 enco...
- 26 May 2023 12:19
- Forum: DOS Batch Forum
- Topic: Combinations of N numbers in sets of K with R repeated elements
- Replies: 9
- Views: 3587
Re: Combinations of N numbers in sets of K with R repeated elements
5- "Brute force" optimization I analyzed the "brute force" method and introduced optimizations in two main points: Cancel loops at end. Lets pay attention to %%i, %%j and %%k loops. When a valid line is found, no other valid line with the same %%k value will be found (because %%i, %%j and %%k would...
- 26 May 2023 00:12
- Forum: DOS Batch Forum
- Topic: Combinations of N numbers in sets of K with R repeated elements
- Replies: 9
- Views: 3587
Re: Combinations of N numbers in sets of K with R repeated elements
4- "Brute force" method I wrote a first version of a "brute force" method program that, giving the max number N, generates all the combinations with K numbers, count the number of elements in common with each previous accepted line, and accept new lines when this number is less or equal R. The tota...
- 26 May 2023 00:12
- Forum: DOS Batch Forum
- Topic: Combinations of N numbers in sets of K with R repeated elements
- Replies: 9
- Views: 3587
Re: Combinations of N numbers in sets of K with R repeated elements
3- Change two repetitions method to variables I liked the relatively short time (15 minutes) that generating combinations with TWO repetitions takes. However, I immediately tried to optimize such a method. I changed the auxiliary files used in "accumulated searchs" to environment variables hoping t...
- 26 May 2023 00:11
- Forum: DOS Batch Forum
- Topic: Combinations of N numbers in sets of K with R repeated elements
- Replies: 9
- Views: 3587
Re: Combinations of N numbers in sets of K with R repeated elements
2- Divide solution in 3 parts; the last uses findstr on Files I reviewed my program and concluded that a better method could be to divide the solution in 3 parts in order to get No, One and Two repeated elements in the generated lines via a precise (non-random) method. In this way I will be sure to...
- 26 May 2023 00:11
- Forum: DOS Batch Forum
- Topic: Combinations of N numbers in sets of K with R repeated elements
- Replies: 9
- Views: 3587
Combinations of N numbers in sets of K with R repeated elements
1- Using random numbers to generate combinations At this SO question an interesting Statistical Combinations problem is stated: Generating lines of six different numbers between 1 and 39 that have no more than two numbers in common with any previous line. The OP requested that 300 lines be generate...
- 23 May 2023 10:54
- Forum: DOS Batch Forum
- Topic: Dos Batch Math Library
- Replies: 69
- Views: 101746
Re: Dos Batch Math Library
The method to avoid that error is the way you already are doing: before the possible zero division assign to the result variable the value you want if the error happens (and redirect the error message to NUL). Your method/formula looks pretty good! 8) The only change I would do it is to rename the "...
- 04 May 2023 06:56
- Forum: DOS Batch Forum
- Topic: create macro: Let's create a small handout with reports .
- Replies: 17
- Views: 5522
Re: create macro: Let's create a small handout with reports .
I think you are not clear enough about what you really want... What do you want? Learn about macros? You can read the several posts here about this topic, modify the examples in order to understand how such a feature work and then, when you find a specific point you have problems with, post your non...
- 04 May 2023 06:16
- Forum: DOS Batch Forum
- Topic: Notepad bug
- Replies: 10
- Views: 9755
Re: Notepad bug
Note also that if you create a new (empty) .txt (or .bat) file and open it with Notepad, the file is saved as UTF-8 by default. All my .BAT files are UTF-8. This usually don't matters until you want to insert certain special graphical characters on it. The cure is "Save as" the file with ANSI encodi...
- 02 May 2023 22:31
- Forum: DOS Batch Forum
- Topic: create macro: Let's create a small handout with reports .
- Replies: 17
- Views: 5522
Re: create macro: Let's create a small handout with reports .
Mmmm... you were not clear enough in your request. I'm afraid I don't follow you... Your descriptions are very theoretical, not practical... You said "I need to optimize a script to run as fast as possible". Why don't just post an example of the (type of) script you want to optimize? This way we cou...
- 14 Apr 2023 22:30
- Forum: DOS Batch Forum
- Topic: Editing a variable (Searching from end)
- Replies: 1
- Views: 1226
Re: Editing a variable (Searching from end)
I think this line solve your problem:
If you change the <space><hypen><space> by a backslash, then the title takes the place of a file name that can be directly extracted via %%~Na FOR parameter modifier.
Code: Select all
for %%a in ("%filename: - =\%") do set "title=%%~Na"
- 30 Mar 2023 12:49
- Forum: DOS Batch Forum
- Topic: How to issue command but not have it execute
- Replies: 1
- Views: 1508
Re: How to issue command but not have it execute
Mmm... Think a minute about this request: "Issue a command but not have it execute" Makes this any sense to you? (neither for me). This phrase makes more sense: "have the letters "fc.exe" typed at the command prompt" At this SO answer there is the solution to a request similar to yours: I would like...