├── Images └── banner.png ├── Challenges ├── 0001-The_3n+1_problem │ └── The3n+1.playground │ │ ├── playground.xcworkspace │ │ └── contents.xcworkspacedata │ │ ├── contents.xcplayground │ │ ├── timeline.xctimeline │ │ └── Contents.swift └── 0002-Minesweeeper │ └── Minesweeper.playground │ ├── playground.xcworkspace │ └── contents.xcworkspacedata │ ├── contents.xcplayground │ ├── timeline.xctimeline │ └── Contents.swift ├── .gitignore └── README.md /Images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fellowswift/SwiftChallenges/HEAD/Images/banner.png -------------------------------------------------------------------------------- /Challenges/0001-The_3n+1_problem/The3n+1.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Challenges/0002-Minesweeeper/Minesweeper.playground/playground.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Challenges/0001-The_3n+1_problem/The3n+1.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Challenges/0002-Minesweeeper/Minesweeper.playground/contents.xcplayground: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Challenges/0001-The_3n+1_problem/The3n+1.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Challenges/0002-Minesweeeper/Minesweeper.playground/timeline.xctimeline: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | 16 | 17 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | # Swift Package Manager 31 | # 32 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 33 | # Packages/ 34 | .build/ 35 | 36 | # CocoaPods 37 | # 38 | # We recommend against adding the Pods directory to your .gitignore. However 39 | # you should judge for yourself, the pros and cons are mentioned at: 40 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 41 | # 42 | # Pods/ 43 | 44 | # Carthage 45 | # 46 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 47 | # Carthage/Checkouts 48 | 49 | Carthage/Build 50 | 51 | # fastlane 52 | # 53 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 54 | # screenshots whenever they are needed. 55 | # For more information about the recommended setup visit: 56 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 57 | 58 | fastlane/report.xml 59 | fastlane/screenshots 60 | -------------------------------------------------------------------------------- /Challenges/0001-The_3n+1_problem/The3n+1.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: 2 | 3 | ## Challenge 1: **The 3n+1 problem** 4 | 5 | Consider the following algorithm to generate a sequence of numbers. Start with an integer n. If n is even, divide by 2. If n is odd, multiply by 3 and add 1. Repeat this process with the new value of n, terminating when n = 1. For example, the following sequence of numbers will be generated for n = 22: 6 | 7 | 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 8 | 9 | It is conjectured (but not yet proven) that this algorithm will terminate at n = 1 for every integer n. Still, the conjecture holds for all integers up to at least 1,000,000. 10 | 11 | For an input n, the cycle-length of n is the number of numbers generated up to and including the 1. In the example above, the cycle length of 22 is 16. Given any two numbers i and j, you are to determine the maximum cycle length over all numbers between i and j, including both endpoints. 12 | 13 | ## Input 14 | The input will consist in a couple of integers. All of them will be less than 1,000,000 and greater than 0. 15 | 16 | ## Output 17 | Output the maximum cycle length found in the range defined by the input values i and j. 18 | */ 19 | 20 | 21 | func challenge_0001(i: Int, _ j: Int) -> Int { 22 | 23 | <#Write here your solution#> 24 | 25 | } 26 | 27 | //assert(challenge_0001(1, 10) == 20) 28 | //assert(challenge_0001(100, 200) == 125) 29 | //assert(challenge_0001(201, 210) == 89) 30 | //assert(challenge_0001(900, 1000) == 174) 31 | 32 | /*: 33 | This problem appeared originally in programming-challenges.com 34 | */ -------------------------------------------------------------------------------- /Challenges/0002-Minesweeeper/Minesweeper.playground/Contents.swift: -------------------------------------------------------------------------------- 1 | /*: 2 | 3 | ## Challenge 2: **Minesweeper** 4 | 5 | 6 | Have you ever played Minesweeper? This cute little game comes with a certain operating system whose name we can't remember. The goal of the game is to find where all the mines are located within a M x N field. 7 | 8 | The game shows a number in a square which tells you how many mines there are adjacent to that square. Each square has at most eight adjacent squares. The 4 x 4 field on the left contains two mines, each represented by a '*' character. If we represent the same field by the hint numbers described above, we end up with the field on the right: 9 | 10 | *... 11 | .... 12 | .*.. 13 | .... 14 | 15 | *100 16 | 2210 17 | 1*10 18 | 1110 19 | 20 | ## Input 21 | 22 | The input will consist in a couple of integers n and m (0 < n, m <= 100) which stand for the number of lines and columns of the field, respectively. Followed by a matrix which contains exactly the characters representing the field. 23 | 24 | Safe squares are denoted by "." and mine squares by "*", both without the quotes. 25 | 26 | ## Output 27 | 28 | A matrix replacing all the "." characters by the number of mines adjacent to that square. 29 | */ 30 | 31 | 32 | func challenge_0002(n: Int, _ m: Int, _ field:[[String]]) -> [[String]] { 33 | 34 | <#Write here your solution#> 35 | 36 | } 37 | 38 | // MARK: Checks 39 | 40 | 41 | /* 42 | let result_1 = challenge_0002(4, 4, [ 43 | ["*", ".", ".", "."], 44 | [".", ".", ".", "."], 45 | [".", "*", ".", "."], 46 | [".", ".", ".", "."]]) 47 | 48 | assert(result_1[0] == ["*", "1", "0", "0"]) 49 | assert(result_1[1] == ["2", "2", "1", "0"]) 50 | assert(result_1[2] == ["1", "*", "1", "0"]) 51 | assert(result_1[3] == ["1", "1", "1", "0"]) 52 | 53 | 54 | 55 | 56 | 57 | let result_2 = challenge_0002(3, 5, [ 58 | ["*", "*", ".", ".", "."], 59 | [".", ".", ".", ".", "."], 60 | [".", "*", ".", ".", "."]]) 61 | 62 | assert(result_2[0] == ["*", "*", "1", "0", "0"]) 63 | assert(result_2[1] == ["3", "3", "2", "0", "0"]) 64 | assert(result_2[2] == ["1", "*", "1", "0", "0"]) 65 | */ 66 | 67 | /*: 68 | This problem appeared originally in programming-challenges.com 69 | */ 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![](Images/banner.png) 3 | 4 | Welcome to this challenging playground for those who love coding. Inspired by [programming-challenges.com](http://programming-challenges.com) and [SwiftAlgorithmsClassroom](https://github.com/gmertk/SwiftAlgorithmsClassroom). Join the [Fellowswift](http://fellowswift.com) community to discuss these Challenges. 5 | 6 | Periodically a programming challenge will be published in this repo as a pending issue. You should fork this repository and send a pull request as your solution to the issue. We will do peer-review by commenting others' solutions. We will learn and teach all together. 7 | 8 | Please avoid the urge to read other's solutions before implementing yours. Try to solve the challenges in your own first and compare it with your collagues afterwards. 9 | 10 | Please remember that you should not make any assumption in the challenges. Your solution should deal with negative numbers, decimals, wrong inputs, etc... unless it is indicated like that in the problem. In case of doubt please send a comment to the corresponding issue. 11 | 12 | And please remember that this is a respectful area. Review and take the comments of your peers with respect. 13 | 14 | ### Challenges 15 | 16 | · [Challenge 0001: The 3n+1 problem](https://github.com/fellowswift/SwiftChallenges/issues/1) 17 | · [Challenge 0002: Minesweeper](https://github.com/fellowswift/SwiftChallenges/issues/9) 18 | 19 | ### Challenges awards 20 | 21 | | Position | Username | Challenges solved | 22 | |-----------|:-----------------------------------------------|:---------------------| 23 | | 1 | 🇦🇹 [@fabb](https://github.com/fabb) | 1 Challenge solved | 24 | | 2 | 🇪🇸 [@raulmpad](https://github.com/raulmpad) | 1 Challenge solved | 25 | | 3 | 🇵🇹 [@phelgo](https://github.com/phelgo) * | 1 Challenge solved | 26 | | 4 | 🇪🇸 [@dcordero](https://github.com/dcordero) * | 1 Challenge solved | 27 | 28 | \* Organisers, don’t trust their numbers, they are probably cheating \o/ 29 | 30 | ### Contributing 31 | 32 | Do you have a nice problem that you would like to propose for the challenge? 33 | Do you have any doubt about the process? 34 | Anything else you would like to share with us? 35 | 36 | Please contact us, we are really looking forward your comments. 37 | 38 | ### Sources 39 | 40 | This is the list of sources from which we got the challenges: 41 | * [programming-challenges.com](http://www.programming-challenges.com) 42 | 43 | 44 | --------------------------------------------------------------------------------