Click here to Skip to main content
15,903,362 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionmath challenge Pin
santi nuñez29-Apr-18 11:35
santi nuñez29-Apr-18 11:35 
AnswerRe: math challenge Pin
Richard MacCutchan29-Apr-18 21:25
mveRichard MacCutchan29-Apr-18 21:25 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 4:31
santi nuñez30-Apr-18 4:31 
GeneralRe: math challenge Pin
Richard MacCutchan30-Apr-18 5:38
mveRichard MacCutchan30-Apr-18 5:38 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 6:43
santi nuñez30-Apr-18 6:43 
GeneralRe: math challenge Pin
Richard MacCutchan30-Apr-18 6:53
mveRichard MacCutchan30-Apr-18 6:53 
GeneralRe: math challenge Pin
santi nuñez30-Apr-18 6:55
santi nuñez30-Apr-18 6:55 
GeneralRe: math challenge Pin
Richard Deeming30-Apr-18 7:02
mveRichard Deeming30-Apr-18 7:02 
Sounds like a good candidate for a recursive algorithm. Smile | :)

To get the results for four numbers, you need to combine:
  • The first number + the results for the other three numbers;
  • The first number - the results for the other three numbers;
  • The first number * the results for the other three numbers;
  • The first number / the results for the other three numbers;

For example:
VB.NET
Public Shared Function AllResults(ByVal ParamArray numbers() As Integer) As IEnumerable(Of Integer)
    If numbers Is Nothing OrElse numbers.Length = 0 Then Return Enumerable.Empty(Of Integer)
    Return AllResultsIterator(numbers, numbers.Length)
End Function

Private Shared Iterator Function AllResultsIterator(ByVal numbers As IEnumerable(Of Integer), ByVal length As Integer) As IEnumerable(Of Integer)
    Dim n0 As Integer = numbers.First()
    If length = 1 Then
        Yield n0
        Return
    End If
    
    For Each result As Integer In AllResultsIterator(numbers.Skip(1), length - 1)
        Yield n0 + result
        Yield n0 - result
        Yield n0 * result
        If result <> 0 Then Yield n0 \ result
    Next
End Function
NB: This will include duplicate results.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: math challenge Pin
santi nuñez30-Apr-18 9:37
santi nuñez30-Apr-18 9:37 
QuestionAdjusting a .VBS/.DOS command. Pin
glenn masters28-Apr-18 1:40
glenn masters28-Apr-18 1:40 
AnswerRe: Adjusting a .VBS/.DOS command. Pin
Eddy Vluggen30-Apr-18 1:26
professionalEddy Vluggen30-Apr-18 1:26 
QuestionVB.NET encryption code to VB6 Pin
Member 305688623-Apr-18 22:57
Member 305688623-Apr-18 22:57 
AnswerRe: VB.NET encryption code to VB6 Pin
Jochen Arndt24-Apr-18 0:48
professionalJochen Arndt24-Apr-18 0:48 
AnswerRe: VB.NET encryption code to VB6 Pin
Chris Quinn24-Apr-18 4:40
Chris Quinn24-Apr-18 4:40 
QuestionFlat NumericUpDown Pin
jtpaa19-Apr-18 20:03
jtpaa19-Apr-18 20:03 
AnswerRe: Flat NumericUpDown Pin
Maciej Los23-Apr-18 10:08
mveMaciej Los23-Apr-18 10:08 
QuestionGetting Run-time error '9' for Subscript out of range Pin
Member 1378560917-Apr-18 23:41
Member 1378560917-Apr-18 23:41 
AnswerRe: Getting Run-time error '9' for Subscript out of range Pin
Richard MacCutchan17-Apr-18 23:58
mveRichard MacCutchan17-Apr-18 23:58 
Questionextracting data problem to ms exel and access database location different in some system Pin
lazy_dude16-Apr-18 2:15
lazy_dude16-Apr-18 2:15 
AnswerRe: extracting data problem to ms exel and access database location different in some system Pin
Jochen Arndt16-Apr-18 3:32
professionalJochen Arndt16-Apr-18 3:32 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude18-Apr-18 4:23
lazy_dude18-Apr-18 4:23 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
Jochen Arndt18-Apr-18 4:50
professionalJochen Arndt18-Apr-18 4:50 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude18-Apr-18 4:51
lazy_dude18-Apr-18 4:51 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
Richard MacCutchan18-Apr-18 5:55
mveRichard MacCutchan18-Apr-18 5:55 
GeneralRe: extracting data problem to ms exel and access database location different in some system Pin
lazy_dude23-Apr-18 6:55
lazy_dude23-Apr-18 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.