Gianni Posted July 18, 2021 Posted July 18, 2021 (edited) at this link https://codegolf.stackexchange.com/questions/37905/mixed-base-conversion there is an interesting "challenge", how would you solve it with AutoIt? Edited July 18, 2021 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Gianni Posted July 18, 2021 Author Posted July 18, 2021 .... just an initial skeleton with no converter yet ... Example() Func Example() Local $aDigit_D[] = [52, 0, 0, 0, 0] ; D - a number passed as a list of digits Local $aBases_I[] = [100, 7, 24, 60, 60] ; I - an input base(s) array, an element for each input digit, ; if there are fewer elements than digits just wrap around Local $aBases_O[] = [10] ; O - an output base(s) array, an element for each output digit, ; if there are fewer elements than digits just wrap around Local $aResult = _MixedRadix($aDigit_D, $aBases_I, $aBases_O) ; an array of output digits EndFunc ;==>Example Func _MixedRadix($aInputDigits, $aInputBases, $aOutputBases) Local $Ib = UBound($aInputBases) Local $Ob = UBound($aOutputBases) Local $aDigits_Out For $dgit = UBound($aInputDigits) - 1 To 0 Step -1 $IndexIb = $Ib - Mod($dgit, $Ib) -1 ; this pointer points to the next input base element (it auto wraps when needed) $IndexOb = $Ob - Mod($dgit, $Ob) -1 ; this pointer points to the next output base element (it auto wraps when needed) ; to be continued ..... Next Return $aDigits_Out EndFunc ;==>_MixedRadix Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Nine Posted July 18, 2021 Posted July 18, 2021 Here my attempt (works for all examples) : #include <Array.au3> ;Const $DIG = [1,0,0], $IN = [10], $OUT = [2] ;Const $DIG = [1,0,0], $IN = [2], $OUT = [10] ;Const $DIG = [1,9,0,3,1,5], $IN = [2,10], $OUT = [10] ;Const $DIG = [1,9,0,3,1,5], $IN = [2,10], $OUT = [4,3,2] ;Const $DIG = [52,0,0,0,0], $IN = [100,7,24,60,60], $OUT = [10] Const $DIG = [0,2,10], $IN = [2,4,8,16], $OUT = [42] ;Const $DIG = [], $IN = [123,456], $OUT = [13] ;Const $DIG = [0, 0], $IN = [123,456], $OUT = [13] Local $Result[0] Local $res = 0, $tmp For $i = 1 To UBound($DIG) $tmp = $DIG[UBound($DIG) - $i] For $j = 1 to $i - 1 $tmp *= $IN[UBound($IN)-Mod($j-1, UBound($IN)) - 1] Next $res += $tmp Next ConsoleWrite($res & @CRLF) $i = 0 While $res > 0 ReDim $Result[$i+1] $tmp = $OUT[UBound($OUT)-Mod($i, UBound($OUT)) - 1] $Result[$i] = Mod($res, $tmp) $res = Floor($res/$tmp) $i += 1 WEnd _ArrayReverse($Result) _ArrayDisplay($Result) Gianni 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Gianni Posted July 19, 2021 Author Posted July 19, 2021 Nice, thanks @Nine ... here's another possible interesting use case suitable for this function:https://codegolf.stackexchange.com/questions/79609/index-of-a-multidimensional-array that's way I was interested in that function, ... see you later ... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
Nine Posted July 19, 2021 Posted July 19, 2021 Optimized code : #include <Array.au3> Const $DIG = [1,0,0], $IN = [10], $OUT = [2] ;Const $DIG = [1,0,0], $IN = [2], $OUT = [10] ;Const $DIG = [1,9,0,3,1,5], $IN = [2,10], $OUT = [10] ;Const $DIG = [1,9,0,3,1,5], $IN = [2,10], $OUT = [4,3,2] ;Const $DIG = [52,0,0,0,0], $IN = [100,7,24,60,60], $OUT = [10] ;Const $DIG = [0,2,10], $IN = [2,4,8,16], $OUT = [42] ;Const $DIG = [], $IN = [123,456], $OUT = [13] ;Const $DIG = [0, 0], $IN = [123,456], $OUT = [13] Local $Result[0], $res = 0, $tmp = 1 For $i = 1 To UBound($DIG) $res += $DIG[UBound($DIG) - $i] * $tmp $tmp *= $IN[UBound($IN)-Mod($i-1, UBound($IN)) - 1] Next ConsoleWrite($res & @CRLF) $i = 0 While $res > 0 ReDim $Result[$i+1] $tmp = $OUT[UBound($OUT)-Mod($i, UBound($OUT)) - 1] $Result[$i] = Mod($res, $tmp) $res = Floor($res/$tmp) $i += 1 WEnd _ArrayReverse($Result) _ArrayDisplay($Result) Gianni 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now