trackler 2.2.1.46 → 2.2.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/nucleotide-count/canonical-data.json +7 -7
- data/tracks/c/README.md +1 -1
- data/tracks/c/docs/SNIPPET.txt +2 -3
- data/tracks/c/exercises/acronym/test/test_acronym.c +8 -0
- data/tracks/c/exercises/all-your-base/test/test_all_your_base.c +8 -0
- data/tracks/c/exercises/allergies/test/test_allergies.c +8 -0
- data/tracks/c/exercises/anagram/test/test_anagram.c +8 -0
- data/tracks/c/exercises/atbash-cipher/test/test_atbash_cipher.c +8 -0
- data/tracks/c/exercises/beer-song/src/example.c +23 -22
- data/tracks/c/exercises/beer-song/src/example.h +3 -3
- data/tracks/c/exercises/beer-song/test/test_beer_song.c +8 -0
- data/tracks/c/exercises/binary-search/test/test_binary_search.c +8 -0
- data/tracks/c/exercises/binary/test/test_binary.c +8 -0
- data/tracks/c/exercises/bob/test/test_bob.c +8 -0
- data/tracks/c/exercises/clock/test/test_clock.c +8 -0
- data/tracks/c/exercises/difference-of-squares/test/test_difference_of_squares.c +8 -0
- data/tracks/c/exercises/gigasecond/test/test_gigasecond.c +8 -0
- data/tracks/c/exercises/grains/test/test_grains.c +8 -0
- data/tracks/c/exercises/hamming/test/test_hamming.c +8 -0
- data/tracks/c/exercises/hello-world/src/example.c +0 -2
- data/tracks/c/exercises/hello-world/test/test_hello_world.c +8 -0
- data/tracks/c/exercises/isogram/test/test_isogram.c +8 -0
- data/tracks/c/exercises/largest-series-product/test/test_largest_series_product.c +8 -0
- data/tracks/c/exercises/leap/test/test_leap.c +8 -0
- data/tracks/c/exercises/meetup/test/test_meetup.c +8 -0
- data/tracks/c/exercises/nth-prime/test/test_nth_prime.c +8 -0
- data/tracks/c/exercises/nucleotide-count/test/test_nucleotide_count.c +8 -0
- data/tracks/c/exercises/palindrome-products/test/test_palindrome_products.c +8 -0
- data/tracks/c/exercises/pangram/test/test_pangram.c +8 -0
- data/tracks/c/exercises/pascals-triangle/test/test_pascals_triangle.c +8 -0
- data/tracks/c/exercises/perfect-numbers/src/example.c +4 -4
- data/tracks/c/exercises/perfect-numbers/src/example.h +4 -4
- data/tracks/c/exercises/perfect-numbers/src/perfect_numbers.h +4 -4
- data/tracks/c/exercises/perfect-numbers/test/test_perfect_numbers.c +23 -13
- data/tracks/c/exercises/phone-number/test/test_phone_number.c +8 -0
- data/tracks/c/exercises/raindrops/test/test_raindrops.c +5 -1
- data/tracks/c/exercises/react/src/example.c +8 -8
- data/tracks/c/exercises/react/test/test_react.c +8 -0
- data/tracks/c/exercises/rna-transcription/test/test_rna_transcription.c +8 -0
- data/tracks/c/exercises/robot-simulator/src/example.c +12 -12
- data/tracks/c/exercises/robot-simulator/src/robot_simulator.h +11 -11
- data/tracks/c/exercises/robot-simulator/test/test_robot_simulator.c +33 -25
- data/tracks/c/exercises/roman-numerals/test/test_roman_numerals.c +8 -0
- data/tracks/c/exercises/scrabble-score/test/test_scrabble_score.c +8 -0
- data/tracks/c/exercises/series/test/test_series.c +8 -0
- data/tracks/c/exercises/sieve/test/test_sieve.c +8 -0
- data/tracks/c/exercises/space-age/src/example.h +8 -8
- data/tracks/c/exercises/space-age/test/test_space_age.c +16 -8
- data/tracks/c/exercises/sum-of-multiples/test/test_sum_of_multiples.c +8 -0
- data/tracks/c/exercises/triangle/test/test_triangle.c +8 -0
- data/tracks/c/exercises/word-count/test/test_word_count.c +8 -0
- data/tracks/cfml/config.json +8 -0
- data/tracks/cfml/exercises/anagram/.meta/HINTS.md +0 -0
- data/tracks/cfml/exercises/anagram/Anagram.cfc +13 -0
- data/tracks/cfml/exercises/anagram/AnagramTest.cfc +79 -0
- data/tracks/cfml/exercises/anagram/README.md +29 -0
- data/tracks/cfml/exercises/anagram/Solution.cfc +42 -0
- data/tracks/cfml/exercises/anagram/SolutionTest.cfc +7 -0
- data/tracks/cfml/exercises/anagram/TestRunner.cfc +103 -0
- data/tracks/cfml/exercises/anagram/box.json +8 -0
- data/tracks/cfml/exercises/anagram/index.cfm +37 -0
- data/tracks/common-lisp/config.json +5 -5
- data/tracks/csharp/exercises/two-bucket/Example.cs +53 -79
- data/tracks/csharp/exercises/two-bucket/TwoBucketTest.cs +2 -2
- data/tracks/csharp/generators/Exercises/QueenAttack.cs +3 -3
- data/tracks/dart/exercises/leap/test/leap_test.dart +1 -1
- data/tracks/delphi/exercises/hamming/uHammingTests.pas +2 -2
- data/tracks/delphi/exercises/leap/uLeapTests.pas +11 -38
- data/tracks/delphi/exercises/nucleotide-count/uNucleotideCountExample.pas +1 -1
- data/tracks/delphi/exercises/nucleotide-count/uNucleotideCountTest.pas +31 -55
- data/tracks/ecmascript/config.json +31 -0
- data/tracks/ecmascript/config/maintainers.json +5 -5
- data/tracks/ecmascript/exercises/accumulate/package.json +1 -1
- data/tracks/ecmascript/exercises/acronym/package.json +1 -1
- data/tracks/ecmascript/exercises/all-your-base/package.json +1 -1
- data/tracks/ecmascript/exercises/allergies/package.json +1 -1
- data/tracks/ecmascript/exercises/alphametics/package.json +1 -1
- data/tracks/ecmascript/exercises/anagram/package.json +1 -1
- data/tracks/ecmascript/exercises/atbash-cipher/package.json +1 -1
- data/tracks/ecmascript/exercises/beer-song/package.json +1 -1
- data/tracks/ecmascript/exercises/binary-search-tree/package.json +1 -1
- data/tracks/ecmascript/exercises/binary-search/package.json +1 -1
- data/tracks/ecmascript/exercises/binary/package.json +1 -1
- data/tracks/ecmascript/exercises/bob/package.json +1 -1
- data/tracks/ecmascript/exercises/bracket-push/package.json +1 -1
- data/tracks/ecmascript/exercises/circular-buffer/package.json +1 -1
- data/tracks/ecmascript/exercises/clock/package.json +1 -1
- data/tracks/ecmascript/exercises/collatz-conjecture/README.md +59 -0
- data/tracks/ecmascript/exercises/collatz-conjecture/collatz-conjecture.spec.js +31 -0
- data/tracks/ecmascript/exercises/collatz-conjecture/example.js +14 -0
- data/tracks/ecmascript/exercises/collatz-conjecture/package.json +69 -0
- data/tracks/ecmascript/exercises/connect/package.json +1 -1
- data/tracks/ecmascript/exercises/crypto-square/package.json +1 -1
- data/tracks/ecmascript/exercises/custom-set/package.json +1 -1
- data/tracks/ecmascript/exercises/diamond/package.json +1 -1
- data/tracks/ecmascript/exercises/difference-of-squares/package.json +1 -1
- data/tracks/ecmascript/exercises/diffie-hellman/package.json +1 -1
- data/tracks/ecmascript/exercises/etl/package.json +1 -1
- data/tracks/ecmascript/exercises/flatten-array/package.json +1 -1
- data/tracks/ecmascript/exercises/food-chain/package.json +1 -1
- data/tracks/ecmascript/exercises/gigasecond/package.json +1 -1
- data/tracks/ecmascript/exercises/grade-school/package.json +1 -1
- data/tracks/ecmascript/exercises/grains/package.json +1 -1
- data/tracks/ecmascript/exercises/hamming/package.json +1 -1
- data/tracks/ecmascript/exercises/hello-world/package.json +1 -1
- data/tracks/ecmascript/exercises/hexadecimal/package.json +1 -1
- data/tracks/ecmascript/exercises/isogram/package.json +1 -1
- data/tracks/ecmascript/exercises/kindergarten-garden/package.json +1 -1
- data/tracks/ecmascript/exercises/largest-series-product/package.json +1 -1
- data/tracks/ecmascript/exercises/leap/package.json +1 -1
- data/tracks/ecmascript/exercises/linked-list/package.json +1 -1
- data/tracks/ecmascript/exercises/list-ops/package.json +1 -1
- data/tracks/ecmascript/exercises/luhn/package.json +1 -1
- data/tracks/ecmascript/exercises/matrix/package.json +1 -1
- data/tracks/ecmascript/exercises/meetup/package.json +1 -1
- data/tracks/ecmascript/exercises/minesweeper/package.json +1 -1
- data/tracks/ecmascript/exercises/nth-prime/package.json +1 -1
- data/tracks/ecmascript/exercises/ocr-numbers/package.json +1 -1
- data/tracks/ecmascript/exercises/octal/package.json +1 -1
- data/tracks/ecmascript/exercises/palindrome-products/package.json +1 -1
- data/tracks/ecmascript/exercises/pangram/package.json +1 -1
- data/tracks/ecmascript/exercises/pascals-triangle/package.json +1 -1
- data/tracks/ecmascript/exercises/perfect-numbers/package.json +1 -1
- data/tracks/ecmascript/exercises/phone-number/package.json +1 -1
- data/tracks/ecmascript/exercises/pig-latin/package.json +1 -1
- data/tracks/ecmascript/exercises/prime-factors/package.json +1 -1
- data/tracks/ecmascript/exercises/proverb/package.json +1 -1
- data/tracks/ecmascript/exercises/pythagorean-triplet/package.json +1 -1
- data/tracks/ecmascript/exercises/queen-attack/package.json +1 -1
- data/tracks/ecmascript/exercises/raindrops/package.json +1 -1
- data/tracks/ecmascript/exercises/rna-transcription/package.json +1 -1
- data/tracks/ecmascript/exercises/robot-name/package.json +1 -1
- data/tracks/ecmascript/exercises/robot-simulator/package.json +1 -1
- data/tracks/ecmascript/exercises/roman-numerals/package.json +1 -1
- data/tracks/ecmascript/exercises/run-length-encoding/package.json +1 -1
- data/tracks/ecmascript/exercises/saddle-points/package.json +1 -1
- data/tracks/ecmascript/exercises/say/package.json +1 -1
- data/tracks/ecmascript/exercises/scrabble-score/package.json +1 -1
- data/tracks/ecmascript/exercises/secret-handshake/package.json +1 -1
- data/tracks/ecmascript/exercises/series/package.json +1 -1
- data/tracks/ecmascript/exercises/sieve/package.json +1 -1
- data/tracks/ecmascript/exercises/simple-cipher/package.json +1 -1
- data/tracks/ecmascript/exercises/simple-linked-list/package.json +1 -1
- data/tracks/ecmascript/exercises/space-age/package.json +1 -1
- data/tracks/ecmascript/exercises/strain/package.json +1 -1
- data/tracks/ecmascript/exercises/sublist/package.json +1 -1
- data/tracks/ecmascript/exercises/sum-of-multiples/package.json +1 -1
- data/tracks/ecmascript/exercises/triangle/package.json +1 -1
- data/tracks/ecmascript/exercises/trinary/package.json +1 -1
- data/tracks/ecmascript/exercises/twelve-days/package.json +1 -1
- data/tracks/ecmascript/exercises/two-bucket/package.json +1 -1
- data/tracks/ecmascript/exercises/word-count/package.json +1 -1
- data/tracks/ecmascript/exercises/word-search/README.md +58 -0
- data/tracks/ecmascript/exercises/word-search/example.js +146 -0
- data/tracks/ecmascript/exercises/word-search/package.json +69 -0
- data/tracks/ecmascript/exercises/word-search/word-search.spec.js +626 -0
- data/tracks/ecmascript/exercises/wordy/package.json +1 -1
- data/tracks/ecmascript/package.json +1 -1
- data/tracks/elixir/config.json +11 -0
- data/tracks/elixir/exercises/luhn/example.exs +26 -46
- data/tracks/elixir/exercises/luhn/luhn.exs +0 -13
- data/tracks/elixir/exercises/luhn/luhn_test.exs +44 -14
- data/tracks/elixir/exercises/transpose/README.md +101 -0
- data/tracks/elixir/exercises/transpose/example.exs +46 -0
- data/tracks/elixir/exercises/transpose/transpose.exs +22 -0
- data/tracks/elixir/exercises/transpose/transpose_test.exs +248 -0
- data/tracks/fsharp/exercises/grains/Example.fs +10 -2
- data/tracks/fsharp/exercises/grains/Grains.fs +2 -4
- data/tracks/fsharp/exercises/grains/GrainsTest.fs +52 -25
- data/tracks/fsharp/exercises/phone-number/Example.fs +11 -3
- data/tracks/fsharp/exercises/phone-number/PhoneNumber.fs +1 -1
- data/tracks/fsharp/exercises/phone-number/PhoneNumberTest.fs +32 -21
- data/tracks/fsharp/exercises/prime-factors/Example.fs +6 -13
- data/tracks/fsharp/exercises/prime-factors/PrimeFactors.fs +1 -1
- data/tracks/fsharp/exercises/prime-factors/PrimeFactorsTest.fs +23 -32
- data/tracks/fsharp/exercises/rail-fence-cipher/RailFenceCipherTest.fs +22 -13
- data/tracks/fsharp/generators/Exercise.fs +3 -4
- data/tracks/fsharp/generators/Generators.fs +31 -0
- data/tracks/gnu-apl/bin/run-all-tests +5 -2
- data/tracks/java/CONTRIBUTING.md +8 -0
- data/tracks/java/POLICIES.md +2 -2
- data/tracks/java/config.json +26 -4
- data/tracks/java/exercises/triangle/.meta/.version +1 -0
- data/tracks/java/exercises/triangle/.meta/src/reference/java/Triangle.java +1 -1
- data/tracks/java/exercises/triangle/src/test/java/TriangleTest.java +59 -40
- data/tracks/javascript/config.json +30 -0
- data/tracks/javascript/config/maintainers.json +8 -8
- data/tracks/javascript/exercises/change/example.js +6 -22
- data/tracks/javascript/exercises/collatz-conjecture/README.md +57 -0
- data/tracks/javascript/exercises/collatz-conjecture/collatz-conjecture.spec.js +37 -0
- data/tracks/javascript/exercises/collatz-conjecture/example.js +20 -0
- data/tracks/javascript/exercises/protein-translation/example.js +30 -31
- data/tracks/javascript/exercises/protein-translation/protein-translation.spec.js +60 -60
- data/tracks/javascript/exercises/transpose/README.md +89 -0
- data/tracks/javascript/exercises/transpose/example.js +17 -0
- data/tracks/javascript/exercises/transpose/transpose.spec.js +67 -0
- data/tracks/objective-c/config.json +283 -263
- data/tracks/objective-c/exercises/grains/GrainsExample.h +6 -0
- data/tracks/objective-c/exercises/grains/GrainsExample.m +19 -0
- data/tracks/objective-c/exercises/grains/GrainsTest.m +85 -0
- data/tracks/objective-c/exercises/nth-prime/NthPrimeExample.h +6 -0
- data/tracks/objective-c/exercises/nth-prime/NthPrimeExample.m +39 -0
- data/tracks/objective-c/exercises/nth-prime/NthPrimeTest.m +53 -0
- data/tracks/python/config.json +42 -11
- data/tracks/python/exercises/change/README.md +34 -0
- data/tracks/python/exercises/two-bucket/README.md +47 -0
- data/tracks/ruby/README.md +4 -1
- data/tracks/ruby/lib/generator/command_line.rb +3 -3
- data/tracks/ruby/lib/generator/command_line/generator_optparser.rb +3 -3
- data/tracks/ruby/test/generator/command_line/generator_optparser_test.rb +4 -4
- data/tracks/ruby/test/generator/command_line_test.rb +5 -5
- data/tracks/typescript/config.json +15 -0
- data/tracks/typescript/exercises/strain/README.md +60 -0
- data/tracks/typescript/exercises/strain/package.json +36 -0
- data/tracks/typescript/exercises/strain/strain.example.ts +23 -0
- data/tracks/typescript/exercises/strain/strain.test.ts +76 -0
- data/tracks/typescript/exercises/strain/strain.ts +0 -0
- data/tracks/typescript/exercises/strain/tsconfig.json +22 -0
- data/tracks/typescript/exercises/strain/tslint.json +127 -0
- data/tracks/typescript/exercises/strain/yarn.lock +2305 -0
- metadata +46 -3
- data/tracks/ecmascript/package-lock.json +0 -2835
@@ -0,0 +1,29 @@
|
|
1
|
+
# Anagram
|
2
|
+
|
3
|
+
Given a word and a list of possible anagrams, select the correct sublist.
|
4
|
+
|
5
|
+
Given `"listen"` and a list of candidates like `"enlists" "google"
|
6
|
+
"inlets" "banana"` the program should return a list containing
|
7
|
+
`"inlets"`.
|
8
|
+
|
9
|
+
* * * *
|
10
|
+
|
11
|
+
To run the code in this exercise, you will only need to have [CommandBox CLI installed](https://ortus.gitbooks.io/commandbox-documentation/content/setup/installation.html). This binary runs CFML code from the command line.
|
12
|
+
|
13
|
+
To run the tests, `cd` into the exercise folder and run the following:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
box task run TestRunner
|
17
|
+
# Or start up a test watcher that will rerun when files change
|
18
|
+
box task run TestRunner --:watcher
|
19
|
+
```
|
20
|
+
|
21
|
+
The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the [BDD style](https://testbox.ortusbooks.com/content/primers/bdd/specs.html) which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:
|
22
|
+
|
23
|
+
[https://testbox.ortusbooks.com/content/](https://testbox.ortusbooks.com/content/)
|
24
|
+
## Source
|
25
|
+
|
26
|
+
Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
|
27
|
+
|
28
|
+
## Submitting Incomplete Solutions
|
29
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
/**
|
2
|
+
* Here is an example solution for the Anagram exercise
|
3
|
+
*/
|
4
|
+
component {
|
5
|
+
|
6
|
+
function anagrams( string subject, array candidates ) {
|
7
|
+
|
8
|
+
var results = [];
|
9
|
+
|
10
|
+
for (var candidate in candidates) {
|
11
|
+
/* Check if the canidate is an anagram and is not already in the results */
|
12
|
+
if ( isAnagram( subject, candidate ) && !results.find( lcase( candidate ) ) ) {
|
13
|
+
results.append( lcase(candidate) );
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
return results;
|
18
|
+
}
|
19
|
+
|
20
|
+
/**
|
21
|
+
*
|
22
|
+
* Is an anagram and canidate is not the exact same as the subject
|
23
|
+
*
|
24
|
+
*/
|
25
|
+
private boolean function isAnagram( string subject, string candidate ) {
|
26
|
+
|
27
|
+
return ( sortString( candidate ) == sortString( subject ) && lcase( candidate ) != lcase( subject ) );
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
/**
|
32
|
+
*
|
33
|
+
* Sort the characters in a string alphabetically
|
34
|
+
*
|
35
|
+
*/
|
36
|
+
private string function sortString( string word ) {
|
37
|
+
|
38
|
+
return listSort( lcase( arguments.word ), "text", "asc", "" );
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/**
|
2
|
+
* I am a CommandBox task runner which you can use to test your implementation of this exercise against the
|
3
|
+
* provided test suite. To use me, open the CommandBox CLI and run this:
|
4
|
+
*
|
5
|
+
* CommandBox> task run TestRunner
|
6
|
+
*
|
7
|
+
* To start up a test watcher that will automatically rerun the test suite every time you save a file change, run this:
|
8
|
+
*
|
9
|
+
* CommandBox> task run TestRunner --watcher
|
10
|
+
*
|
11
|
+
*/
|
12
|
+
component {
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @solution Runs the tests against the solution
|
16
|
+
* @watcher Start up a file watch that re-runs the tests on file changes. Use Ctrl-C to stop
|
17
|
+
*/
|
18
|
+
function run( boolean solution=false, boolean watcher=false ) {
|
19
|
+
|
20
|
+
ensureTestBox();
|
21
|
+
|
22
|
+
if( watcher ) {
|
23
|
+
|
24
|
+
// Tabula rasa
|
25
|
+
command( 'cls' ).run();
|
26
|
+
|
27
|
+
// Start watcher
|
28
|
+
watch()
|
29
|
+
.paths( '*.cfc' )
|
30
|
+
.inDirectory( getCWD() )
|
31
|
+
.withDelay( 500 )
|
32
|
+
.onChange( function() {
|
33
|
+
|
34
|
+
// Clear the screen
|
35
|
+
command( 'cls' )
|
36
|
+
.run();
|
37
|
+
|
38
|
+
// This is neccessary so changes to tests get picked up right away.
|
39
|
+
pagePoolClear();
|
40
|
+
|
41
|
+
runTests( solution );
|
42
|
+
|
43
|
+
} )
|
44
|
+
.start();
|
45
|
+
|
46
|
+
} else {
|
47
|
+
runTests( solution );
|
48
|
+
}
|
49
|
+
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Make sure the TestBox framework is installed
|
54
|
+
*/
|
55
|
+
private function ensureTestBox() {
|
56
|
+
var excerciseRoot = getCWD();
|
57
|
+
var testBoxRoot = excerciseRoot & '/testbox';
|
58
|
+
|
59
|
+
if( !directoryExists( testBoxRoot ) ) {
|
60
|
+
|
61
|
+
print.boldYellowLine( 'Installing some missing dependencies for you!' ).toConsole();
|
62
|
+
command( 'install' )
|
63
|
+
.inWorkingDirectory( excerciseRoot )
|
64
|
+
.run();
|
65
|
+
}
|
66
|
+
|
67
|
+
// Bootstrap TestBox framework
|
68
|
+
filesystemUtil.createMapping( '/testbox', testBoxRoot );
|
69
|
+
}
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Invoke TestBox to run the test suite
|
73
|
+
*/
|
74
|
+
private function runTests( boolean solution=false ) {
|
75
|
+
|
76
|
+
// Create TestBox and run the tests
|
77
|
+
testData = new testbox.system.TestBox()
|
78
|
+
.runRaw( directory = {
|
79
|
+
// Find all CFCs...
|
80
|
+
mapping = filesystemUtil.makePathRelative( getCWD() ),
|
81
|
+
// ... in this directory ...
|
82
|
+
recurse = false,
|
83
|
+
// ... whose name ends in "test"
|
84
|
+
filter = function( path ) {
|
85
|
+
return path.reFind( ( solution ? 'Solution' : '' ) & 'Test.cfc$' );
|
86
|
+
}
|
87
|
+
} )
|
88
|
+
.getMemento();
|
89
|
+
|
90
|
+
// Print out the results with ANSI formatting for the CLI
|
91
|
+
getInstance( 'CLIRenderer@testbox-commands' )
|
92
|
+
.render( print, testData, true );
|
93
|
+
|
94
|
+
print.toConsole();
|
95
|
+
|
96
|
+
// Set proper exit code
|
97
|
+
if( testData.totalFail || testData.totalError ) {
|
98
|
+
setExitCode( 1 );
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
}
|
103
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<!---
|
2
|
+
|
3
|
+
This file will only be used if you want to start up a web server in this directory. You can do so by running:
|
4
|
+
|
5
|
+
$> box
|
6
|
+
CommandBox> install
|
7
|
+
CommandBox> server start
|
8
|
+
|
9
|
+
However, this is not necessary unless you really just want to use the HTML reporters on TestBox.
|
10
|
+
Ideally, you'll skip the need for this file entirely and just run the tests directly frm the CLI like this:
|
11
|
+
|
12
|
+
CommandBox> task run TestRunner
|
13
|
+
|
14
|
+
--->
|
15
|
+
<cfsetting showDebugOutput="false">
|
16
|
+
<cfparam name="url.reporter" default="simple">
|
17
|
+
<cfscript>
|
18
|
+
// get a list of all CFCs in this folder whose name looks like "XXXTest.cfc"
|
19
|
+
// And turn it into compnent path relative to the web root
|
20
|
+
url.bundles = directoryList(
|
21
|
+
path=expandPath( '/' ),
|
22
|
+
filter='*Test.cfc' )
|
23
|
+
.map( function( path ) {
|
24
|
+
return path
|
25
|
+
.replaceNoCase( expandPath( '/' ), '' )
|
26
|
+
.left( -4 )
|
27
|
+
} )
|
28
|
+
.toList();
|
29
|
+
</cfscript>
|
30
|
+
|
31
|
+
<!--- Ensure TestBox --->
|
32
|
+
<cfif fileExists( "/testbox/system/runners/HTMLRunner.cfm" )>
|
33
|
+
<!--- Include the TestBox HTML Runner --->
|
34
|
+
<cfinclude template="/testbox/system/runners/HTMLRunner.cfm">
|
35
|
+
<cfelse>
|
36
|
+
Oops, you don't have TestBox installed yet! Please run <b>box install</b> from the root of your excercise folder and refresh this page.
|
37
|
+
</cfif>
|
@@ -15,7 +15,7 @@
|
|
15
15
|
{
|
16
16
|
"uuid": "c029678b-9b9f-4fb2-958f-3a118efa16a9",
|
17
17
|
"slug": "hamming",
|
18
|
-
"core":
|
18
|
+
"core": true,
|
19
19
|
"unlocked_by": null,
|
20
20
|
"difficulty": 1,
|
21
21
|
"topics": [
|
@@ -29,7 +29,7 @@
|
|
29
29
|
{
|
30
30
|
"uuid": "8bfa54a8-4ee6-4e6e-b286-7fc8c70b9e9f",
|
31
31
|
"slug": "leap",
|
32
|
-
"core":
|
32
|
+
"core": true,
|
33
33
|
"unlocked_by": null,
|
34
34
|
"difficulty": 1,
|
35
35
|
"topics": [
|
@@ -68,7 +68,7 @@
|
|
68
68
|
{
|
69
69
|
"uuid": "1e6c8365-775d-4a4f-8fc7-e376912d7912",
|
70
70
|
"slug": "bob",
|
71
|
-
"core":
|
71
|
+
"core": true,
|
72
72
|
"unlocked_by": null,
|
73
73
|
"difficulty": 1,
|
74
74
|
"topics": [
|
@@ -167,7 +167,7 @@
|
|
167
167
|
{
|
168
168
|
"uuid": "5c6f22e7-109c-4d9e-b8bf-4ea63b2823ca",
|
169
169
|
"slug": "beer-song",
|
170
|
-
"core":
|
170
|
+
"core": true,
|
171
171
|
"unlocked_by": null,
|
172
172
|
"difficulty": 1,
|
173
173
|
"topics": [
|
@@ -330,7 +330,7 @@
|
|
330
330
|
{
|
331
331
|
"uuid": "40f3b911-0739-4fec-95cc-cfab99788c19",
|
332
332
|
"slug": "sieve",
|
333
|
-
"core":
|
333
|
+
"core": true,
|
334
334
|
"unlocked_by": null,
|
335
335
|
"difficulty": 1,
|
336
336
|
"topics": [
|
@@ -1,4 +1,6 @@
|
|
1
1
|
using System;
|
2
|
+
using System.Collections.Generic;
|
3
|
+
using System.Linq;
|
2
4
|
|
3
5
|
public enum Bucket
|
4
6
|
{
|
@@ -13,97 +15,69 @@ public class TwoBucketResult
|
|
13
15
|
public int OtherBucket { get; set; }
|
14
16
|
}
|
15
17
|
|
16
|
-
public class
|
18
|
+
public class TwoBucket
|
17
19
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
Capacity = capacity;
|
22
|
-
}
|
23
|
-
|
24
|
-
public int Contents { get; set; }
|
25
|
-
|
26
|
-
public int Capacity { get; }
|
27
|
-
|
28
|
-
public bool IsEmpty => Contents == 0;
|
29
|
-
|
30
|
-
public bool IsFull => Contents == Capacity;
|
31
|
-
|
32
|
-
public void Fill()
|
20
|
+
private int[] sizes;
|
21
|
+
private int startBucket;
|
22
|
+
public TwoBucket(int bucketOne, int bucketTwo, Bucket startBucket)
|
33
23
|
{
|
34
|
-
|
24
|
+
this.sizes = new[] {bucketOne, bucketTwo};
|
25
|
+
this.startBucket = (int)startBucket;
|
35
26
|
}
|
36
27
|
|
37
|
-
|
38
|
-
|
39
|
-
Contents = 0;
|
40
|
-
}
|
41
|
-
|
42
|
-
public void PourTo(BucketContainer other)
|
43
|
-
{
|
44
|
-
var amount = Math.Min(other.Capacity - other.Contents, Contents);
|
45
|
-
Contents -= amount;
|
46
|
-
other.Contents += amount;
|
47
|
-
}
|
48
|
-
|
49
|
-
public bool CanPourTo(BucketContainer other) => !IsEmpty && !other.IsFull;
|
50
|
-
}
|
28
|
+
private int[] Empty(int[] _buckets, int i) =>
|
29
|
+
i == 0 ? new[] {0, _buckets[1]} : new[] {_buckets[0], 0};
|
51
30
|
|
52
|
-
|
53
|
-
{
|
54
|
-
private readonly BucketContainer bucketOne;
|
55
|
-
private readonly BucketContainer bucketTwo;
|
56
|
-
private readonly Action strategy;
|
31
|
+
private int[] Fill(int[] _buckets, int i) =>
|
32
|
+
i == 0 ? new[] {sizes[0], _buckets[1]} : new[] {_buckets[0], sizes[1]};
|
57
33
|
|
58
|
-
|
34
|
+
private int[] Consolidate(int[] _buckets, int i)
|
59
35
|
{
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
36
|
+
var amount = new[]{_buckets[1 - i], sizes[i] - _buckets[i]}.Min();
|
37
|
+
var target = _buckets[i] + amount;
|
38
|
+
var src = _buckets[1 - i] - amount;
|
39
|
+
return i == 0 ? new[] {target, src} : new[] {src, target};
|
64
40
|
}
|
65
41
|
|
66
42
|
public TwoBucketResult Measure(int goal)
|
67
43
|
{
|
68
|
-
var
|
69
|
-
|
70
|
-
|
44
|
+
var invalid = new[]{0,0};
|
45
|
+
invalid[1 - startBucket] = sizes[1 - startBucket];
|
46
|
+
var invalidStr = string.Join(",",invalid);
|
47
|
+
var buckets = new[]{0,0};
|
48
|
+
buckets[startBucket] = sizes[startBucket];
|
49
|
+
var toVisit = new Queue<(int[], int)>();
|
50
|
+
var visited = new HashSet<string>();
|
51
|
+
var count = 1;
|
52
|
+
var goalBucket = Array.IndexOf(buckets, goal);
|
53
|
+
while (goalBucket < 0)
|
71
54
|
{
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
55
|
+
var key = string.Join(",",buckets);
|
56
|
+
if (!visited.Contains(key) && !key.Equals(invalidStr))
|
57
|
+
{
|
58
|
+
visited.Add(key);
|
59
|
+
var nc = count + 1;
|
60
|
+
for (int i=0;i<2;i++)
|
61
|
+
{
|
62
|
+
if (buckets[i] != 0)
|
63
|
+
toVisit.Enqueue((Empty(buckets, i), nc));
|
64
|
+
if (buckets[i] != sizes[i])
|
65
|
+
{
|
66
|
+
toVisit.Enqueue((Fill(buckets, i), nc));
|
67
|
+
toVisit.Enqueue((Consolidate(buckets, i), nc));
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
if (!toVisit.Any())
|
72
|
+
throw new ArgumentException("no more moves!");
|
73
|
+
(buckets, count) = toVisit.Dequeue();
|
74
|
+
goalBucket = Array.IndexOf(buckets, goal);
|
81
75
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
if (bucketOne.IsEmpty)
|
89
|
-
bucketOne.Fill();
|
90
|
-
else if (bucketTwo.IsFull)
|
91
|
-
bucketTwo.Empty();
|
92
|
-
else if (bucketOne.CanPourTo(bucketTwo))
|
93
|
-
bucketOne.PourTo(bucketTwo);
|
94
|
-
else
|
95
|
-
throw new InvalidOperationException("Cannot transition from current state.");
|
96
|
-
}
|
97
|
-
|
98
|
-
public void StartFromSecondBucket()
|
99
|
-
{
|
100
|
-
if (bucketOne.IsFull)
|
101
|
-
bucketOne.Empty();
|
102
|
-
else if (bucketTwo.IsEmpty)
|
103
|
-
bucketTwo.Fill();
|
104
|
-
else if (bucketTwo.CanPourTo(bucketOne))
|
105
|
-
bucketTwo.PourTo(bucketOne);
|
106
|
-
else
|
107
|
-
throw new InvalidOperationException("Cannot transition from current state.");
|
76
|
+
return new TwoBucketResult
|
77
|
+
{
|
78
|
+
Moves = count,
|
79
|
+
GoalBucket = (Bucket)goalBucket,
|
80
|
+
OtherBucket = buckets[1 - goalBucket]
|
81
|
+
};
|
108
82
|
}
|
109
83
|
}
|
@@ -59,8 +59,8 @@ public void Measure_using_bucket_one_of_size_2_and_bucket_two_of_size_3_start_wi
|
|
59
59
|
{
|
60
60
|
var sut = new TwoBucket(2, 3, Bucket.One);
|
61
61
|
var result = sut.Measure(3);
|
62
|
-
Assert.Equal(
|
63
|
-
Assert.Equal(
|
62
|
+
Assert.Equal(2, result.Moves);
|
63
|
+
Assert.Equal(2, result.OtherBucket);
|
64
64
|
Assert.Equal(Bucket.Two, result.GoalBucket);
|
65
65
|
}
|
66
66
|
}
|