├── .gitignore ├── README.md ├── challenges ├── 2016-11-09-roman-numerals-converter │ ├── README.md │ └── code.py ├── 2016-12-07-longest-palindrome │ ├── .babelrc │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2016-12-21-battleships │ ├── README.md │ ├── main.go │ └── main_test.go ├── 2017-01-18-fizzbuzz-kotlin │ ├── .gradle │ │ └── 3.1 │ │ │ └── taskArtifacts │ │ │ ├── cache.properties │ │ │ ├── cache.properties.lock │ │ │ ├── fileHashes.bin │ │ │ ├── fileSnapshots.bin │ │ │ └── taskArtifacts.bin │ ├── .idea │ │ ├── compiler.xml │ │ ├── gradle.xml │ │ ├── libraries │ │ │ ├── Gradle__junit_junit_4_11.xml │ │ │ ├── Gradle__org_hamcrest_hamcrest_core_1_3.xml │ │ │ ├── Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_6.xml │ │ │ ├── Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_6.xml │ │ │ ├── Gradle__org_jetbrains_kotlin_kotlin_test_1_0_6.xml │ │ │ └── Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_0_6.xml │ │ ├── misc.xml │ │ ├── modules.xml │ │ ├── modules │ │ │ ├── codingdojojo.iml │ │ │ ├── codingdojojo_main.iml │ │ │ └── codingdojojo_test.iml │ │ └── workspace.xml │ ├── build.gradle │ ├── build │ │ ├── classes │ │ │ ├── main │ │ │ │ ├── META-INF │ │ │ │ │ └── codingdojojo_main.kotlin_module │ │ │ │ ├── Main.class │ │ │ │ └── MainKt.class │ │ │ └── test │ │ │ │ ├── MainTest$testFizzBuzz$1.class │ │ │ │ ├── MainTest$testFizzBuzz$2.class │ │ │ │ └── MainTest.class │ │ └── kotlin-build │ │ │ └── caches │ │ │ └── version.txt │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── readme.md │ ├── settings.gradle │ └── src │ │ ├── main │ │ └── kotlin │ │ │ └── Main.kt │ │ └── test │ │ └── kotlin │ │ └── MainTest.kt ├── 2017-01-25-get-number │ ├── .babelrc │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-02-01-bank-entries │ ├── dojo.playground │ │ ├── Contents.swift │ │ ├── contents.xcplayground │ │ ├── playground.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── ostanik.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── timeline.xctimeline │ └── readme.md ├── 2017-02-08-urinol │ ├── README.md │ ├── code.py │ └── requirements.txt ├── 2017-02-15-prime-words │ ├── .babelrc │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-02-22-coin-change │ ├── README.md │ ├── main.go │ └── main_test.go ├── 2017-03-01-zigzag-py │ ├── README.md │ ├── code.py │ └── requirements.txt ├── 2017-03-01-zigzag │ ├── .babelrc │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-03-08-character-count │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-03-15-atm-problem │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-03-22-game-of-life │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-04-05-tennis-game │ ├── README.md │ ├── codingdojo.cabal │ ├── dist │ │ ├── build │ │ │ ├── Code.dyn_hi │ │ │ ├── Code.dyn_o │ │ │ ├── Code.hi │ │ │ ├── Code.o │ │ │ ├── Code.p_hi │ │ │ ├── Code.p_o │ │ │ ├── autogen │ │ │ │ ├── Paths_codingdojo.hs │ │ │ │ └── cabal_macros.h │ │ │ ├── libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh-ghc8.0.2.dylib │ │ │ ├── libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh.a │ │ │ ├── libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh_p.a │ │ │ └── spec │ │ │ │ ├── spec │ │ │ │ └── spec-tmp │ │ │ │ ├── CodeSpec.hi │ │ │ │ ├── CodeSpec.o │ │ │ │ ├── Main.hi │ │ │ │ └── Main.o │ │ ├── package.conf.inplace │ │ │ ├── codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh.conf │ │ │ └── package.cache │ │ ├── setup-config │ │ └── test │ │ │ ├── codingdojo-0.0.0-spec.log │ │ │ └── codingdojo-0.0.0.log │ ├── src │ │ └── Code.hs │ └── test │ │ ├── CodeSpec.hs │ │ └── Spec.hs ├── 2017-04-19-find-the-murderer │ ├── README.md │ ├── code.py │ └── requirements.txt ├── 2017-05-03-tic-tac-toe │ ├── index.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-05-24-a-little-world │ ├── .gitignore │ ├── index.test.js │ ├── package.json │ ├── readme.md │ └── yarn.lock ├── 2017-06-21-complex-number-multiplication │ ├── CodingDojo.playground │ │ ├── Contents.swift │ │ ├── contents.xcplayground │ │ └── playground.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ └── nicholas.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── README.md ├── 2017-07-kata-poker-dojo │ ├── .gitignore │ ├── README.md │ ├── config │ │ └── config.exs │ ├── lib │ │ ├── deck.ex │ │ └── poker_dojo.ex │ ├── mix.exs │ ├── mix.lock │ └── test │ │ ├── poker_dojo_test.exs │ │ └── test_helper.exs ├── 2017-08-10-radio-transmitters │ ├── README.md │ ├── code.py │ ├── requirements.txt │ └── test_code.py ├── 2017-08-16-kata-bathroom-security │ ├── README.md │ ├── doorpassword.exs │ └── doorpasword.clj ├── 2017-08-30-monkey-path │ ├── .gitignore │ ├── README.md │ ├── index.test.js │ ├── package.json │ ├── positions.png │ └── yarn.lock ├── 2018-02-23-inverse-captcha │ ├── README.md │ ├── code.py │ └── requirements.txt ├── 2018-07-25-high-entropy-passphrases │ ├── .gitignore │ ├── README.md │ ├── requirements.txt │ └── test_code.py ├── 2018-08-15-elixir-proj-euler │ ├── README.md │ ├── problem007.exs │ └── problem020.exs ├── 2019-04-26-mictorio │ ├── README.md │ └── code.py ├── 2019-05-10-fizzbuzz │ ├── README.md │ └── code.ex └── 2019-05-24-minesweeper │ ├── README.md │ └── code.ex ├── codingdojo.png └── templates ├── Swift ├── README.md └── SwiftTestsTemplate.playground │ ├── Contents.swift │ ├── contents.xcplayground │ └── playground.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ └── ostanik.xcuserdatad │ └── UserInterfaceState.xcuserstate ├── elixir ├── README.md └── template.exs ├── go ├── README.md ├── main.go └── main_test.go ├── haskell ├── .ghci ├── .gitignore ├── README.md ├── codingdojo.cabal ├── src │ └── Code.hs └── test │ ├── CodeSpec.hs │ └── Spec.hs ├── javascript ├── .gitignore ├── index.test.js ├── package.json ├── readme.md └── yarn.lock ├── kotlin ├── .idea │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── modules │ │ └── kotlin.iml │ ├── vcs.xml │ └── workspace.xml ├── build.gradle ├── build │ ├── classes │ │ ├── main │ │ │ ├── META-INF │ │ │ │ └── codingdojojo_main.kotlin_module │ │ │ ├── Main.class │ │ │ └── MainKt.class │ │ └── test │ │ │ ├── MainTest$testFizzBuzz$1.class │ │ │ ├── MainTest$testFizzBuzz$2.class │ │ │ └── MainTest.class │ └── kotlin-build │ │ └── caches │ │ └── version.txt ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src │ ├── main │ └── kotlin │ │ └── Main.kt │ └── test │ └── kotlin │ └── MainTest.kt └── python ├── README.md ├── code.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cheesecake Labs Coding Dojo 2 | 3 | ![CodingDojo](/codingdojo.png) 4 | 5 | Hi, 6 | this is the repository where we will keep our results from Coding Dojo sessions and all challenges that we want to do! 7 | 8 | But, what is a Coding Dojo? 9 | 10 | > A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge. They are there have fun and to engage in deliberate practice in order to improve their skills. 11 | 12 | To get more information, here is some links: 13 | 14 | - [What is coding dojo?](http://codingdojo.org/) 15 | - [The coding dojo](http://code.joejag.com/2009/the-coding-dojo.html) 16 | 17 | ## Modes 18 | The Dojo can be made in three different modes: 19 | 20 | ### Kata 21 | A presenter shows how to solve a problem. All participants should be able to reproduce the solution on their own, interrupting to make question or commentaries at any time. 22 | 23 | ### Randori 24 | Everyone helps to solve a problem using one machine - in pairs - the pilot (who is coding) and the co-pilot (who is assisting). Each time frame (between 5 or 10 minutes), the co-pilot assumes the keyboard and someone from the audiance takes its place. The problem may has tests already produced, to create a definition of done. Also, the pair decides what to do to solve the problem, which should be explained as it goes. 25 | 26 | ### Kake 27 | Likely the Randori, but multiple pairs working at the same time. On each turn, the pairs are changed, promoting more integration among all participants. 28 | 29 | ## Structure 30 | Each challenge will be placed inside the `challenges` directory, with a descriptive name and the problem to be solved. 31 | 32 | Once finished, the code created will be uploaded inside the challenge's directory. 33 | 34 | ## Contributing 35 | Do you have a cool challenge or puzzle to be used in a Dojo session? Just create a pull request with a new folder inside `challenges` with its name and description. 36 | Also, here's a list of links with cool puzzles (if you know others, PR them too!): 37 | 38 | - [DojoPuzzles.com](http://dojopuzzles.com/) 39 | - [Ruby Quiz](http://rubyquiz.com/) 40 | - [LeetCode](https://leetcode.com/problemset/algorithms/) 41 | - [Facebook CodeLab](https://codelab.interviewbit.com/) 42 | - [CarrerCup](https://www.careercup.com/page) 43 | - [awesome-challenges (1)](https://github.com/mauriciovieira/awesome-challenges) 44 | - [awesome-challenges (2)](https://github.com/eliotsykes/awesome-challenges) 45 | 46 | ## Help 47 | If you need any help, just yell on the #codingdojo Slack channel, at Cheesecake Labs. 48 | 49 | **Happy coding!** 50 | -------------------------------------------------------------------------------- /challenges/2016-11-09-roman-numerals-converter/README.md: -------------------------------------------------------------------------------- 1 | # Roman numbers 2 | 3 | The Roman numeration system (or Roman numerals) developed in Ancient Rome and was used throughout its Empire. In this system the figures are written with certain letters, which represent the numbers. The letters are always uppercase, because don't exists lowercase letters in the Roman alphabet. The letters are I, V, X, L, C, D and M. 4 | 5 | Our task is to develop a program that converts Arabic numbers to Roman format and vice versa. The rules for the formation of Roman numerals are given below. 6 | 7 | Each letter corresponds to a certain value: 8 | * I = 1 9 | * V = 5 10 | * X = 10 11 | * L = 50 12 | * C = 100 13 | * D = 500 14 | * M = 1000 15 | 16 | By grouping the letters above, we can represent the numbers according to a set of rules: 17 | With the exception of V, L and D, the other numerals can be repeated no more than three times: 18 | * III = 3 19 | * XXX = 30 20 | * CCC = 300 21 | * MMM = 3000 22 | 23 | When written to the right of larger numerals, I, X and C add up to the values of the first ones: 24 | * VIII = 5 + 1 + 1 + 1 = 8 25 | * LXII = 50 + 10 + 1 + 1 = 62 26 | * CLVIII = 158 27 | * MCXX = 1000 + 100 + 10 + 10 = 1120 28 | 29 | But if the numerals I, X and C are to the left of the larger ones, their values are subtracted, for example, in: 30 | * IV = 5 - 1 = 4 31 | * IX = 10 - 1 = 9 32 | * XC = 100 - 10 = 90 33 | 34 | [Source](http://dojopuzzles.com/problemas/exibe/numeros-romanos/) 35 | 36 | # Python Template 37 | 38 | ## Install 39 | Tested with Python 3. 40 | 41 | ## Run 42 | Run the tests with `python code.py` 43 | -------------------------------------------------------------------------------- /challenges/2016-11-09-roman-numerals-converter/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | roman_values = { 4 | 'I':1, 5 | 'V':5, 6 | 'X':10, 7 | 'L':50, 8 | 'C':100, 9 | 'D':500, 10 | 'M':1000 11 | } 12 | 13 | can_subtract = ['I', 'X', 'C'] 14 | 15 | def check_invalid_number(roman): 16 | invalid_combinations = [ 17 | 'IIII', 18 | 'XXXX', 19 | 'CCCC', 20 | 'MMMM', 21 | ] 22 | for invalid_combination in invalid_combinations: 23 | if roman.find(invalid_combination) >= 0: 24 | raise Exception 25 | return roman 26 | 27 | def convert_into_decimal(roman): 28 | roman = check_invalid_number(roman) 29 | decimal_list = [] 30 | for number in roman: 31 | decimal_list.append(roman_values[number]) 32 | 33 | sum_list = [] 34 | skip = False 35 | for index, decimal in enumerate(decimal_list): 36 | if skip: 37 | skip = False 38 | continue 39 | 40 | if index < len(decimal_list) - 1 and decimal < decimal_list[index + 1]: 41 | if decimal not in [1,10,100]: 42 | raise Exception 43 | if decimal_list[index + 1] / decimal > 10: 44 | raise Exception 45 | sum_list.append(decimal_list[index + 1] - decimal) 46 | skip = True 47 | else: 48 | sum_list.append(decimal) 49 | 50 | sum_list_sorted = sorted(sum_list, reverse=True) 51 | 52 | if sum_list != sum_list_sorted: 53 | raise Exception 54 | 55 | return sum(sum_list) 56 | 57 | class TestDojo(unittest.TestCase): 58 | def setUp(self): 59 | self.test_data = [ 60 | ('X', 10), 61 | ('XX', 20), 62 | ('XXX', 30), 63 | ('IX', 9), 64 | ('MDC', 1600) 65 | ] 66 | 67 | def test_stuff(self): 68 | self.assertEquals(convert_into_decimal('X'), 10) 69 | self.assertEquals(convert_into_decimal('XX'), 20) 70 | self.assertEquals(convert_into_decimal('XXV'), 25) 71 | self.assertEquals(convert_into_decimal('IX'), 9) 72 | self.assertEquals(convert_into_decimal('IV'), 4) 73 | self.assertEquals(convert_into_decimal('XC'), 90) 74 | self.assertEquals(convert_into_decimal('MCXX'), 1120) 75 | self.assertEquals(convert_into_decimal('XIX'), 19) 76 | 77 | def test_invalid(self): 78 | with self.assertRaises(Exception): 79 | convert_into_decimal('MMMM') 80 | with self.assertRaises(Exception): 81 | convert_into_decimal('IC') 82 | with self.assertRaises(Exception): 83 | convert_into_decimal('VLC') 84 | with self.assertRaises(Exception): 85 | convert_into_decimal('VX') 86 | with self.assertRaises(Exception): 87 | convert_into_decimal('XLC') 88 | with self.assertRaises(Exception): 89 | convert_into_decimal('IXX') 90 | with self.assertRaises(Exception): 91 | convert_into_decimal('IIX') 92 | with self.assertRaises(Exception): 93 | convert_into_decimal('JOJO') 94 | 95 | if __name__ == "__main__": 96 | unittest.main() 97 | -------------------------------------------------------------------------------- /challenges/2016-12-07-longest-palindrome/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["latest"] 3 | } 4 | -------------------------------------------------------------------------------- /challenges/2016-12-07-longest-palindrome/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | const inputs = [ 4 | 'aba', 5 | 'abad', 6 | 'natan', 7 | 'tanznaia', 8 | 'a', 9 | 'nnnnnnnnnnatannnnnnnnnncivilwartestingwhetherthatnaptionoranynartionsoconceivedandsodedicatedcanlongendureWeareqmetonagreatbattlefiemldoftzhatwarWehavecometodedicpateaportionofthatfieldasafinalrestingplaceforthosewhoheregavetheirlivesthatthatnationmightliveItisaltogetherfangandproperthatweshoulddothisButinalargersensewecannotdedicatewecannotconsecratewecannothallowthisgroundThebravelmenlivinganddeadwhostruggledherehaveconsecrateditfaraboveourpoorponwertoaddordetractTgheworldadswfilllittlenotlenorlongrememberwhatwesayherebutitcanneverforgetwhattheydidhereItisforusthelivingrathertobededicatedheretotheulnfinishedworkwhichtheywhofoughtherehavethusfarsonoblyadvancedItisratherforustobeherededicatedtothegreattdafskremainingbeforeusthatfromthesehonoreddeadwetakeincreaseddevotiontothatcauseforwhichtheygavethelastpfullmeasureofdevotionthatweherehighlyresolvethatthesedeadshallnothavediedinvainthatthisnationunsderGodshallhaveanewbirthoffreedomandthatgovernmentofthepeoplebythepeopleforthepeopleshallnotperishfromtheearth', 10 | 11 | ] 12 | 13 | const outputs = [ 14 | 'aba', 15 | 'aba', 16 | 'natan', 17 | 'anzna', 18 | 'a', 19 | 'nnnnnnnnnnatannnnnnnnnn', 20 | ] 21 | 22 | test('sum 1', t => { 23 | t.true(isPalindrome('natan')) 24 | t.false(isPalindrome('iurhaoiejapw')) 25 | for (var i = inputs.length - 1; i >= 0; i--) { 26 | t.is(getLongestPalindrome(inputs[i]), outputs[i], 'test ' + i) 27 | } 28 | }) 29 | 30 | function isPalindrome (value) { 31 | 32 | for (var i = 0; i < value.length / 2; i++) { 33 | if(value[i] !== value[value.length - 1 - i]) { 34 | return false 35 | } 36 | 37 | } 38 | return true 39 | } 40 | 41 | function getLongestPalindrome (value) { 42 | var longest = "" 43 | 44 | for(var i = 0; i < value.length; i++) { 45 | for (var j = value.length; j > longest.length && j > i; j--){ 46 | var substr = value.substring(i,j); 47 | if(substr.length > longest.length && isPalindrome(substr)) { 48 | longest = substr; 49 | } 50 | } 51 | } 52 | return longest 53 | } 54 | -------------------------------------------------------------------------------- /challenges/2016-12-07-longest-palindrome/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": "inherit" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /challenges/2016-12-07-longest-palindrome/readme.md: -------------------------------------------------------------------------------- 1 | # Longest Palindromic Substring 2 | 3 | Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. 4 | 5 | *Example:* 6 | ``` 7 | Input: "babad" 8 | 9 | Output: "bab" 10 | 11 | Note: "aba" is also a valid answer. 12 | ``` 13 | 14 | *Example:* 15 | 16 | ``` 17 | Input: "cbbd" 18 | 19 | Output: "bb" 20 | ``` 21 | 22 | [Source](https://leetcode.com/problems/longest-palindromic-substring/) 23 | 24 | # Javascript Template 25 | 26 | ## Install 27 | 28 | `npm install` 29 | 30 | ## Run 31 | 32 | `npm test` 33 | 34 | -------------------------------------------------------------------------------- /challenges/2016-12-21-battleships/README.md: -------------------------------------------------------------------------------- 1 | ## Challenge 2 | 3 | Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules: 4 | 5 | * You receive a valid board, made of only battleships or empty slots. 6 | * Battleships can only be placed horizontally or vertically. In other words, they can only be made of the shape `1xN` (1 row, N columns) or `Nx1` (N rows, 1 column), where N can be of any size. 7 | * At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships. 8 | 9 | Example: 10 | 11 | ``` 12 | X..X 13 | ...X 14 | ...X 15 | ``` 16 | 17 | In the above board there are 2 battleships. 18 | 19 | Invalid Example: 20 | ``` 21 | ...X 22 | XXXX 23 | ...X 24 | ``` 25 | 26 | This is an invalid board that you will not receive - as battleships will always have a cell separating between them. 27 | 28 | [Source](https://leetcode.com/problems/battleships-in-a-board/?tab=Description) 29 | 30 | # Go Template 31 | 32 | ## Install 33 | You need Go! This was tested with version 1.8. 34 | You'll also need [bro](https://github.com/marioidival/bro), a Go test runner with file watch. Install it with `go get github.com/marioidival/bro`. 35 | 36 | ## Run 37 | On the directory, run `bro`. 38 | 39 | -------------------------------------------------------------------------------- /challenges/2016-12-21-battleships/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func CountBattleships(board [][]string) int { 8 | 9 | totalShips := 0 10 | 11 | for line := 0; line < len(board); line++ { 12 | for column := 0; column < len(board[line]); column++ { 13 | position := board[line][column] 14 | fmt.Print(board[line][column]) 15 | 16 | if IsGhostBattleship(position) { 17 | if (line-1 >= 0 && IsGhostBattleship(board[line-1][column])) || 18 | (column-1 >= 0 && IsGhostBattleship(board[line][column-1])) { 19 | continue 20 | } 21 | totalShips++ 22 | } 23 | } 24 | fmt.Println("") 25 | } 26 | return totalShips 27 | } 28 | 29 | func IsGhostBattleship(position string) bool { 30 | return position == "X" 31 | } 32 | 33 | func main() { 34 | } 35 | -------------------------------------------------------------------------------- /challenges/2016-12-21-battleships/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | var validBoard = [][]string{ 6 | []string{"X", ".", ".", "X"}, 7 | []string{"X", ".", ".", "X"}, 8 | []string{".", "X", ".", "X"}, 9 | } 10 | 11 | func TestCountBattleships(t *testing.T) { 12 | if CountBattleships(validBoard) != 3 { 13 | t.Fatal("Not valid") 14 | } 15 | } 16 | 17 | func TestIsBattleships(t *testing.T) { 18 | if !IsGhostBattleship("X") { 19 | t.Fatal("Not valid") 20 | } 21 | 22 | if IsGhostBattleship(".") { 23 | t.Fatal("Not valid") 24 | } 25 | } -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/cache.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 18 11:05:02 BRST 2017 2 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/cache.properties.lock: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/cache.properties.lock -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/fileHashes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/fileHashes.bin -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/fileSnapshots.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/fileSnapshots.bin -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/taskArtifacts.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/.gradle/3.1/taskArtifacts/taskArtifacts.bin -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__junit_junit_4_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_1_0_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_test_junit_1_0_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/modules/codingdojojo.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/modules/codingdojojo_main.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 74 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/.idea/modules/codingdojojo_test.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 74 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | group 'cheesecakelabs' 2 | version '1.0-SNAPSHOT' 3 | 4 | buildscript { 5 | ext.kotlin_version = '1.0.6' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | dependencies { 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | } 13 | } 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'kotlin' 17 | 18 | sourceCompatibility = 1.5 19 | 20 | mainClassName = 'codingdojojo.Main' 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | dependencies { 27 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 28 | testCompile group: 'junit', name: 'junit', version: '4.11' 29 | testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" 30 | } 31 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/main/META-INF/codingdojojo_main.kotlin_module: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MainKt -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/build/classes/main/Main.class -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/main/MainKt.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/build/classes/main/MainKt.class -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest$testFizzBuzz$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest$testFizzBuzz$1.class -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest$testFizzBuzz$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest$testFizzBuzz$2.class -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/build/classes/test/MainTest.class -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/build/kotlin-build/caches/version.txt: -------------------------------------------------------------------------------- 1 | 11001 -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-01-18-fizzbuzz-kotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 18 11:23:22 BRST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip 7 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then 166 | cd "$(dirname "$0")" 167 | fi 168 | 169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 170 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/readme.md: -------------------------------------------------------------------------------- 1 | # FizzBuzz 2 | 3 | In this problem, you must display a list from 1 to 100, one number in each line, with the following exceptions: 4 | 5 | * Divisible numbers by 3 should appear as `Fizz` instead of the number. 6 | * Divisible numbers by 5 should appear as `Buzz` instead of the number. 7 | * Divisible numbers by 3 and 5 should appear as `FizzBuzz` instead of the number. 8 | 9 | [Source](http://dojopuzzles.com/problemas/exibe/fizzbuzz/) 10 | 11 | # Kotlin Template 12 | 13 | ## Install and Run 14 | Install the IntelliJ IDEA with the Kotlin plugin, then just import the project and run it. 15 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'codingdojojo' 2 | 3 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | /** 4 | * Created by marciorodrigues on 18/01/17. 5 | */ 6 | 7 | fun main(args : Array) { 8 | 9 | } 10 | 11 | class Main { 12 | 13 | fun fizzBuzz(input: Int) : Array { 14 | if (input < 1) { return arrayOf() } 15 | 16 | val multiples = Array(size = input) {""} 17 | 18 | for (n in 1..input) { 19 | var stringVar = "" 20 | 21 | if (n % 3 == 0) { 22 | stringVar += "Fizz" 23 | } 24 | 25 | if (n % 5 == 0) { 26 | stringVar += "Buzz" 27 | } 28 | 29 | if (stringVar.isEmpty()) { 30 | stringVar = n.toString() 31 | } 32 | 33 | multiples[n - 1] = stringVar 34 | } 35 | 36 | return multiples 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /challenges/2017-01-18-fizzbuzz-kotlin/src/test/kotlin/MainTest.kt: -------------------------------------------------------------------------------- 1 | import org.junit.Test 2 | import java.util.* 3 | import kotlin.test.assertEquals 4 | import kotlin.test.assertTrue 5 | 6 | /** 7 | * Created by marciorodrigues on 18/01/17. 8 | */ 9 | 10 | class MainTest { 11 | 12 | @Test fun testFizzBuzz() { 13 | val main = Main() 14 | var n = 1 15 | var expected = arrayOf("1", 16 | "2", 17 | "Fizz", 18 | "4", 19 | "Buzz", 20 | "Fizz", 21 | "7", 22 | "8", 23 | "Fizz", 24 | "Buzz", 25 | "11", 26 | "Fizz", 27 | "13", 28 | "14", 29 | "FizzBuzz" 30 | ) 31 | assertTrue { Arrays.equals(expected, main.fizzBuzz(n)) } 32 | 33 | n = 0 34 | expected = arrayOf() 35 | assertTrue { Arrays.equals(expected, main.fizzBuzz(n)) } 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /challenges/2017-01-25-get-number/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["latest"] 3 | } 4 | -------------------------------------------------------------------------------- /challenges/2017-01-25-get-number/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | const inputs = [ 4 | 5 | ] 6 | 7 | const outputs = [ 8 | 9 | ] 10 | 11 | // ABC -> 2 12 | // DEF -> 3 13 | // GHI -> 4 14 | // JKL -> 5 15 | // MNO -> 6 16 | // PQRS -> 7 17 | // TUV -> 8 18 | // WXYZ -> 9 19 | 20 | const map = { 21 | 'A': '2', 'B': '2', 'C': '2', 22 | 'D': '3', 'E': '3', 'F': '3', 23 | 'G': '4', 'H': '4', 'I': '4', 24 | 'J': '5', 'K': '5', 'L': '5', 25 | 'M': '6', 'N': '6', 'O': '6', 26 | 'P': '7', 'Q': '7', 'R': '7', 'S': '7', 27 | 'T': '8', 'U': '8', 'V': '8', 28 | 'W': '9', 'X': '9', 'Y': '9', 'Z': '9', 29 | } 30 | 31 | 32 | test(t => { 33 | t.is(getNumber('A'), '2') 34 | t.is(getNumber('ABC'), '222') 35 | t.is(getNumber('MY-LOVE'), '69-5683') 36 | t.is(getNumber('1-HOME-SWEET-HOME'), '1-4663-79338-4663') 37 | t.is(getNumber('MY-MISERABLE-JOB'), '69-647372253-562') 38 | t.is(getNumber('MY-MISE7ABLE-JOB'), '69-647372253-562') 39 | }) 40 | 41 | function getNumber(value) { 42 | let response = '' 43 | 44 | for (var i = 0; i < value.length; i++) { 45 | const char = value[i] 46 | response += map[char] || char 47 | } 48 | 49 | return response 50 | } 51 | -------------------------------------------------------------------------------- /challenges/2017-01-25-get-number/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": "inherit" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /challenges/2017-01-25-get-number/readme.md: -------------------------------------------------------------------------------- 1 | # Find the telephone number 2 | 3 | Some places it is common to remember a telephone number by associating its digits with characters, this way the phrase `MY LOVE` can be translated to `69 5683`. Of course there are some problems, as some phone numbers do not form a phrase and the numbers 0 and 1 are not associated with a char. 4 | The task is read an expression and find the telephone number based on the table below. One expression is constructed by upper case chars, hyphen and the numbers 1 and 0. 5 | 6 | ``` 7 | Chars -> Number 8 | * ABC -> 2 9 | * DEF -> 3 10 | * GHI -> 4 11 | * JKL -> 5 12 | * MNO -> 6 13 | * PQRS -> 7 14 | * TUV -> 8 15 | * WXYZ -> 9 16 | ``` 17 | 18 | The input consists in a set of expressions. Each expression is alone in one line and has C characters, where `1 ≤ C ≤ 30`. The input is determined by the end of file (EOF). 19 | For each expression you should print the telephone number correspondent. 20 | 21 | *Input Example*: 22 | ``` 23 | 1-HOME-SWEET-HOME 24 | MY-MISERABLE-JOB 25 | ``` 26 | 27 | *Out Example*: 28 | ``` 29 | 1-4663-79338-4663 30 | 69-647372253-562 31 | ``` 32 | 33 | [Source](http://dojopuzzles.com/problemas/exibe/encontre-o-telefone/) 34 | 35 | # Javascript Template 36 | 37 | ## Install 38 | `npm install` 39 | 40 | ## Run 41 | `npm test` 42 | -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/dojo.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | import UIKit 4 | import XCTest 5 | 6 | 7 | class MainTests: XCTestCase { 8 | let inputInvalid = [ 9 | "[2017-01-32 10:20:22] - Door open OK", 10 | "[2017-01-31 10:20:22] - Door open", 11 | "[2017-22-31 10:20:22] - Door open OK" 12 | ] 13 | 14 | 15 | let inputValid = [ 16 | "[2017-01-31 09:20:22] - Door open OK", 17 | "[2017-01-31 10:20:22] - Door open OK", 18 | "[2017-01-31 11:20:22] - Door open OK", 19 | "[2017-01-31 12:20:22] - Door open OK", 20 | "[2017-01-31 13:20:22] - Door open OK", 21 | "[2017-01-31 17:20:22] - Door open OK", 22 | "[2017-02-31 19:20:22] - Door open OK" 23 | ] 24 | 25 | func testDates() { 26 | let main = Main() 27 | XCTAssertEqual(main.countInTimeRange(arr: inputValid), 4) 28 | } 29 | 30 | func testValidate() { 31 | let main = Main() 32 | inputValid.forEach { (value) in 33 | XCTAssertTrue(main.validate(str: value)) 34 | } 35 | inputInvalid.forEach { (value) in 36 | XCTAssertFalse(main.validate(str: value)) 37 | } 38 | 39 | } 40 | } 41 | 42 | class Main { 43 | 44 | func countInTimeRange(arr: Array) -> Int { 45 | var i = 0 46 | arr.forEach { (value) in 47 | if (validate(str: value)) { 48 | let components = value.components(separatedBy: " - ") 49 | let dateString = components[0] 50 | let date = dateStringToDate(dateString: dateString) 51 | if (isInTimeRange(date: date) ) { 52 | i += 1 53 | } 54 | } 55 | } 56 | return i 57 | } 58 | 59 | func isInTimeRange(date: Date?) -> Bool { 60 | guard let d = date else { return false } 61 | let calendar = Calendar.current 62 | let hour = calendar.component(.hour, from: d) 63 | 64 | return hour >= 10 && hour < 16 65 | } 66 | 67 | func validate(str: String) -> Bool{ 68 | let components = str.components(separatedBy: " - ") 69 | 70 | if(!validateComponents(components: components)){ 71 | return false 72 | } 73 | 74 | let message = components[1] 75 | if(!validateMessage(message: message)){ 76 | return false 77 | } 78 | 79 | let dateString = components[0] 80 | if(!validateDateString(dateString: dateString)){ 81 | return false 82 | } 83 | 84 | return true 85 | } 86 | 87 | private func validateComponents(components: [String]) -> Bool { 88 | return components.count == 2 89 | } 90 | 91 | private func validateMessage(message: String) -> Bool { 92 | if message != "Door open OK" { return false } 93 | return true 94 | } 95 | 96 | private func dateStringToDate(dateString: String) -> Date? { 97 | let date = dateString.replacingOccurrences(of: "[", with: "").replacingOccurrences(of: "]", with: "") 98 | let dateFormat = DateFormatter() 99 | dateFormat.dateFormat = "yyyy-MM-dd HH:mm:ss" 100 | return dateFormat.date(from: date) 101 | } 102 | 103 | private func validateDateString(dateString: String) -> Bool { 104 | return dateStringToDate(dateString: dateString) != nil 105 | } 106 | } 107 | 108 | MainTests.defaultTestSuite().run() 109 | 110 | 111 | -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/dojo.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/dojo.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/dojo.playground/playground.xcworkspace/xcuserdata/ostanik.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-02-01-bank-entries/dojo.playground/playground.xcworkspace/xcuserdata/ostanik.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/dojo.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /challenges/2017-02-01-bank-entries/readme.md: -------------------------------------------------------------------------------- 1 | # Bank Entries 2 | 3 | Every time someone entry on the largest bank in the city of Pirenopolis, a log file is written 4 | with the date and time the door was opened. Each record in the log file has the following format: 5 | 6 | 7 | ``` 8 | [YYYY-mm-dd H:i:s] - Door open OK 9 | ``` 10 | 11 | The bank manager needs to know how many people came in bank during the office hours, 12 | so he asked we to make a program that checks if the entries are valid and within bank's operating 13 | range. We should consider the bank's operating range between 10:00:00 until 16:00:00. 14 | 15 | [Source](http://dojopuzzles.com/problemas/exibe/entradas-no-banco/) 16 | 17 | # Swift Template 18 | 19 | ## Install 20 | You need Xcode 8! 21 | 22 | ## Run 23 | Just open the playground file and the Xcode will compile and run your changes automatically 24 | -------------------------------------------------------------------------------- /challenges/2017-02-08-urinol/README.md: -------------------------------------------------------------------------------- 1 | # Distribution of urinals 2 | 3 | One problem faced by men in the use of urinals in public toilets is the embarrassment caused by another man urinating in the next urinal. A counter-situation is defined when two "users" should occupy adjacent urinals. 4 | 5 | Given a number of urinals in a tailet and the initial occupation of them (telling them which one already has a "user"), determine how many "users" can still use urinals and what position they have before so there will not be an embarrassing situation. 6 | 7 | [Source](http://dojopuzzles.com/problemas/exibe/distribuicao-de-mictorios/) 8 | 9 | # Python Template 10 | 11 | ## Install 12 | Tested with Python 3. 13 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 14 | 15 | ## Run 16 | Run the tests with `nosetests --with-watch` 17 | -------------------------------------------------------------------------------- /challenges/2017-02-08-urinol/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | URINOL_OCCUPIED = 'x' 5 | URINOL_FREE = '.' 6 | 7 | # Define your code here 8 | def create_urinol(quantity, occupied): 9 | urinol = [] 10 | 11 | for i in range(quantity): 12 | urinol.append(URINOL_FREE) 13 | 14 | for i in occupied: 15 | urinol[i] = URINOL_OCCUPIED 16 | 17 | return urinol 18 | 19 | def get_position_of_users(urinol): 20 | aux = urinol[::] 21 | positions = [] 22 | for i, urinol in enumerate(aux): 23 | if i == 0 and aux[i] == URINOL_FREE and aux[i+1] == URINOL_FREE: 24 | aux[i] = URINOL_OCCUPIED 25 | positions.append(i) 26 | continue 27 | 28 | if i == len(aux)-1 and aux[i-1] == URINOL_FREE and aux[i] == URINOL_FREE: 29 | aux[i] = URINOL_OCCUPIED 30 | positions.append(i) 31 | continue 32 | 33 | if aux[i-1] == URINOL_FREE and aux[i] == URINOL_FREE and aux[i+1] == URINOL_FREE: 34 | aux[i] = URINOL_OCCUPIED 35 | positions.append(i) 36 | return positions 37 | 38 | def get_number_of_users(urinol): 39 | return len(get_position_of_users(urinol)) 40 | 41 | # Define your tests here 42 | class Testing(unittest.TestCase): 43 | 44 | def setUp(self): 45 | pass 46 | 47 | def test_create_urinol(self): 48 | self.assertEqual( 49 | create_urinol(3, [0, 2]), 50 | [URINOL_OCCUPIED, URINOL_FREE, URINOL_OCCUPIED] 51 | ) 52 | 53 | self.assertEqual( 54 | create_urinol(5, [0, 2, 4]), 55 | [URINOL_OCCUPIED, URINOL_FREE, URINOL_OCCUPIED, URINOL_FREE, URINOL_OCCUPIED] 56 | ) 57 | 58 | def test_get_number_of_users(self): 59 | urinol = create_urinol(3, [0, 2]) 60 | self.assertEqual( 61 | get_number_of_users(urinol), 62 | 0 63 | ) 64 | 65 | urinol = create_urinol(15, [0, 8, 12]) 66 | self.assertEqual( 67 | get_number_of_users(urinol), 68 | 5 69 | ) 70 | 71 | urinol = create_urinol(11, [0, 3, 5, 10]) 72 | self.assertEqual( 73 | get_number_of_users(urinol), 74 | 1 75 | ) 76 | 77 | def test_get_position_of_users(self): 78 | urinol = create_urinol(3, [0, 2]) 79 | self.assertEqual( 80 | get_position_of_users(urinol), 81 | [] 82 | ) 83 | 84 | urinol = create_urinol(15, [0, 8, 12]) 85 | self.assertEqual( 86 | get_position_of_users(urinol), 87 | [2, 4, 6, 10, 14] 88 | ) 89 | 90 | urinol = create_urinol(11, [0, 3, 5, 10]) 91 | self.assertEqual( 92 | get_position_of_users(urinol), 93 | [7] 94 | ) 95 | 96 | # Executing the tests 97 | if __name__ == '__main__': 98 | unittest.main() 99 | -------------------------------------------------------------------------------- /challenges/2017-02-08-urinol/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | -------------------------------------------------------------------------------- /challenges/2017-02-15-prime-words/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["latest"] 3 | } 4 | -------------------------------------------------------------------------------- /challenges/2017-02-15-prime-words/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test(t => { 4 | t.is(charToNumeric('a'), 1) 5 | t.is(charToNumeric('z'), 26) 6 | t.is(charToNumeric('A'), 27) 7 | t.is(charToNumeric('Z'), 52) 8 | t.is(stringToNumeric('ab'), 3) 9 | t.is(stringToNumeric('abAC'), 59) 10 | t.is(isPrime(4),false) 11 | t.is(isPrime(3),true) 12 | t.is(isPrime(367),true) 13 | t.is(isStringNumericPrime('abAC'), true) 14 | t.is(isStringNumericPrime('ZZZZZ'), false) 15 | }) 16 | 17 | function charToNumeric(char) { 18 | const numeric = char.charCodeAt(0) - 96 19 | 20 | if (numeric > 0) { 21 | return numeric 22 | } 23 | return numeric + 58 24 | } 25 | 26 | function stringToNumeric(string) { 27 | var number = 0 28 | 29 | for (var c of string) { 30 | number += charToNumeric(c) 31 | } 32 | return number 33 | } 34 | 35 | function isPrime(number) { 36 | for (var i = 2; i <= number / 2; i++){ 37 | if (number % i === 0){ 38 | return false 39 | } 40 | } 41 | return true 42 | } 43 | 44 | function isStringNumericPrime(inputString) { 45 | return isPrime(stringToNumeric(inputString)) 46 | } 47 | -------------------------------------------------------------------------------- /challenges/2017-02-15-prime-words/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": "inherit" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /challenges/2017-02-15-prime-words/readme.md: -------------------------------------------------------------------------------- 1 | # Prime Words 2 | 3 | A prime number is defined if it has exactly two divisors: the number one and itself. Examples are 2, 3, 5, 101, 367, 523. 4 | 5 | In this problem, you must read a word composed by only chars `[a-z][A-Z]`. Each char has a specific value: `a = 1`, `b = 2` until `z = 26`. Either way, `A = 27`, `B = 28` until `Z = 52`. 6 | 7 | You need to define if each word in a word set is prime or not. For it to be, the sum of the chars' value should be a primer number. 8 | 9 | [Source](http://dojopuzzles.com/problemas/exibe/palavras-primas/) 10 | 11 | # Javascript Template 12 | 13 | ## Install 14 | `npm install` 15 | 16 | ## Run 17 | `npm test` 18 | -------------------------------------------------------------------------------- /challenges/2017-02-22-coin-change/README.md: -------------------------------------------------------------------------------- 1 | # Challenge 2 | 3 | **IMPORTANT:** We were not able to finish this challenge in our schedule time. So, yeah, life goes on. 4 | 5 | You are given coins of different denominations and a total amount of money. Write a function to compute the number of combinations that make up that amount. You may assume that you have infinite number of each kind of coin. 6 | 7 | **Note: You can assume that:** 8 | `0 <= amount <= 5000` 9 | `1 <= coin <= 5000` 10 | `the number of coins is less than 500` 11 | `the answer is guaranteed to fit into signed 32-bit integer` 12 | 13 | **Example 1:** 14 | 15 | ``` 16 | Input: amount = 5, coins = [1, 2, 5] 17 | Output: 4 18 | Explanation: there are four ways to make up the amount: 19 | 5=5 20 | 5=2+2+1 21 | 5=2+1+1+1 22 | 5=1+1+1+1+1 23 | ``` 24 | 25 | **Example 2:** 26 | 27 | ``` 28 | Input: amount = 3, coins = [2] 29 | Output: 0 30 | Explanation: the amount of 3 cannot be made up just with coins of 2. 31 | ``` 32 | 33 | **Example 3:** 34 | 35 | ``` 36 | Input: amount = 10, coins = [10] 37 | Output: 1 38 | ``` 39 | 40 | [Source](https://leetcode.com/problems/coin-change-2) 41 | 42 | # Go Template 43 | 44 | ## Install 45 | You need Go! This was tested with version 1.8. 46 | You'll also need [bro](https://github.com/marioidival/bro), a Go test runner with file watch. Install it with `go get github.com/marioidival/bro`. 47 | 48 | ## Run 49 | On the directory, run `bro`. 50 | 51 | -------------------------------------------------------------------------------- /challenges/2017-02-22-coin-change/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Your code goes here 4 | func PrintHelloWorld() string { 5 | return "Hello World!" 6 | } 7 | 8 | 9 | func Sum(array []int) int { 10 | total := 0 11 | for _, value := range(array) { 12 | total += value 13 | } 14 | return total 15 | } 16 | 17 | func Combinations(amount int, coins []int) int { 18 | total := 0 19 | 20 | for _, value := range(coins) { 21 | 22 | newAmount := amount - value 23 | 24 | if newAmount == 0 { 25 | total += 1 26 | } else if newAmount > 0 { 27 | total += Combinations(newAmount, coins 28 | } else { 29 | total += 0 30 | } 31 | } 32 | return total 33 | } 34 | 35 | func main() { 36 | } 37 | -------------------------------------------------------------------------------- /challenges/2017-02-22-coin-change/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | // Your tests go here 6 | func TestMain(t *testing.T) { 7 | if PrintHelloWorld() != "Hello World!" { 8 | t.Fatal("Not valid") 9 | } 10 | 11 | if Combinations(10, []int{10}) != 1 { 12 | t.Fatal("Not valid") 13 | } 14 | 15 | if Combinations(3, []int{2}) != 0 { 16 | t.Fatal("Not valid") 17 | } 18 | 19 | test := Combinations(5, []int{1,2,5}) 20 | if test != 4 { 21 | t.Fatal("Not valid ", test) 22 | } 23 | 24 | test2 := Combinations(5, []int{5,2,1}) 25 | if test2 != 4 { 26 | t.Fatal("Not valid ", test2) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag-py/README.md: -------------------------------------------------------------------------------- 1 | # ZigZag Conversion 2 | 3 | The string `PAYPALISHIRING` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility). 4 | 5 | ``` 6 | P A H N 7 | A P L S I I G 8 | Y I R 9 | ``` 10 | 11 | And then read line by line: `PAHNAPLSIIGYIR` 12 | 13 | Write the code that will take a string and make this conversion given a number of rows: 14 | 15 | **Example:** 16 | `string convert(string text, int nRows);` 17 | `convert("PAYPALISHIRING", 3)` should return `PAHNAPLSIIGYIR`. 18 | 19 | [Source](https://leetcode.com/problems/zigzag-conversion/?tab=Description) 20 | 21 | [Solution Submission](https://leetcode.com/submissions/detail/95031131/) 22 | 23 | # Python Template 24 | 25 | ## Install 26 | Tested with Python 3. 27 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 28 | 29 | ## Run 30 | Run the tests with `nosetests --with-watch` 31 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag-py/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | def converter(text, num_rows): 5 | if not text or num_rows <= 1: 6 | return text 7 | 8 | result = [] 9 | 10 | # TOP ROW 11 | for i in range(0, len(text), 2 * num_rows - 2): 12 | result.append(text[i]) 13 | 14 | # MIDDLE ROWS 15 | for i in range(1, num_rows - 1): 16 | steps = [(num_rows - 1 - i) * 2, i * 2] 17 | flag = True 18 | pos = i 19 | while pos < len(text): 20 | result.append(text[pos]) 21 | pos += steps[0] if flag else steps[1] 22 | flag = not flag 23 | 24 | # BOTTOM ROW 25 | for i in range(num_rows - 1, len(text), 2 * num_rows - 2): 26 | result.append(text[i]) 27 | 28 | return ''.join(result) 29 | 30 | 31 | class TestConvert(unittest.TestCase): 32 | def test_1(self): 33 | self.assertEqual( 34 | converter("PAYPALISHIRING", 3), 35 | "PAHNAPLSIIGYIR" 36 | ) 37 | 38 | def test_2(self): 39 | self.assertEqual( 40 | converter("AB", 2), 41 | "AB" 42 | ) 43 | 44 | def test_3(self): 45 | self.assertEqual( 46 | converter('TOBEORNOTTOBETHATSTHEQUESTION', 8), 47 | 'THNOTAOBETIEBSTOOTSRTHENTEUOQ' 48 | ) 49 | 50 | 51 | if __name__ == "__main__": 52 | unittest.main() 53 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag-py/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["latest"] 3 | } 4 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | test(t => { 4 | t.is(converter('PAYPALISHIRING', 3), 'PAHNAPLSIIGYIR') 5 | t.is(converter('TOBEORNOTTOBETHATSTHEQUESTION', 8), 'THNOTAOBETIEBSTOOTSRTHENTEUOQ') 6 | }) 7 | 8 | function converter(text, numberOfRows) { 9 | 10 | let lowerBound = 0 11 | let upperBound = numberOfRows - 1 12 | let col = 0 13 | let row = 0 14 | let desc = true 15 | 16 | let matrix = [] 17 | 18 | text.split('').forEach((x, i) => { 19 | if (!matrix[row]) 20 | matrix[row] = [] 21 | matrix[row][col] = x 22 | 23 | if (desc) { 24 | row += 1 25 | } else { 26 | row -= 1 27 | col += 1 28 | } 29 | if (row == upperBound) { 30 | desc = false 31 | } 32 | 33 | if (row == lowerBound) { 34 | desc = true 35 | } 36 | }) 37 | 38 | return matrix.map(row => row.join('')).join('') 39 | } 40 | 41 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": "inherit" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /challenges/2017-03-01-zigzag/readme.md: -------------------------------------------------------------------------------- 1 | # ZigZag Conversion 2 | 3 | The string `PAYPALISHIRING` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility). 4 | 5 | ``` 6 | P A H N 7 | A P L S I I G 8 | Y I R 9 | ``` 10 | 11 | And then read line by line: `PAHNAPLSIIGYIR` 12 | 13 | Write the code that will take a string and make this conversion given a number of rows: 14 | 15 | **Example:** 16 | `string convert(string text, int nRows);` 17 | `convert("PAYPALISHIRING", 3)` should return `PAHNAPLSIIGYIR`. 18 | 19 | [Source](https://leetcode.com/problems/zigzag-conversion/?tab=Description) 20 | 21 | # Javascript Template 22 | 23 | ## Install 24 | 25 | `npm install` 26 | 27 | ## Run 28 | 29 | `npm test` 30 | -------------------------------------------------------------------------------- /challenges/2017-03-08-character-count/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | const inputs = [ 4 | 5 | ] 6 | 7 | const outputs = [ 8 | 9 | ] 10 | 11 | test(t => { 12 | t.deepEqual(countString('aaabbc'), [{a: 3}, {b: 2}, {c: 1}]) 13 | t.deepEqual(countString('aaabbca'), [{a: 4}, {b: 2}, {c: 1}]) 14 | t.deepEqual(countString('aaabbbbbbca'), [{b: 6}, {a: 4}, {c: 1}]) 15 | t.deepEqual(countString('aaab bbbb bca'), [{b: 6}, {a: 4}, {' ': 2}, {c: 1}]) 16 | t.deepEqual(countString('aaab bbbb baaca'), [{a: 6}, {b: 6}, {' ': 2}, {c: 1}]) 17 | t.deepEqual(countString('baaa bbbb baaca'), [{a: 6}, {b: 6}, {' ': 2}, {c: 1}]) 18 | t.deepEqual(countString('baaa bbbb baaca '), [{' ': 6}, {a: 6}, {b: 6}, {c: 1}]) 19 | t.deepEqual(countString('Coding do jojo'), [{o: 4}, {' ': 2}, {d: 2}, {j: 2}, {C: 1}, {g: 1}, {i: 1}, {n: 1}]) 20 | }) 21 | 22 | test(t => { 23 | t.deepEqual(functionalCountString('aaabbc'), [{a: 3}, {b: 2}, {c: 1}]) 24 | t.deepEqual(functionalCountString('aaabbca'), [{a: 4}, {b: 2}, {c: 1}]) 25 | t.deepEqual(functionalCountString('aaabbbbbbca'), [{b: 6}, {a: 4}, {c: 1}]) 26 | t.deepEqual(functionalCountString('aaab bbbb bca'), [{b: 6}, {a: 4}, {' ': 2}, {c: 1}]) 27 | t.deepEqual(functionalCountString('aaab bbbb baaca'), [{a: 6}, {b: 6}, {' ': 2}, {c: 1}]) 28 | t.deepEqual(functionalCountString('baaa bbbb baaca'), [{a: 6}, {b: 6}, {' ': 2}, {c: 1}]) 29 | t.deepEqual(functionalCountString('baaa bbbb baaca '), [{' ': 6}, {a: 6}, {b: 6}, {c: 1}]) 30 | t.deepEqual(functionalCountString('Coding do jojo'), [{o: 4}, {' ': 2}, {d: 2}, {j: 2}, {C: 1}, {g: 1}, {i: 1}, {n: 1}]) 31 | }) 32 | 33 | const functionalCountString = (str) => { 34 | return str.split('').reduce((previous, current) => { 35 | const charVerificationArray = previous.filter((value) => Object.keys(value).includes(current)) 36 | 37 | if (charVerificationArray.length) { 38 | const key = Object.keys(charVerificationArray[0]) 39 | const value = charVerificationArray[0][key] + 1 40 | return [ 41 | ...previous, 42 | {[key]: value} 43 | ] 44 | } 45 | 46 | return [ 47 | ...previous, 48 | {[current]: 1} 49 | ] 50 | }, []) 51 | } 52 | 53 | function countString (str) { 54 | let charMap = {} 55 | let charOutput = [] 56 | 57 | for (let char of str) { 58 | if (!charMap[char]) { 59 | charMap[char] = 1 60 | } else { 61 | charMap[char] += 1 62 | } 63 | } 64 | 65 | for (let key of Object.keys(charMap)) { 66 | charOutput.push({ 67 | [key]: charMap[key] 68 | }) 69 | } 70 | 71 | return charOutput.sort((a, b) => { 72 | if (a[Object.keys(a)] === b[Object.keys(b)]) { 73 | return Object.keys(a) > Object.keys(b) 74 | } 75 | return a[Object.keys(a)] < b[Object.keys(b)] 76 | }) 77 | } 78 | 79 | -------------------------------------------------------------------------------- /challenges/2017-03-08-character-count/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": { 17 | "presets": ["latest"] 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /challenges/2017-03-08-character-count/readme.md: -------------------------------------------------------------------------------- 1 | # Count characters in a string 2 | 3 | Write a console application that outputs the results of the following analysis of the input string: 4 | 5 | For each unique character that appears in the input string, report the number of occurrences of that character in the input. Report each character on its own line, in descending order based on the number of occurrences. Each line should be formatted as follows: 6 | 7 | ``` 8 | : 9 | ``` 10 | 11 | There is no defined order for reporting characters that have the same number of occurrences. Such entries can appear in any order of your choosing in the output. 12 | 13 | Examples: 14 | 15 | **analyze aaabbc** 16 | ```javascript 17 | a: 3 18 | b: 2 19 | c: 1 20 | ``` 21 | 22 | 23 | **analyze "I really want to work for Wingspan"** 24 | ``` 25 | : 6 26 | o: 3 27 | r: 3 28 | a: 3 29 | n: 3 30 | w: 2 31 | l: 2 32 | t: 2 33 | k: 1 34 | W: 1 35 | p: 1 36 | g: 1 37 | i: 1 38 | I: 1 39 | f: 1 40 | y: 1 41 | s: 1 42 | e: 1 43 | ``` 44 | 45 | [Source](https://github.com/turingschool/challenges/blob/master/character_count.markdown) 46 | 47 | *PS: In a second moment we tried a functional approach, but did not finish it due lack of time.* 48 | 49 | # Javascript Template 50 | 51 | ## Install 52 | 53 | `npm install` 54 | 55 | ## Run 56 | 57 | `npm test` 58 | -------------------------------------------------------------------------------- /challenges/2017-03-15-atm-problem/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | const BANK_BILLS = [100, 50, 50, 20, 10, 10, 10, 10, 10, 10, 10, 10] 4 | 5 | test(t => { 6 | t.is(isValidAmount(10), true) 7 | t.is(isValidAmount(21), false) 8 | t.is(isValidAmount(21.2), false) 9 | t.is(isValidAmount(10.11), false) 10 | t.deepEqual(gimmeMoney(500), [100, 100, 100, 100, 100]) 11 | t.deepEqual(gimmeMoney(50), [50]) 12 | t.deepEqual(gimmeMoney(51), []) 13 | t.deepEqual(gimmeMoney(470), [100, 100, 100, 100, 50, 20]) 14 | 15 | t.deepEqual(gimmeMoney(30), [20, 10]) 16 | t.deepEqual(gimmeMoney(80), [50, 20, 10]) 17 | 18 | t.deepEqual(gimmeMoneyFromBank(250, BANK_BILLS), [100, 50, 50, 20, 10, 10, 10]) 19 | t.deepEqual(gimmeMoneyFromBank(1250, BANK_BILLS), []) 20 | t.is(hasEnoughMoney(250, BANK_BILLS), true) 21 | t.deepEqual(gimmeMoneyFromBank(300, BANK_BILLS), [100, 50, 50, 20, 10, 10, 10, 10, 10, 10, 10, 10]) 22 | t.deepEqual(gimmeMoneyFromBank(350, BANK_BILLS), []) 23 | }) 24 | 25 | const ALL_BILLS = [100, 50, 20, 10] 26 | 27 | const isValidAmount = (value) => (value % 10 === 0) 28 | 29 | const gimmeMoney = (amount) => { 30 | if (!isValidAmount(amount)) 31 | return [] 32 | 33 | let result = [] 34 | let rest = amount 35 | for (let bill of ALL_BILLS) { 36 | const numberOfBills = Math.floor(rest / bill) 37 | rest %= bill 38 | for (let i = 0; i < numberOfBills; i++ ) 39 | result.push(bill) 40 | } 41 | 42 | return result 43 | } 44 | 45 | const gimmeMoneyFromBank = (amount, bankBills) => { 46 | if (!isValidAmount(amount)) { 47 | return [] 48 | } 49 | 50 | if (!hasEnoughMoney(amount, bankBills)) { 51 | return [] 52 | } 53 | 54 | let result = [] 55 | let rest = amount 56 | for (let bill of bankBills) { 57 | if (rest < bill) { 58 | continue 59 | } 60 | rest -= bill 61 | result.push(bill) 62 | } 63 | return result 64 | } 65 | 66 | const hasEnoughMoney = (amount, bankBills) => 67 | bankBills.reduce((previous, current) => current + previous, 0) >= amount 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /challenges/2017-03-15-atm-problem/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": { 17 | "presets": ["latest"] 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /challenges/2017-03-15-atm-problem/readme.md: -------------------------------------------------------------------------------- 1 | # ATM Problem 2 | 3 | Develop a program that simulates note delivery when a customer cashes an ATM. The basic requirements are as follows: 4 | 5 | - Deliver the least number of notes 6 | - It is possible to extract the requested value with the available notes 7 | - Infinite customer balance 8 | - Quantity of infinity notes (one can put a finite amount of notes to increase the difficulty of the problem) 9 | - Available notes of R$100.00; R$50.00; R$20.00 and R$10.00 10 | 11 | [Source](http://dojopuzzles.com/problemas/exibe/caixa-eletronico/) 12 | 13 | # Javascript Template 14 | 15 | ## Install 16 | 17 | `npm install` 18 | 19 | ## Run 20 | 21 | `npm test` 22 | -------------------------------------------------------------------------------- /challenges/2017-03-22-game-of-life/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | const initialMatrix = [ 4 | [1, 1, 0], 5 | [1, 0, 1], 6 | [0, 0, 1], 7 | ] 8 | 9 | const finalMatrix = [ 10 | [1, 1, 0], 11 | [1, 0, 1], 12 | [0, 1, 0] 13 | ] 14 | 15 | const nextFinalMatrix = [ 16 | [1, 1, 0], 17 | [1, 0, 1], 18 | [0, 1, 0] 19 | ] 20 | 21 | const anotherInitialMatrix = [ 22 | [1, 0, 1], 23 | [0, 1, 1], 24 | [0, 1, 0], 25 | ] 26 | 27 | const anotherFinalMatrix = [ 28 | [0, 0, 1], 29 | [1, 0, 1], 30 | [0, 1, 1], 31 | ] 32 | 33 | test(t => { 34 | t.is(calcNumNeighbors(initialMatrix, 0, 0), 2) 35 | t.is(calcNumNeighbors(initialMatrix, 1, 1), 5) 36 | t.is(calcNumNeighbors(initialMatrix, 2, 2), 1) 37 | t.is(calcNumNeighbors(initialMatrix, 3, 3), 0) 38 | t.deepEqual(nextCellState(1, 2), 1) 39 | t.deepEqual(nextCellState(1, 3), 1) 40 | t.deepEqual(nextCellState(1, 1), 0) 41 | t.deepEqual(nextCellState(1, 4), 0) 42 | t.deepEqual(nextCellState(0, 2), 0) 43 | t.deepEqual(nextCellState(0, 3), 1) 44 | t.deepEqual(nextCellState(0, 1), 0) 45 | t.deepEqual(nextCellState(0, 4), 0) 46 | t.deepEqual(nextStep(initialMatrix), finalMatrix) 47 | t.deepEqual(nextStep(finalMatrix), nextFinalMatrix) 48 | t.deepEqual(nextStep(anotherInitialMatrix), anotherFinalMatrix) 49 | }) 50 | 51 | function calcNumNeighbors(matrix, lin, col) { 52 | let neighbors = 0 53 | 54 | if (lin < 0 || lin >= matrix.length || col < 0 || col >= matrix[0].length) { 55 | return 0 56 | } 57 | 58 | for (let line = lin-1; line <= lin +1 ; line++) { 59 | if (line < 0 || line >= matrix.length) 60 | continue 61 | for (let column = col-1; column <= col +1 ; column++) { 62 | if (column < 0 || column >= matrix[0].length) 63 | continue 64 | if (lin === line && col === column) 65 | continue 66 | neighbors += matrix[line][column] 67 | } 68 | } 69 | return neighbors 70 | } 71 | 72 | function nextCellState(currentState, numberOfNeighbors) { 73 | if (numberOfNeighbors < 2 || numberOfNeighbors > 3) { 74 | return 0 75 | } 76 | if (currentState == 0 && numberOfNeighbors == 2){ 77 | return 0 78 | } 79 | return 1 80 | } 81 | 82 | function nextStep(matrix) { 83 | const resultMatrix = [[], [], []] 84 | for (let line = 0; line < matrix.length ; line++) { 85 | for (let column = 0; column < matrix[line].length ; column++) { 86 | const neighbors = calcNumNeighbors(matrix, line, column) 87 | const currentState = matrix[line][column] 88 | resultMatrix[line][column] = nextCellState(currentState, neighbors) 89 | } 90 | } 91 | return resultMatrix 92 | } 93 | -------------------------------------------------------------------------------- /challenges/2017-03-22-game-of-life/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": { 17 | "presets": ["latest"] 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /challenges/2017-03-22-game-of-life/readme.md: -------------------------------------------------------------------------------- 1 | # Game of Life 2 | 3 | Develop an algorithm that takes "one step" in the game of life. The behaviour examples may simply be the rules of the game: 4 | 5 | - Any live cell with fewer than two live neighbours dies, as if caused by underpopulation. 6 | - Any live cell with more than three live neighbours dies, as if by overcrowding. 7 | - Any live cell with two or three live neighbours lives on to the next generation. 8 | - Any dead cell with exactly three live neighbours becomes a live cell. 9 | 10 | You also have to think of things such as how to represent the board in a test-friendly way, and what "value" cells outside the board has. Or maybe the board does not have borders? 11 | 12 | 13 | [Source](https://leetcode.com/problems/zigzag-conversion/?tab=Description) 14 | 15 | # Javascript Template 16 | 17 | ## Install 18 | 19 | `npm install` 20 | 21 | ## Run 22 | 23 | `npm test` 24 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/README.md: -------------------------------------------------------------------------------- 1 | # Tennis Game 2 | 3 | In this problem you will implement the rules of a simple tennis game (only two players). They are: 4 | 5 | * In each game, a player can have the following points: 0, 15, 30 or 40. 6 | * The players start with 0 points. 7 | * If the player has 40 points and wins the match, he wins the game. 8 | * If both players reach 40 points, there's a deuce. 9 | * Being in deuce, the player who wins the match will be in advantage. 10 | * If the player in advantage wins the match again, he wins the game. 11 | * If the player is in advantage and the other one wins the match, there's a deuce again. 12 | 13 | The code should receive both players score and the player that will win the match, returning the result score. 14 | 15 | [Source](http://dojopuzzles.com/problemas/exibe/partida-de-tenis/) 16 | 17 | # Haskell Template 18 | 19 | ## Install 20 | `cabal install --only-dependencies --enable-tests` 21 | 22 | ## Run 23 | `cabal test` 24 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/codingdojo.cabal: -------------------------------------------------------------------------------- 1 | -- This file has been generated from package.yaml by hpack version 0.17.0. 2 | -- 3 | -- see: https://github.com/sol/hpack 4 | 5 | name: codingdojo 6 | version: 0.0.0 7 | author: CheesecakeLabs 8 | maintainer: CheesecakeLabs 9 | copyright: (c) 2017 CheesecakeLabs 10 | build-type: Simple 11 | cabal-version: >= 1.10 12 | 13 | library 14 | hs-source-dirs: 15 | src 16 | ghc-options: -Wall 17 | build-depends: 18 | base == 4.* 19 | exposed-modules: 20 | Code 21 | default-language: Haskell2010 22 | 23 | test-suite spec 24 | type: exitcode-stdio-1.0 25 | main-is: Spec.hs 26 | hs-source-dirs: 27 | test 28 | ghc-options: -Wall 29 | build-depends: 30 | base == 4.* 31 | , codingdojo 32 | , hspec == 2.* 33 | other-modules: 34 | CodeSpec 35 | default-language: Haskell2010 36 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.dyn_hi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.dyn_hi -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.dyn_o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.dyn_o -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.hi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.hi -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.o -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.p_hi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.p_hi -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/Code.p_o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/Code.p_o -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/autogen/Paths_codingdojo.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | {-# OPTIONS_GHC -fno-warn-missing-import-lists #-} 3 | {-# OPTIONS_GHC -fno-warn-implicit-prelude #-} 4 | module Paths_codingdojo ( 5 | version, 6 | getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, 7 | getDataFileName, getSysconfDir 8 | ) where 9 | 10 | import qualified Control.Exception as Exception 11 | import Data.Version (Version(..)) 12 | import System.Environment (getEnv) 13 | import Prelude 14 | 15 | #if defined(VERSION_base) 16 | 17 | #if MIN_VERSION_base(4,0,0) 18 | catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a 19 | #else 20 | catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a 21 | #endif 22 | 23 | #else 24 | catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a 25 | #endif 26 | catchIO = Exception.catch 27 | 28 | version :: Version 29 | version = Version [0,0,0] [] 30 | bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath 31 | 32 | bindir = "/Users/danieloliveira/Library/Haskell/bin" 33 | libdir = "/Users/danieloliveira/Library/Haskell/ghc-8.0.2-x86_64/lib/codingdojo-0.0.0" 34 | dynlibdir = "/Users/danieloliveira/Library/Haskell/ghc-8.0.2-x86_64/lib/x86_64-osx-ghc-8.0.2" 35 | datadir = "/Users/danieloliveira/Library/Haskell/share/ghc-8.0.2-x86_64/codingdojo-0.0.0" 36 | libexecdir = "/Users/danieloliveira/Library/Haskell/libexec" 37 | sysconfdir = "/Users/danieloliveira/Library/Haskell/etc" 38 | 39 | getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath 40 | getBinDir = catchIO (getEnv "codingdojo_bindir") (\_ -> return bindir) 41 | getLibDir = catchIO (getEnv "codingdojo_libdir") (\_ -> return libdir) 42 | getDynLibDir = catchIO (getEnv "codingdojo_dynlibdir") (\_ -> return dynlibdir) 43 | getDataDir = catchIO (getEnv "codingdojo_datadir") (\_ -> return datadir) 44 | getLibexecDir = catchIO (getEnv "codingdojo_libexecdir") (\_ -> return libexecdir) 45 | getSysconfDir = catchIO (getEnv "codingdojo_sysconfdir") (\_ -> return sysconfdir) 46 | 47 | getDataFileName :: FilePath -> IO FilePath 48 | getDataFileName name = do 49 | dir <- getDataDir 50 | return (dir ++ "/" ++ name) 51 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/autogen/cabal_macros.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT: This file is automatically generated by Cabal */ 2 | 3 | /* package codingdojo-0.0.0 */ 4 | #define VERSION_codingdojo "0.0.0" 5 | #define MIN_VERSION_codingdojo(major1,major2,minor) (\ 6 | (major1) < 0 || \ 7 | (major1) == 0 && (major2) < 0 || \ 8 | (major1) == 0 && (major2) == 0 && (minor) <= 0) 9 | 10 | /* package base-4.9.1.0 */ 11 | #define VERSION_base "4.9.1.0" 12 | #define MIN_VERSION_base(major1,major2,minor) (\ 13 | (major1) < 4 || \ 14 | (major1) == 4 && (major2) < 9 || \ 15 | (major1) == 4 && (major2) == 9 && (minor) <= 1) 16 | 17 | /* package hspec-2.4.3 */ 18 | #define VERSION_hspec "2.4.3" 19 | #define MIN_VERSION_hspec(major1,major2,minor) (\ 20 | (major1) < 2 || \ 21 | (major1) == 2 && (major2) < 4 || \ 22 | (major1) == 2 && (major2) == 4 && (minor) <= 3) 23 | 24 | /* tool alex-3.2.1 */ 25 | #define TOOL_VERSION_alex "3.2.1" 26 | #define MIN_TOOL_VERSION_alex(major1,major2,minor) (\ 27 | (major1) < 3 || \ 28 | (major1) == 3 && (major2) < 2 || \ 29 | (major1) == 3 && (major2) == 2 && (minor) <= 1) 30 | 31 | /* tool gcc-4.2.1 */ 32 | #define TOOL_VERSION_gcc "4.2.1" 33 | #define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\ 34 | (major1) < 4 || \ 35 | (major1) == 4 && (major2) < 2 || \ 36 | (major1) == 4 && (major2) == 2 && (minor) <= 1) 37 | 38 | /* tool ghc-8.0.2 */ 39 | #define TOOL_VERSION_ghc "8.0.2" 40 | #define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\ 41 | (major1) < 8 || \ 42 | (major1) == 8 && (major2) < 0 || \ 43 | (major1) == 8 && (major2) == 0 && (minor) <= 2) 44 | 45 | /* tool ghc-pkg-8.0.2 */ 46 | #define TOOL_VERSION_ghc_pkg "8.0.2" 47 | #define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\ 48 | (major1) < 8 || \ 49 | (major1) == 8 && (major2) < 0 || \ 50 | (major1) == 8 && (major2) == 0 && (minor) <= 2) 51 | 52 | /* tool haddock-2.17.3 */ 53 | #define TOOL_VERSION_haddock "2.17.3" 54 | #define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\ 55 | (major1) < 2 || \ 56 | (major1) == 2 && (major2) < 17 || \ 57 | (major1) == 2 && (major2) == 17 && (minor) <= 3) 58 | 59 | /* tool happy-1.19.5 */ 60 | #define TOOL_VERSION_happy "1.19.5" 61 | #define MIN_TOOL_VERSION_happy(major1,major2,minor) (\ 62 | (major1) < 1 || \ 63 | (major1) == 1 && (major2) < 19 || \ 64 | (major1) == 1 && (major2) == 19 && (minor) <= 5) 65 | 66 | /* tool hpc-0.67 */ 67 | #define TOOL_VERSION_hpc "0.67" 68 | #define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\ 69 | (major1) < 0 || \ 70 | (major1) == 0 && (major2) < 67 || \ 71 | (major1) == 0 && (major2) == 67 && (minor) <= 0) 72 | 73 | /* tool hsc2hs-0.68.1 */ 74 | #define TOOL_VERSION_hsc2hs "0.68.1" 75 | #define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\ 76 | (major1) < 0 || \ 77 | (major1) == 0 && (major2) < 68 || \ 78 | (major1) == 0 && (major2) == 68 && (minor) <= 1) 79 | 80 | /* tool hscolour-1.24 */ 81 | #define TOOL_VERSION_hscolour "1.24" 82 | #define MIN_TOOL_VERSION_hscolour(major1,major2,minor) (\ 83 | (major1) < 1 || \ 84 | (major1) == 1 && (major2) < 24 || \ 85 | (major1) == 1 && (major2) == 24 && (minor) <= 0) 86 | 87 | #define CURRENT_COMPONENT_ID "codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh" 88 | 89 | #define CURRENT_PACKAGE_KEY "codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh" 90 | 91 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh-ghc8.0.2.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh-ghc8.0.2.dylib -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh.a -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh_p.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/libHScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh_p.a -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/spec/spec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/spec/spec -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/CodeSpec.hi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/CodeSpec.hi -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/CodeSpec.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/CodeSpec.o -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/Main.hi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/Main.hi -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/Main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/build/spec/spec-tmp/Main.o -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/package.conf.inplace/codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh.conf: -------------------------------------------------------------------------------- 1 | name: codingdojo 2 | version: 0.0.0 3 | id: codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh 4 | key: codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh 5 | license: UnspecifiedLicense 6 | copyright: (c) 2017 CheesecakeLabs 7 | maintainer: CheesecakeLabs 8 | author: CheesecakeLabs 9 | exposed: True 10 | exposed-modules: 11 | Code 12 | abi: 13 | trusted: False 14 | import-dirs: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/build 15 | library-dirs: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/build 16 | dynamic-library-dirs: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/build 17 | data-dir: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell 18 | hs-libraries: HScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh 19 | depends: 20 | base-4.9.1.0 21 | haddock-interfaces: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojo/codingdojo.haddock 22 | haddock-html: /Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojo 23 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/package.conf.inplace/package.cache: -------------------------------------------------------------------------------- 1 | ghcpkgCcodingdojo-0.0.0 2 | codingdojo&codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh base-4.9.1.0M/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/build(HScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHhM/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/buildM/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/buildn/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojo/codingdojo.haddock[/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojoCode 3 | codingdojo&codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh&codingdojo-0.0.0-O89NcY1WlHGQ8029dJqHhUnspecifiedLicense(c) 2017 CheesecakeLabsCheesecakeLabs CheesecakeLabs CodeM/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/buildM/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/buildM/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/buildB/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell(HScodingdojo-0.0.0-O89NcY1WlHGQ8029dJqHh base-4.9.1.0n/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojo/codingdojo.haddock[/Users/danieloliveira/_cheesecakelabs/codingdojo/templates/haskell/dist/doc/html/codingdojo -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/setup-config: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-04-05-tennis-game/dist/setup-config -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/test/codingdojo-0.0.0-spec.log: -------------------------------------------------------------------------------- 1 | Test suite spec: RUNNING... 2 | 3 | Code 4 | next score 5 | should add point to first player 6 | 7 | Finished in 0.0008 seconds 8 | 1 example, 0 failures 9 | Test suite spec: PASS 10 | Test suite logged to: dist/test/codingdojo-0.0.0-spec.log 11 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/dist/test/codingdojo-0.0.0.log: -------------------------------------------------------------------------------- 1 | PackageLog {package = PackageIdentifier {pkgName = PackageName {unPackageName = "codingdojo"}, pkgVersion = Version {versionBranch = [0,0,0], versionTags = []}}, compiler = CompilerId GHC (Version {versionBranch = [8,0,2], versionTags = []}), platform = Platform X86_64 OSX, testSuites = [TestSuiteLog {testSuiteName = "spec", testLogs = TestLog {testName = "spec", testOptionsReturned = [], testResult = Pass}, logFile = "dist/test/codingdojo-0.0.0-spec.log"}]} -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/src/Code.hs: -------------------------------------------------------------------------------- 1 | module Code where 2 | 3 | calcNextScore :: Integer -> [Integer] -> [Integer] 4 | calcNextScore player [40, 40] = 5 | case player of 6 | 1 -> [45, 40] 7 | 2 -> [40, 45] 8 | _ -> [40, 40] 9 | calcNextScore player [45, 40] = 10 | case player of 11 | 1 -> [50, 40] 12 | 2 -> [40, 40] 13 | _ -> [45, 40] 14 | calcNextScore player [40, 45] = 15 | case player of 16 | 1 -> [40, 40] 17 | 2 -> [40, 50] 18 | _ -> [40, 45] 19 | calcNextScore player currScore = 20 | case player of 21 | 1 -> 22 | [ calculateNextPoint (head currScore) 23 | , currScore !! 1 24 | ] 25 | 2 -> 26 | [ currScore !! 0 27 | , calculateNextPoint (last currScore) 28 | ] 29 | _ -> 30 | currScore 31 | 32 | playerOneScore :: [Integer] -> [Integer] 33 | playerOneScore = 34 | calcNextScore 1 35 | 36 | playerTwoScore :: [Integer] -> [Integer] 37 | playerTwoScore = 38 | calcNextScore 2 39 | 40 | calculateNextPoint :: Integer -> Integer 41 | calculateNextPoint 0 = 15 42 | calculateNextPoint 15 = 30 43 | calculateNextPoint 30 = 40 44 | calculateNextPoint point = point 45 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/test/CodeSpec.hs: -------------------------------------------------------------------------------- 1 | module CodeSpec (main, spec) where 2 | 3 | import Test.Hspec 4 | import Code 5 | 6 | main :: IO () 7 | main = hspec spec 8 | 9 | spec :: Spec 10 | spec = do 11 | describe "next score" $ do 12 | it "should add point to first player" $ do 13 | shouldBe (calcNextScore 1 [0, 0]) [15, 0] 14 | shouldBe (calcNextScore 2 [0, 0]) [0, 15] 15 | shouldNotBe (calcNextScore 2 [0, 0]) [0, 150] 16 | shouldBe (playerOneScore [0, 0]) [15, 0] 17 | shouldBe (playerTwoScore [0, 0]) [0, 15] 18 | shouldBe (calcNextScore 3 [0, 0]) [0, 0] 19 | shouldBe (calculateNextPoint 15) 30 20 | shouldBe (calculateNextPoint 30) 40 21 | shouldBe (playerTwoScore [0, 30]) [0, 40] 22 | shouldBe (playerOneScore [30, 15]) [40, 15] 23 | shouldBe (playerOneScore [40, 40]) [45, 40] 24 | shouldBe (playerOneScore [45, 40]) [50, 40] 25 | shouldBe (playerOneScore [40, 45]) [40, 40] 26 | shouldBe (playerOneScore [50, 40]) [50, 40] 27 | -------------------------------------------------------------------------------- /challenges/2017-04-05-tennis-game/test/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -F -pgmF hspec-discover #-} 2 | -------------------------------------------------------------------------------- /challenges/2017-04-19-find-the-murderer/README.md: -------------------------------------------------------------------------------- 1 | # Find the Murderer 2 | 3 | A manager was murdered and its body was left in front of the police station. A smart detective was chosen to solve the case. After a series of investigation, he organized a list with possible murderers, crime places and weapons. 4 | 5 | ```python 6 | suspects = [ 7 | 'Charles B. Abbage', 8 | 'Donald Duck Knuth', 9 | 'Ada L. Ovelace', 10 | 'Alan T. Uring', 11 | 'Ivar J. Acobson', 12 | 'Ras Mus Ler Dorf' 13 | ] 14 | places = [ 15 | 'Redmond', 16 | 'Palo Alto', 17 | 'San Francisco', 18 | 'Tokio', 19 | 'Restaurante no Fim do Universo', 20 | 'São Paulo', 21 | 'Cupertino', 22 | 'Helsinki', 23 | 'Maida Vale', 24 | 'Toronto', 25 | ] 26 | weapons = [ 27 | 'Peixeira', 28 | 'DynaTAC 8000X', 29 | 'Trezoitão', 30 | 'Trebuchet', 31 | 'Maça', 32 | 'Gládio', 33 | ] 34 | ``` 35 | 36 | A witness was found, but she can only answer if the detective presents a theory. For each theory, he guesses a murderer, a place and a weapon. The witness answers with just a number. If the theory is correct, she answers 0. If wrong, a value of 1, 2 or 3 is returned. 1 indicates that the murderer is wrong, 2 that the place is incorrect and 3 that the weapon is incorrect. If more than one assumption is wrong, she returns a random value between the ones that are incorrect. 37 | 38 | For example, if the murderer is Donald Duck Knuth, using a Trezoitão em Tokio: 39 | 40 | Theory: 1, 1, 1 41 | Returns: 1, or 2, or 3 (all incorrect) 42 | 43 | Theory: 3, 1, 3 44 | Returns: 1, or 3 (just the place is correct) 45 | 46 | Theory: 5, 3, 4 47 | Returns: 1 (just the murderer is incorrect) 48 | 49 | Theory: 2, 3, 4 50 | Returns: 0 (all correct, case solved) 51 | 52 | Write a program that solve this problem. Initially, don't worry with the number of attempts to find the solution. After, try to improve the way that the theories are tested by the detective with the least number of attempts. 53 | 54 | [Source](http://dojopuzzles.com/problemas/exibe/descubra-o-assassino/) 55 | 56 | # Participants 57 | * Alan 58 | * Daniel 59 | * Ceará 60 | * Clarice 61 | * Márcio 62 | * Douglas 63 | * Natan 64 | * Bruninho 65 | * Jojo 66 | 67 | # Python Template 68 | 69 | ## Install 70 | Tested with Python 3. 71 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 72 | 73 | ## Run 74 | Run the tests with `nosetests --with-watch` 75 | -------------------------------------------------------------------------------- /challenges/2017-04-19-find-the-murderer/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import random 3 | 4 | suspects = [ 5 | 'Charles B. Abbage', 6 | 'Donald Duck Knuth', 7 | 'Ada L. Ovelace', 8 | 'Alan T. Uring', 9 | 'Ivar J. Acobson', 10 | 'Ras Mus Ler Dorf' 11 | ] 12 | 13 | places = [ 14 | 'Redmond', 15 | 'Palo Alto', 16 | 'San Francisco', 17 | 'Tokio', 18 | 'Restaurante no Fim do Universo', 19 | 'São Paulo', 20 | 'Cupertino', 21 | 'Helsinki', 22 | 'Maida Vale', 23 | 'Toronto', 24 | ] 25 | 26 | weapons = [ 27 | 'Peixeira', 28 | 'DynaTAC 8000X', 29 | 'Trezoitão', 30 | 'Trebuchet', 31 | 'Maça', 32 | 'Gládio', 33 | ] 34 | 35 | 36 | def is_theory_correct(suspect, place, weapon, solution): 37 | wront_solutions = [] 38 | if suspect != solution[0]: 39 | wront_solutions.append(1) 40 | if place != solution[1]: 41 | wront_solutions.append(2) 42 | if weapon != solution[2]: 43 | wront_solutions.append(3) 44 | 45 | if wront_solutions: 46 | return random.choice(wront_solutions) 47 | 48 | return 0 49 | 50 | 51 | def solve_problem(solution): 52 | wrong_suspects = [] 53 | wrong_places = [] 54 | wrong_weapons = [] 55 | 56 | for suspect_index, _ in enumerate(suspects): 57 | if suspect_index in wrong_suspects: 58 | continue 59 | for place_index, _ in enumerate(places): 60 | if suspect_index in wrong_suspects: 61 | break 62 | if place_index in wrong_places: 63 | continue 64 | for weapon_index, _ in enumerate(weapons): 65 | if suspect_index in wrong_suspects or place_index in wrong_places: 66 | break 67 | if weapon_index in wrong_weapons: 68 | continue 69 | 70 | response = is_theory_correct(suspect_index, place_index, weapon_index, solution) 71 | if response == 0: 72 | return [suspect_index, place_index, weapon_index] 73 | elif response == 1: 74 | wrong_suspects.append(suspect_index) 75 | elif response == 2: 76 | wrong_places.append(place_index) 77 | elif response == 3: 78 | wrong_weapons.append(weapon_index) 79 | 80 | return [] 81 | 82 | 83 | class Testing(unittest.TestCase): 84 | 85 | def setUp(self): 86 | pass 87 | 88 | def test_is_theory_correct(self): 89 | self.assertEqual(is_theory_correct(1, 2, 3, [1, 2, 3]), 0) 90 | self.assertEqual(is_theory_correct(1, 3, 3, [1, 2, 3]), 2) 91 | self.assertNotEqual(is_theory_correct(3, 3, 3, [1, 2, 3]), 0) 92 | self.assertIn(is_theory_correct(3, 3, 3, [1, 2, 3]), [1, 2]) 93 | 94 | def test_solve_problem(self): 95 | self.assertEqual(solve_problem([1, 2, 3]), [1, 2, 3]) 96 | self.assertEqual(solve_problem([2, 2, 3]), [2, 2, 3]) 97 | self.assertEqual(solve_problem([4, 2, 3]), [4, 2, 3]) 98 | 99 | # Executing the tests 100 | if __name__ == '__main__': 101 | unittest.main() 102 | -------------------------------------------------------------------------------- /challenges/2017-04-19-find-the-murderer/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | -------------------------------------------------------------------------------- /challenges/2017-05-03-tic-tac-toe/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava' 2 | 3 | let state = [['x', '', ''], 4 | ['', '', ''], 5 | ['', '', '']] 6 | 7 | const emptyState = [['', '', ''], 8 | ['', '', ''], 9 | ['', '', '']] 10 | 11 | test(t => { 12 | t.deepEqual(emptyState, [['', '', ''], 13 | ['', '', ''], 14 | ['', '', '']]) 15 | t.deepEqual(state, play(emptyState, 'x', 0, 0)) 16 | t.deepEqual(state, play(state, 'o', 0, 0)) 17 | t.is(check([['x', '', ''], 18 | ['', '', ''], 19 | ['', '', '']], [[0,0],[0,1],[0,2]]), false) 20 | t.is(check([['', '', ''], 21 | ['', '', ''], 22 | ['', '', '']], [[0,0],[0,1],[0,2]]), false) 23 | t.is(check([['x', 'x', 'x'], 24 | ['', '', ''], 25 | ['', '', '']], [[0,0],[0,1],[0,2]]), true) 26 | t.is(check([['x', 'o', 'x'], 27 | ['', '', ''], 28 | ['', '', '']], [[0,0],[0,1],[0,2]]), false) 29 | t.is(check([['x', 'o', 'x'], 30 | ['', 'x', ''], 31 | ['', '', 'x']], [[0,0],[1,1],[2,2]]), true) 32 | t.is(didWin([['x', 'o', 'x'], 33 | ['', 'x', ''], 34 | ['', '', 'x']]), true) 35 | t.is(didWin([['x', 'o', 'x'], 36 | ['', 'o', ''], 37 | ['', '', 'x']]), false) 38 | t.is(didWin([['x', 'o', 'o'], 39 | ['', 'o', ''], 40 | ['o', '', 'x']]), true) 41 | }) 42 | 43 | const check = (state, positions) => { 44 | const pos1 = state[positions[0][0]][positions[0][1]] 45 | const pos2 = state[positions[1][0]][positions[1][1]] 46 | const pos3 = state[positions[2][0]][positions[2][1]] 47 | return pos1 === pos2 && pos2 === pos3 && ['x', 'o'].includes(pos1) 48 | } 49 | 50 | const play = (state, player, line, col) => { 51 | if (state[col][line] !== ''){ 52 | return state 53 | } 54 | 55 | let newState = [...state] 56 | newState[col][line] = player 57 | 58 | return newState 59 | } 60 | 61 | const didWin = (state) => { 62 | const array = [ 63 | [[0,0], [0,1], [0,2]], 64 | [[1,0], [1,1], [1,2]], 65 | [[2,0], [2,1], [2,2]], 66 | 67 | [[0,0], [1,0], [2,0]], 68 | [[0,1], [1,1], [2,1]], 69 | [[0,2], [1,2], [2,2]], 70 | 71 | [[0,0], [1,1], [2,2]], 72 | [[0,2], [1,1], [2,0]], 73 | ] 74 | return array.some((array) => check(state, array)) 75 | } 76 | -------------------------------------------------------------------------------- /challenges/2017-05-03-tic-tac-toe/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "ava --watch index.js" 8 | }, 9 | "devDependencies": { 10 | "ava": "^0.17.0", 11 | "babel-cli": "^6.18.0", 12 | "babel-core": "^6.18.2", 13 | "babel-preset-latest": "^6.16.0" 14 | }, 15 | "ava": { 16 | "babel": { 17 | "presets": ["latest"] 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /challenges/2017-05-03-tic-tac-toe/readme.md: -------------------------------------------------------------------------------- 1 | # Tic-tac-toe 2 | 3 | Tic-tac-toe (also known as noughts and crosses or Xs and Os) is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row wins the game. 4 | 5 | *Example:* 6 | ``` 7 | x |__|__ 8 | x |__|__ 9 | x | | 10 | 11 | _x_|___|__ 12 | ___|_x_|__ 13 | | | x 14 | ``` 15 | 16 | [Source](https://en.wikipedia.org/wiki/Tic-tac-toe) 17 | 18 | # Participants 19 | * Daniel 20 | * Iacami 21 | * Alan 22 | * Márcio 23 | * Nicholas 24 | * Bruninho 25 | * Ramon 26 | * Clarice 27 | * Arthur 28 | 29 | # Javascript Template 30 | 31 | ## Install 32 | 33 | `npm install` 34 | 35 | ## Run 36 | 37 | `npm test` 38 | -------------------------------------------------------------------------------- /challenges/2017-05-24-a-little-world/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /challenges/2017-05-24-a-little-world/index.test.js: -------------------------------------------------------------------------------- 1 | test('Lets test!', () => { 2 | expect(distance({ x: 9, y: 5}, { x: 9, y: 4})).toBe(1) 3 | 4 | expect(distance({ x: 9, y: 5}, { x: 9, y: 3})).not.toBe(1) 5 | 6 | expect(distanceToAllPoints({x:0, y:0}, [{x:3, y:4}, {x:1, y:0}])) 7 | .toEqual([{d: 5, point: {x: 3, y: 4}}, {d: 1, point: {x: 1, y: 0}}]) 8 | 9 | expect(findThreeClosestPoints({x:0, y:0}, [{x:3, y:4}, {x:1, y:0}])) 10 | .toEqual([{d: 1, point: {x:1, y:0}}, {d: 5, point: {x:3, y:4}}]) 11 | 12 | expect(findThreeClosestPoints({x:0, y:0}, POINTS)) 13 | .toEqual( 14 | [ 15 | { 16 | d: 5, 17 | point: { x:3, y:4 } 18 | }, 19 | { 20 | d: 8, 21 | point: { x:2, y:8 } 22 | }, 23 | { 24 | d: 9, 25 | point: { x:9, y:2 } 26 | } 27 | ]) 28 | }) 29 | 30 | const POINTS = [ 31 | { 32 | x: 3, 33 | y: 4, 34 | }, 35 | { 36 | x: 1, 37 | y: 10, 38 | }, 39 | { 40 | x: 2, 41 | y: 8, 42 | }, 43 | { 44 | x: 3, 45 | y: 13, 46 | }, 47 | { 48 | x: 30, 49 | y: 2, 50 | }, 51 | { 52 | x: 9, 53 | y: 2, 54 | }, 55 | { 56 | x: 12, 57 | y: 2, 58 | }, 59 | ] 60 | 61 | const distance = (point1, point2) => 62 | Math.round(Math.sqrt( 63 | (point1.x - point2.x)*(point1.x - point2.x) + 64 | (point1.y - point2.y)*(point1.y - point2.y) 65 | )) 66 | 67 | const distanceToAllPoints = (point1, otherPoints) => 68 | otherPoints.map(point2 => ({ 69 | d: distance(point1, point2), 70 | point: point2 71 | })) 72 | 73 | const findThreeClosestPoints = (point, otherPoints) => 74 | distanceToAllPoints(point, otherPoints) 75 | .sort((p1, p2) => p1.d - p2.d) 76 | .slice(0,3) 77 | -------------------------------------------------------------------------------- /challenges/2017-05-24-a-little-world/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.test.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "jest --watch" 8 | }, 9 | "devDependencies": {}, 10 | "dependencies": { 11 | "babel-jest": "^19.0.0", 12 | "jest": "^19.0.2" 13 | }, 14 | "jest": { 15 | "verbose": false, 16 | "transform": { 17 | ".*": "babel-jest" 18 | }, 19 | "moduleFileExtensions": [ 20 | "js" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /challenges/2017-05-24-a-little-world/readme.md: -------------------------------------------------------------------------------- 1 | # A Little World 2 | 3 | As a popular developer, you know a lot of people in your country. As you travel a lot, you decided that it would be useful to have a program that would say which of your friends are closer based on which friend you are actually visiting. 4 | 5 | Each one of your friends live in a specific position (lat, lon) - to this problem the world is plane, the lat and lon are cartesian coordinates in a plane - and you can identify them somehow. Also, each friend lives in a different position (two friends are never in the same position). 6 | 7 | Write a program that receives the location of all your friends and, for each one of them, tell who are the three closest. 8 | 9 | [Source](http://dojopuzzles.com/problemas/exibe/um-mundo-pequeno/) 10 | 11 | # Participants 12 | 13 | * Jojo 14 | * Endy 15 | * Dleitee 16 | * Douglas 17 | * Iacami 18 | * Nicholas 19 | * Lek 20 | * Ceará 21 | * Matheurs 22 | 23 | # Javascript Template 24 | 25 | ## Install 26 | 27 | `npm install` 28 | 29 | ## Run 30 | 31 | `npm test` 32 | -------------------------------------------------------------------------------- /challenges/2017-06-21-complex-number-multiplication/CodingDojo.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | //Input: "1+1i", "1+1i" 4 | //Output: "0+2i" 5 | //Explanation: (1 + i) * (1 + i) = 1 + i2 + 2 * i = 2i, and you need convert it to the form of 0+2i. 6 | 7 | 8 | import XCTest 9 | 10 | struct ComplexNumber { 11 | var real: Int 12 | var imaginary: Int 13 | 14 | init(real: Int, imaginary: Int) { 15 | self.real = real 16 | self.imaginary = imaginary 17 | } 18 | } 19 | 20 | func stringToComplexNumber(string: String) -> ComplexNumber { 21 | if let index = string.characters.index(of: "+") { 22 | var stringArray = string.components(separatedBy: "+") 23 | let realPart = stringArray[0] 24 | let imaginaryPart = stringArray[1].replacingOccurrences(of: "i", with: "") 25 | return ComplexNumber(real: Int(realPart) ?? 0, imaginary: Int(imaginaryPart) ?? 0) 26 | } 27 | return ComplexNumber(real: 0, imaginary: 0) 28 | } 29 | 30 | func complexNumberToString(number: ComplexNumber) -> String { 31 | let realString = String(number.real) 32 | var imaginaryString = String(number.imaginary) + "i" 33 | 34 | if (number.imaginary >= 0) { 35 | imaginaryString = "+" + imaginaryString 36 | } 37 | 38 | return realString + imaginaryString 39 | } 40 | 41 | func multiplyComplexNumbers(struct1: ComplexNumber, struct2: ComplexNumber) -> ComplexNumber { 42 | let part1 = struct1.real * struct2.real 43 | let part2 = struct1.real * struct2.imaginary 44 | let part3 = struct1.imaginary * struct2.real 45 | let part4 = (struct1.imaginary * struct2.imaginary) * -1 46 | return ComplexNumber(real: part1 + part4, imaginary: part2 + part3) 47 | } 48 | 49 | func multiplyComplexNumberFromString(string1: String, string2: String) -> String { 50 | let number1 = stringToComplexNumber(string: string1) 51 | let number2 = stringToComplexNumber(string: string2) 52 | let multiplied = multiplyComplexNumbers(struct1: number1, struct2: number2) 53 | return complexNumberToString(number: multiplied) 54 | } 55 | 56 | class Tests: XCTestCase { 57 | 58 | func testStringToComplexNumber() { 59 | let testStruct = ComplexNumber(real: 1, imaginary: 1) 60 | let data = stringToComplexNumber(string: "1+1i") 61 | XCTAssert(data.real == testStruct.real) 62 | XCTAssert(data.imaginary == testStruct.imaginary) 63 | } 64 | 65 | func testComplexNumberToString() { 66 | let testStruct = ComplexNumber(real: 1, imaginary: 1) 67 | let string = complexNumberToString(number: testStruct) 68 | XCTAssert(string == "1+1i") 69 | } 70 | 71 | func testMultiplyComplexNumbers() { 72 | let testStruct1 = ComplexNumber(real: 1, imaginary: 1) 73 | let testStruct2 = ComplexNumber(real: 1, imaginary: 1) 74 | let result = multiplyComplexNumbers(struct1: testStruct1, struct2: testStruct2) 75 | 76 | let testResultStruct = ComplexNumber(real: 0, imaginary: 2) 77 | XCTAssert(result.real == testResultStruct.real) 78 | XCTAssert(result.imaginary == testResultStruct.imaginary) 79 | } 80 | 81 | func testMultiplyComplexNumberFromString() { 82 | let string1 = "1+1i" 83 | let string2 = "1+1i" 84 | let result = "0+2i" 85 | XCTAssert(multiplyComplexNumberFromString(string1: string1, string2: string2) == result) 86 | } 87 | } 88 | 89 | Tests.defaultTestSuite().run() 90 | 91 | //participants 92 | //alex 93 | //endy 94 | //dougs [s|k] 95 | //b 96 | //jojo -> mediador 97 | //nicholas 98 | //matheus 99 | -------------------------------------------------------------------------------- /challenges/2017-06-21-complex-number-multiplication/CodingDojo.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /challenges/2017-06-21-complex-number-multiplication/CodingDojo.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /challenges/2017-06-21-complex-number-multiplication/CodingDojo.playground/playground.xcworkspace/xcuserdata/nicholas.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-06-21-complex-number-multiplication/CodingDojo.playground/playground.xcworkspace/xcuserdata/nicholas.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /challenges/2017-06-21-complex-number-multiplication/README.md: -------------------------------------------------------------------------------- 1 | # Complex Number Multiplication 2 | 3 | A complex number is a number that can be expressed in the form `a + bi`, where `a` and `b` are real numbers and `i` is the imaginary unit, satisfying the equation `i2 = −1`. In this expression, `a` is the real part and `b` is the imaginary part of the complex number. 4 | 5 | In this challenge, we have to develop a program that receives 2 Complex Numbers as a String, multiply them and return the result as a String. 6 | 7 | [Source](https://leetcode.com/problems/complex-number-multiplication/#/description) 8 | 9 | # Swift Template 10 | 11 | ## Install 12 | Xcode 8 13 | 14 | ## Run 15 | Just open the playground file and the Xcode will compile and run your changes automatically 16 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/.gitignore: -------------------------------------------------------------------------------- 1 | # The directory Mix will write compiled artifacts to. 2 | /_build 3 | 4 | # If you run "mix test --cover", coverage assets end up here. 5 | /cover 6 | 7 | # The directory Mix downloads your dependencies sources to. 8 | /deps 9 | 10 | # Where 3rd-party dependencies like ExDoc output generated docs. 11 | /doc 12 | 13 | # Ignore .fetch files in case you like to edit your project deps locally. 14 | /.fetch 15 | 16 | # If the VM crashes, it generates a dump, let's ignore it too. 17 | erl_crash.dump 18 | 19 | # Also ignore archive artifacts (built via "mix archive.build"). 20 | *.ez 21 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/README.md: -------------------------------------------------------------------------------- 1 | # PokerDojo 2 | 3 | We'll be gradually building a web-based Texas Hold 'Em application in Elixir. 4 | 5 | [Source](http://blog.tokafish.com/playing-poker-with-elixir-part-1/) 6 | 7 | ## Installation 8 | 9 | If [available in Hex](https://hex.pm/docs/publish), the package can be installed 10 | by adding `poker_dojo` to your list of dependencies in `mix.exs`: 11 | 12 | ## Install 13 | 14 | First, you have to install the Erlang language using 15 | ``` 16 | brew install erlang 17 | ``` 18 | 19 | Then, install the Elixir language 20 | ``` 21 | brew install elixir 22 | ``` 23 | 24 | ## Run 25 | Go to the application folder and execute 26 | 27 | ``` 28 | iex -S mix 29 | ``` 30 | 31 | # Participants 32 | ## 2017-07-05 33 | * Jojo 34 | * End 35 | * Ceará 36 | * Little Bruno 37 | * Leite 38 | * Be 39 | * Nich 40 | * Douglas Gimli 41 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for 9 | # 3rd-party users, it should be done in your "mix.exs" file. 10 | 11 | # You can configure for your application as: 12 | # 13 | # config :poker_dojo, key: :value 14 | # 15 | # And access this configuration in your application as: 16 | # 17 | # Application.get_env(:poker_dojo, :key) 18 | # 19 | # Or configure a 3rd-party app: 20 | # 21 | # config :logger, level: :info 22 | # 23 | 24 | # It is also possible to import configuration files, relative to this 25 | # directory. For example, you can emulate configuration per environment 26 | # by uncommenting the line below and defining dev.exs, test.exs and such. 27 | # Configuration from the imported file will override the ones defined 28 | # here (which is why it is important to import them last). 29 | # 30 | # import_config "#{Mix.env}.exs" 31 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/lib/deck.ex: -------------------------------------------------------------------------------- 1 | defmodule PokerDojo.Deck do 2 | @ranks Enum.to_list(2..14) 3 | @suits [:spades, :clubs, :hearts, :diamonds] 4 | 5 | 6 | defmodule Card do 7 | defstruct [:rank, :suit] 8 | end 9 | 10 | 11 | def new_deck do 12 | for rank <- @ranks, suit <- @suits do 13 | %Card{rank: rank, suit: suit} 14 | end 15 | end 16 | 17 | 18 | def evaluate(cards) when is_list(cards) do 19 | cards 20 | |> Enum.map(&to_tuple/1) 21 | |> Enum.sort 22 | |> eval 23 | end 24 | 25 | 26 | defp to_tuple( 27 | %Card{rank: rank, suit: suit} 28 | ), do: {rank, suit} 29 | 30 | 31 | def eval( 32 | [{10, s}, {11, s}, {12, s}, {13, s}, {14, s}] 33 | ), do: 10 # royal straight flush 34 | 35 | def eval( 36 | [{a, s}, {_, s}, {_, s}, {_, s}, {e, s}] 37 | ) when e - a == 4, do: 9 # straight flush 38 | def eval( 39 | [{2, s}, {3, s}, {4, s}, {5, s}, {14, s}] 40 | ), do: 9 # straight flush 41 | 42 | def eval( 43 | [{a, _}, {a, _}, {a, _}, {a, _}, {_, _}] 44 | ), do: 8 # four of a kind 45 | def eval( 46 | [{_, _}, {a, _}, {a, _}, {a, _}, {a, _}] 47 | ), do: 8 # four of a kind 48 | 49 | 50 | def eval( 51 | [{a, _}, {a, _}, {a, _}, {b, _}, {b, _}] 52 | ), do: 7 # full house 53 | def eval( 54 | [{a, _}, {a, _}, {b, _}, {b, _}, {b, _}] 55 | ), do: 7 # full house 56 | end 57 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/lib/poker_dojo.ex: -------------------------------------------------------------------------------- 1 | defmodule PokerDojo do 2 | 3 | def hello(a), do: hello(a, 3) 4 | def hello(_, 3), do: "peixe" 5 | def hello(_peixe, 4), do: "nao acontece" 6 | def hello(_, _), do: "qualquer coisa" 7 | end 8 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/mix.exs: -------------------------------------------------------------------------------- 1 | defmodule PokerDojo.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [app: :poker_dojo, 6 | version: "0.1.0", 7 | elixir: "~> 1.4", 8 | build_embedded: Mix.env == :prod, 9 | start_permanent: Mix.env == :prod, 10 | deps: deps()] 11 | end 12 | 13 | # Configuration for the OTP application 14 | # 15 | # Type "mix help compile.app" for more information 16 | def application do 17 | # Specify extra applications you'll use from Erlang/Elixir 18 | [extra_applications: [:logger, :httpotion]] 19 | end 20 | 21 | # Dependencies can be Hex packages: 22 | # 23 | # {:my_dep, "~> 0.3.0"} 24 | # 25 | # Or git/path repositories: 26 | # 27 | # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} 28 | # 29 | # Type "mix help deps" for more examples and options 30 | defp deps do 31 | [{:httpotion, "~> 3.0.2"}] 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/mix.lock: -------------------------------------------------------------------------------- 1 | %{"httpotion": {:hex, :httpotion, "3.0.2", "525b9bfeb592c914a61a8ee31fdde3871e1861dfe805f8ee5f711f9f11a93483", [:mix], [{:ibrowse, "~> 4.2", [hex: :ibrowse, optional: false]}]}, 2 | "ibrowse": {:hex, :ibrowse, "4.4.0", "2d923325efe0d2cb09b9c6a047b2835a5eda69d8a47ed6ff8bc03628b764e991", [:rebar3], []}} 3 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/test/poker_dojo_test.exs: -------------------------------------------------------------------------------- 1 | defmodule PokerDojoTest do 2 | use ExUnit.Case 3 | alias PokerDojo.Deck 4 | alias PokerDojo.Deck.Card 5 | 6 | test "that plays work" do 7 | assert Deck.eval([{10, :clubs}, {11, :clubs}, {12, :clubs}, {13, :clubs}, {14, :clubs}]) == 10 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /challenges/2017-07-kata-poker-dojo/test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | -------------------------------------------------------------------------------- /challenges/2017-08-10-radio-transmitters/README.md: -------------------------------------------------------------------------------- 1 | # Radio Transmitters 2 | 3 | Hackerland is a one-dimensional city with N houses, where each house is located at some point on the axis. The Mayor wants to install radio transmitters on the roofs of the city's houses. Each transmitter has a range D, meaning it can transmit a signal to all houses D units of distance away. 4 | 5 | Given a map of Hackerland and the value of D, can you find and print the minimum number of transmitters needed to cover every house in the city? (Every house must be covered by at least one transmitter). Each transmitter must be installed on top of an existing house. 6 | 7 | [Source](https://www.hackerrank.com/challenges/hackerland-radio-transmitters/problem) 8 | 9 | ## Install 10 | Tested with Python 3. 11 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 12 | 13 | ## Run 14 | Run the tests with pytest-watch: `ptw` -------------------------------------------------------------------------------- /challenges/2017-08-10-radio-transmitters/code.py: -------------------------------------------------------------------------------- 1 | def get_min_houses_coverage(houses, coverage): 2 | sorted_houses = sorted(houses) 3 | towers = 0 4 | end_coverage = 0 5 | 6 | for house in sorted_houses: 7 | if house <= end_coverage: 8 | continue 9 | 10 | coverage_range = range(house + coverage, house - 1, -1) 11 | for cr in coverage_range: 12 | if cr in sorted_houses: 13 | end_coverage = cr + coverage 14 | towers += 1 15 | break 16 | 17 | return towers 18 | -------------------------------------------------------------------------------- /challenges/2017-08-10-radio-transmitters/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest==3.2.0 2 | pytest-watch==4.1.0 3 | -------------------------------------------------------------------------------- /challenges/2017-08-10-radio-transmitters/test_code.py: -------------------------------------------------------------------------------- 1 | from .code import get_min_houses_coverage 2 | 3 | 4 | def test_code(): 5 | houses = [7, 2, 4, 6, 5, 9, 12, 11] 6 | coverage = 2 7 | assert get_min_houses_coverage(houses, coverage) == 3 8 | 9 | houses = [1, 2, 4, 5, 8, 12, 13, 15] 10 | coverage = 2 11 | assert get_min_houses_coverage(houses, coverage) == 4 12 | -------------------------------------------------------------------------------- /challenges/2017-08-16-kata-bathroom-security/README.md: -------------------------------------------------------------------------------- 1 | # Bathroom Security Challenge 2 | 3 | _This is an Advent of Code 2016 challenge -- you can check it out at: https://adventofcode.com/2016/day/2_ 4 | 5 | You arrive at Easter Bunny Headquarters under cover of darkness. However, you left in such a rush that you forgot to use the bathroom! Fancy office buildings like this one usually have keypad locks on their bathrooms, so you search the front desk for the code. 6 | 7 | "In order to improve security," the document you find says, "bathroom codes will no longer be written down. Instead, please memorize and follow the procedure below to access the bathrooms." 8 | 9 | The document goes on to explain that each button to be pressed can be found by starting on the previous button and moving to adjacent buttons on the keypad: U moves up, D moves down, L moves left, and R moves right. Each line of instructions corresponds to one button, starting at the previous button (or, for the first line, the "5" button); press whatever button you're on at the end of each line. If a move doesn't lead to a button, ignore it. 10 | 11 | You can't hold it much longer, so you decide to figure out the code as you walk to the bathroom. You picture a keypad like this: 12 | 13 | ``` 14 | 1 2 3 15 | 4 5 6 16 | 7 8 9 17 | ``` 18 | 19 | Suppose your instructions are: 20 | 21 | ``` 22 | ULL 23 | RRDDD 24 | LURDL 25 | UUUUD 26 | ``` 27 | 28 | - You start at "5" and move up (to "2"), left (to "1"), and left (you can't, and stay on "1"), so the first button is 1. 29 | - Starting from the previous button ("1"), you move right twice (to "3") and then down three times (stopping at "9" after two moves and ignoring the third), ending up with 9. 30 | - Continuing from "9", you move left, up, right, down, and left, ending with 8. 31 | - Finally, you move up four times (stopping at "2"), then down once, ending with 5. 32 | - So, in this example, the bathroom code is 1985. 33 | 34 | 35 | # Running the challenge 36 | 37 | 1. Install Elixir: `brew update && brew install elixir` 38 | 2. Run the tests for the challenge: `elixir doorpassword.exs` 39 | -------------------------------------------------------------------------------- /challenges/2017-08-16-kata-bathroom-security/doorpassword.exs: -------------------------------------------------------------------------------- 1 | defmodule Kata do 2 | @moduledoc """ 3 | Solution to 2016's Advent of Code - Day 2 4 | http://adventofcode.com/2016/day/2 5 | 6 | Position system: 7 | 8 | | -1,+1 0,+1 +1,+1 | | 1 2 3 | 9 | | -1, 0 0, 0 +1, 0 | = | 4 5 6 | 10 | | -1,-1 0,-1 +1,-1 | | 7 8 9 | 11 | 12 | U = [ 0, 1] 13 | D = [ 0, -1] 14 | R = [ 1, 0] 15 | L = [-1, 0] 16 | """ 17 | def position_to_digit(pos) do 18 | case pos do 19 | [-1, 1] -> 1 20 | [ 0, 1] -> 2 21 | [ 1, 1] -> 3 22 | [-1, 0] -> 4 23 | [ 0, 0] -> 5 24 | [ 1, 0] -> 6 25 | [-1, -1] -> 7 26 | [ 0, -1] -> 8 27 | [ 1, -1] -> 9 28 | end 29 | end 30 | 31 | def instruction_to_vector("U"), do: [ 0, 1] 32 | def instruction_to_vector("D"), do: [ 0, -1] 33 | def instruction_to_vector("R"), do: [ 1, 0] 34 | def instruction_to_vector("L"), do: [-1, 0] 35 | 36 | def instruction_string_to_vector_list(instruction_string) do 37 | instruction_string 38 | |> String.codepoints() 39 | |> Enum.map(&instruction_to_vector(&1)) 40 | # |> Enum.map(fn character -> instruction_to_vector(character) end) 41 | end 42 | 43 | def apply_vector_to_position([x_vector, y_vector], [x_pos, y_pos] = pos) do 44 | new_pos = [x_vector + x_pos, y_vector + y_pos] 45 | case new_pos do 46 | [x, y] when ((abs x) > 1) or ((abs y) > 1) -> pos 47 | _ -> new_pos 48 | end 49 | end 50 | 51 | def find_end_position(instruction_string, initial_pos \\ [0, 0]) do 52 | instruction_string 53 | |> instruction_string_to_vector_list() 54 | |> Enum.reduce(initial_pos, &apply_vector_to_position/2) 55 | end 56 | 57 | def process_recipe(instruction_string_list, position_list \\ [], initial_position \\ [0, 0]) 58 | def process_recipe([], position_list, _), do: Enum.map(position_list, &position_to_digit/1) 59 | def process_recipe([current_instruction_string | next_instructions], position_list, current_position) do 60 | new_position = find_end_position(current_instruction_string, current_position) 61 | new_position_list = Enum.concat(position_list, [new_position]) 62 | process_recipe(next_instructions, new_position_list, new_position) 63 | end 64 | end 65 | 66 | ExUnit.start 67 | 68 | defmodule KataTest do 69 | use ExUnit.Case 70 | 71 | test "Convert position to digit" do 72 | assert Kata.position_to_digit([-1, 1]) == 1 73 | assert Kata.position_to_digit([ 0, 1]) == 2 74 | assert Kata.position_to_digit([ 1, 1]) == 3 75 | assert Kata.position_to_digit([-1, 0]) == 4 76 | assert Kata.position_to_digit([ 0, 0]) == 5 77 | assert Kata.position_to_digit([ 1, 0]) == 6 78 | assert Kata.position_to_digit([-1, -1]) == 7 79 | assert Kata.position_to_digit([ 0, -1]) == 8 80 | assert Kata.position_to_digit([ 1, -1]) == 9 81 | end 82 | 83 | test "Convert an instruction char to a vector [x, y]" do 84 | assert Kata.instruction_to_vector("U") == [ 0, 1] 85 | assert Kata.instruction_to_vector("D") == [ 0, -1] 86 | assert Kata.instruction_to_vector("R") == [ 1, 0] 87 | assert Kata.instruction_to_vector("L") == [-1, 0] 88 | end 89 | 90 | test "Convert string of instructions (e.g.: UDRL) to list of vectors [x, y]" do 91 | assert Kata.instruction_string_to_vector_list("UDRL") == [[0, 1], [0, -1], [1, 0], [-1, 0]] 92 | end 93 | 94 | test "Apply vector to a position" do 95 | assert Kata.apply_vector_to_position([-1, 0], [ 0, 0]) == [-1, 0] 96 | assert Kata.apply_vector_to_position([ 1, 0], [-1, -1]) == [ 0, -1] 97 | assert Kata.apply_vector_to_position([ 0, -1], [ 0, 0]) == [ 0, -1] 98 | assert Kata.apply_vector_to_position([ 0, 1], [-1, -1]) == [-1, 0] 99 | end 100 | 101 | test "Gracefully reject invalid commands" do 102 | assert Kata.apply_vector_to_position([-1, 0], [-1, 0]) == [-1, 0] 103 | assert Kata.apply_vector_to_position([ 1, 0], [-1, -1]) == [ 0, -1] 104 | assert Kata.apply_vector_to_position([ 0, -1], [ 0, 0]) == [ 0, -1] 105 | assert Kata.apply_vector_to_position([ 0, 1], [-1, -1]) == [-1, 0] 106 | end 107 | 108 | test "Process string of instructions and output a position" do 109 | assert Kata.find_end_position("UUUUUUU", [0, 0]) == [0, 1] 110 | assert Kata.find_end_position("UDR", [0, 0]) == [1, 0] 111 | end 112 | 113 | test "Process the password recipe" do 114 | assert Kata.process_recipe(["ULL", "RRDDD", "LURDL", "UUUUD"]) == [1, 9, 8, 5] 115 | assert Kata.process_recipe(["UUDLRL", "UDR", "RUDL", "LLLL"]) == [4, 5, 5, 4] 116 | end 117 | end 118 | -------------------------------------------------------------------------------- /challenges/2017-08-16-kata-bathroom-security/doorpasword.clj: -------------------------------------------------------------------------------- 1 | ; Solution to 2016's Advent of Code - Day 2 2 | ; http://adventofcode.com/2016/day/2 3 | ; 4 | ; Position system: 5 | ; 6 | ; | -1,+1 0,+1 +1,+1 | | 1 2 3 | 7 | ; | -1, 0 0, 0 +1, 0 | = | 4 5 6 | 8 | ; | -1,-1 0,-1 +1,-1 | | 7 8 9 | 9 | 10 | (defn pos-to-digit 11 | "Convert from position to number" 12 | [pos] 13 | (cond 14 | (= pos [-1 1]) 1 15 | (= pos [ 0 1]) 2 16 | (= pos [ 1 1]) 3 17 | (= pos [-1 0]) 4 18 | (= pos [ 0 0]) 5 19 | (= pos [ 1 0]) 6 20 | (= pos [-1 -1]) 7 21 | (= pos [ 0 -1]) 8 22 | (= pos [ 1 -1]) 9)) 23 | 24 | 25 | (defn instruction-to-vector 26 | "Convert instruction to vector" 27 | [instruction-char] 28 | (cond 29 | (= instruction-char \U) [ 0 1] 30 | (= instruction-char \D) [ 0 -1] 31 | (= instruction-char \R) [ 1 0] 32 | (= instruction-char \L) [-1 0])) 33 | 34 | 35 | (defn instruction-string-to-vector-list 36 | "Convert instruction list to a list of vectors" 37 | [instruction-string] 38 | (map (fn [^Character c] (instruction-to-vector c)) instruction-string)) 39 | 40 | 41 | (defn apply-vector-to-position 42 | "Apply a vector to a position, respecting the constraints" 43 | [[pos-x pos-y] [vector-x vector-y]] 44 | (cond 45 | (or 46 | (> (Math/abs (+ vector-x pos-x)) 1) 47 | (> (Math/abs (+ vector-y pos-y)) 1)) [pos-x pos-y] 48 | "else" [(+ vector-x pos-x) (+ vector-y pos-y)])) 49 | 50 | 51 | (defn find-end-position 52 | "Find the end position, based on an instruction string and an initial position" 53 | [instruction-string pos] 54 | (let [instruction-list (instruction-string-to-vector-list instruction-string)] 55 | (reduce apply-vector-to-position pos instruction-list))) 56 | 57 | 58 | (defn process-recipe 59 | ([instruction-string-list] 60 | (process-recipe instruction-string-list [0 0] [])) 61 | ([instruction-string-list current-pos pos-list] 62 | (cond 63 | (= (count instruction-string-list) 0) (map pos-to-digit pos-list) 64 | "else" (let 65 | [new-pos (find-end-position (first instruction-string-list) current-pos) 66 | new-pos-list (conj pos-list new-pos) 67 | remaining-list (rest instruction-string-list)] 68 | (process-recipe remaining-list new-pos new-pos-list))))) 69 | -------------------------------------------------------------------------------- /challenges/2017-08-30-monkey-path/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /challenges/2017-08-30-monkey-path/README.md: -------------------------------------------------------------------------------- 1 | # Challenge 2 | 3 | ## Monkey Path 4 | A monkey wants to get to the other side of a river. The monkey is initially located on one bank of the river (position -1) and wants to get to the opposite bank (position N). The monkey can jump any (integer) distance between 1 and D. If D is less than or equal to N then the monkey cannot jump across the river. Luckily, there are many stones hidden under the water. The monkey can jump to and from the stones, but only when the particular stone is already out of the water. 5 | 6 | The stones in the river are described in array A consisting of N integers. A[K] represents a time when the stone at position K will be out of the water (A[K] = -1 means that there is no stone at position K). You can assume that no two stones will surface simultaneously. The goal is to find the earliest time when the monkey can get to the other side of the river. 7 | 8 | For example, consider integer D = 3 and the following array A consisting of N = 6 integers: 9 | 10 | ``` 11 | A[0] = 1 12 | A[1] = -1 13 | A[2] = 0 14 | A[3] = 2 15 | A[4] = 3 16 | A[5] = 5 17 | ``` 18 | 19 | Initially , the monkey cannot jump across the river in a single jump. However, at time 2, there will be three stones out of water. 20 | 21 | Time 2 is the earliest moment when the monkey can jump across the river (for example, by jumps of length 1, 3 and 3, as marked on the picture above). 22 | 23 | Write a function: 24 | 25 | `function solution(A, D)` 26 | 27 | that, given a zero-indexed array A consisting of N integers, and integer D, returns the earliest time when the monkey can jump to the other side of the river. If the money can leap across the river in just one jump, the function should return 0. If the monkey is never able to jump to the other side of the river, the function should return -1. 28 | 29 | For example, given array A and integer D as defined above, the function should return 2 as explained above. 30 | 31 | For given A = [3, 2, 1] and D = 1, the function should return 3, since the monkey has to wait for each stone. 32 | 33 | For given A = [1, 2, 3, 4, -1, -1, -1] and D = 3, the function should return -1, since the monkey will never get to the other side of the river. 34 | 35 | # Javascript Template 36 | 37 | ## Install 38 | 39 | `npm install` 40 | 41 | ## Run 42 | 43 | `npm test` 44 | -------------------------------------------------------------------------------- /challenges/2017-08-30-monkey-path/index.test.js: -------------------------------------------------------------------------------- 1 | const riverPathAtTime = (path, time) => 2 | path.map(stone => stone <= time && stone >= 0 ? 1 : 0) 3 | 4 | const canCrossThePath = (path, distance) => { 5 | for(let i = 0, valid ; i < path.length ; i++) { 6 | valid = false 7 | for(let j = 0 ; j < distance ; j++) { 8 | if (path[i + j] === 1 || path[i + j] === undefined) { 9 | valid = true 10 | } 11 | } 12 | if (!valid) { 13 | return false 14 | } 15 | } 16 | return true 17 | } 18 | 19 | const validTimeToCrossRiver = (path, distance) => { 20 | const highestTime = 21 | path.reduce((higherPosition, position) => 22 | position > higherPosition ? position : higherPosition, 0) 23 | for(let currentTime = 1 ; currentTime <= highestTime ; currentTime++) { 24 | const currentPath = riverPathAtTime(path, currentTime) 25 | const canCross = canCrossThePath(currentPath, distance) 26 | if (canCross) { 27 | return currentTime 28 | } 29 | } 30 | return -1 31 | } 32 | 33 | test('river path at given time', () => { 34 | expect(riverPathAtTime([3, 2, 1], 0)).toEqual([0, 0, 0]) 35 | expect(riverPathAtTime([3, 2, 1], 1)).toEqual([0, 0, 1]) 36 | expect(riverPathAtTime([3, 2, 1], 2)).toEqual([0, 1, 1]) 37 | expect(riverPathAtTime([3, 2, 1], 3)).toEqual([1, 1, 1]) 38 | expect(riverPathAtTime([3, 2, 1], 4)).toEqual([1, 1, 1]) 39 | }) 40 | 41 | test('check if can jump river stones at a normalized path', () => { 42 | expect(canCrossThePath([0, 0, 0, 0, 0, 0], 2)).toBe(false) 43 | expect(canCrossThePath([1, 1, 1, 0, 1, 0], 2)).toBe(true) 44 | expect(canCrossThePath([1, 1, 0, 1, 0, 1], 2)).toBe(true) 45 | expect(canCrossThePath([1, 0, 1, 0, 0, 0], 2)).toBe(false) 46 | expect(canCrossThePath([1, 1, 1, 1, 1, 1], 1)).toBe(true) 47 | expect(canCrossThePath([1, 1, 1, 1, 0, 1], 1)).toBe(false) 48 | expect(canCrossThePath([0, 0, 0, 0, 0], 6)).toBe(true) 49 | expect(canCrossThePath([0, 0, 0, 0, 0, 0], 6)).toBe(false) 50 | expect(canCrossThePath([0, 0, 1, 0, 0, 1, 0], 3)).toBe(true) 51 | }) 52 | 53 | test('earliest moment monkey can jump', () => { 54 | expect(validTimeToCrossRiver([3, 2, 1], 1)).toEqual(3) 55 | expect(validTimeToCrossRiver([1, 2, 1], 1)).toEqual(2) 56 | expect(validTimeToCrossRiver([1, 2, 1], 3)).toEqual(1) 57 | expect(validTimeToCrossRiver([1, -1, 0, 2, 3, 5], 3)).toEqual(2) 58 | expect(validTimeToCrossRiver([1, 2, 3, 4, -1, -1, -1], 1)).toEqual(-1) 59 | }) 60 | -------------------------------------------------------------------------------- /challenges/2017-08-30-monkey-path/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.test.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "jest --watch" 8 | }, 9 | "devDependencies": {}, 10 | "dependencies": { 11 | "babel-jest": "^19.0.0", 12 | "jest": "^19.0.2" 13 | }, 14 | "jest": { 15 | "verbose": false, 16 | "transform": { 17 | ".*": "babel-jest" 18 | }, 19 | "moduleFileExtensions": [ 20 | "js" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /challenges/2017-08-30-monkey-path/positions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/challenges/2017-08-30-monkey-path/positions.png -------------------------------------------------------------------------------- /challenges/2018-02-23-inverse-captcha/README.md: -------------------------------------------------------------------------------- 1 | # Inverse Captcha 2 | 3 | Review a sequence of digits (your puzzle input) and find the sum of all digits that match the next 4 | digit in the list. The list is circular, so the digit after the last digit is the first digit in 5 | the list. 6 | 7 | For example: 8 | - 1122 produces a sum of 3 (1 + 2) because the first digit (1) matches the second digit and the 9 | third digit (2) matches the fourth digit. 10 | - 1111 produces 4 because each digit (all 1) matches the next. 11 | - 1234 produces 0 because no digit matches the next. 12 | - 91212129 produces 9 because the only digit that matches the next one is the last digit, 9. 13 | 14 | What is the solution to your captcha? 15 | 16 | Input: ( 17 | '367436765224262147416876392821832169781285655941123648172835986213848397566284241467793119283' 18 | '183835972359686446876651595915734132336167171121577524691918457577129283476247264385162111539' 19 | '468922414495231484194262592917889386218863347344978231632813893898536759322467341535638612338' 20 | '949526576258684154323161554872428137984257797435619875637349449628468652637227127686748382444' 21 | '443857685684898429898781636557718473626561533722659454641286684124392489669393987654461718551' 22 | '445442854635172587498137313143659473725488114346463815952731729824661422484742387625548586546' 23 | '794154186934785126418641683987221996387756677449779411837724945386853988623441645214461159255' 24 | '285344917887284486684553495889724432953913853895517832894173498233833247484116891982193299966' 25 | '667522518155625227593745426529691476964196699145345867324369127985196977225867957463716973384' 26 | '167168422143133932285874133995347163949841839431233755178196228379727964311662646464328934785' 27 | '576593877955732348891418973131584576371422383153278774939949335141126455863511271394292816759' 28 | '123666694759317119743322713682874139856823749431958864559278395739864645551416792919986459366' 29 | '836391625883759745494677676234639355618478695273833952782489523147921121131262312467427531197' 30 | '481138288439178125472244983198499475177456258448191759739868436366284149656644665821724191972' 31 | '276953684924333531992335588723195296268257882881762755465664748242573368639775743473284691533' 32 | '194288837486963995449741333925898233437738973131733365688833853641663363623986366844598862839' 33 | '642422492289383832192555139964685869535196381115999352291152288375592427529259436536236829855' 34 | '763239294154454433781894727824549582323419866267911828616441129744182392864867226544421448511' 35 | '735387568596472187681345728583318495432661696727452213916593636749214694811436869524787717145' 36 | '857933229268246234829235799864347417141671343463845513626641778654528953489489534723289669957' 37 | '311696725735556219395848721879993253223278933367366119297526132419352116642489615276877783719' 38 | '71259654541239471766714469122213793348414477789271187324629397292446879752673' 39 | ) 40 | 41 | Solution: 1069 42 | 43 | ## Install 44 | Tested with Python 3. 45 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 46 | 47 | ## Run 48 | Run the tests with `nosetests --with-watch` 49 | -------------------------------------------------------------------------------- /challenges/2018-02-23-inverse-captcha/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | # Define your code here 5 | def sum_numbers(input): 6 | return sum([int(value) for i, value in enumerate(input) if is_previous_the_same(input, i)]) 7 | 8 | 9 | def is_previous_the_same(input, index): 10 | return input[-1] == input[index] if index == 0 else input[index-1] == input[index] 11 | 12 | 13 | # Define your tests here 14 | class Testing(unittest.TestCase): 15 | def setUp(self): 16 | pass 17 | 18 | def test_is_previous_same(self): 19 | self.assertEqual(is_previous_the_same("1122", 0), False) 20 | self.assertEqual(is_previous_the_same('1122', 1), True) 21 | self.assertEqual(is_previous_the_same('1122', 2), False) 22 | self.assertEqual(is_previous_the_same('1122', 3), True) 23 | 24 | for i, value in enumerate('91212129'): 25 | if i == 0: 26 | self.assertEqual(is_previous_the_same('91212129', i), True) 27 | else: 28 | self.assertEqual(is_previous_the_same('91212129', i), False) 29 | 30 | def test_sum(self): 31 | self.assertEqual(sum_numbers('91212129'), 9) 32 | self.assertEqual(sum_numbers('1234'), 0) 33 | self.assertEqual(sum_numbers('1111'), 4) 34 | self.assertEqual(sum_numbers('1122'), 3) 35 | 36 | 37 | # Executing the tests 38 | if __name__ == '__main__': 39 | unittest.main() 40 | -------------------------------------------------------------------------------- /challenges/2018-02-23-inverse-captcha/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | -------------------------------------------------------------------------------- /challenges/2018-07-25-high-entropy-passphrases/.gitignore: -------------------------------------------------------------------------------- 1 | venv/ 2 | -------------------------------------------------------------------------------- /challenges/2018-07-25-high-entropy-passphrases/README.md: -------------------------------------------------------------------------------- 1 | # Python Template 2 | 3 | ## Install 4 | Tested with Python 3. 5 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 6 | 7 | ## Run 8 | Run the tests with `nosetests --with-watch` 9 | -------------------------------------------------------------------------------- /challenges/2018-07-25-high-entropy-passphrases/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | -------------------------------------------------------------------------------- /challenges/2018-07-25-high-entropy-passphrases/test_code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | def split_words(passphrase): 5 | return passphrase.split(" ") 6 | 7 | 8 | def count_words(word_list): 9 | word_counter = {} 10 | for word in word_list: 11 | if word not in word_counter.keys(): 12 | word_counter[word] = 1 13 | else: 14 | word_counter[word] += 1 15 | 16 | return word_counter 17 | 18 | 19 | def check_duplicates(word_counter): 20 | word_values = set(word_counter.values()) 21 | if len(word_values) > 1: 22 | return False 23 | return True 24 | 25 | 26 | # 1-liner: 27 | is_valid_passphrase2 = lambda word: len(word.split(" ")) == len(set(word.split(" "))) 28 | 29 | 30 | class Testing(unittest.TestCase): 31 | 32 | def setUp(self): 33 | pass 34 | 35 | def test_split_words(self): 36 | self.assertEqual(split_words("aa bb cc dd ee"), ["aa", "bb", "cc", "dd", "ee"]) 37 | 38 | def test_count_words(self): 39 | self.assertEqual(count_words(["aa", "bb", "cc", "dd", "ee"]), 40 | { 41 | "aa": 1, 42 | "bb": 1, 43 | "cc": 1, 44 | "dd": 1, 45 | "ee": 1, 46 | }) 47 | 48 | self.assertEqual(count_words(["aa", "aa", "cc", "dd", "ee"]), 49 | { 50 | "aa": 2, 51 | "cc": 1, 52 | "dd": 1, 53 | "ee": 1, 54 | }) 55 | 56 | def test_check_duplicates(self): 57 | self.assertEqual(check_duplicates({ 58 | "aa": 2, 59 | "cc": 1, 60 | "dd": 1, 61 | "ee": 1, 62 | }), False) 63 | self.assertEqual(check_duplicates({ 64 | "aa": 1, 65 | "cc": 1, 66 | "dd": 1, 67 | "ee": 1, 68 | }), True) 69 | 70 | def test_oneliner(self): 71 | self.assertEqual(is_valid_passphrase2("aa bb cc dd ee"), True) 72 | self.assertEqual(is_valid_passphrase2("aa bb cc dd ee aa"), False) 73 | 74 | # Executing the tests 75 | if __name__ == '__main__': 76 | unittest.main() 77 | -------------------------------------------------------------------------------- /challenges/2018-08-15-elixir-proj-euler/README.md: -------------------------------------------------------------------------------- 1 | # Coding Dojo (2018-08-15): Using Elixir to solve Project Euler 2 | 3 | ## [Factorial digit sum](https://projecteuler.net/problem=20) 4 | 5 | ### Description 6 | 7 | n! means n × (n − 1) × ... × 3 × 2 × 1 8 | 9 | For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, 10 | and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. 11 | 12 | Find the sum of the digits in the number 100! 13 | 14 | ### Run 15 | 16 | `elixir problem020.exs` 17 | 18 | ## [10001st prime](https://projecteuler.net/problem=7) 19 | 20 | ### Description 21 | 22 | By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. 23 | 24 | What is the 10 001st prime number? 25 | 26 | ### Run 27 | 28 | `elixir problem007.exs` -------------------------------------------------------------------------------- /challenges/2018-08-15-elixir-proj-euler/problem007.exs: -------------------------------------------------------------------------------- 1 | defmodule Challenge do 2 | @moduledoc """ 3 | By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. 4 | 5 | What is the 10 001st prime number? 6 | """ 7 | 8 | def is_prime?(1), do: false 9 | def is_prime?(2), do: true 10 | def is_prime?(3), do: true 11 | def is_prime?(number) do 12 | 2..trunc(:math.sqrt(number)) 13 | |> Enum.all?(&(rem(number, &1) != 0)) 14 | end 15 | 16 | # def nth_prime(target) do 17 | # Stream.iterate(2, &(&1+1)) 18 | # |> Stream.filter(&is_prime?/1) 19 | # |> Stream.take(target) 20 | # |> Enum.take(-1) 21 | # |> List.first() 22 | # end 23 | 24 | def nth_prime(target), do: nth_prime(target, 2, 0) 25 | def nth_prime(target, acc, counter) do 26 | if counter < target do 27 | if is_prime?(acc) do 28 | nth_prime(target, acc+1, counter+1) 29 | else 30 | nth_prime(target, acc+1, counter) 31 | end 32 | else 33 | acc-1 34 | end 35 | end 36 | end 37 | 38 | ExUnit.start 39 | 40 | defmodule ChallengeTest do 41 | use ExUnit.Case 42 | 43 | test "is prime number?" do 44 | assert Challenge.is_prime?(13) == true 45 | assert Challenge.is_prime?(12) == false 46 | end 47 | 48 | test "6th prime number" do 49 | assert Challenge.nth_prime(6) == 13 50 | end 51 | 52 | test "nth prime number" do 53 | assert Challenge.nth_prime(10_001) == 104743 54 | end 55 | end -------------------------------------------------------------------------------- /challenges/2018-08-15-elixir-proj-euler/problem020.exs: -------------------------------------------------------------------------------- 1 | defmodule Challenge do 2 | @moduledoc """ 3 | n! means n × (n − 1) × ... × 3 × 2 × 1 4 | 5 | For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, 6 | and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. 7 | 8 | Find the sum of the digits in the number 100! 9 | """ 10 | 11 | def factorial(number) do 12 | 1..number 13 | |> Enum.reduce(&(&1 * &2)) 14 | end 15 | 16 | def sum_digits(number) do 17 | Integer.digits(number) 18 | |> Enum.sum() 19 | end 20 | 21 | def factorial_sum(number) do 22 | factorial(number) 23 | |> sum_digits() 24 | end 25 | 26 | end 27 | 28 | ExUnit.start 29 | 30 | defmodule ChallengeTest do 31 | use ExUnit.Case 32 | 33 | test "factorial" do 34 | assert Challenge.factorial(10) == 3628800 35 | end 36 | 37 | test "sum digits of an int" do 38 | assert Challenge.sum_digits(3628800) == 27 39 | end 40 | 41 | test "sum of the factorial of 100" do 42 | assert Challenge.factorial_sum(100) == 648 43 | end 44 | end -------------------------------------------------------------------------------- /challenges/2019-04-26-mictorio/README.md: -------------------------------------------------------------------------------- 1 | # Challenge 2 | 3 | ## Distribuição de Mictórios 4 | 5 | http://dojopuzzles.com/problemas/exibe/distribuicao-de-mictorios/ 6 | 7 | > Este problema foi utilizado em 204 Dojo(s). 8 | > 9 | > Um problema enfrentado pelos homens no uso de mictórios em banheiros públicos é o constrangimento causado por outro 10 | homem urinando no mictório ao lado. Uma situação contrangedora é definida quando dois "mijões" deveriam ocupar mictórios 11 | adjacentes. 12 | > 13 | > Dada uma quantidade de mictórios em um banheiro e a ocupação inicial deles (informando em qual deles já existe um 14 | "mijão"), determine quantos "mijões" ainda podem usar os mictórios e qual a posição deles antes para que não ocorra uma 15 | situação constrangedora. 16 | 17 | # Solution 18 | 19 | Language of choice: Python 20 | 21 | ## Running the code 22 | 23 | `python code.py` 24 | 25 | ## Explanation: 26 | 27 | We are considering the input to be a list of numbers. The list size is the total number of urinols, and its availability 28 | is being represented by either a `0` (for empty urinols) or a `1` (for occupied). 29 | 30 | Our expected output is a list of positions, where the list size is an indication of the total number of men who can 31 | join in on the peeing without causing embarrassment. 32 | 33 | So here are some test cases: 34 | 35 | | Input | Output | 36 | | ----------------------------------- | ---------- | 37 | | `[0]` | `[0]` | 38 | | `[0,0]` | `[0]` | 39 | | `[0,0,0,0,0,0,1,1,1,0,1]` | `[0,2,4]` | 40 | | `[1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0]` | `[2,4,12]` | 41 | 42 | To achieve this, we have defined two functions: `get_availables()` and `get_peers()`. 43 | 44 | The function `get_availables()` lists the urinols which don't have anyone besides them. We can interpret this as the 45 | options a man has when given the initial state. 46 | 47 | To compute this, we group urinols in threes and then filter those which have no `1`s: 48 | 49 | ```python 50 | def get_availables(urinols): 51 | availables = zip([0] + urinols[:-1], urinols, urinols[1:] + [0]) 52 | return [ i[0] for i in enumerate(availables) if i[1] == (0, 0, 0) ] 53 | ``` 54 | 55 | The function `get_peers()` goes one step further in order to compute the complete occupation. It starts out listing 56 | available urinols and choosing the first one. After that, it recursively calls itself with the new occupation: 57 | 58 | ```python 59 | def get_peers(urinols): 60 | availables = get_availables(urinols) 61 | 62 | if availables: 63 | index = availables[0] 64 | urinols[index] = 1 65 | return [index] + get_peers(urinols) 66 | 67 | return [] 68 | ``` 69 | -------------------------------------------------------------------------------- /challenges/2019-04-26-mictorio/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | def get_availables(urinols): 5 | availables = zip([0] + urinols[:-1], urinols, urinols[1:] + [0]) 6 | return [ i[0] for i in enumerate(availables) if i[1] == (0, 0, 0) ] 7 | 8 | 9 | def get_peers(urinols): 10 | availables = get_availables(urinols) 11 | 12 | if availables: 13 | index = availables[0] 14 | urinols[index] = 1 15 | return [index] + get_peers(urinols) 16 | 17 | return [] 18 | 19 | 20 | class Testing(unittest.TestCase): 21 | 22 | def test_availables(self): 23 | self.assertEqual(get_availables([0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0]), [0,1,2,3,4,12]) 24 | 25 | def test_peers(self): 26 | self.assertEqual(get_peers([0]), [0]) 27 | self.assertEqual(get_peers([0,0]), [0]) 28 | self.assertEqual(get_peers([0,0,0,0,0,0,1,1,1,0,1]), [0,2,4]) 29 | self.assertEqual(get_peers([0,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0]), [0,2,4,12]) 30 | self.assertEqual(get_peers([1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0]), [2,4,12]) 31 | 32 | 33 | # Executing the tests 34 | if __name__ == '__main__': 35 | unittest.main() 36 | -------------------------------------------------------------------------------- /challenges/2019-05-10-fizzbuzz/README.md: -------------------------------------------------------------------------------- 1 | # Challenge 2 | 3 | ## FizzBuzz 4 | 5 | http://dojopuzzles.com/problemas/exibe/fizzbuzz/ 6 | 7 | > Este problema foi utilizado em 554 Dojo(s). 8 | > 9 | > FizzBuzz 10 | > 11 | > Neste problema, você deverá exibir uma lista de 1 a 100, um em cada linha, com as seguintes exceções: 12 | > 13 | > Números divisíveis por 3 deve aparecer como 'Fizz' ao invés do número; 14 | > Números divisíveis por 5 devem aparecer como 'Buzz' ao invés do número; 15 | > Números divisíveis por 3 e 5 devem aparecer como 'FizzBuzz' ao invés do número'. 16 | 17 | # Solution 18 | 19 | Language of choice: Elixir 20 | 21 | ## Running the code 22 | 23 | `elixir code.ex` 24 | 25 | ## Explanation: 26 | 27 | We define a function `fizz_buzz/1` that receives an `Integer` argument and returns either `"Fizz"`, `"Buzz"`, 28 | `"FizzBuzz"` or the string representation of the number, depending on which of the cases the number falls into. 29 | 30 | We implement this by having a function defined multiple times with [guards clauses](https://hexdocs.pm/elixir/master/guards.html) 31 | to define which one will be used. The first matching pattern will be used, so we define the most specific first: 32 | 33 | ```elixir 34 | def fizz_buzz(i) when rem(i, 3) == 0 and rem(i, 5) == 0, do: "FizzBuzz" 35 | def fizz_buzz(i) when rem(i, 3) == 0, do: "Fizz" 36 | def fizz_buzz(i) when rem(i, 5) == 0, do: "Buzz" 37 | def fizz_buzz(i), do: Integer.to_string(i) 38 | ``` 39 | 40 | After having that function ready, we can just create a stream of numbers, map them to the `fizz_buzz/1` function, take 41 | the first 100 occurrences and print them to the screen: 42 | 43 | ```elixir 44 | def solve() do 45 | Stream.iterate(1, &(&1 + 1)) 46 | |> Stream.map(&fizz_buzz/1) 47 | |> Stream.take(100) 48 | |> Enum.each(&IO.puts/1) 49 | end 50 | ``` 51 | -------------------------------------------------------------------------------- /challenges/2019-05-10-fizzbuzz/code.ex: -------------------------------------------------------------------------------- 1 | defmodule FizzBuzz do 2 | @moduledoc """ 3 | Neste problema, você deverá exibir uma lista de 1 a 100, um em cada linha, com as seguintes exceções: 4 | 5 | Números divisíveis por 3 deve aparecer como 'Fizz' ao invés do número; 6 | Números divisíveis por 5 devem aparecer como 'Buzz' ao invés do número; 7 | Números divisíveis por 3 e 5 devem aparecer como 'FizzBuzz' ao invés do número'. 8 | """ 9 | 10 | def fizz_buzz(i) when rem(i, 3) == 0 and rem(i, 5) == 0, do: "FizzBuzz" 11 | def fizz_buzz(i) when rem(i, 3) == 0, do: "Fizz" 12 | def fizz_buzz(i) when rem(i, 5) == 0, do: "Buzz" 13 | def fizz_buzz(i), do: Integer.to_string(i) 14 | 15 | def solve() do 16 | Stream.iterate(1, &(&1 + 1)) 17 | |> Stream.map(&fizz_buzz/1) 18 | |> Stream.take(100) 19 | |> Enum.each(&IO.puts/1) 20 | end 21 | end 22 | 23 | FizzBuzz.solve() 24 | -------------------------------------------------------------------------------- /challenges/2019-05-24-minesweeper/README.md: -------------------------------------------------------------------------------- 1 | # Challenge 2 | 3 | ## Campo Minado 4 | 5 | http://dojopuzzles.com/problemas/exibe/fizzbuzz/ 6 | 7 | Você já jogou Campo Minado? É um pequeno jogo que vem instalado em um certo Sistema Operacional cujo nome não 8 | conseguimos lembrar. O objetivo deste jogo é encontrar onde estão todas as minas em um campo de tamanho MxN (M e N 9 | inteiros). Para te ajudar, para cada posição, o jogo exibe o número de minas que são adjacentes a ela. 10 | 11 | Por exemplo, suponha o seguinte campo 4x4 com 2 minas (representadas pelo caractere *): 12 | 13 | * . . . 14 | . . . . 15 | . * . . 16 | . . . . 17 | Representando o mesmo campo, colocando os números de dicas como descrito acima, teremos: 18 | 19 | * 1 0 0 20 | 2 2 1 0 21 | 1 * 1 0 22 | 1 1 1 0 23 | Como você pode perceber, cada quadrado pode ter até 8 quadrados adjacentes. 24 | 25 | Sua tarefa é, dado a definição de um campo (definido por suas dimensões e pelo posicionamento das minas), retornar o 26 | mesmo campo com as indicações de números de minas adjacentes em cada posição que não contenha uma mina. 27 | 28 | # Solution 29 | 30 | Language of choice: Elixir 31 | 32 | ## Running the code 33 | 34 | `elixir code.ex` -------------------------------------------------------------------------------- /challenges/2019-05-24-minesweeper/code.ex: -------------------------------------------------------------------------------- 1 | defmodule Challenge do 2 | @moduledoc """ 3 | Você já jogou Campo Minado? É um pequeno jogo que vem instalado em um certo Sistema Operacional cujo nome não 4 | conseguimos lembrar. O objetivo deste jogo é encontrar onde estão todas as minas em um campo de tamanho MxN (M e N 5 | inteiros). Para te ajudar, para cada posição, o jogo exibe o número de minas que são adjacentes a ela. 6 | 7 | Por exemplo, suponha o seguinte campo 4x4 com 2 minas (representadas pelo caractere *): 8 | 9 | * . . . 10 | . . . . 11 | . * . . 12 | . . . . 13 | Representando o mesmo campo, colocando os números de dicas como descrito acima, teremos: 14 | 15 | * 1 0 0 16 | 2 2 1 0 17 | 1 * 1 0 18 | 1 1 1 0 19 | Como você pode perceber, cada quadrado pode ter até 8 quadrados adjacentes. 20 | 21 | Sua tarefa é, dado a definição de um campo (definido por suas dimensões e pelo posicionamento das minas), retornar o 22 | mesmo campo com as indicações de números de minas adjacentes em cada posição que não contenha uma mina. 23 | """ 24 | 25 | def calculate(width, height, bombs) do 26 | for x <- 0..width-1, 27 | y <- 0..height-1 do 28 | 29 | case Enum.member?(bombs, {x,y}) do 30 | true -> {{x,y}, '*'} 31 | false -> {{x,y}, [ 32 | {x-1, y-1}, {x, y-1}, {x+1, y-1}, 33 | {x-1, y}, {x+1, y}, 34 | {x-1, y+1}, {x, y+1}, {x+1, y+1}, 35 | ] 36 | |> Enum.filter(fn spot -> Enum.member?(bombs, spot) end) 37 | |> Enum.count() 38 | } 39 | end 40 | 41 | end 42 | |> Map.new() 43 | end 44 | 45 | end 46 | 47 | ExUnit.start 48 | 49 | defmodule ChallengeTest do 50 | use ExUnit.Case 51 | 52 | test "end_to_end" do 53 | assert Challenge.calculate(4, 4, [{0,0}, {1,2}]) == %{ 54 | {0, 0} => '*', 55 | {0, 1} => 2, 56 | {0, 2} => 1, 57 | {0, 3} => 1, 58 | {1, 0} => 1, 59 | {1, 1} => 2, 60 | {1, 2} => '*', 61 | {1, 3} => 1, 62 | {2, 0} => 0, 63 | {2, 1} => 1, 64 | {2, 2} => 1, 65 | {2, 3} => 1, 66 | {3, 0} => 0, 67 | {3, 1} => 0, 68 | {3, 2} => 0, 69 | {3, 3} => 0, 70 | } 71 | end 72 | 73 | end 74 | -------------------------------------------------------------------------------- /codingdojo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/codingdojo.png -------------------------------------------------------------------------------- /templates/Swift/README.md: -------------------------------------------------------------------------------- 1 | # Swift Template 2 | 3 | ## Install 4 | Xcode 8 5 | 6 | ## Run 7 | Just open the playground file and the Xcode will compile and run your changes automatically 8 | -------------------------------------------------------------------------------- /templates/Swift/SwiftTestsTemplate.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | //: Playground - noun: a place where people can play 2 | 3 | import UIKit 4 | import XCTest 5 | 6 | 7 | class MainTests: XCTestCase { 8 | var numbersToTest = [1,2,3,4,5,6] 9 | 10 | func testSum() { 11 | let main = Main() 12 | for i in numbersToTest { 13 | XCTAssertEqual(main.sum(i, y: i + 1), i + (i + 1)) 14 | XCTAssertNotEqual(main.sum(i, y: i + 2), i + i) 15 | } 16 | } 17 | 18 | func testMultiply() { 19 | let main = Main() 20 | for i in numbersToTest { 21 | XCTAssertEqual(main.multiply(i, y: i + 1), i * (i + 1)) 22 | XCTAssertNotEqual(main.multiply(i, y: i + 2), i + i) 23 | } 24 | } 25 | } 26 | 27 | class Main { 28 | 29 | fileprivate func sum(_ x:Int, y:Int) -> Int { 30 | return x + y 31 | } 32 | 33 | fileprivate func multiply(_ x: Int, y:Int) -> Int{ 34 | return x * y 35 | } 36 | 37 | } 38 | 39 | MainTests.defaultTestSuite().run() 40 | 41 | 42 | -------------------------------------------------------------------------------- /templates/Swift/SwiftTestsTemplate.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /templates/Swift/SwiftTestsTemplate.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /templates/Swift/SwiftTestsTemplate.playground/playground.xcworkspace/xcuserdata/ostanik.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/Swift/SwiftTestsTemplate.playground/playground.xcworkspace/xcuserdata/ostanik.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /templates/elixir/README.md: -------------------------------------------------------------------------------- 1 | # Using the Elixir template 2 | 3 | 1. Install elixir: `brew update && brew install elixir` 4 | 2. Run the file: `elixir template.exs` 5 | 3. Profit 6 | -------------------------------------------------------------------------------- /templates/elixir/template.exs: -------------------------------------------------------------------------------- 1 | defmodule Challenge do 2 | @moduledoc """ 3 | Template for solving test-driven challenges 4 | """ 5 | 6 | def foo do 7 | "bar" 8 | end 9 | end 10 | 11 | ExUnit.start 12 | 13 | defmodule ChallengeTest do 14 | use ExUnit.Case 15 | 16 | test "mytest" do 17 | assert Challenge.foo == "bar" 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /templates/go/README.md: -------------------------------------------------------------------------------- 1 | # Go Template 2 | 3 | ## Install 4 | You need Go! This was tested with version 1.8. 5 | You'll also need [bro](https://github.com/marioidival/bro), a Go test runner with file watch. Install it with `go get github.com/marioidival/bro`. 6 | 7 | ## Run 8 | On the directory, run `bro`. 9 | -------------------------------------------------------------------------------- /templates/go/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Your code goes here 4 | func PrintHelloWorld() string { 5 | return "Hello World!" 6 | } 7 | 8 | func main() { 9 | } 10 | -------------------------------------------------------------------------------- /templates/go/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "testing" 4 | 5 | // Your tests go here 6 | func TestMain(t *testing.T) { 7 | if PrintHelloWorld() != "Hello World!" { 8 | t.Fatal("Not valid") 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /templates/haskell/.ghci: -------------------------------------------------------------------------------- 1 | :set -isrc -itest 2 | 3 | -- for generated source files 4 | :set -idist/build/ 5 | 6 | -- for Paths_.hs 7 | :set -idist/build/autogen 8 | 9 | :set -optP-include -optPdist/build/autogen/cabal_macros.h 10 | -------------------------------------------------------------------------------- /templates/haskell/.gitignore: -------------------------------------------------------------------------------- 1 | /dist/ 2 | -------------------------------------------------------------------------------- /templates/haskell/README.md: -------------------------------------------------------------------------------- 1 | # Haskell Template 2 | 3 | ## Install 4 | `cabal install --only-dependencies --enable-tests` 5 | 6 | ## Run 7 | `cabal test` 8 | -------------------------------------------------------------------------------- /templates/haskell/codingdojo.cabal: -------------------------------------------------------------------------------- 1 | -- This file has been generated from package.yaml by hpack version 0.17.0. 2 | -- 3 | -- see: https://github.com/sol/hpack 4 | 5 | name: codingdojo 6 | version: 0.0.0 7 | author: CheesecakeLabs 8 | maintainer: CheesecakeLabs 9 | copyright: (c) 2017 CheesecakeLabs 10 | build-type: Simple 11 | cabal-version: >= 1.10 12 | 13 | library 14 | hs-source-dirs: 15 | src 16 | ghc-options: -Wall 17 | build-depends: 18 | base == 4.* 19 | exposed-modules: 20 | Code 21 | default-language: Haskell2010 22 | 23 | test-suite spec 24 | type: exitcode-stdio-1.0 25 | main-is: Spec.hs 26 | hs-source-dirs: 27 | test 28 | ghc-options: -Wall 29 | build-depends: 30 | base == 4.* 31 | , codingdojo 32 | , hspec == 2.* 33 | other-modules: 34 | CodeSpec 35 | default-language: Haskell2010 36 | -------------------------------------------------------------------------------- /templates/haskell/src/Code.hs: -------------------------------------------------------------------------------- 1 | module Code where 2 | 3 | add :: Integer -> Integer -> Integer 4 | add x y = x + y 5 | -------------------------------------------------------------------------------- /templates/haskell/test/CodeSpec.hs: -------------------------------------------------------------------------------- 1 | module CodeSpec (main, spec) where 2 | 3 | import Test.Hspec 4 | import Code 5 | 6 | main :: IO () 7 | main = hspec spec 8 | 9 | spec :: Spec 10 | spec = do 11 | describe "next score" $ do 12 | it "should add x and y" $ do 13 | shouldBe (add 1 1) 2 14 | 15 | -------------------------------------------------------------------------------- /templates/haskell/test/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -F -pgmF hspec-discover #-} 2 | -------------------------------------------------------------------------------- /templates/javascript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /templates/javascript/index.test.js: -------------------------------------------------------------------------------- 1 | const sum = (a, b) => a + b 2 | const sumAll = (...args) => args.reduce(sum, 0) 3 | 4 | test('some name', () => { 5 | expect(sum(1, 1)).toBe(2) 6 | expect(sum('1', 1)).not.toBe(2) // '11' 7 | expect(sumAll(1, 1, 1, 1)).toBe(4) 8 | expect(sumAll(10, 11, 12, 13)).toBe(46) 9 | expect(sumAll(33)).toBe(33) 10 | }) 11 | 12 | -------------------------------------------------------------------------------- /templates/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dojo-javascript", 3 | "version": "1.0.0", 4 | "main": "index.test.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "test": "jest --watch" 8 | }, 9 | "devDependencies": {}, 10 | "dependencies": { 11 | "babel-jest": "^19.0.0", 12 | "jest": "^19.0.2" 13 | }, 14 | "jest": { 15 | "verbose": false, 16 | "transform": { 17 | ".*": "babel-jest" 18 | }, 19 | "moduleFileExtensions": [ 20 | "js" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /templates/javascript/readme.md: -------------------------------------------------------------------------------- 1 | # Javascript Template 2 | 3 | ## Install 4 | 5 | `npm install` 6 | 7 | ## Run 8 | 9 | `npm test` 10 | -------------------------------------------------------------------------------- /templates/kotlin/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /templates/kotlin/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | 21 | 1.8 22 | 23 | 28 | 29 | 30 | 31 | 32 | 33 | 1.8 (1) 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /templates/kotlin/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /templates/kotlin/.idea/modules/kotlin.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 70 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /templates/kotlin/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /templates/kotlin/build.gradle: -------------------------------------------------------------------------------- 1 | group 'cheesecakelabs' 2 | version '1.0-SNAPSHOT' 3 | 4 | buildscript { 5 | ext.kotlin_version = '1.0.6' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | dependencies { 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 12 | } 13 | } 14 | 15 | apply plugin: 'java' 16 | apply plugin: 'kotlin' 17 | 18 | sourceCompatibility = 1.5 19 | 20 | mainClassName = 'Main' 21 | 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | dependencies { 27 | compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 28 | testCompile group: 'junit', name: 'junit', version: '4.11' 29 | testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" 30 | } 31 | -------------------------------------------------------------------------------- /templates/kotlin/build/classes/main/META-INF/codingdojojo_main.kotlin_module: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | MainKt -------------------------------------------------------------------------------- /templates/kotlin/build/classes/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/build/classes/main/Main.class -------------------------------------------------------------------------------- /templates/kotlin/build/classes/main/MainKt.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/build/classes/main/MainKt.class -------------------------------------------------------------------------------- /templates/kotlin/build/classes/test/MainTest$testFizzBuzz$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/build/classes/test/MainTest$testFizzBuzz$1.class -------------------------------------------------------------------------------- /templates/kotlin/build/classes/test/MainTest$testFizzBuzz$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/build/classes/test/MainTest$testFizzBuzz$2.class -------------------------------------------------------------------------------- /templates/kotlin/build/classes/test/MainTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/build/classes/test/MainTest.class -------------------------------------------------------------------------------- /templates/kotlin/build/kotlin-build/caches/version.txt: -------------------------------------------------------------------------------- 1 | 11001 -------------------------------------------------------------------------------- /templates/kotlin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CheesecakeLabs/codingdojo/e56bbbf27a91ce01054156e4e23fc76b7dbbf873/templates/kotlin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /templates/kotlin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jan 18 11:23:22 BRST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.1-all.zip 7 | -------------------------------------------------------------------------------- /templates/kotlin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn ( ) { 37 | echo "$*" 38 | } 39 | 40 | die ( ) { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 165 | if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then 166 | cd "$(dirname "$0")" 167 | fi 168 | 169 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 170 | -------------------------------------------------------------------------------- /templates/kotlin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /templates/kotlin/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'kotlin' 2 | 3 | -------------------------------------------------------------------------------- /templates/kotlin/src/main/kotlin/Main.kt: -------------------------------------------------------------------------------- 1 | import java.util.* 2 | 3 | /** 4 | * Created by marciorodrigues on 18/01/17. 5 | */ 6 | 7 | /** 8 | Write a program that outputs the string representation of numbers from 1 to n. 9 | 10 | But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. 11 | For numbers which are multiples of both three and five output “FizzBuzz”. 12 | */ 13 | 14 | fun main(args : Array) { 15 | 16 | } 17 | 18 | class Main { 19 | 20 | fun sum(num1: Int, num2: Int) : Int { 21 | return num1 + num2 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /templates/kotlin/src/test/kotlin/MainTest.kt: -------------------------------------------------------------------------------- 1 | import org.junit.Test 2 | import java.util.* 3 | import kotlin.test.assertEquals 4 | import kotlin.test.assertTrue 5 | 6 | /** 7 | * Created by marciorodrigues on 18/01/17. 8 | */ 9 | 10 | class MainTest { 11 | 12 | @Test fun testFizzBuzz() { 13 | val main = Main() 14 | assertEquals(main.sum(1, 2), 3) 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /templates/python/README.md: -------------------------------------------------------------------------------- 1 | # Python Template 2 | 3 | ## Install 4 | Tested with Python 3. 5 | Create a virtual environment and install the requirements with `pip install -r requirements.txt` 6 | 7 | ## Run 8 | Run the tests with `nosetests --with-watch` 9 | -------------------------------------------------------------------------------- /templates/python/code.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | # Define your code here 5 | def hello_world(): 6 | return 'Hello world' 7 | 8 | 9 | # Define your tests here 10 | class Testing(unittest.TestCase): 11 | 12 | def setUp(self): 13 | pass 14 | 15 | def test_hello_world(self): 16 | self.assertEqual(hello_world(), 'Hello world') 17 | 18 | # Executing the tests 19 | if __name__ == '__main__': 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /templates/python/requirements.txt: -------------------------------------------------------------------------------- 1 | nose==1.3.7 2 | nose-watch==0.9.1 3 | --------------------------------------------------------------------------------