Created
September 6, 2012 21:41
-
-
Save lucassmagal/3660567 to your computer and use it in GitHub Desktop.
Solução do problema do Caixa Eletrônico em Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package caixa_eletronico | |
// Solucao do problema do caixa eletronico | |
// http://dojopuzzles.com/problemas/exibe/caixa-eletronico/ | |
func Saque(valor int) (resultado []int) { | |
cedulas := [7]int{100, 50, 20, 10, 5, 2, 1} | |
for _, cedula := range cedulas { | |
for valor >= cedula { | |
resultado = append(resultado, cedula) | |
valor -= cedula | |
} | |
} | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package caixa_eletronico | |
import ( | |
"testing" | |
"github.com/bmizerany/assert" | |
) | |
func TestSaque(t *testing.T) { | |
assert.Equal(t, Saque(83), []int{50, 20, 10, 2, 1}) | |
assert.Equal(t, Saque(79), []int{50, 20, 5, 2, 2}) | |
assert.Equal(t, Saque(30), []int{20, 10}) | |
assert.Equal(t, Saque(157), []int{100, 50, 5, 2}) | |
assert.Equal(t, Saque(15), []int{10, 5}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment