# Mixed Base Conversion (coding challenge)

## Recommended Posts

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 by Chimp

Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

##### Share on other sites

What you got ready to start testing ? ,if yet

##### Share on other sites

.... 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

Local \$Ib = UBound(\$aInputBases)
Local \$Ob = UBound(\$aOutputBases)

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

Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

##### Share on other sites

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)```

Not much of a signature but working on it...

Spoiler

##### Share on other sites

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....

##### Share on other sites

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)```

Not much of a signature but working on it...

Spoiler

## Create an account

Register a new account

• ### Similar Content

• By guinness
I have been known in the past to do these kind of challenges and thought it was that time once again that I present the AutoIt community with a new challenge. I suggest you first go and read the link below as to what is the purpose of the challenge, as I would only repeat what was already said.
Anyway, once you've read the challenge, try and fill in the missing code to solve Josephus problem. Good luck.
Local \$aArray = [1,2,3,4,5,6,7] Josephus(\$aArray, 3) ; Returns [3,6,2,7,5,1,4] Josephus(\$aArray, 1) ; Returns [1,2,3,4,5,6,7] Func Josephus(\$aArray, \$iCount) ; Code here ; Returns an array EndFunc Source: http://www.codewars.com/kata/josephus-permutation

• Hello, I have a simple task today, I am sure that I made a similar post a long time ago... I want trim (delete or remove or wipe) the contents of a file (text or binary) WITHOUT storing the contents of the file anywhere in the script. Here is a text file for the purpose of experimenting: (contents of text.txt)
1234567890The task is simple, remove "456" from the contents of text.txt WITHOUT storing the contents anywhere! I wanted to post some code but it seems impossible to provide any relevant code this time...

Good luck with the challenge! TD
• By TheSaint
Hi everyone,
Perhaps, if you have a spare moment, you might like to take a look at >Wiki Examples Challenge Part 2 in the Developer Chat section, and do AutoIt and the contestants a favor, by examining the six Examples and casting a vote for one of them.
That would be really appreciated.
P.S. Jos, ETC, Melba23 - I hope you don't mind me posting this here and in General Help as well?
• By guinness
Last time I had a >Paper, Rock, Scissors - Challenge and now I think it's time for a new one.
Challenge: Create a lottery game with the least amount of lines in AutoIt. The user should be prompted to enter a string of 7 lottery numbers from 1 to 49 and have either a comma (,) or single space as the delimiter e.g. 1,5,10,37,15,43,2. It should be checked against 7 random numbers to see if they all match. If all 7 match then they win, otherwise they lose. The numbers should be valid and contain zero duplicates in both the user's choice and computer generated sequence.
Good luck.

Note: I am not playing this time around as some people said it was unfair that I took part last time. Oh and serious contenders need only apply please.
PS. I created this in C# using 4 lines of code when the idea was presented to me by a mate...so yeah...good luck! -_0
NO /AutoItExecuteScript workarounds.
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...