A random brute force solution to Google Code Jam 2016 :CoinJam problem in golang
The provided solution solves the large problem input in <10 seconds
!!.
Remember the style is not necessarily idiomatic Go
, however it uses several ( around 200 ) goroutines ( I know Go can easily handle way more... ) for each coin condition checking as well as a single goroutine to generate a random coin of required size.
#####Getting Program
- You need go installed
- Then run command on terminal/bash:
$ go get github.com/GwiBo/GoCoinJam
The command wil download source files, compile and install binary in$GOPATH/bin
directory - There is a sample input file available in $GOPATH/src/github.com/GwiBo/GoCoinJam/C-Large.in
#####Usage instruction
- The program takes input from stdin (standard input) and outputs to stdout (standard output)
- the first line takes number of test cases
- the second line takes 2 (space separated) arguments :
size of coins
number of coins to generate
#####Hint
- When running on bash terminal, you can use pipes to get result
i.e.$ GoCoinJam < input.file > output.file
- With go properly installed / environment variables setup the full command to run the sample is as follows
$ $GOPATH/bin/GoCoinJam < $GOPATH/src/github.com/GwiBo/GoCoinJam/C-Large.in > sample.out
this will placesample.out
output file in your current working directory - If the program runs for more than (around) 30 seconds, then probably: either the input cannot be satisfied OR badluck ( run again )
###Test Hardware:
Hardware | Details |
---|---|
CPU | Intel Core i7 first generation (mobile edition) |
Ram | 8 GB |
Software | Details |
---|---|
OS | Ubuntu 16.04 |
Programming Language | go 1.6.2 ( currently, originally used go 1.6 |
####And the BIG question : Why such elaborate README.md for such trivial program?
Ans:
Just wanted to scratch an itch to write a Markdown text document. :) :) :)