├── .gitignore ├── etc ├── requirements.txt └── praw.ini.example ├── Easy Challenges ├── Challenge 0005 Easy │ ├── solutions │ │ ├── access.txt │ │ ├── solution.js │ │ ├── solution.m │ │ └── solution3.py │ └── challenge_text.md ├── Challenge 0037 Easy │ ├── solutions │ │ ├── solution.rb │ │ └── solution.exs │ └── challenge_text.md ├── Challenge 0015 Easy │ └── challenge_text.md ├── Challenge 0020 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.java │ │ └── solution.js ├── Challenge 0040 Easy │ ├── solutions │ │ ├── solution.exs │ │ ├── solution.pl │ │ ├── solution.js │ │ └── solution.c │ └── challenge_text.md ├── Challenge 0021 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0038 Easy │ └── challenge_text.md ├── Challenge 0016 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.js │ │ ├── solution.py │ │ └── Solution1.java ├── Challenge 0039 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.js │ │ ├── solution.rb │ │ ├── solution.exs │ │ ├── solution.py │ │ ├── solution.R │ │ ├── solution.c │ │ └── solution.rs ├── Challenge 0006 Easy │ └── challenge_text.md ├── Challenge 0062 Easy │ └── challenge_text.md ├── Challenge 0046 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0147 Easy - Sport Points │ └── solutions │ │ └── solution.py ├── Challenge 0212 Easy - Rövarspråket │ └── challenge_text.md ├── Challenge 0088 Easy - Vigenère cipher │ └── challenge_text.md ├── Challenge 0112 Easy - Get that URL! │ └── challenge_text.md ├── Challenge 0213 Easy - Pronouncing Hex │ └── challenge_text.md ├── Challenge 0208 Easy - Culling Numbers │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0235 Easy - Ruth-Aaron Pairs │ └── challenge_text.md ├── Challenge 0008 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution2.py │ │ ├── solution.py │ │ ├── solution.js │ │ └── Solution.java ├── Challenge 0009 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.py │ │ └── solution.js ├── Challenge 0204 Easy - Remembering your lines │ └── challenge_text.md ├── Challenge 0013 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0022 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0055 Easy │ └── challenge_text.md ├── Challenge 0034 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0011 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0028 Easy │ ├── solutions │ │ └── solution.py │ └── challenge_text.md ├── Challenge 0286 Easy - Reverse Factorial │ └── solutions │ │ └── solution.py ├── Challenge 0003 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.m ├── Challenge 0014 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0068 Easy │ └── challenge_text.md ├── Challenge 0122 Easy - Sum Them Digits │ └── solutions │ │ └── solution.js ├── Challenge 0023 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0004 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution1.py │ │ ├── solution.m │ │ ├── solution.js │ │ └── solution.py ├── Challenge 0027 Easy │ ├── solutions │ │ ├── solution.py │ │ ├── solution.js │ │ └── Solution.java │ └── challenge_text.md ├── Challenge 0053 Easy │ └── challenge_text.md ├── Challenge 0012 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0025 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0001 Easy │ ├── solutions │ │ ├── solution.m │ │ ├── solution.js │ │ ├── solution.tcl │ │ ├── solution3.c │ │ ├── solution.rb │ │ ├── solution3.py │ │ ├── solution.lisp │ │ ├── solution.py │ │ ├── solution.c │ │ ├── solution.cpp │ │ └── solution2.py │ └── challenge_text.md ├── Challenge 0031 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.js ├── Challenge 0041 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0029 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0010 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0026 Easy │ ├── solutions │ │ ├── solution.js │ │ └── solution.java │ └── challenge_text.md ├── Challenge 0048 Easy │ ├── challenge_text.md │ └── solution │ │ └── solution.c ├── Challenge 0030 Easy │ ├── solutions │ │ ├── solution.js │ │ └── solution.py │ └── challenge_text.md ├── Challenge 0060 Easy │ ├── challenge_text.md │ └── solutions │ │ └── solution.py ├── Challenge 0035 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0017 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.js │ │ ├── solution.cpp │ │ └── solution2.py ├── Challenge 0197 Easy - ISBN Validator │ └── solutions │ │ └── solution.js ├── [Easy] Longest Two-Character Sub-String │ ├── solutions │ │ └── solution.rb │ └── challenge_text.md ├── Challenge 0255 Easy - Playing with light switches │ └── solutions │ │ ├── solution.R │ │ └── solution.js ├── Challenge 0033 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0018 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.js │ │ ├── solution3.py │ │ └── solution2.py ├── Challenge 0019 Easy │ └── challenge_text.md ├── Challenge 0052 Easy │ ├── solutions │ │ └── solution.R │ └── challenge_text.md ├── Challenge 0111 Easy - Star delete │ └── challenge_text.md ├── Challenge 0070 Easy │ └── challenge_text.md ├── Challenge 0099 Easy - Words with letters in alphabetical order │ └── challenge_text.md ├── Challenge 0254 Easy - Atbash Cipher │ └── solutions │ │ └── solution.js ├── Challenge 0271 Easy - Critical Hit │ └── solutions │ │ └── solution.c ├── Challenge 0239 Easy - A Game of Threes │ └── solutions │ │ ├── solution.py │ │ ├── solution.c │ │ └── solution.rs ├── Challenge 0002 Easy │ ├── challenge_text.md │ └── solutions │ │ ├── solution.tcl │ │ ├── solution.js │ │ └── solution.m ├── Challenge 0036 Easy │ ├── solutions │ │ └── solution.js │ └── challenge_text.md ├── Challenge 0238 Easy - Consonants and Vowels │ └── solutions │ │ └── solution.py ├── Challenge 0007 Easy │ └── challenge_text.md ├── Challenge 0059 Easy │ └── challenge_text.md ├── Challenge 0263 Easy - Calculating Shannon Entropy of a String │ └── solutions │ │ └── solution.c ├── Challenge 0047 Easy │ └── solutions │ │ └── solution.js ├── Challenge 0044 Easy │ └── solutions │ │ └── solution.js ├── Challenge 0079 Easy - Counting in steps │ └── solutions │ │ └── solution.c ├── Challenge 0032 Easy │ └── challenge_text.md ├── Challenge 0168 Easy - String Index │ └── solutions │ │ └── solution.py ├── Challenge 0108 Easy - Scientific Notation Translator │ └── challenge_text.md ├── Challenge 0063 Easy │ ├── solution │ │ └── solution.c │ └── challenge_text.md ├── Challenge 0158 Easy - The Torn Number │ ├── solutions │ │ └── solution.c │ └── challenge_text.md ├── Challenge 0072 Easy │ └── challenge_text.md ├── Challenge 0107 Easy - All possible decodings │ └── challenge_text.md ├── Challenge 0066 Easy │ └── challenge_text.md ├── Challenge 0324 Easy - manual square root procedure (intermediate) │ └── challenge_text.md ├── Challenge 0051 Easy │ └── challenge_text.md ├── Challenge 0100 Easy - Sleep Cycle Estimator │ └── challenge_text.md ├── Challenge 0276 Easy - Recktangles │ └── solutions │ │ └── solution.py ├── Challenge 0252 Easy - Sailors and monkeys and coconuts, oh my! │ └── solutions │ │ └── solution.js ├── Challenge 0093 Easy - Two-Way Morse Code Translator │ └── challenge_text.md ├── Challenge 0042 Easy │ └── challenge_text.md ├── Challenge 0057 Easy │ └── challenge_text.md ├── Challenge 0306 Easy - Pandigital Roman Numbers │ └── challenge_text.md ├── Challenge 0106 Easy - Random Talker, Part 1 │ └── challenge_text.md ├── Challenge 0267 Easy - All the places your dog didn't win │ └── solutions │ │ └── solution.py ├── Challenge 0049 Easy │ └── solutions │ │ └── solution.js ├── Challenge 0104 Easy - Powerplant Simulation │ └── challenge_text.md ├── Challenge 0089 Easy - Simple statistical functions │ └── challenge_text.md ├── Challenge 0086 Easy - Run-length encoding │ └── challenge_text.md ├── Challenge 0175 Easy - Bogo! │ └── solutions │ │ └── solution.c ├── Challenge 0193 Easy - A Cube, Ball, Cylinder, Cone walk into a warehouse │ └── challenge_text.md ├── Challenge 0092 Easy - Digital number display │ └── challenge_text.md ├── Challenge 0149 Easy - Disemvoweler │ └── solutions │ │ └── solution.c ├── Challenge 0109 Easy - Digits Check │ └── challenge_text.md ├── Challenge 0169 Easy - 90 Degree 2D Array Rotate │ └── challenge_text.md ├── Challenge 0323 Easy - 3SUM │ └── challenge_text.md ├── Challenge 0203 Easy - The Start of Something Big │ └── challenge_text.md ├── Challenge 0122 Easy - Words With Ordered Vowels │ └── challenge_text.md ├── Challenge 0321 Easy - Talking Clock │ └── challenge_text.md ├── Challenge 0114 Easy - Word ladder steps │ └── challenge_text.md ├── Challenge 0045 Easy │ └── solutions │ │ └── solution.js ├── Challenge 0275 Easy - Splurthian Chemistry 101 │ └── solutions │ │ └── solution.c └── Challenge 0058 Easy │ └── solutions │ └── solution.rs ├── Hard Challenges ├── Challenge 0006 Hard │ └── challenge_text.md ├── Challenge 0037 Hard │ └── challenge_text.md ├── Challenge 0055 Hard │ └── challenge_text.md ├── Challenge 0052 Hard │ └── challenge_text.md ├── Challenge 0017 Hard │ └── challenge_text.md ├── Challenge 0002 Hard │ └── challenge_text.md ├── Challenge 0104 Hard - (Stack Attack) │ └── challenge_text.md ├── Challenge 0228 Hard - Golomb Rulers │ └── challenge_text.md ├── Challenge 0240 Hard - KenKen Solver │ └── challenge_text.md ├── Challenge 0127 Hard - Language Detection │ └── challenge_text.md ├── Challenge 0010 Hard │ └── challenge_text.md ├── Challenge 0020 Hard │ └── challenge_text.md ├── Challenge 0239 Hard - An Encoding of Threes │ └── challenge_text.md ├── Challenge 0130 Hard - Coloring France's Departments │ └── challenge_text.md ├── Challenge 0012 Hard │ └── challenge_text.md ├── Challenge 0166b Hard - A Day in the Life of a Network Router │ └── challenge_text.md ├── Challenge 0013 Hard │ └── challenge_text.md ├── Challenge 0032 Hard │ └── challenge_text.md ├── Challenge 0207 Hard - Bioinformatics 3 - Predicting Protein Secondary Structures │ └── challenge_text.md ├── Challenge 0011 Hard │ └── challenge_text.md ├── Challenge 0014 Hard │ └── challenge_text.md ├── Challenge 0001 Hard │ └── challenge_text.md ├── Challenge 0005 Hard │ └── challenge_text.md ├── Challenge 0015 Hard │ └── challenge_text.md ├── Challenge 0009 Hard │ └── challenge_text.md ├── Challenge 0036 Hard │ └── challenge_text.md ├── Challenge 0046 Hard │ └── challenge_text.md ├── Challenge 0057 Hard │ └── challenge_text.md ├── Challenge 0068 Hard │ └── challenge_text.md ├── Challenge 0018 Hard │ └── challenge_text.md ├── Challenge 0088 Hard - (ASCII art) │ └── challenge_text.md ├── Challenge 0025 Hard │ └── challenge_text.md ├── Challenge 0074 Hard │ └── challenge_text.md ├── Challenge 0064 Hard │ └── challenge_text.md ├── Challenge 0066 Hard │ └── challenge_text.md ├── Challenge 0092 Hard - (Bags and balls) │ └── challenge_text.md ├── Challenge 0003 Hard │ ├── challenge_text.md │ ├── solutions │ │ └── solution.pl │ └── solution │ │ └── solution.py ├── Challenge 0114 Hard - Longest word ladder │ └── challenge_text.md ├── Challenge 0031 Hard │ └── challenge_text.md ├── Challenge 0038 Hard │ └── challenge_text.md ├── Challenge 0065 Hard │ └── challenge_text.md ├── Challenge 0028 Hard │ └── challenge_text.md ├── Challenge 0019 Hard │ └── challenge_text.md ├── Challenge 0093 Hard - (15-puzzle) │ └── challenge_text.md ├── Challenge 0197 Hard - Crazy Professor │ └── challenge_text.md ├── Challenge 0004 Hard │ └── challenge_text.md ├── Challenge 0044 Hard │ └── challenge_text.md ├── Challenge 0034 Hard │ └── challenge_text.md ├── Challenge 0047 Hard │ └── challenge_text.md ├── Challenge 0077 Hard - (Boggle solver) │ └── challenge_text.md ├── Challenge 0109 Hard - (Steiner Inellipse) │ └── challenge_text.md ├── Challenge 0101 Hard - (Boolean Minimization) │ └── challenge_text.md ├── Challenge 0111 Hard - The Josephus Problem │ └── challenge_text.md ├── Challenge 0262 Hard - 4x4 puzzle swapper │ └── challenge_text.md ├── Challenge 0081 Hard - (Matrix Exponential) │ └── challenge_text.md └── Challenge 0051 Hard │ └── challenge_text.md ├── Intermediate Challenges ├── .DS_Store ├── Challenge 0013 Intermediate │ ├── solutions │ │ ├── solution.cr │ │ ├── solution.rb │ │ └── solution.exs │ └── challenge_text.md ├── Challenge 0017 Intermediate │ └── challenge_text.md ├── Challenge 0011 Intermediate │ └── challenge.txt ├── Challenge 0039 Intermediate │ ├── challenge_text.md │ └── solutions │ │ └── solution.py ├── Challenge 0010 Intermediate │ └── challenge_text.md ├── Challenge 0066 Intermediate │ └── challenge_text.md ├── Challenge 0025 Intermediate │ └── challenge_text.md ├── Challenge 0200 Intermediate - Metro Tile Meltdown │ └── challenge_text.md ├── Challenge 0198 Intermediate - Base-Negative Numbers │ └── challenge_text.md ├── Challenge 0242 Intermediate - VHS recording problem │ └── challenge_text.md ├── Challenge 0005 Intermediate │ ├── challenge_text.md │ └── solutions │ │ └── solution.pl ├── Challenge 0012 Intermediate │ └── challenge_text.md ├── Challenge 0253 Intermediate - Countdown (numbers game) │ └── challenge_text.md ├── Challenge 0034 Intermediate │ └── challenge_text.md ├── Challenge 0247 Intermediate - Moving (diagonally) Up in Life │ └── challenge_text.md ├── Challenge 0004 Intermediate │ ├── challenge_text.md │ └── solutions │ │ └── solution.py ├── Challenge 0009 Intermediate │ └── challenge_text.md ├── Challenge 0014 Intermediate │ ├── challenge_text.md │ └── solutions │ │ └── solution.c ├── Challenge 0032 Intermediate │ └── challenge_text.md ├── Challenge 0008 Intermediate │ └── challenge_text.md ├── Challenge 0023 Intermediate │ └── solutions │ │ ├── solution.py │ │ └── solution.c ├── Challenge 0037 Intermediate │ └── challenge_text.md ├── Challenge 0202 Intermediate - Easter │ └── challenge_text.md ├── Challenge 0003 Intermediate │ └── challenge_text.md ├── Challenge 0028 Intermediate │ └── challenge_text.md ├── Challenge 0002 Intermediate │ └── challenge_text.md ├── Challenge 0015 Intermediate │ └── challenge_text.md ├── Challenge 0027 Intermediate │ └── challenge_text.md ├── Challenge 0086 Intermediate - (Weekday calculations) │ └── challenge_text.md ├── Challenge 0050 Intermediate │ └── challenge_text.md ├── Challenge 0019 Intermediate │ └── challenge_text.md ├── Challenge 0021 Intermediate │ └── challenge_text.md ├── Challenge 0047 Intermediate │ └── challenge_text.md ├── Challenge 0055 Intermediate │ └── challenge_text.md ├── Challenge 0016 Intermediate │ └── challenge_text.md ├── Challenge 0077 Intermediate - (Last digit of factorial) │ └── challenge_text.md ├── Challenge 0036 Intermediate │ └── challenge_text.md ├── Challenge 0062 Intermediate │ └── challenge_text.md ├── Challenge 0035 Intermediate │ └── challenge_text.md ├── Challenge 0060 Intermediate │ └── challenge_text.md ├── Challenge 0007 Intermediate │ └── challenge_text.md ├── Challenge 0096 Intermediate - (Parsing English Values) │ └── challenge_text.md ├── Challenge 0112 Intermediate - Sorting │ └── solutions │ │ └── solution.pl ├── Challenge 0108 Intermediate - (Minesweeper Generation) │ └── challenge_text.md ├── Challenge 0041 Intermediate │ └── challenge_text.md ├── Challenge 0053 Intermediate │ └── challenge_text.md ├── Challenge 0033 Intermediate │ └── challenge_text.md ├── Challenge 0061 Intermediate │ └── challenge_text.md ├── Challenge 0310 Intermediate - Simplifying square roots │ └── challenge_text.md ├── Challenge 0105 Intermediate - Boolean logic calculator │ └── challenge_text.md ├── Challenge 0070 Intermediate │ └── challenge_text.md ├── Challenge 0067 Intermediate │ └── challenge_text.md ├── Challenge 0312 Intermediate - Next largest number │ └── challenge_text.md ├── Challenge 0046 Intermediate │ └── solutions │ │ └── solution.py ├── Challenge 0059 Intermediate │ └── challenge_text.md ├── Challenge 0298 Intermediate - Too many or too few Parentheses │ └── challenge_text.md ├── Challenge 0100 Intermediate - (Bad Word Filter) │ └── challenge_text.md ├── Challenge 0058 Intermediate │ └── challenge_text.md ├── Challenge 0322 Intermediate - Largest Palindrome │ └── challenge_text.md ├── Challenge 0081 Intermediate - (Local Minimization) │ └── challenge_text.md ├── Challenge 0114 Intermediate - Shortest word ladder │ └── challenge_text.md ├── Challenge 0006 Intermediate │ └── challenge_text.md ├── Challenge 0038 Intermediate │ └── challenge_text.md ├── Challenge 0104 Intermediate - (Bracket Racket) │ └── challenge_text.md └── Challenge 0139 Intermediate - Telephone Keypads │ └── solutions │ └── solution.py └── Extra-Bonus Challenges ├── [Monthly Challenge #22 - September, 2017] Procedural Bacteria Fungus Virus • rproceduralgeneration └── challenge_text.md ├── [PSA] [Monthly Challenge #11 - October, 2016] - Procedural Ghosts and Jack-o-Lanterns! • rproceduralgeneration └── challenge_text.md ├── [Weekly] #1 -- Handling Console Input └── challenge_text.md └── Weekly #26 - Mini Challenges └── challenge_text.md /.gitignore: -------------------------------------------------------------------------------- 1 | dpc.log 2 | *.swp 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /etc/requirements.txt: -------------------------------------------------------------------------------- 1 | praw>=5.1.0 2 | pprint>=0.1 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0005 Easy/solutions/access.txt: -------------------------------------------------------------------------------- 1 | daniel 2 | qwerty 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0037 Easy/solutions/solution.rb: -------------------------------------------------------------------------------- 1 | puts File.readlines(ARGV[0]).length 2 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0015 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program to left or right justify a text file -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0020 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a program that will find all prime numbers below 2000 2 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0040 Easy/solutions/solution.exs: -------------------------------------------------------------------------------- 1 | # Not very sporting, but... 2 | Enum.each(1..1000, &IO.puts/1) 3 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0006 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | create an AI that will play [NIM](http://en.wikipedia.org/wiki/Nim) 2 | -------------------------------------------------------------------------------- /Intermediate Challenges/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/.DS_Store -------------------------------------------------------------------------------- /Extra-Bonus Challenges/[Monthly Challenge #22 - September, 2017] Procedural Bacteria Fungus Virus • rproceduralgeneration/challenge_text.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0021 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Input: a number 2 | 3 | Output : the next higher number that uses the same set of digits. 4 | -------------------------------------------------------------------------------- /Extra-Bonus Challenges/[PSA] [Monthly Challenge #11 - October, 2016] - Procedural Ghosts and Jack-o-Lanterns! • rproceduralgeneration/challenge_text.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0040 Easy/solutions/solution.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -- 2 | 3 | use v5.18; 4 | use warnings; 5 | 6 | $, = "\n"; 7 | say 1..1000; 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0040 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | // tlseabra @github 2 | 3 | Array.apply(null, { length: 1000 }).map((_, i) => console.log(i+1)); 4 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0013 Intermediate/solutions/solution.cr: -------------------------------------------------------------------------------- 1 | user_input = STDIN.gets || "" 2 | File.write("output.txt", user_input.chomp.reverse) 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0038 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Implement [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra's_algorithm) in any way you can :) 2 | 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0016 Easy/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0016 Easy/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0039 Easy/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0040 Easy/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0040 Easy/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0037 Hard/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0037 Hard/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0055 Hard/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0055 Hard/challenge_text.md -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0013 Intermediate/solutions/solution.rb: -------------------------------------------------------------------------------- 1 | print 'Your string: ' 2 | File.open('output.txt', 'w') do |f| 3 | f.print gets.reverse 4 | end 5 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0017 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | build an application that will search a web page for instances of sentences in quotations: "like this". 2 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0052 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your task is to write functions that encrypt and decrypt using the [solitaire cipher](http://www.schneier.com/solitaire.html). 2 | 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0006 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | You're challenge for today is to create a program that can calculate pi accurately to at least 30 decimal places. 2 | 3 | Try not to cheat :) -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0062 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Give the [Ullman's Puzzle](http://regator.com/p/246306389/ullmans_puzzle/) 2 | 3 | Write a function that makes that determination 4 | 5 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0017 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | build a tic tac toe game with opponent AI 2 | 3 | bonus points for cooler AI implementations (depth/breadth first search, neural network, etc) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0011 Intermediate/challenge.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0011 Intermediate/challenge.txt -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0013 Intermediate/solutions/solution.exs: -------------------------------------------------------------------------------- 1 | reversed_input = IO.gets("Your string: ") |> String.rstrip |> String.reverse 2 | File.write("output.txt", reversed_input) 3 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0046 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | function bitstringCount(n){ 4 | return n.toString(2).split("").reduce((a,b) => parseInt(a)+parseInt(b)); 5 | } 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0147 Easy - Sport Points/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def valid_score(score): 4 | print(('Va' if score not in [1, 2, 4, 5] else 'Inva') + 'lid Score') 5 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0212 Easy - Rövarspråket/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0212 Easy - Rövarspråket/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0002 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your mission is to create a stopwatch program. this program should have start, stop, and lap options, and it should write out to a file to be viewed later. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0039 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Today's challenge is to determine if a number is a [Kaprekar Number](http://mathworld.wolfram.com/KaprekarNumber.html) 2 | 3 | Enjoy :) -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0088 Easy - Vigenère cipher/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0088 Easy - Vigenère cipher/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0112 Easy - Get that URL!/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0112 Easy - Get that URL!/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0213 Easy - Pronouncing Hex/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0213 Easy - Pronouncing Hex/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0104 Hard - (Stack Attack)/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0104 Hard - (Stack Attack)/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0228 Hard - Golomb Rulers/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0228 Hard - Golomb Rulers/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0240 Hard - KenKen Solver/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0240 Hard - KenKen Solver/challenge_text.md -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0010 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0010 Intermediate/challenge_text.md -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0013 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Create a program that will take any string and write it out to a text file, reversed. 2 | 3 | input: "hello!" 4 | 5 | output: "!olleh" -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0066 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0066 Intermediate/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0208 Easy - Culling Numbers/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | function cull(input){ 4 | return input.split(' ').filter((a, i, b) => b.indexOf(a) == i).join(' '); 5 | } 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0235 Easy - Ruth-Aaron Pairs/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0235 Easy - Ruth-Aaron Pairs/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0008 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | write a program that will print the song "99 bottles of beer on the wall". 2 | 3 | for extra credit, do not allow the program to print each loop on a new line. 4 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0127 Hard - Language Detection/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0127 Hard - Language Detection/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0009 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | write a program that will allow the user to input digits, and arrange them in numerical order. 2 | 3 | for extra credit, have it also arrange strings in alphabetical order -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0204 Easy - Remembering your lines/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Easy Challenges/Challenge 0204 Easy - Remembering your lines/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0010 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your task is to implement the interactive game of [hangman](http://en.wikipedia.org/wiki/Hangman_\(game\)) 2 | 3 | bonus point for making the game unique. be more creative! -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0020 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a program that will remind you to stop procrastinating every two hours with a pop up message! :) 2 | 3 | This program has the potential of helping many people :D -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0239 Hard - An Encoding of Threes/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0239 Hard - An Encoding of Threes/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0013 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Find the number of the year for the given date. For example, january 1st would be 1, and december 31st is 365. 2 | 3 | 4 | for extra credit, allow it to calculate leap years, as well. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0022 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function append(a, b){ 4 | for(var i=0; i < b.length; i++) 5 | if( a.indexOf(b[i]) === -1) a.push(b[i]); 6 | 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0055 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program to solve the sliding window minimum problem using any of the methods possible. [This](http://home.tiac.net/~cri/2001/slidingmin.html) could be a helpful link. 2 | 3 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0130 Hard - Coloring France's Departments/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0130 Hard - Coloring France's Departments/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0034 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function addLargestSquares(a, b, c){ 4 | arr = [a, b, c].sort(function(a, b){return b-a}); 5 | return arr[0]*arr[0] + arr[1]*arr[1]; 6 | } 7 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0037 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | write a program that takes 2 | 3 | input : a file as an argument 4 | 5 | output: counts the total number of lines. 6 | 7 | for bonus, also count the number of words in the file. 8 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0025 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program to do the following: 2 | 3 | input: a base ten (non-fractional) number at the command line 4 | 5 | output: the binary representation of that number. 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0011 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | The program should take three arguments. The first will be a day, the second will be month, and the third will be year. Then, your program should compute the day of the week that date will fall on. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0200 Intermediate - Metro Tile Meltdown/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0200 Intermediate - Metro Tile Meltdown/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function fizzBuzz(n){ 4 | for(var i=1; i <= n; i++) 5 | console.log( !(i%3) && !(i%5) ? "FizzBuzz" : !(i%3) ? "Fizz" : !(i%5) ? "Buzz" : i); 6 | } 7 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0198 Intermediate - Base-Negative Numbers/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0198 Intermediate - Base-Negative Numbers/challenge_text.md -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0242 Intermediate - VHS recording problem/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0242 Intermediate - VHS recording problem/challenge_text.md -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0012 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program which will take string inputs "A", "B", "C", "D", "E", "F", and "G", and make the corresponding notes, in any method of your choosing. 2 | 3 | Thanks to electric_machinery for this challenge! -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0166b Hard - A Day in the Life of a Network Router/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0166b Hard - A Day in the Life of a Network Router/challenge_text.md -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0005 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your challenge today is to write a program that can find the amount of anagrams within a .txt file. For example, "snap" would be an anagram of "pans", and "skate" would be an anagram of "stake". -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0012 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Create a program that will factor a number. for example: 2 | 3 | 12 = 2 * 2 * 3 4 | 5 | 14 = 7 * 2 6 | 7 | 20 = 2 * 2 * 5 8 | 9 | thanks to bears_in_bowlers for todays challenge! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0253 Intermediate - Countdown (numbers game)/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0253 Intermediate - Countdown (numbers game)/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0022 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will compare two lists, and append any elements in the second list that doesn't exist in the first. 2 | input: ["a","b","c",1,4,], ["a", "x", 34, "4"] 3 | output: ["a", "b", "c",1,4,"x",34, "4"] -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0034 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your task today is show the implementation of two sorting algorithms [Stooge sort](http://en.wikipedia.org/wiki/Stooge_sort) and [Bogosort](http://en.wikipedia.org/wiki/Bogosort) in anyway you like! 2 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0037 Easy/solutions/solution.exs: -------------------------------------------------------------------------------- 1 | input = System.argv |> File.read! |> String.codepoints 2 | lines = Enum.count(input, &(&1 == "\n")) 3 | words = Enum.count(input, &(&1 == " ")) + lines 4 | IO.puts("#{lines} lines.") 5 | IO.puts("#{words} words.") 6 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0247 Intermediate - Moving (diagonally) Up in Life/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Intermediate Challenges/Challenge 0247 Intermediate - Moving (diagonally) Up in Life/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0016 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function strClear(input, clear){ 4 | for(var i=0; i < clear.length; i++) 5 | input = input.replace( new RegExp(clear.charAt(i), "g"), ""); 6 | 7 | return input; 8 | } 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0028 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | #Solution by https://github.com/Ouss4 2 | 3 | max_interval = 10 4 | numbers_array = [1,2,2,3,4,5,6,7,8,9,10] 5 | print("Number {} is twice in the array".format(sum(numbers_array) - (max_interval*(max_interval + 1) ) / 2)) 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0286 Easy - Reverse Factorial/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def reverse_factorial(n, f=2): 4 | if n == 1: 5 | return str(f-1) + "!" 6 | elif n%f != 0: 7 | return "NONE" 8 | return reverse_factorial(n/f, f+1) 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0003 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Welcome to cipher day! 2 | 3 | write a program that can encrypt texts with an alphabetical caesar cipher. This cipher can ignore numbers, symbols, and whitespace. 4 | 5 | for extra credit, add a "decrypt" function to your program! -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0013 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Create a rock-paper-scissors program, however, there should be no user input. the computer should play against itself. Make the program keep score, and for extra credit, give the option to "weigh" the chances, so one AI will one more often. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0032 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | A quine is a computer program which takes no input and produces a copy of its own source code as its only output which, in turn, compiles and print out itself 2 | 3 | [Hint](http://en.wikipedia.org/wiki/Quine_(computing)) 4 | 5 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0039 Intermediate/solutions/solution.py: -------------------------------------------------------------------------------- 1 | #Solution by https://github.com/Ouss4 2 | 3 | x = int(input("Enter a number : ")) 4 | 5 | print("{} is a {} Kaprekar number".format(x, "" if (x == (x*x // 10**len(str(x))) + (x*x % 10**len(str(x)))) else "not" )) 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0008 Easy/solutions/solution2.py: -------------------------------------------------------------------------------- 1 | song_lines = ['{0} bottles of beer on the wall, {1} bottles of beer, you take one down and pass it around,{2} bottles of beer on the wall!'.format(i,i, i-1) for i in reversed(range(0,100))] 2 | print ','.join(str(i) for i in song_lines) 3 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0207 Hard - Bioinformatics 3 - Predicting Protein Secondary Structures/challenge_text.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/freddiev4/dailyprogrammerchallenges/HEAD/Hard Challenges/Challenge 0207 Hard - Bioinformatics 3 - Predicting Protein Secondary Structures/challenge_text.md -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0014 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function blockReverse(input, k){ 4 | var i, output=[]; 5 | 6 | for(i=0; i < input.length; i += k) 7 | output.push(input.slice(i, i + k).reverse()); 8 | 9 | return output; 10 | } 11 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.rb: -------------------------------------------------------------------------------- 1 | def fizzbuzz(n) 2 | if n % 15 == 0 3 | 'FizzBuzz' 4 | elsif n % 5 == 0 5 | 'Buzz' 6 | elsif n % 3 == 0 7 | 'Fizz' 8 | else 9 | n.to_s 10 | end 11 | end 12 | 13 | (1..ARGV[0].to_i).each { |n| puts fizzbuzz(n) } 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0068 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | [Emirp](http://mathworld.wolfram.com/Emirp.html) is an interesting concept. The explanation about it is provided in the link i just gave. 2 | 3 | Your task is to implement a function which prints out the emirps below a number(input) given by the user. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0011 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Create a program which prints out a table with the month's calendar in it, when the month and year is given as input. 2 | 3 | Extra points for highlighting the current day and providing links to next and previous months. 4 | 5 | Happy coding :) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0004 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a calculator program that will take an input, following normal calculator input (5*5+4) and give an answer (29). This calculator should use all four operators. 2 | 3 | For extra credit, add other operators (6(4+3), 3 ** 3, etc.) -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0034 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | A very basic challenge: 2 | 3 | In this challenge, the 4 | 5 | input is are : 3 numbers as arguments 6 | 7 | output: the sum of the squares of the two larger numbers. 8 | 9 | 10 | Your task is to write the indicated challenge. 11 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0122 Easy - Sum Them Digits/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | function sumDemDigitz(input){ 3 | if(input.toString().length === 1) 4 | return input; 5 | else 6 | return sumDemDigitz(input.toString().split('').reduce((a, b) => a + parseInt(b), 0)); 7 | } 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0023 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function breakInHalf(input){ 4 | var top = [], length = input.length; 5 | 6 | for(var i=0; i < Math.floor(length/2); i++){ 7 | top.push(input.shift()); 8 | } 9 | 10 | return [top, input]; 11 | } 12 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0009 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will take a string ("I LIEK CHOCOLATE MILK"), and allow the user to scan a text file for strings that match. after this, allow them to replaces all instances of the string with another ("I quite enjoy chocolate milk. hrmmm. yes.") -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0004 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | You're challenge for today is to create a random password generator! 2 | 3 | For extra credit, allow the user to specify the amount of passwords to generate. 4 | 5 | For even more extra credit, allow the user to specify the length of the strings he wants to generate! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0023 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Input: a list 2 | 3 | Output: Return the two halves as different lists. 4 | 5 | If the input list has an odd number, the middle item can go to any of the list. 6 | 7 | Your task is to write the function that splits a list in two halves. 8 | 9 | 10 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0014 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your task is to implement the [sieve of Sundaram](http://en.wikipedia.org/wiki/Sieve_of_Sundaram) and calculate the list of primes to 10000. 2 | 3 | [this](http://plus.maths.org/content/sundarams-sieve) is also an interesting article about it. 4 | 5 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0032 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | [Tower of Hanoi](http://en.wikipedia.org/wiki/Tower_of_Hanoi) is a famous problem. 2 | 3 | the challenge today is a very famous one where you are to write a function to calculate the total number of moves to solve the tower in fastest way possible 4 | 5 | -------------------------------------------------------------------------------- /etc/praw.ini.example: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | client_id=CHANGE ME 3 | client_secret=CHANGE ME 4 | password=CHANGE ME 5 | username=CHANGE ME 6 | 7 | # The URL prefix for OAuth-related requests. 8 | oauth_url=https://oauth.reddit.com 9 | 10 | # The URL prefix for regular requests. 11 | reddit_url=https://www.reddit.com 12 | 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0027 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | #Solution by https://github.com/Ouss4 2 | 3 | from math import ceil 4 | 5 | year = int(input("Enter year: ")) 6 | 7 | print("Centry : {}".format(ceil(year/100))) 8 | print("Leap Year: {}".format("Yes" if (year % 400 == 0 or (year % 4 == 0 and year % 100 != 0)) else "No")) 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0053 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that given two sorted lists, returns a list whith the two lists merged together into one sorted list. 2 | 3 | So, for instance, for inputs [1,5,7,8] and [2,3,4,7,9] it should return [1,2,3,4,5,7,7,8,9]. 4 | 5 | Try and make your code as efficient as possible. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0005 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your challenge for today is to create a program which is password protected, and wont open unless the correct user and password is given. 2 | 3 | For extra credit, have the user and password in a seperate .txt file. 4 | 5 | for even more extra credit, break into your own program :) -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0004 Easy/solutions/solution1.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def passgen(num, len): 4 | for x in range(num): 5 | print('Password ',x+1,' : ',random.randrange(1000,10**len)) 6 | 7 | n=int(input('How many pass do you want to generate? ')) 8 | l=int(input('What should be the length of the password')) 9 | passgen(n, l) -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0012 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a small program that can take a string: 2 | 3 | "hi!" 4 | 5 | and print all the possible permutations of the string: 6 | 7 | "hi!" 8 | 9 | "ih!" 10 | 11 | "!hi" 12 | 13 | "h!i" 14 | 15 | "i!h" 16 | 17 | etc... 18 | 19 | thanks to hewts for this challenge! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0008 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will print the english name of a value. for example, "1211" would become "one-thousand, two hundred, eleven". 2 | 3 | for extra credit, allow it to read the english value of a number and output the integer. 4 | 5 | input: one-hundred, four 6 | output: 104 -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0013 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function dayOfYear(day, month){ 4 | var numberDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], 5 | count = 0; 6 | 7 | for(var i=0; i < month - 1; i++) 8 | count += numberDays[i]; 9 | 10 | return count + day; 11 | } 12 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0025 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | In an election, the person with the majority of the votes is the winner. Sometimes due to similar number of votes, there are no winners. 2 | 3 | Your challenge is to write a program that determines the winner of a vote, or shows that there are no winners due to a lack of majority. 4 | 5 | 6 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0023 Intermediate/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def not_McNugget(n): 4 | mcn = lambda x: x != 3 and (x > 43 or x % 3 == 0) 5 | for i in range(1, n+1): 6 | d = i 7 | while i >= 0: 8 | if mcn(i): break 9 | i -= 20 10 | else: print(d) 11 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.m: -------------------------------------------------------------------------------- 1 | %Author: Evilk9 (github.com/evilk9) 2 | name = input('What is your name? ', 's'); 3 | age = input('What is your age? '); 4 | username = input('What is your Reddit Username? ', 's'); 5 | 6 | fprintf('Your name is %s, you are %d years old, and your username is %s', name, age, username); 7 | 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0031 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that takes two base-26 numbers in which digits are represented by letters with A=0, B=1, … Z=25 and returns their product using the same notation. As an example, CSGHJ × CBA = FNEUZJA. 2 | Your task is to write the base-26 multiplication function. 3 | Try to be very efficient in your code! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0041 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | // tlseabra @github 2 | 3 | var input = prompt("Please enter a sentence:"); 4 | 5 | for(var line ="*", pad="*", i=0; i < input.length+2; i++){ 6 | line+="*"; 7 | pad+=" "; 8 | } 9 | line+="*\n"; 10 | pad+="*\n"; 11 | 12 | console.log(line + pad + "* " + input + " *\n" + pad + line); 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0046 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | The population count of a bitstring is the number of set bits (1-bits) in the string. For instance, the population count of the number 23, which is represented in binary as 10111 is 4. 2 | 3 | Your task is to write a function that determines the population count of a number representing a bitstring 4 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0029 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | function palindrome(str) { 2 | var lowerCaseStr = str.replace(/[\W_]/g, '').toLowerCase(); 3 | str = lowerCaseStr.split('').reverse().join(''); 4 | 5 | if (str == lowerCaseStr) { 6 | return true; 7 | } else { 8 | return false; 9 | } 10 | } 11 | 12 | palindrome("race car"); 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.exs: -------------------------------------------------------------------------------- 1 | fizzbuzz = fn n -> 2 | case {rem(n, 3), rem(n, 5)} do 3 | {0, 0} -> "FizzBuzz" 4 | {0, _} -> "Fizz" 5 | {_, 0} -> "Buzz" 6 | {_, _} -> "#{n}" 7 | end 8 | end 9 | 10 | with n <- String.to_integer(hd System.argv) do 11 | Enum.each(1..n, &(IO.puts fizzbuzz.(&1))) 12 | end 13 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0014 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will generate a random array/collection of 1 million integers, then sort them using a multi-threaded algorithm. 2 | 3 | Your program should take the number of threads through standard input. 4 | 5 | Bonus points if you can find the most efficient number of threads for your program. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0037 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Enter an integer for the number of iterations, and create a program that prints out a sierpinski triangle. 2 | 3 | [ First 4 iterations as an example](http://i.imgur.com/fjlTg.png) 4 | 5 | * Thanks to Rinfiyks for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format: 2 | 3 | your name is (blank), you are (blank) years old, and your username is (blank) 4 | 5 | for extra credit, have the program log this information in a file to be accessed later. 6 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0202 Intermediate - Easter/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description: 2 | 3 | Given the year - Write a program to figure out the exact date of Easter for that year. 4 | 5 | #Input: 6 | 7 | A year. 8 | 9 | #Output: 10 | 11 | The date of easter for that year. 12 | 13 | #Challenge: 14 | 15 | Figure out easter for 2015 to 2025. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0010 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function isNumberValid(input){ 4 | var re = /\d{10}|\d{3}\.\d{3}\.\d{4}|\d{3}\-\d{3}\-\d{4}|\(\d{3}\) ?\d{3}\-\d{4}/; 5 | return re.test(input) ? true : false; 6 | } 7 | 8 | isNumberValid(prompt("Please insert a Phone Number:")) ? alert("Valid!") : alert("Not Valid!"); 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0026 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function removeDuplicates(input){ 4 | var output = []; 5 | input = input.split(""); 6 | 7 | for(var i=1; i < input.length; i++) 8 | if(input[i] === input[i-1]) output.push(input.splice(i--, 1)); 9 | 10 | return [input.join(""), output.join("")]; 11 | } 12 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0048 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Take an array of integers and partition it so that all the even integers in the array precede all the odd integers in the array. Your solution must take linear time in the size of the array and operate in-place with only a constant amount of extra space. 2 | 3 | 4 | Your task is to write the indicated function. 5 | 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0005 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | var correctUser = "daniel", 4 | correctPass = "qwerty"; 5 | 6 | var user = prompt("Username:"); 7 | var password = prompt("Password:"); 8 | 9 | (user === correctUser && password === correctPass) ? alert("Welcome to this useless program!") : alert("Access Denied!"); 10 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0030 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function targetSum(list, target){ 4 | var i,j; 5 | for(i = 0; i < list.length - 1; i++){ 6 | for(j = i+1; j < list.length; j++){ 7 | if(list[i] + list[j] == target) 8 | return [list[i], list[j]]; 9 | } 10 | } 11 | 12 | return null; 13 | } 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def fizz_buzz(n): 4 | for i in range(1, n+1): 5 | if i % 3 == 0 and i % 5 == 0: 6 | print("FizzBuzz") 7 | elif i % 3 == 0: 8 | print("Fizz") 9 | elif i % 5 == 0: 10 | print("Buzz") 11 | else: 12 | print(i) 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0060 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | A polite number n is an integer that is the sum of two or more consecutive nonnegative integers in at least one way. 2 | 3 | [Here](http://en.wikipedia.org/wiki/Polite_number) is an article helping in understanding Polite numbers 4 | 5 | Your challenge is to write a function to determine the ways if a number is polite or not. 6 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0001 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | we all know the classic "guessing game" with higher or lower prompts. lets do a role reversal; you create a program that will guess numbers between 1-100, and respond appropriately based on whether users say that the number is too high or too low. Try to make a program that can guess your number based on user input and great code! 2 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0005 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Arrr, me mateys! Yer' challenge fer' today be a tough one. It be gettin awfully borein' on the high seas, so yer' job be to create a pirate based fightin' game! This game oughter' be turn based, and you oughter' be able to pick yer attacks every turn. The best game'll be winnin' some custom flair, and all the rest o' ya will be walkin the plank! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0014 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Input: list of elements and a block size k or some other variable of your choice 2 | 3 | Output: return the list of elements with every block of k elements reversed, starting from the beginning of the list. 4 | 5 | For instance, given the list 12, 24, 32, 44, 55, 66 and the block size 2, the result is 24, 12, 44, 32, 66, 55. 6 | 7 | 8 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0004 Intermediate/solutions/solution.py: -------------------------------------------------------------------------------- 1 | def operation(): 2 | op = raw_input('> ') 3 | return op 4 | 5 | def calc(op): 6 | print '>', eval(op) 7 | 8 | def main(): 9 | try: 10 | print "Operators: +, -, *, /, **" 11 | calc(operation()) 12 | except NameError: 13 | print "Numbers and Operators, please." 14 | calc(operation()) 15 | 16 | main() 17 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0040 Easy/solutions/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static int top = 1000; 4 | 5 | int print_numbers(void); 6 | 7 | int main(int argc, char **argv){ 8 | print_numbers(); 9 | 10 | return 0; 11 | } 12 | 13 | int print_numbers(void){ 14 | static int i = 0; 15 | i++; 16 | printf("%d\n", i); 17 | return (i - top) && print_numbers(); 18 | } 19 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0015 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a pair of programs that communicate with one another through socket connections. AKA a client-server connection. 2 | 3 | Your server should be an echo server that simply echoes any information it receives back to the client. 4 | 5 | For bonus points, your server should take a special command that will echo the subsequent information in reverse. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0003 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Welcome to cipher day! 2 | 3 | Create a program that can take a piece of text and encrypt it with an alphabetical substitution cipher. This can ignore white space, numbers, and symbols. 4 | 5 | 6 | for extra credit, make it encrypt whitespace, numbers, and symbols! 7 | 8 | 9 | for extra extra credit, decode someone elses cipher! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | function main() { 2 | var name = prompt("Hi, what is your name?"); 3 | var age = prompt("Nice to meet you " + name + ", how old are you?"); 4 | var username = prompt("Cool, what is your Reddit username?"); 5 | 6 | alert("Your name is " + name + ", you are " + age + " years old, and your username is " + username + "."); 7 | } 8 | 9 | main(); 10 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0009 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | The U.S government has commissioned you to catch the terrorists! 2 | 3 | There is a mathematical pyramid with the following pattern: 4 | 5 | 1 6 | 7 | 11 8 | 9 | 21 10 | 11 | 1211 12 | 13 | 111221 14 | 15 | 312211 16 | 17 | you must write a program to calculate up to the 40th line of this pyramid. If you don't, the terrorists win! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0035 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function rightTriangle(input){ 4 | var sum = 0, str = []; 5 | for(var i = 1; sum + i <= input; i++){ 6 | str[i-1] = ""; 7 | for(var j = 0; j < i; j++) 8 | str[i-1] += (sum + j + 1) + " "; 9 | sum += i; 10 | } 11 | for(i = str.length - 1; i >= 0; i--) 12 | console.log(str[i]); 13 | } 14 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0028 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | A [tetrahedral number](http://en.wikipedia.org/wiki/Tetrahedral_number) is is a figurate number that represents a pyramid with a triangular base and three sides. 2 | 3 | Write a program to find the base of the tetrahedron that contains an input number of balls. 4 | 5 | example: 169179692512835000 balls 6 | 7 | * taken from programmingpraxis.com -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0017 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | write an application which will print a triangle of stars of user-specified height, with each line having twice as many stars as the last. 2 | sample output: 3 | 4 | @ 5 | 6 | @@ 7 | 8 | @@@@ 9 | 10 | 11 | hint: in many languages, the "+" sign concatenates strings. 12 | 13 | bonus features: print the triangle in reverse, print the triangle right justified -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.R: -------------------------------------------------------------------------------- 1 | # tlseabra @github 2 | 3 | fizzbuzz <- function(n){ 4 | for(i in 1:n){ 5 | a <- if(i%%3 == 0 && i%%5 == 0){ 6 | "FizzBuzz" 7 | } else if(i%%3 == 0){ 8 | "Fizz" 9 | } else if(i%%5 == 0){ 10 | "Buzz" 11 | } else{ 12 | i 13 | } 14 | print(a, quote = FALSE) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0197 Easy - ISBN Validator/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* tlseabra@github */ 2 | 3 | function ISBNvalidator(input){ 4 | return input.replace(/-/g,'').split('').reduce((a, b, i) => b == "X" ? 5 | a + 10 : 6 | a + (10-i)*parseInt(b, 10), 0) 7 | % 11 == 0; 8 | } 9 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0002 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a short text adventure that will call the user by their name. The text adventure should use standard text adventure commands ("l, n, s, e, i, etc."). 2 | 3 | for extra credit, make sure the program doesn't fault, quit, glitch, fail, or loop no matter what is put in, even empty text or spaces. These will be tested rigorously! 4 | 5 | For super extra credit, code it in C -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0028 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | The array duplicates problem is when one integer is in an array for more than once. 2 | 3 | If you are given an array with integers between 1 and 1,000,000 or in some other interval and one integer is in the array twice. How can you determine which one? 4 | 5 | 6 | Your task is to write code to solve the challenge. 7 | 8 | Note: try to find the most efficient way to solve this challenge. 9 | -------------------------------------------------------------------------------- /Easy Challenges/[Easy] Longest Two-Character Sub-String/solutions/solution.rb: -------------------------------------------------------------------------------- 1 | puts 'Enter input string:' 2 | input = gets.chomp 3 | 4 | puts "Longest 2-unique-character substring is:" 5 | puts input 6 | .to_enum(:scan, /(.)\1*(.)(\1|\2)*/) # Find all 2-char substrings 7 | .map { Regexp.last_match[0] } # Convert MatchData object to matched string 8 | .reverse # Use the right-most result 9 | .max_by(&:length) # Select the longest result 10 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0036 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Let's play Lingo! Click [here](http://www.youtube.com/watch?feature=player_detailpage&v=HzWh_G0DiGw#t=113s) for an idea of how the game works. Now write a program that reads a random 5-letter word from a dictionary file and plays the game Lingo. If you're doing a text-based version, you can surround the correct letters at the correct location with [] and correct letters at the wrong location with (). -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0025 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function revealWinner(input){ 4 | var sum = input.reduce( (a,b) => a + b, 0 ); 5 | 6 | for(var i=0; i < input.length; i++){ 7 | if(input[i] >= Math.ceil(sum/2)){ 8 | console.log("The winner is candidate " + String.fromCharCode(65 + i) + "!"); 9 | return; 10 | } 11 | } 12 | 13 | console.log("There is no winner!"); 14 | } 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0030 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that takes a list of integers and a target number and determines if any two integers in the list sum to the target number. If so, return the two numbers. If not, return an indication that no such integers exist. 2 | 3 | ______________________________________________________________________________________________ 4 | Edit : Note the "Intermediate" challenge #30 has been changed. Thank you! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0255 Easy - Playing with light switches/solutions/solution.R: -------------------------------------------------------------------------------- 1 | #tlseabra @github 2 | 3 | countBulbs <- function(input){ 4 | input <- as.numeric(unlist(strsplit(input, "[ \n]"))) 5 | bulbs <- array(FALSE, input[1]) 6 | for (i in seq(2,length(input),2)){ 7 | a <- seq(min(input[i], input[i+1]), max(input[i], input[i+1])) + 1 8 | bulbs[a] <- !bulbs[a] 9 | } 10 | sum(bulbs, na.rm = TRUE) 11 | } 12 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0033 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function checkAnswers(questions, answers){ 4 | var i, size = questions.length, input; 5 | 6 | do{ 7 | i = Math.floor(Math.random() * size); 8 | input = prompt(questions[i]); 9 | if(input.toLowerCase() !== answers[i] && input !== "exit") 10 | alert("The right answer is: " + answers[i]); 11 | } 12 | while(input !== "exit") 13 | } 14 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0046 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | The prime HP reached starting from a number , concatenating its prime factors, and repeating until a prime is reached. If you have doubts, refer the article [here](http://mathworld.wolfram.com/HomePrime.html) 2 | 3 | write a function to calculate the HP of a given number. 4 | 5 | Also write a function to compute the [Euclid-Mullin sequence](http://mathworld.wolfram.com/Euclid-MullinSequence.html). 6 | 7 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.tcl: -------------------------------------------------------------------------------- 1 | puts "What's your name? " 2 | set name [gets stdin] 3 | puts "What's your age in years? " 4 | set age [gets stdin] 5 | puts "What's your username? " 6 | set username [gets stdin] 7 | set string "Your name is $name, you are $age years old and your username is $username." 8 | puts $string 9 | 10 | #Now put it in a file 11 | set file [open "result.txt" "w"] 12 | puts $file $string 13 | close $file 14 | 15 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0057 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Lets play some games shall we! .. for many of the next challenges i will be giving old classic games to be programmed. 2 | 3 | Today your task is to implement [Hamurabi](http://atariarchives.org/basicgames/showpage.php?page=78). the link gives data required in implementing. Enjoy! :) 4 | 5 | ________________________ 6 | 7 | Edit: [Here](http://pastebin.com/LvsZHGTd) is the basic code for making things easier. 8 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0015 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | A 30x30 grid of squares contains 900 fleas, initially one flea per square. 2 | When a bell is rung, each flea jumps to an adjacent square at random (usually 4 possibilities, except for fleas on the edge of the grid or at the corners). 3 | 4 | 5 | What is the expected number of unoccupied squares after 50 rings of the bell? Give your answer rounded to six decimal places. 6 | 7 | source: project euler -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0018 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Often times in commercials, phone numbers contain letters so that they're easy to remember (e.g. 1-800-VERIZON). Write a program that will convert a phone number that contains letters into a phone number with only numbers and the appropriate dash. Click [here](http://en.wikipedia.org/wiki/Telephone_keypad) to learn more about the telephone keypad. 2 | 3 | Example Execution: 4 | Input: 1-800-COMCAST 5 | Output: 1-800-266-2278 -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0019 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Challenge #19 will use [The Adventures of Sherlock Holmes](http://www.gutenberg.org/cache/epub/1661/pg1661.txt) from [Project Gutenberg](http://www.gutenberg.org). 2 | 3 | Write a program that counts the number of alphanumeric characters there are in The Adventures of Sherlock Holmes. Exclude the Project Gutenberg header and footer, book title, story titles, and chapters. Post your code and the alphanumeric character count. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0027 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function isLeapYear(input){ 4 | return (input % 4 != 0 || (input % 100 == 0 && input % 400 != 0)) ? false : true; 5 | } 6 | 7 | function century(input){ 8 | return Math.floor((input - 1)/100) + 1; 9 | } 10 | 11 | var year = prompt("Please input a year"); 12 | console.log("Year: " + year + "\nCentury: " + century(year) + "\nLeap Year: " + ((isLeapYear(year)) ? "Yes" : "No")); 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0004 Easy/solutions/solution.m: -------------------------------------------------------------------------------- 1 | %Author Evilk9 (github.com/evilk9) 2 | password_number = input('Enter How Many Passwords To Generate: '); 3 | password_length = input('Enter Password Length: '); 4 | 5 | for i = 1:password_number 6 | fprintf('Password: %d\n', i); 7 | for i = 1:password_length 8 | character = randi([33, 126]); 9 | fprintf('%s', char(character)); 10 | end 11 | fprintf('\n'); 12 | end 13 | 14 | 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0008 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | #Python 3.X solution for Easy Challenge #0008 2 | #GitHub: https://github.com/Ashkore 3 | #https://www.reddit.com/user/Ashkoree/ 4 | 5 | string = " bottles of beer on the wall, take one down, pass it around." 6 | bottles = 99 7 | for x in range(bottles+1): 8 | print (str(bottles-x)+string) 9 | 10 | #Extra Credit ?? 11 | newstring = "" 12 | for x in range(bottles+1): 13 | newstring += str(bottles-x)+string 14 | print (newstring) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0027 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Happy St. Patrick's Day! Write a program that accepts a year as input and outputs what day St. Patrick's Day falls on. 2 | 3 | Bonus: Print out the number of times St. Patrick's Day falls on a Saturday for this century. 4 | 5 | Sample Run: 6 | 7 | 8 | 9 | Enter Year: 2012 10 | 11 | St. Patrick's Day is on a Saturday. 12 | 13 | 14 | Enter Year: 2010 15 | 16 | St. Patrick's Day is on a Wednesday. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0052 Easy/solutions/solution.R: -------------------------------------------------------------------------------- 1 | # tlseabra @github 2 | 3 | wordRank <- function(input){ 4 | sums <- numeric(length(input)) 5 | 6 | for(i in 1:length(input)) { 7 | for (j in 1:nchar(input[i])){ 8 | sums[i] <- sums[i] + which(letters == tolower(substr(input[i], j, j)), 9 | arr.ind = TRUE) 10 | } 11 | sums[i] <- sums[i] / nchar(input[i]) 12 | } 13 | 14 | input[order(sums)] 15 | } 16 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0060 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def polite_seq(n): 4 | odd = lambda x: [odd for odd in range(3, x+1, 2) if x%odd==0] 5 | divisors = odd(n) 6 | sequences = [[] for i in range(len(divisors))] 7 | for i in range(len(divisors)): 8 | d = divisors[i] 9 | for j in range(int(abs(n/d - d/2)) + 1, int(n/d + d/2 + 1)): 10 | sequences[i].append(j) 11 | for x in sequences: 12 | print(''.join(str(x))) 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0111 Easy - Star delete/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that, given a string, removes from the string any `*` character, or any character that's one to the left or one to the right of a `*` character. Examples: 2 | 3 | `"adf*lp" --> "adp"` 4 | `"a*o" --> ""` 5 | `"*dech*" --> "ec"` 6 | `"de**po" --> "do"` 7 | `"sa*n*ti" --> "si"` 8 | `"abc" --> "abc"` 9 | 10 | Thanks to user __larg3-p3nis__ for suggesting this problem in /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0070 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that takes a filename and a parameter n and prints the n most common words in the file, and the count of their occurrences, in descending order. 2 | 3 | ___________________________________________ 4 | 5 | Request: Please take your time in browsing /r/dailyprogrammer_ideas and helping in the correcting and giving suggestions to the problems given by other users. It will really help us in giving quality challenges! 6 | 7 | Thank you! 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0099 Easy - Words with letters in alphabetical order/challenge_text.md: -------------------------------------------------------------------------------- 1 | How many words contained in [this dictionary](http://code.google.com/p/dotnetperls-controls/downloads/detail?name=enable1.txt) have their letters in alphabetical order? So, for instance the letters in "ghost" and "bee" is in alphabetical order, but the letters in "cab" are not. 2 | 3 | *** 4 | 5 | * Thanks to [EvanHahn](http://www.reddit.com/user/EvanHahn) for suggesting this problem at /r/dailyprogrammer_ideas! 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0254 Easy - Atbash Cipher/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | function atbash(input){ 4 | letters = "abcdefghijklmnopqrstuvwxyz".split("").reverse(); 5 | return input.split("").map(function(a){ 6 | if(/[a-z]/i.test(a)){ 7 | return a === a.toLowerCase() ? 8 | letters[a.charCodeAt(0) - 97] : 9 | letters[a.charCodeAt(0) - 65].toUpperCase(); 10 | } 11 | return a; 12 | }).join(""); 13 | } 14 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0086 Intermediate - (Weekday calculations)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Today's intermediate challenge comes from user [nagasgura](http://www.reddit.com/r/dailyprogrammer_ideas/comments/xx3cq/intermediate_calculate_the_day_of_the_week_on_any/) 2 | 3 | >Calculate the day of the week on any date in history 4 | 5 | >You could use the [Doomsday rule](http://en.wikipedia.org/wiki/Doomsday_rule) to program it. It should take in a day, month, and year as input, and return the day of the week for that date. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0068 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Implement a program you can use to play the classic game of chess. White and black alternate inputting their moves using some form of [chess notation](http://en.wikipedia.org/wiki/Chess_notation). The computer checks if the moves are legal and if so, executes them. The program should be able to tell whenever a player is in check or check-mate. You can represent the chessboard in the terminal in ascii form. 2 | 3 | Bonus: implement a simple AI that can play chess against you. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0018 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that draws a [square spiral](http://10binary.deviantart.com/art/square-spiral-203786602). You can print out this spiral in ASCII text, but using a graphics library would produce a more pleasant output. 2 | 3 | Bonus: Now draw a normal spiral. Some samples of spirals can be found [here](http://images.google.com/search?tbm=isch&hl=en&source=hp&biw=1920&bih=987&q=spiral&gbv=2&oq=spiral&aq=f&aqi=g10&aql=&gs_sm=3&gs_upl=2312l3239l0l3992l6l6l0l1l1l0l104l429l4.1l5l0). 4 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0271 Easy - Critical Hit/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | 4 | float p(int d, int h){ 5 | if(h > d) 6 | return (1 / (float) d) * p(d, h-d); 7 | else 8 | return (1 / (float) d * (d-h+1)); 9 | } 10 | 11 | int main(void){ 12 | int input[][2] = {{4,1}, {4,4}, {4,5}, {4,6}, {1,10}, {100, 200}, {8,20}}; 13 | for(int i=0; i < 7; i++) 14 | printf("%3d : %3d --> %0.5f\n", input[i][0], input[i][1], p(input[i][0], input[i][1])); 15 | } 16 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0239 Easy - A Game of Threes/solutions/solution.py: -------------------------------------------------------------------------------- 1 | def request(): 2 | print "Type a number" 3 | number = int(raw_input('> ')) 4 | return number 5 | 6 | def threes(number): 7 | while number > 1: 8 | if number % 3 == 0: 9 | print number, '0' 10 | elif number % 3 == 1: 11 | print number, '-1' 12 | number -= 1 13 | elif number % 3 == 2: 14 | print number, '+1' 15 | number += 1 16 | number /= 3 17 | print 1 18 | 19 | def main(): 20 | threes(request()) 21 | 22 | main() 23 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0088 Hard - (ASCII art)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that given an image file, produces an ASCII-art version of that image. Try it out on [Snoo](http://i.imgur.com/tJmB9.png) (note that the background is transparent, not white). There's no requirement that the ASCII-art be particularly good, it only needs to be good enough so that you recognize the original image in there. 2 | 3 | 4 | * Thanks to [akaritakai](http://www.reddit.com/user/akaritakai) for suggesting this problem at /r/dailyprogrammer_ideas! 5 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0027 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that accepts a year as input and outputs the century the year belongs in (e.g. 18th century's year ranges are 1701 to 1800) and whether or not the year is a leap year. Pseudocode for leap year can be found [here](http://en.wikipedia.org/wiki/Leap_year#Algorithm). 2 | 3 | Sample run: 4 | 5 | 6 | 7 | Enter Year: 1996 8 | 9 | Century: 20 10 | 11 | Leap Year: Yes 12 | 13 | 14 | 15 | Enter Year: 1900 16 | 17 | Century: 19 18 | 19 | Leap Year: No -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0255 Easy - Playing with light switches/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | function countBulbs(input){ 4 | input = input.split(/[ \n]/); 5 | for(var i = 0, bulbs = []; i < input[0]; i++){ 6 | bulbs[i] = false; 7 | } 8 | for(i = 1; i < input.length; i += 2){ 9 | for(j = Math.min(input[i], input[i+1]); j <= Math.max(input[i], input[i+1]); j++){ 10 | bulbs[j] = !bulbs[j]; 11 | } 12 | } 13 | return bulbs.reduce((a,b) => a + (b ? 1:0)); 14 | } 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0002 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Hello, coders! An important part of programming is being able to apply your programs, so your challenge for today is to create a calculator application that has use in your life. It might be an interest calculator, or it might be something that you can use in the classroom. For example, if you were in physics class, you might want to make a F = M * A calc. 2 | 3 | EXTRA CREDIT: make the calculator have multiple functions! Not only should it be able to calculate F = M * A, but also A = F/M, and M = F/A! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0005 Easy/solutions/solution.m: -------------------------------------------------------------------------------- 1 | %Author Evilk9 (github.com/evilk9) 2 | user_username = input('Enter Username: ', 's'); 3 | user_password = input('Enter Password: ','s'); 4 | 5 | info = fileread('login.txt'); 6 | info = strsplit(info); 7 | username = info(1); 8 | password = info(2); 9 | 10 | 11 | if(strcmp(user_password,password) && strcmp(user_username, username)) 12 | fprintf('ACCESS GRANTED'); 13 | 14 | else 15 | fprintf('ACCESS DENIED'); 16 | end 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0018 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function convertString(input){ 4 | output = input.split(""); 5 | var convert = [2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9]; 6 | 7 | for(var i=0; i < output.length; i++){ 8 | if(output[i].charCodeAt(0) >= 65 && output[i].charCodeAt(0) <= 90) 9 | output[i] = convert[ output[i].charCodeAt(0) - 65].toString(); 10 | } 11 | output.splice(9, 0, "-"); 12 | 13 | return output.join(""); 14 | } 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0036 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | var numLockers = 1000; 4 | var lockers = []; 5 | 6 | for(var i=0; i <= numLockers; i++) 7 | lockers.push(false); 8 | 9 | for(i=1; i <= numLockers; i++) 10 | for(var j=1; j <= numLockers; j++) 11 | if(!(j%i)) 12 | lockers[j] = !lockers[j]; 13 | 14 | console.log("Number of open lockers: " + lockers.reduce((total, a) => a ? total + a : total, 0)); 15 | for(i=1; i <= numLockers; i++) 16 | if(lockers[i]) 17 | console.log(i); 18 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0050 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Given an absolute path, write a program that outputs an ASCII tree of that directory. 2 | 3 | Example output here: [HERE](http://www.acooke.org/cute/UnixComman0.html) 4 | 5 | Note: 'tree' utility is not allowed. 6 | 7 | Extra credit: Limit the depth of the tree by variable n. 8 | 9 | Thanks to jnaranjo for the challenge at /r/dailyprogrammer_ideas ... [LINK](http://www.reddit.com/r/dailyprogrammer_ideas/comments/sbu4b/easy_generate_directory_tree_maps/) 10 | 11 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0023 Intermediate/solutions/solution.c: -------------------------------------------------------------------------------- 1 | /* tlseabra@github */ 2 | 3 | #include 4 | #include 5 | 6 | void prt_not_mcn(int n){ 7 | for(int i = 1; i <= n; i++){ 8 | int d = i; 9 | while(d >= 0){ 10 | if(d!=3 && (d>43 || d%3==0)) break; 11 | d -=20; 12 | } 13 | if(d < 0) printf("%d\n", i); 14 | } 15 | } 16 | 17 | int main(int argc, char* argv[]){ 18 | int n = strtol(argv[1], NULL, 10); 19 | prt_not_mcn(n); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0239 Easy - A Game of Threes/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | #include 4 | 5 | int main(int argc, char* argv[]){ 6 | int n = (int) strtol(argv[1], NULL, 10); 7 | while(n != 1){ 8 | switch(n%3){ 9 | case 0: printf("%d 0\n", n); 10 | break; 11 | case 1: printf("%d -1\n", n--); 12 | break; 13 | case 2: printf("%d +1\n", n++); 14 | } 15 | n /= 3; 16 | } 17 | printf("%d", n); 18 | } 19 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0025 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that places N queens on an NxN chessboard such that no two queens are on the same row, column, or diagonal, and no queen is on either of the two major diagonals (corner to corner). Get a solution for as large a value of N as you can. 2 | 3 | * [Sample valid board for N = 8](http://pastebin.com/5JYt1XND) 4 | * [Sample valid board for N = 48](http://pastebin.com/nwgdf8rk) 5 | 6 | thanks to Cosmologicon for today's challenge submitted at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 7 | 8 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0074 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Using the data-structure described in [today's intermediate problem](http://www.reddit.com/r/dailyprogrammer/comments/wa10w/792012_challenge_74_intermediate/), [follow Knuth's paper](http://arxiv.org/abs/cs/0011047) and make a complete implementation of Dancing Links that is able to solve exact cover problems. 2 | 3 | Bonus: make a Sudoku solver using your implemented algorithm. If you need help converting Sudoku into an exact cover problem, see this [wikipedia article](http://en.wikipedia.org/wiki/Exact_cover#Sudoku). -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0030 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | #Solution by https://github.com/Ouss4 2 | 3 | from collections import deque 4 | 5 | numbersList = [1,2,3,4,5,6,7,8,9,10] 6 | target = 5 7 | listInfTarget = [n for n in sorted(numbersList,reverse=False) if n < target] 8 | 9 | resultDeque = deque() 10 | for elt in listInfTarget: 11 | if target - elt in listInfTarget: 12 | resultDeque.append([elt, target - elt]) 13 | listInfTarget.pop() 14 | 15 | if not resultDeque: 16 | print("Nothing") 17 | else: 18 | print(resultDeque) 19 | 20 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0039 Easy/solutions/solution.c: -------------------------------------------------------------------------------- 1 | // tlseabra @github 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char* argv[]){ 7 | 8 | int n = (int) strtol(argv[1], NULL, 10); 9 | 10 | for(int i = 1; i <= n; i++){ 11 | if(i%3 == 0 && i%5 == 0){ 12 | printf("FizzBuzz\n"); 13 | }else if(i%3 == 0){ 14 | printf("Fizz\n"); 15 | }else if(i%5 == 0){ 16 | printf("Buzz\n"); 17 | }else{ 18 | printf("%d\n", i); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0019 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Challenge #19 will use [The Adventures of Sherlock Holmes](http://www.gutenberg.org/cache/epub/1661/pg1661.txt) from [Project Gutenberg](http://www.gutenberg.org). 2 | 3 | The Adventures of Sherlock Holmes is composed of 12 stories. Write a program that counts the number of words in each story. Then, print out the story titles ordered by its word count in descending order followed by how many words each story contains. Exclude the Project Gutenberg header and footer, book title, story titles, and chapters. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0018 Easy/solutions/solution3.py: -------------------------------------------------------------------------------- 1 | def convert_phone_number(phone_number): 2 | telephone_keypad = {'A':2,'B':2,'C':2, 'D':3,'E':3,'F':3,'G':4,'H':4,'I':4,'J':5,'K':5,'L':5,'M':6, 3 | 'N':6,'O':6, 'P':7,'Q':7,'R':7,'S':7,'T':8,'U':8,'V':8,'W':9,'X':9,'Y':9,'Z':9} 4 | final_number = [] 5 | for i in phone_number: 6 | try: 7 | new_number = str(telephone_keypad[i]) 8 | final_number.append(new_number) 9 | except KeyError: 10 | final_number.append(i) 11 | print ''.join(final_number) 12 | 13 | convert_phone_number('1-800-COMCAST') 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution3.c: -------------------------------------------------------------------------------- 1 | /*ask the user his name age and reddit username.*/ 2 | #include 3 | #include 4 | 5 | int main() 6 | {char name[15],uname[15]; 7 | int age; 8 | printf("What is you name ?"); 9 | scanf("%s",&name[0]); 10 | printf("What is your age ?"); 11 | scanf("%d",&age); 12 | printf("What is your reddit username ?"); 13 | scanf("%s",&uname[0]); 14 | 15 | printf("Your name is %s, you are %d years old, and your username is %s",&name[0],age,&uname[0]); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0238 Easy - Consonants and Vowels/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | import random 4 | 5 | def replace_vc(x): 6 | if x in 'vV': 7 | y = "aeiou"[random.randint(0, 4)] 8 | elif x in 'cC': 9 | y = "bcdfghjklmnpqrstvwxyz"[random.randint(0, 20)] 10 | return y if x.islower() else y.upper() 11 | 12 | def create_word(pattern): 13 | if len([x for x in pattern if x in 'cCvV']) != len(pattern): 14 | return "Input should only consist of 'c's and 'v's" 15 | return ''.join(list(map(replace_vc, pattern))) 16 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0064 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | One of the sites where daily weather forecasts are shown is [here](http://weather.noaa.gov/pub/data/forecasts/.) 2 | 3 | Get the forecast of any asked city and also try to be more innovative in your answers 4 | 5 | _____________________________________________________ 6 | 7 | It seems the number of users giving challenges have been reduced. Since my final exams are going on and its kinda difficult to think of all the challenges, I kindly request you all to suggest us interesting challenges at /r/dailyprogrammer_ideas .. Thank you! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0029 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | A [Palindrome](http://en.wikipedia.com/wiki/Palindrome) is a sequence that is the same in reverse as it is forward. 2 | 3 | I.e. hannah, 12321. 4 | 5 | Your task is to write a function to determine whether a given string is palindromic or not. 6 | 7 | 8 | Bonus: Support multiple lines in your function to validate Demetri Martin's [224 word palindrome poem](http://www.pastemagazine.com/articles/2009/02/demetri-martins-palindrome-poem.html). 9 | 10 | 11 | Thanks to _lerp for submitting this idea in /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0021 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | This idea is to implement the [haar wavelet](http://en.wikipedia.org/wiki/Haar_wavelet) transform on an array of length 2^n . This algorithm is a critical algorithm for many image compression and image processing applications, and it is relatively simple both recursively and iteratively. 2 | 3 | 4 | The solution should take in as input an array of floating-point values, and return an array of floating point values that in some sense implements the haar wavelet transform. 5 | 6 | 7 | 8 | * thanks to Steve132 for the challenge -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.rb: -------------------------------------------------------------------------------- 1 | if File.exist?('userinfo.txt') 2 | name, age, username = File.readlines('userinfo.txt').map(&:chomp) 3 | puts "Your name is #{name}, you are #{age} years old, and your username is #{username}" 4 | else 5 | print 'Your name: ' 6 | name = gets 7 | print 'Your age: ' 8 | age = gets 9 | print 'Your username: ' 10 | username = gets 11 | File.open('userinfo.txt', 'w') do |f| 12 | puts "Your name is #{name}, you are #{age} years old, and your username is #{username}" 13 | f.puts [name, age, username] 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution3.py: -------------------------------------------------------------------------------- 1 | ##Solution to Challenge 0001 in Python 3 2 | ##https://github.com/mattmatheus 3 | 4 | 5 | def solution(): 6 | name = input("What is your name? :") 7 | age = input("What is your age? :") 8 | username = input ("What is your username? :") 9 | print(str("Your name is {0}, your age is {1}, your username is {2}").format(name, age, username)) 10 | with open('outputfile.txt','a') as outfile: 11 | outfile.write(str("Your name is {0}, your age is {1}, your username is {2}").format(name, age, username)) 12 | 13 | solution() -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0007 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that can translate Morse code in the format of ...---... 2 | 3 | A space and a slash will be placed between words. ..- / --.- 4 | 5 | For bonus, add the capability of going from a string to Morse code. 6 | 7 | Super-bonus if your program can flash or beep the Morse. 8 | 9 | This is your Morse to translate: 10 | 11 | .... . .-.. .-.. --- / -.. .- .. .-.. -.-- / .--. .-. --- --. .-. .- -- -- . .-. / --. --- --- -.. / .-.. ..- -.-. -.- / --- -. / - .... . / -.-. .... .- .-.. .-.. . -. --. . ... / - --- -.. .- -.-- 12 | 13 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0066 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Today's difficult problem is similar to challenge #64's difficult problem 2 | 3 | 4 | Baseball is very famous in the USA. Your task is write a program that retrieves the current statistic for a requested team. [THIS](http://www.baseball-reference.com/) site is to be used for the reference. You are also encouraged to retrieve some more information from the site .. just use your creativity! :D 5 | 6 | Bonus: Stock prices can be retrieved from [this site](http://finance.yahoo.com/) ... your task is to retrieve the current price of a requested company. 7 | 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0012 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | /* Heavily based on http://www.graemeboy.com/string-permutations */ 4 | function strPerm(rest, soFar) { 5 | var next, 6 | remaining, 7 | i; 8 | 9 | if (rest == "") 10 | console.log(soFar); 11 | 12 | else { 13 | for (i = 0; i < rest.length; i++) { 14 | remaining = rest.substr(0,i) + rest.substr(i+1,rest.length-1); 15 | next = soFar + rest[i]; 16 | 17 | strPerm(remaining, next); //recursion is weird 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0059 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that given two strings, finds out if the second string is contained in the first, and if it is, where it is. 2 | 3 | I.e. given the strings "Double, double, toil and trouble" and "il an" will return 18, because the second substring is embedded in the first, starting on position 18. 4 | 5 | NOTE: Pretty much every language have this functionality built in for their strings, sometimes called find() (as in Python) or indexOf() (as in Java). But the point of this problem is to write the program yourself, so you **are not** allowed to use functions like this! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0263 Easy - Calculating Shannon Entropy of a String/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | float shannon(char* str){ 8 | float count[128] = {0}; 9 | float sum = 0; 10 | for(int i=0; i < strlen(str); i++) 11 | count[str[i]]++; 12 | 13 | for(int i=0; i < 128; i++) 14 | sum += count[i] ? (count[i] / strlen(str)) * log2f(count[i] / strlen(str)) : 0; 15 | 16 | return -1 * sum; 17 | } 18 | 19 | int main(int argc, char* argv[]){ 20 | printf("%f", shannon(argv[1])); 21 | } 22 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0047 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | function caesar(input, shift){ 3 | if(shift < 0){ 4 | shift = (shift % 26) + 26; 5 | } 6 | 7 | input = input.split(""); 8 | for(var i = 0; i < input.length; i++){ 9 | var c = input[i].charCodeAt(0); 10 | 11 | if(input[i].match(/[A-Z]/)){ 12 | input[i] = String.fromCharCode(65 + (c + shift - 65) % 26); 13 | }else if(input[i].match(/[a-z]/)){ 14 | input[i] = String.fromCharCode(97 + (c + shift - 97) % 26); 15 | } 16 | } 17 | return input.join("") 18 | } 19 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0047 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Given a string containing the English word for one of the single-digit numbers, return the number *without using any of the words in your code*. Examples: 2 | 3 | eng_to_dec('zero') # => 0 4 | eng_to_dec('four') # => 4 5 | 6 | Note: there is no right or wrong way to complete this challenge. Be creative with your solutions! 7 | *** 8 | * Thanks to [HazierPhonics](http://www.reddit.com/user/HazierPhonics) for posting this idea on /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, head over there and contribute! 9 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0055 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will allow the user to enter two characters. The program will validate the characters to make sure they are in the range '0' to '9'. The program will display their sum. The output should look like this. 2 | 3 | INPUT .... OUTPUT 4 | 5 | 3 6 ........ 3 + 6 = 9 6 | 4 9 ........ 4 + 9 = 13 7 | 0 9 ........ 0 + 9 = 9 8 | g 6 ........ Invalid 9 | 7 h ........ Invalid 10 | 11 | * thanks to frenulem for the challenge at /r/dailyprogrammer_ideas .. please ignore the dots :D .. it was messing with the formatting actually -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0017 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | /* iterative version */ 4 | function tree(input){ 5 | for(var i=0; i < input; i++){ 6 | var str = ""; 7 | for(j=0; j < Math.pow(2, i); j++) 8 | str += "@"; 9 | console.log(str); 10 | } 11 | } 12 | 13 | /* recursive version */ 14 | function printLine(height){ 15 | if(height == 0) 16 | return "@"; 17 | else 18 | return printLine(height - 1).concat(printLine(height - 1)); 19 | } 20 | 21 | function drawTree(input){ 22 | for(var i = 0; i < input; i++) 23 | console.log(printLine(i)); 24 | } 25 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0044 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | // tlseabra @github 2 | 3 | function txtBreak(input){ 4 | var broken = input.split(/[\.\!\?]/g); 5 | var output = broken.reduce((pre, curr) => curr.length > pre.length ? curr : pre); 6 | console.log(output); 7 | console.log(output.split(" ").filter(a => a.length > 0).length); 8 | output = output.split(" ").map( a => a.replace(/[\,\;]/, "")); 9 | for(var i = 0, words = []; i < output.length; i++){ 10 | if(output[i].length > 4){ 11 | words.push(output[i]); 12 | } 13 | } 14 | console.log(words.toString()); 15 | } 16 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0026 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | you have a string "ddaaiillyypprrooggrraammeerr". We want to remove all the consecutive duplicates and put them in a separate string, which yields two separate instances of the string "dailyprogramer". 2 | 3 | use this list for testing: 4 | 5 | input: "balloons" 6 | 7 | expected output: "balons" "lo" 8 | 9 | input: "ddaaiillyypprrooggrraammeerr" 10 | 11 | expected output: "dailyprogramer" "dailyprogramer" 12 | 13 | input: "aabbccddeded" 14 | 15 | expected output: "abcdeded" "abcd" 16 | 17 | input: "flabby aapples" 18 | 19 | expected output: "flaby aples" "bap" 20 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0079 Easy - Counting in steps/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | #include 4 | 5 | float * step_count(float a, float b, int steps){ 6 | float add = (b-a)/(steps-1); 7 | float * out = malloc(sizeof(float) * steps); 8 | for(int i=0; i < steps; i++) 9 | out[i] = a+add*i; 10 | return out; 11 | } 12 | 13 | int main(int argc, char *argv[]){ 14 | float *myArr = step_count(strtof(argv[1], NULL), strtof(argv[2], NULL), strtol(argv[3], NULL, 10)); 15 | for(int i=0; i < strtol(argv[3], NULL, 10); i++) 16 | printf("%0.3f ", myArr[i]); 17 | } 18 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0239 Easy - A Game of Threes/solutions/solution.rs: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | use std::io; 3 | use std::io::Write; 4 | 5 | fn main(){ 6 | print!("Input a number: "); 7 | io::stdout().flush().unwrap(); 8 | let mut n = String::new(); 9 | io::stdin().read_line(&mut n).unwrap(); 10 | let mut n: u32 = n.trim().parse().unwrap(); 11 | while n > 1 { 12 | match n%3 { 13 | 0 => println!("{} 0", n), 14 | 1 => {println!("{} -1", n); n -= 1} 15 | _ => {println!("{} 1", n); n += 1} 16 | } 17 | n /= 3; 18 | } 19 | println!("{}", n); 20 | } 21 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0092 Hard - (Bags and balls)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Compute all the permutations of placing 9 balls into 4 bags such that each bag contains an odd number of balls. 2 | 3 | Ball count is transient when placing bags within one another. For example, a bag containing 3 balls is placed inside a bag containing 2 balls. The inner bag contains 3 balls and the outer bag contains 5 balls. 4 | 5 | Some example permutations: 6 | 7 | ((((9)))) 8 | (8(((1)))) 9 | (1)(1)((7)) 10 | 11 | *** 12 | 13 | * Thanks to [skeeto](http://www.reddit.com/user/skeeto) for suggesting this problem at /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0016 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | [Craps is a gambling game](http://en.wikipedia.org/wiki/Craps) 2 | 3 | 4 | Your task is to write a program that simulates a game of craps. 5 | 6 | Use the program to calculate various features of the game: 7 | 8 | for example, What is the most common roll or average rolls in a game or maximum roll? What is the average winning percentage? Or you can make your own questions. 9 | 10 | 11 | 12 | edit: if anyone has any suggestions for the subreddit, kindly post it in the feedback thread posted a day before. It will be easier to assess. Thank you. 13 | 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0032 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | lets simulate a roulette wheel! 2 | a program that takes as input your bet, and gives as output how much you won, with the appropriate probability 3 | 4 | 5 | write a program that will take a players bet and output the resulting spin and payout. 6 | try using an american roulette wheel (which has the 00 slot) to add a slight twist. and try to incorporate as many complex bets as you can to. a comprehensive list can be found [here](http://en.wikipedia.org/wiki/Roulette#Bet_odds_table) 7 | 8 | * thanks to SleepyTurtle for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 9 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0017 Easy/solutions/solution.cpp: -------------------------------------------------------------------------------- 1 | // (Badly) made by https://github.com/lolibutts 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int triangle(int a) 8 | { 9 | char star = '@'; 10 | for (int i = 0; i <= a; i++) 11 | { 12 | std::cout << std::setw(a*2); 13 | std::cout << std::right << std::string(i*2, star) << std::endl; 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | std::cout << "Enter a number: " << std::endl; 20 | int num; 21 | std::cin >> num; 22 | 23 | triangle(num); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0168 Easy - String Index/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # @Author: Ouss4 2 | # @Github: github.com/Ouss4 3 | # @Date: 15/05/2016 4 | # @Description: Solution for Easy 168. 5 | 6 | import re 7 | def getAtI(s, i): 8 | words = "".join([c if re.search('([a-zA-Z0-9]+)', c) else " " for c in s]).split() 9 | return " " if i-1 > len(words) - 1 or i-1 < 0 else words[i-1] 10 | 11 | s = "...You...!!!@!3124131212 Hello have this is a --- string Solved !!...? to test @\n\n\n#!#@#@%$^**#$@ Congratz this!!!!!!!!!!!!!!!!one ---Problem\n\n" 12 | for i in [12, -1, 1, -100, 4, 1000, 9, -1000, 16, 13, 17, 15]: 13 | print(getAtI(s, i)) 14 | 15 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0077 Intermediate - (Last digit of factorial)/challenge_text.md: -------------------------------------------------------------------------------- 1 | The factorial of 10 is 3628800. The last non-zero digit of that factorial is 8. 2 | 3 | Similarly, the last non-zero digit of the factorial of 10^3 is 2. 4 | 5 | Compute the last non-zero digit of the factorial of 10^9 . 6 | 7 | *** 8 | 9 | Bonus: Compute the last non-zero digit of the factorial of 10^100 . 10 | 11 | *** 12 | 13 | * Thanks to [ashashwat](http://www.reddit.com/user/ashashwat) for suggesting this problem at /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, why not head over there and suggest it? 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0041 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will accept a sentence as input and then output that sentence surrounded by some type of an ASCII decoratoin banner. 2 | 3 | Sample run: 4 | 5 | 6 | 7 | Enter a sentence: So long and thanks for all the fish 8 | 9 | Output 10 | 11 | ***************************************** 12 | * * 13 | * So long and thanks for all the fish * 14 | * * 15 | ***************************************** 16 | 17 | 18 | 19 | 20 | Bonus: If the sentence is too long, move words to the next line. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0108 Easy - Scientific Notation Translator/challenge_text.md: -------------------------------------------------------------------------------- 1 | If you haven't gathered from the title, the challenge here is to go from decimal notation -> scientific notation. For those that don't know, scientific notation allows for a decimal less than ten, greater than zero, and a power of ten to be multiplied. 2 | 3 | For example: 239487 would be 2.39487 x 10^5 4 | 5 | And .654 would be 6.54 x 10^-1 6 | 7 | _____________ 8 | 9 | Bonus Points: 10 | 11 | * Have you program randomly generate the number that you will translate. 12 | 13 | * Go both ways (i.e., given 0.935 x 10^3, output 935.) 14 | 15 | Good luck, and have fun! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0011 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | //Only works with numbers as inputs. No zero padding in the output string. 4 | function getWeekDay(day, month, year){ 5 | var weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; 6 | 7 | return weekDays[new Date(year, month - 1, day).getDay()]; 8 | } 9 | 10 | var day = prompt("Please enter the day of the month:"), 11 | month = prompt("Please enter the month as a number:"), 12 | year = prompt("Please enter the year:"); 13 | 14 | alert(day + "/" + month + "/" + year + " is/was a " + getWeekDay(day, month, year) + "!"); 15 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0036 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Because I want to watch the world burn, write a program that accepts a sentence as input and outputs the sentence in leetspeak. [Here](http://en.wikipedia.org/wiki/Leet) is a link for a leetspeak translation table. Since leetspeak has multiple character selections per letter, randomly pick the character selection. The challenging part will be to be a resourceful developer and write a utility or use an existing application to save the table into a format that you will load in your program to do the translation. Oh yeah, if the input sentence contains one !, for the love of God translate that into !!!!11!!!1! ;) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0062 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Find all the subsets of a set of non-negative integers where the largest number is the sum of the remaining numbers, and return a count of the number of them. For instance, for the set { 1, 2, 3, 4, 6 } the subsets are 1+2=3, 1+3=4, 2+4=6, and 1+2+3=6, so the result is 4 subsets. Apply your program to the set { 3, 4, 9, 14, 15, 19, 28, 37, 47, 50, 54, 56, 59, 61, 70, 73, 78, 81, 92, 95, 97, 99 }. 2 | 3 | Your task is to write a program to solve the challenge. 4 | 5 | Bonus: you might like to apply your solution to the set of prime numbers less than 2^10 6 | 7 | * taken from http://challenge.greplin.com/ -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0016 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Solution by: Ahmed Dhanani 4 | 5 | github: ahmeddhanani 6 | 7 | SO: http://stackoverflow.com/users/5538805/mrpycharm 8 | 9 | """ 10 | 11 | def ManipulateString(stringOne, stringTwo): 12 | 13 | index = len(stringOne) - 1 14 | while index >= 0: 15 | if stringOne[index] in stringTwo: 16 | stringOne = stringOne[ : index] + stringOne[index + 1 : ] 17 | 18 | index -= 1 19 | 20 | return stringOne 21 | 22 | if __name__ == "__main__": 23 | text = ManipulateString("Daily Programmer", "aeiou ") 24 | print text 25 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0035 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will take a number and print a right triangle attempting to use all numbers from 1 to that number. 2 | 3 | 4 | 5 | Sample Run: 6 | 7 | 8 | 9 | Enter number: 10 10 | 11 | Output: 12 | 13 | 7 8 9 10 14 | 15 | 4 5 6 16 | 17 | 2 3 18 | 19 | 1 20 | 21 | 22 | 23 | Enter number: 6 24 | 25 | Output: 26 | 27 | 4 5 6 28 | 29 | 2 3 30 | 31 | 1 32 | 33 | 34 | 35 | Enter number: 3 36 | 37 | Output: 38 | 39 | 2 3 40 | 41 | 1 42 | 43 | 44 | 45 | Enter number: 12 46 | 47 | Output: 48 | 49 | 7 8 9 10 50 | 51 | 4 5 6 52 | 53 | 2 3 54 | 55 | 1 -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0063 Easy/solution/solution.c: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Jack Zheng 3 | Github: jackzheng2496 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #define ARR_LENGTH 5 10 | 11 | void reverse(int n, int array[]) { 12 | int i; 13 | 14 | for (i = 0, n -= 1; i < n; ++i, --n) { 15 | int temp = array[i]; 16 | array[i] = array[n]; 17 | array[n] = temp; 18 | } 19 | } 20 | 21 | int main(int argc, char *argv[]) { 22 | int array[ARR_LENGTH] = {51, 41, 12, 62, 74}; 23 | 24 | reverse(3, array); 25 | 26 | for (int i = 0; i < ARR_LENGTH; i++) { 27 | printf("%d ", array[i]); 28 | } 29 | 30 | printf("\n"); 31 | 32 | return EXIT_SUCCESS; 33 | } 34 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0158 Easy - The Torn Number/solutions/solution.c: -------------------------------------------------------------------------------- 1 | /* tlseabra@github */ 2 | #include 3 | 4 | char checkDigits(int num){ 5 | char digits[4] = {}; 6 | for(int i = 0; i < 4; i++){ 7 | digits[i] = num%10; 8 | for(int j = i-1; j >= 0; j--){ 9 | if(digits[i] == digits[j]) 10 | return 1; 11 | } 12 | num /= 10; 13 | } 14 | return 0; 15 | } 16 | 17 | int main(){ 18 | for(int num = 1000; num < 10000; num++){ 19 | if(checkDigits(num)) continue; 20 | int sum = num/100 + num%100; 21 | if(sum*sum == num) 22 | printf("%d\n", num); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0005 Easy/solutions/solution3.py: -------------------------------------------------------------------------------- 1 | #create a separate file with the name Account.txt in this files location and type the id in the first line and password in the second line 2 | 3 | def check(name , passw): 4 | fr = open('Account.txt','r') 5 | text = str(fr.read()) 6 | lines = text.split("\n") 7 | if name == lines[0]: 8 | if passw == lines[1]: 9 | print('Welcome',name) 10 | else: 11 | print('Invalid Entry') 12 | else: 13 | print('Invalid Entry') 14 | fr.close() 15 | 16 | name = input ('what is your user id? ') 17 | passw = input ('what is your password? ') 18 | 19 | check(name,passw) 20 | 21 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0035 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Imagine you are given a function flip() that returns a random bit (0 or 1 with equal probability). Write a program that uses flip to generate a random number in the range 0...N-1 such that each of the N numbers is generated with equal probability. For instance, if your program is run with N = 6, then it will generate the number 0, 1, 2, 3, 4, or 5 with equal probability. 2 | 3 | N can be any integer >= 2. 4 | 5 | Pseudocode is okay. 6 | 7 | You're not allowed to use rand or anything that maintains state other than flip. 8 | 9 | 10 | Thanks to Cosmologicon for posting this challenge to /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0060 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program or a function that can print out arbitrarily sized smiley face in ascii art. The smiley face can be however you want, but the eyes can't be single points (that is, they have to be circles at large size). Your program should be able to take in an integer between 16 and 1000 that represents the dimensions to render the face. 2 | 3 | [Here](http://www.reddit.com/r/dailyprogrammer_ideas/comments/sq93c/dynamic_ascii_smiley_face_intermediatehard/c4g485v) is a sample output. 4 | 5 | 6 | * thanks to Steve132 for the challenge at /r/dailyprogrammer_ideas ! .. if you have a challenge you could suggest it there :) 7 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.lisp: -------------------------------------------------------------------------------- 1 | ;;;; Solution to /r/dailyprogrammer challenge #0001 by Kabir Goel (/u/kbrgl) 2 | 3 | (defun prompt-read (q) 4 | (format *query-io* q) 5 | (force-output *query-io*) 6 | (read-line *query-io*)) 7 | 8 | 9 | (defvar name (prompt-read "name: ")) 10 | (defvar age (prompt-read "age: ")) 11 | (defvar username (prompt-read "username: ")) 12 | (defvar result (format nil "your name is ~a, you're ~a years old and your username is ~a" name age username)) 13 | 14 | (format t result) 15 | (with-open-file (out "output.txt" 16 | :direction :output 17 | :if-exists :supersede) 18 | (format out result)) 19 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0009 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | ################################### 2 | ## Python 2. Only sorts numbers. ## 3 | ################################### 4 | 5 | # numbers list 6 | nums = [] 7 | 8 | def show(): 9 | print "Sorted numbers: " 10 | for i in nums: 11 | print "%g" % i, 12 | 13 | def add(num): 14 | nums.append(num) 15 | 16 | def sort(nums): 17 | nums.sort() 18 | 19 | def request(): 20 | num = 0 21 | print "Type a number. Write 'C' to stop." 22 | while True: 23 | num = raw_input('> ') 24 | if num != 'C': 25 | add(float(num)) 26 | else: 27 | break 28 | 29 | def main(): 30 | request() 31 | sort(nums) 32 | show() 33 | 34 | main() 35 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0005 Intermediate/solutions/solution.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -- 2 | 3 | use v5.18; 4 | #use warnings; 5 | 6 | die "Need name of text file" unless @ARGV; 7 | 8 | my %dictionary; 9 | my $num_anagrams; 10 | 11 | open my $fh, "<", $ARGV[0] or die "Cannot open $ARGV[0]"; 12 | 13 | while ( my $word = <$fh> ) { 14 | chomp $word; 15 | my $key = join "", sort split "", $word; 16 | push @{ $dictionary{$key} }, $word; 17 | } 18 | 19 | close $fh; 20 | 21 | $, = ","; 22 | while ( my ($key, $words ) = each %dictionary) { 23 | if ( @$words > 1 ) { 24 | say @$words; 25 | $num_anagrams += @$words; 26 | } 27 | } 28 | 29 | say $num_anagrams; 30 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0003 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Welcome to cipher day! 2 | 3 | For this challenge, you need to write a program that will take the scrambled words from this post, and compare them against [THIS WORD LIST](http://pastebin.com/jSD873gL) to unscramble them. For bonus points, sort the words by length when you are finished. Post your programs and/or subroutines! 4 | 5 | Here are your words to de-scramble: 6 | 7 | 8 | `mkeart` 9 | 10 | `sleewa` 11 | 12 | `edcudls` 13 | 14 | `iragoge` 15 | 16 | `usrlsle` 17 | 18 | `nalraoci` 19 | 20 | `nsdeuto` 21 | 22 | `amrhat` 23 | 24 | `inknsy` 25 | 26 | `iferkna` 27 | 28 | 29 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0003 Hard/solutions/solution.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -- 2 | 3 | use v5.18; 4 | use warnings; 5 | 6 | my %dictionary; 7 | my @scrambled_words = qw{ 8 | mkeart sleewa edcudls 9 | iragoge usrlsle nalraoci 10 | nsdeuto amrhat inknsy 11 | iferkna 12 | }; 13 | 14 | open my $fh, "<", "wordlist.txt" or die "Cannot open wordlist"; 15 | 16 | while (my $word = <$fh>) { 17 | chomp $word; 18 | my $key = join "", sort split "", $word; 19 | $dictionary{$key} = $word; 20 | } 21 | 22 | close $fh or die "Cannot close wordlist"; 23 | 24 | for my $word (sort @scrambled_words) { 25 | my $key = join "", sort split "", $word; 26 | say $dictionary{$key}; 27 | } 28 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0007 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that draws a recursive image. 2 | 3 | For example, a [Sierpinski triangle](http://www.zeuscat.com/andrew/chaos/sierpinski.clear.gif), a [Barnsley fern](http://underdown.files.wordpress.com/2007/10/fern.png), or a [Mandelbrot set fractal](http://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Mandel_zoom_00_mandelbrot_set.jpg/322px-Mandel_zoom_00_mandelbrot_set.jpg) would be good drawings. 4 | 5 | Any recursive image will do, but try to make them look fun or interesting. 6 | 7 | Bonus points for adding a color scheme! 8 | 9 | Please post a link to a sample image produced by your program, and above all, be creative. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0014 Intermediate/solutions/solution.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX_NUMBER 10000 4 | 5 | int main(int argc, char **argv){ 6 | int numbers[MAX_NUMBER + 1]; 7 | 8 | int i, j; 9 | for ( i = 1; i <= MAX_NUMBER; i++) 10 | numbers[i] = 1; 11 | 12 | for ( j = 1; j <= MAX_NUMBER; j++ ) { 13 | for ( i = 1; i <= j; i++ ) { 14 | if ( i + j + 2*i*j > MAX_NUMBER ) 15 | break; 16 | numbers[i + j + 2*i*j] = 0; 17 | } 18 | } 19 | 20 | for ( i = 1; i <= MAX_NUMBER; i++ ) { 21 | if ( numbers[i] ) 22 | printf("%d\n", 2 * i + 1); 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0096 Intermediate - (Parsing English Values)/challenge_text.md: -------------------------------------------------------------------------------- 1 | In intermediate problem #8 we did a number to english converter. Your task this time is to write a function that 2 | can take in a string like "One-Hundred and Ninety-Seven" or "Seven-Hundred and Forty-Four Million", parse it, and 3 | return the integer that it represents. 4 | 5 | The definition of the exact input grammar is somewhat non-standard, so interpret it how you want and implement whatever grammar 6 | you feel is reasonable for the problem. However, try to handle at least up to one-billion, non-inclusive. Of course, more is good too! 7 | 8 | parseenglishint("One-Thousand and Thirty-Four")->1034 -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0072 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | The one-dimensional simple cellular automata [Rule 110] (http://en.wikipedia.org/wiki/Rule_110) 2 | is the only such cellular automata currently known to be turing-complete, and many people say it is the simplest known turing-complete 3 | system. 4 | 5 | Implement a program capable of outputting an ascii-art representation of applying Rule 110 to some initial state. How many iterations and what your initial state is is up to you! 6 | 7 | You may chose to implement rule 124 instead if you like (which is the same thing, albeit backwards). 8 | 9 | Bonus points if your program can take an arbitrary rule integer from 0-255 as input and run that rule instead! -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0114 Hard - Longest word ladder/challenge_text.md: -------------------------------------------------------------------------------- 1 | What's the longest valid [word ladder](http://www.reddit.com/r/dailyprogrammer/comments/149kec/1242012_challenge_114_easy_word_ladder_steps/) you can make using [this list of 3,807 four-letter words](http://pastebin.com/zY4Xt7iB) without repeating any words? (Normally a word ladder would require you to take the shortest possible path between two words, but obviously you don't do that here.) 2 | 3 | [Here's a ladder I found of 1,709 words](http://pastebin.com/DgeX0CTC). What's the best you can do? Also post the code you used to generate it, of course. 4 | 5 | _Thanks to **Thomas1122** for suggesting this challenge on /r/dailyprogrammer_ideas!_ -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0112 Intermediate - Sorting/solutions/solution.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -- 2 | 3 | use v5.18; 4 | use warnings; 5 | 6 | while (<>) { 7 | chomp; 8 | my @dates = m{ 9 | ( 10 | \d{4} # year 11 | \s* 12 | \d{2} # month 13 | \s* 14 | \d{2} # day 15 | \s* 16 | \d{2} # hour 17 | : 18 | \d{2} # minute 19 | : 20 | \d{2} # second 21 | ) 22 | }gx; 23 | $, = " "; 24 | say sort @dates; 25 | } 26 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0010 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | The exercise today asks you to validate a telephone number, as if written on an input form. Telephone numbers can be written as ten digits, or with dashes, spaces, or dots between the three segments, or with the area code parenthesized; both the area code and any white space between segments are optional. 2 | 3 | Thus, all of the following are valid telephone numbers: 1234567890, 123-456-7890, 123.456.7890, (123)456-7890, (123) 456-7890 (note the white space following the area code), and 456-7890. 4 | 5 | The following are not valid telephone numbers: 123-45-6789, 123:4567890, and 123/456-7890. 6 | 7 | 8 | 9 | 10 | source: programmingpraxis.com 11 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0026 Easy/solutions/solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | String str1 = ""; 7 | String str2 = ""; 8 | 9 | Scanner reader = new Scanner(System.in); 10 | 11 | System.out.println("Please enter your string!"); 12 | str1 = reader.nextLine(); 13 | 14 | for(int i=0;i 1` through `z -> 26`. Every sequence of letters can be translated into a string of numbers this way, with the numbers being mushed together. For instance `hello -> 85121215`. Unfortunately the reverse translation is not unique. `85121215` could map to `hello`, but also to `heaubo`. Write a program that, given a string of digits, outputs every possible translation back to letters. 2 | 3 | Sample input: 4 | 5 | ` 123` 6 | 7 | Sample output: 8 | 9 | ` abc` 10 | 11 | ` aw` 12 | 13 | ` lc` 14 | 15 | Thanks to __ashashwat__ for posting this idea in /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0031 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | In this challenge, given an array of integers, the goal is to efficiently find the subarray that has the greatest value when all of its elements are summed together. Note that because some elements of the array may be negative, the problem is not solved by simply picking the start and end elements of the array to be the subarrray, and summing the entire array. 2 | For example, given the array 3 | 4 | {1, 2, -5, 4, -3, 2} 5 | 6 | The maximum sum of a subarray is 4. It is possible for the subarray to be zero elements in length (if every element of the array were negative). 7 | 8 | Try to come up with an efficient algorithm! 9 | 10 | * taken from cprogramming.com -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0041 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will use the [FOIL method](http://www.algebrahelp.com/lessons/simplifying/foilmethod/pg2.htm) to solve multiplying binomials. Your program will accept a binomial algebraic formula as input and you will parse the data, use the FOIL method to reduce the formula, and print out the solution. You decide how you want to represent exponents (could use caret, or just write out the value after the variable). 2 | 3 | 4 | 5 | Sample Run: 6 | 7 | Enter Binomials: (2x + 6)(7x + 3) 8 | Result: 14x^2 + 48x + 18 9 | Enter Binomials: (2x2 + 3x)(5x2 + 9x) 10 | Result: 10x4 + 33x3 + 27x2 11 | 12 | Bonus: Support trinomials -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0053 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | A simple pseudo-random number generator looks like this: 2 | 3 | s(0) = 123456789 4 | s(n) = (22695477 * s(n-1) + 12345) mod 1073741824 5 | 6 | So each number is generated from the previous one. 7 | 8 | Using this generator, generate 10 million numbers (i.e. s(0) through s(9,999,999)) and find the 1000 largest numbers in that list. What is the sum of those numbers? 9 | 10 | Try to make your solution as efficient as possible. 11 | 12 | * Thanks to [sim642](http://www.reddit.com/user/sim642) for submitting this problem in /r/dailyprogrammer_ideas! If you have a problem that you think would be good, head on over there and help us out! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0066 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that takes two arguments, x and y, which are two strings containing Roman Numerals without prefix subtraction (so for instance, 14 is represented as XIIII, not XIV). The function must return true if and only if the number represented by x is less than the number represented by y. Do it without actually converting the Roman numerals into regular numbers. 2 | 3 | Challenge: handle prefix subtraction as well. 4 | 5 | * Thanks to cosmologicon for the challenge at /r/dailyprogrammer_ideas ! [LINK](http://www.reddit.com/r/dailyprogrammer_ideas/comments/u983p/easy_comparing_roman_numerals/) .. If you think you got any challenge worthy for this sub submit it there! 6 | 7 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0324 Easy - manual square root procedure (intermediate)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that outputs the highest number that is lower or equal than the square root of the given number, with the given number of decimal fraction digits. 2 | 3 | Use this technique, (do not use your language's built in square root function): https://medium.com/i-math/how-to-find-square-roots-by-hand-f3f7cadf94bb 4 | 5 | **input format: 2 numbers:** precision-digits Number 6 | 7 | **sample input** 8 | 9 | 0 7720.17 10 | 1 7720.17 11 | 2 7720.17 12 | 13 | **sample output** 14 | 15 | 87 16 | 87.8 17 | 87.86 18 | 19 | **challenge inputs** 20 | 21 | 0 12345 22 | 8 123456 23 | 1 12345678901234567890123456789 -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0020 Easy/solutions/solution.java: -------------------------------------------------------------------------------- 1 | package dailyprogrammerchallenges; 2 | 3 | import static java.lang.Math.sqrt; 4 | import java.util.Scanner; 5 | 6 | /** 7 | * 8 | * @author coderMato 9 | */ 10 | public class PrimeNumbers { 11 | public static void main(String[] args){ 12 | int prime,i,j; 13 | System.out.println("2"); 14 | for(i=3; i <= 2000; i++){ 15 | for(j=2; j <= (int) sqrt(i) + 1; j++){ 16 | if(i % j != 0 && j == (int) sqrt(i) + 1){ 17 | System.out.println(i); 18 | } 19 | if (i%j == 0){ 20 | break; 21 | } 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0051 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that given an array A and a number N, generates all combinations of items in A of length N. 2 | 3 | That is, if you are given the array [1,2,3,4,5] and 3, you're supposed to generate 4 | 5 | * [1,2,3] 6 | * [1,2,4] 7 | * [1,2,5] 8 | * [1,3,4] 9 | * [1,3,5] 10 | * [1,4,5] 11 | * [2,3,4] 12 | * [2,3,5] 13 | * [2,4,5] 14 | * [3,4,5] 15 | 16 | Note that order doesn't matter when counting combinations, both [1,2,3] and [3,2,1] are considered the same. Order also doesn't matter in the output of the combinations, as long as you generate all of them, you don't have to worry about what order they pop out. You can also assume that every element of the array is distinct. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | def data_parser(data): 2 | print 'Your name is {0}, you are {1} years old, and your username is {2}.'.format(data[0],data[1],data[2]) 3 | if 'y' in data[3]: 4 | f = open('data_logger.txt','w') 5 | f.write('Your name is {0}, you are {1} years old, and your username is {2}.'.format(data[0],data[1],data[2])) 6 | 7 | def data_retriever(): 8 | save_prompt = input('Save this data to disk, or no?\n>') 9 | name_input = input('What\'s your name?\n>') 10 | age_input = input('What\'s your age?\n>') 11 | reddit_username_input = input('What\'s your reddit username?\n>') 12 | return name_input,age_input,reddit_username_input,save_prompt 13 | 14 | data_parser(data_retriever()) 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0002 Easy/solutions/solution.tcl: -------------------------------------------------------------------------------- 1 | if 0 { 2 | Author: Altlock 3 | 4 | Description: Calculation done with command line arguments. 5 | } 6 | 7 | # Get correct amount of arguments 8 | 9 | if {$argc != 3 && $argc != 4} { 10 | puts "This script requires exactly 3 or 4 numbers to be put in." 11 | puts "For example: (tclsh $argv0 160 5 39)," 12 | puts "the calculation of the example is (160 % 5 + 39 = 39)." 13 | puts "If you put in 4 numbers, the sum will be multiplied by that number." 14 | } elseif {$argc == 3} { ;#If correct amount, calculate 15 | puts [expr [lindex $argv 0] % [lindex $argv 1] + [lindex $argv 2]] 16 | } else { 17 | puts [expr ([lindex $argv 0] % [lindex $argv 1] + [lindex $argv 2]) * [lindex $argv 3]] 18 | } 19 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0009 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function willSort(input){ 4 | var = nums = [], str = [], output = [], 5 | i; 6 | 7 | input = input.split(","); 8 | 9 | for(i=0; i < input.length; i++){ 10 | if( !isNaN(+input[i]) ) 11 | nums.push(parseInt(input[i])); 12 | else 13 | str.push(input[i]); 14 | } 15 | 16 | nums.sort(function(a, b){return a-b}); 17 | str.sort(function(a, b){return a.toLowerCase().localeCompare(b.toLowerCase)}); 18 | 19 | output = nums.concat(str); 20 | 21 | for(i=0; i < output.length; i++) 22 | console.log(output[i]); 23 | 24 | } 25 | 26 | var input = prompt("Please input a series of digits/strings, limited by a comma:"), 27 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0100 Easy - Sleep Cycle Estimator/challenge_text.md: -------------------------------------------------------------------------------- 1 | This challenge comes to us from nagasgura 2 | 3 | The human body goes through 90 minute sleep cycles during the night, and you feel more refreshed if you wake up at the end of a sleep cycle than if you wake up during a sleep cycle. The challenge is to make a program that takes a wake-up time and outputs the possible times to fall asleep so that you will wake up at the end of a sleep cycle. 4 | 5 | Example: 6 | 7 | Input (Wake-up time): 6:15 AM 8 | 9 | Output (when to go to sleep): 9:15 PM, 10:45 PM, 12:15 AM, or 1:45 AM 10 | 11 | Bonus 1: Be able to input a sleep time and output potential wake-up times 12 | 13 | Bonus 2: Account for how long it takes to fall asleep -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0276 Easy - Recktangles/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | 3 | def shit_post(word, width, height): 4 | ln = len(word)-1 5 | spaced = ' '.join(list(word)) 6 | data = ['']*(ln*height+1) 7 | for h in range(ln*height+1): 8 | for w in range(width): 9 | start = 1 if w>0 else 0 10 | if h%ln == 0: 11 | data[h] += spaced[start:] if int(h/ln+w)%2==0 else spaced[::-1][start:] 12 | else: 13 | index = h%ln if int(h/ln)%2==0 else ln - h%ln 14 | middle = word[index] + ' '*(ln*2-1) + word[::-1][index] 15 | data[h] += middle[start:] if w%2==0 else middle[::-1][start:] 16 | for l in data: 17 | print(l) 18 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0033 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that will help you play poker by telling you what kind of hand you have. 2 | 3 | 4 | input 5 | 6 | The first line of input contains the number of test cases (no more than 20). Each test case consists of one line - five space separated cards. Each card is represented by a two-letter (or digit) word. The first character is the rank (A,K,Q,J,T,9,8,7,6,5,4,3 or 2), the second character is the suit (S,H,D,C standing for spades, hearts, diamonds and clubs). The cards can be in any order (but they will not repeat). 7 | 8 | 9 | Output 10 | 11 | 12 | For each test case output one line describing the type of a hand, exactly like in the list above. 13 | 14 | 15 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0004 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | var chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890", 4 | numPasswords = parseInt(prompt("How many passwords do you want to generate?")), 5 | numChars = parseInt(prompt("How many characters do you want your password(s) to have?")), 6 | password = new Array(), 7 | printStr = "", 8 | i, 9 | j; 10 | 11 | for(j=0; j < numPasswords; j++ ){ 12 | password[j] = ""; 13 | for(i=0; i < numChars; i++) 14 | password[j] += chars.charAt(Math.floor(Math.random()*chars.length)); 15 | } 16 | 17 | for(i = 0; i < numPasswords; i++) 18 | printStr += password[i] + "\n"; 19 | 20 | alert("Here are your generated password(s):\n" + printStr); 21 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0008 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | function main() { 2 | for (var i = 99; i >= 0; i--) { 3 | if (i > 1) { 4 | console.log(i + ' bottles of beer on the wall, ' + i + ' bottles of beer.'); 5 | console.log('Take one down and pass it around, ' + (i - 1) + ' bottles of beer on the wall.'); 6 | } else if (i == 1) { 7 | console.log(i + ' bottle of beer on the wall, ' + i + ' bottle of beer.'); 8 | console.log('Take one down and pass it around, no more bottle of beer on the wall.'); 9 | } else { 10 | console.log('No more bottles of beer on the wall, no more bottles of beer.'); 11 | console.log('Go to the store and buy some more, 99 bottles of beer on the wall.'); 12 | } 13 | } 14 | } 15 | main(); 16 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0252 Easy - Sailors and monkeys and coconuts, oh my!/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | //Brute-force implementation, more efficient way available 4 | var sailors = prompt("How many sailors are stranded in the isle?"), 5 | test, 6 | coconuts = 1; 7 | 8 | while(true){ 9 | test = nightStash(sailors, coconuts); 10 | if( test !== null && (test % sailors === 0)) 11 | break; 12 | else 13 | coconuts ++; 14 | } 15 | 16 | console.log(sailors + " sailors need " + coconuts + " coconuts!" ); 17 | 18 | function nightStash(s, c){ 19 | 20 | for(var i = 0; i < s; i++){ 21 | if(c % s !== 1 || Math.floor( c/s ) == 0) return null; 22 | c -= (Math.floor( c/s ) + 1); 23 | } 24 | return c; 25 | } 26 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0093 Easy - Two-Way Morse Code Translator/challenge_text.md: -------------------------------------------------------------------------------- 1 | This challenge courtesy of user [nagasgura](http://www.reddit.com/user/nagasgura) 2 | 3 | In this challenge, we read in a string from standard input and output the translation to or from morse code on standard output. 4 | 5 | When translating to Morse code, one space should be used to separate morse code letters, and two spaces should be used to separate morse code words. When translating to English, there should only be one space in between words, and no spaces in between letters. 6 | 7 | Here's a chart of the morse code symbols: [1] http://www.w1wc.com/pdf_files/international_morse_code.pdf 8 | 9 | Example input and output: 10 | 'sos' -> '... --- ...' 11 | '... --- ...' -> 'sos' -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0042 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that prints out the lyrics for "Ninety-nine bottles of beer", "Old McDonald had a farm" or "12 days of Christmas". 2 | 3 | If you choose "Ninety-nine bottles of beer", you need to spell out the number, not just write the digits down. It's "Ninety-nine bottles of beer on the wall", not "99 bottles of beer"! 4 | 5 | For Old McDonald, you need to include at least 6 animals: a cow, a chicken, a turkey, a kangaroo, a T-Rex and an animal of your choosing (Old McDonald has a weird farm). The cow goes "moo", the chicken goes "cluck", the turkey goes "gobble", the kangaroo goes "g'day mate" and the T-Rex goes "GAAAAARGH". You can have more animals if you like. 6 | 7 | Make your code shorter than the song it prints out! 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0031 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function from26ToDecimal(input){ 4 | var i, result = 0; 5 | input = input.split("").reverse(); 6 | 7 | for(i=0; i < input.length; i++) 8 | result += (input[i].charCodeAt(0) - 65) * Math.pow(26, i); 9 | 10 | return result; 11 | } 12 | 13 | function fromDecimalTo26(input){ 14 | var i=1, result = []; 15 | 16 | while(input >= Math.pow(26, i)) i++; 17 | 18 | for(--i; i >= 0; i--){ 19 | result.push(String.fromCharCode(Math.floor(input/Math.pow(26, i)) + 65 )); 20 | input = input % Math.pow(26, i); 21 | } 22 | 23 | return result.join(""); 24 | } 25 | 26 | function multiply26(a, b){ 27 | return fromDecimalTo26( from26ToDecimal(a) * from26ToDecimal(b)); 28 | } 29 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0061 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Today you should implement a function that all of us programmers depend heavily on, but most never give a second thought as to how it's actually coded: the square root function. 2 | 3 | Write a function that given a number as input, will return the square root of that number, in floating point. 4 | 5 | Obviously, you are not allowed to use the library version of sqrt() in the implementation of your function. Also, stay away from log() and exp(). In fact, don't use any mathematical functions that aren't the basic arithmetic ones (addition, subtraction, multiplication, division) or bit operations (though you can of course still use operators that compares numbers with each other, like "less than", "equal to", "more than", etc.) 6 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0057 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | ~~Your task is to implement [Ackermann Function](http://en.wikipedia.org/wiki/Ackermann_function) in the most efficient way possible.~~ 2 | 3 | ~~Please refer the wiki page link given for its explanation.~~ 4 | 5 | ____________________________________________________ 6 | 7 | Since many did not like the previous challenge because it was quite unsatisfactory here is a new challenge ... 8 | 9 | Input: A sequence of integers either +ve or -ve 10 | 11 | Output : a part of the sequence in the list with the maximum sum. 12 | 13 | __________________________ 14 | 15 | **UPDATE:** I have given some more info on the [difficult] challenge since it seems to be very tough. you have upto monday to finish all these challenges. pls note it :) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0310 Intermediate - Simplifying square roots/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description 2 | Simplify square roots in the form `(a sqrt(b))/(c sqrt(d))`. A simplified radical should have no square roots in the denominator and no number in a square root should have a square factor. For example, the input `2 5 5 10` for `a b c d`, respectively, should simplify to `1 2 5` where a=1, b=2, and c=5. 3 | 4 | #Output description 5 | 6 | a b c 7 | 8 | (d should not exist after simplifying) 9 | 10 | #Challenge input 11 | 12 | 45 1465 26 15 13 | 14 | #Challenge output 15 | 16 | 15 879 26 17 | 18 | # Credit 19 | This challenge was suggested by user /u/alchzh on /r/dailyprogrammer_ideas, many thanks. If you have an idea, please share it there and we might use it! 20 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0105 Intermediate - Boolean logic calculator/challenge_text.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | [Boolean logic](https://en.wikipedia.org/wiki/Boolean_algebra) is something all programmers have to deal with, whether we like it or not. 4 | Why not automate the task to make it easier? 5 | 6 | Your objective, if you choose to accept it, is to make a boolean logic calculator that can parse boolean logic statements. 7 | Given: 8 | 9 | * \| = or 10 | * \* = and 11 | * \^ = xor 12 | * \! = not 13 | 14 | Take input of 1s and 0s (or T and F) and output the evaluation of that statement.
15 | Try not to use statement evaluators built into your language of choice, like [eval](http://php.net/eval).
16 | Your parser should be able to evaluate statements in parentheses as well. 17 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution.c: -------------------------------------------------------------------------------- 1 | // Solution by https://github.com/mateoKaradza 2 | 3 | #include 4 | #include 5 | 6 | typedef struct User{ 7 | unsigned int age; 8 | char name[50]; 9 | char username[50]; 10 | }User; 11 | 12 | int main(void) { 13 | 14 | User user; 15 | 16 | printf("Enter your name, age and reddit username: "); 17 | scanf("%s %d %s", user.name, &user.age, user.username); 18 | 19 | FILE* file = fopen("info.txt", "w"); 20 | if (!file) { 21 | perror("Unable to open the file"); 22 | exit(EXIT_FAILURE); /* so that you don't try to use the null ptr */ 23 | } 24 | 25 | fprintf(file, "%s %d %s", user.name, user.age, user.username); 26 | 27 | fclose(file); 28 | 29 | return 0; // return 1 would indicate an error wouldn't it? 30 | } 31 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0158 Easy - The Torn Number/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description: 2 | 3 | I had the other day in my possession a label bearing the number 3 0 2 5 in large figures. This got accidentally torn in half, so that 3 0 was on one piece and 2 5 on the other. On looking at these pieces I began to make a calculation, when I discovered this little peculiarity. If we add the 3 0 and the 2 5 together and square the sum we get as the result, the complete original number on the label! Thus, 30 added to 25 is 55, and 55 multiplied by 55 is 3025. Curious, is it not? 4 | 5 | Now, the challenge is to find another number, composed of four figures, all different, which may be divided in the middle and produce the same result. 6 | 7 | #Bonus 8 | Create a program that verifies if a number is a valid torn number. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0016 Easy/solutions/Solution1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Solution1 { 4 | 5 | public static void main(String[] args) { 6 | String str1 = null; 7 | String str2 = null; 8 | 9 | Scanner reader = new Scanner(System.in); 10 | 11 | System.out.println("Please enter the first string!"); 12 | str1 = reader.nextLine(); 13 | System.out.println("Please enter the characters to be removed!"); 14 | str2 = reader.nextLine(); 15 | 16 | for(int i=0;i 4 | #include 5 | int main() 6 | { 7 | int age; 8 | std::string name; 9 | std::string username; 10 | 11 | std::cout << "Enter your name: " << std::endl; 12 | std::cin >> name; 13 | 14 | std::cout << "Enter your age: " << std::endl; 15 | std::cin >> age; 16 | 17 | std::cout << "Enter your username: " << std::endl; 18 | std::cin >> username; 19 | 20 | std::cout << "\nName: " << name << "\nAge: " << age << "\nUsername: " << username << std::endl; 21 | 22 | std::ofstream myFile; 23 | myFile.open("Userdata.txt"); 24 | myFile << "Name: " << name << "\nAge: " << age << "\nUsername: " << username << std::endl; 25 | myFile.close(); 26 | 27 | return 0; 28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0067 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | You are given a list of 999,998 integers, which include all the integers between 1 and 1,000,000 (inclusive on both ends) in some unknown order, with the exception of two numbers which have been removed. By making only *one pass* through the data and using only a constant amount of memory (i.e. O(1) memory usage), can you figure out what two numbers have been excluded? 2 | 3 | 4 | Note that since you are only allowed one pass through the data, you are not allowed to sort the list! 5 | 6 | EDIT: clarified problem 7 | 8 | *** 9 | 10 | * Thanks to [Cosmologicon](http://www.reddit.com/user/Cosmologicon) for suggesting this problem at /r/dailyprogrammer_ideas? Do you have a problem you think would be good for us? Why not head over there and suggest it? 11 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0312 Intermediate - Next largest number/challenge_text.md: -------------------------------------------------------------------------------- 1 | # Description 2 | Given an integer, find the *next largest* integer using **ONLY** the digits from the given integer. 3 | 4 | # Input Description 5 | An **integer**, one per line. 6 | 7 | # Output Description 8 | The next largest integer possible using the digits available. 9 | 10 | ### Example 11 | Given `292761` the next largest integer would be `296127`. 12 | 13 | # Challenge Input 14 | 15 | 1234 16 | 1243 17 | 234765 18 | 19000 19 | 20 | # Challenge Output 21 | 22 | 1243 23 | 1324 24 | 235467 25 | 90001 26 | 27 | # Credit 28 | 29 | This challenge was suggested by user /u/caa82437, many thanks. If you have a challenge idea, please share it in /r/dailyprogrammer_ideas and there's a good chance we'll use it. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0038 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that tests whether large numbers are prime or not, with extremely high certainty. There are several primality tests that can do this. Fairly simple ones include the [Fermat Test](http://en.wikipedia.org/wiki/Fermat_primality_test) and the even better [Miller-Rabin test.](http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test) The Wikipedia articles have pseudocode you can implement. 2 | 3 | Use your function and a random number generator to post a 100-digit prime. You can [test your result at Wolfram|Alpha.](http://www.wolframalpha.com/input/?i=factor+3413620168870555693820518760938238015371255549104140276735527985110834446323816207929693506740255567) 4 | 5 | * thanks to cosmologicon for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 6 | 7 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0033 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | This would be a good study tool too. I made one myself and I thought it would also be a good challenge. 2 | 3 | Write a program that prints a string from a list at random, expects input, checks for a right or wrong answer, and keeps doing it until the user types "exit". If given the right answer for the string printed, it will print another and continue on. If the answer is wrong, the correct answer is printed and the program continues. 4 | 5 | Bonus: Instead of defining the values in the program, the questions/answers is in a file, formatted for easy parsing. 6 | 7 | Example file: 8 | 12 * 12?,144 9 | What is reddit?,website with cats 10 | Translate: hola,hello 11 | 12 | * thanks to Iggyhopper for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 13 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0001 Easy/solutions/solution2.py: -------------------------------------------------------------------------------- 1 | #Python 3.X solution for Easy Challenge #0001 2 | #GitHub: https://github.com/Ashkore 3 | #https://www.reddit.com/user/Ashkoree/ 4 | 5 | Name = None 6 | Age = None 7 | RedditUserName = None 8 | while Name == None: 9 | Name = input("What is your name?") 10 | while Age == None: 11 | Age = input("What is your age?") 12 | try: 13 | Age = int(Age) 14 | except: 15 | print("Please input a valid number") 16 | Age = None 17 | while RedditUserName == None: 18 | RedditUserName = input("What is your reddit username?") 19 | 20 | output = "Your name is "+Name+", you are "+str(Age)+" year(s) old, and your username is "+RedditUserName+"." 21 | print(output) 22 | #ExtraCredit 23 | with open("Easy Challenge #0001.txt","a") as LogFile: 24 | LogFile.write(output+"\r") -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0002 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | var variable = prompt("F=m*a calculator. Which variable do you want to calculate (F, m, a)?", 'f'); 4 | var f, a, m; 5 | 6 | switch(variable.toLowerCase()){ 7 | case('f'): m = prompt("Mass value:"); 8 | a = prompt("Accelaration value:"); 9 | alert("F = " + m*a + " N"); 10 | break; 11 | case('m'): f = prompt("Force value:"); 12 | a = prompt("Accelaration value:"); 13 | alert("m = " + f/a + " kg"); 14 | break; 15 | case('a'): f = prompt("Force value:"); 16 | m = prompt("Mass value:"); 17 | alert("a = " + f/m + " m s^-2"); 18 | break; 19 | default: alert("There seems to be a problem with your input. Oops."); 20 | } 21 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0003 Hard/solution/solution.py: -------------------------------------------------------------------------------- 1 | # nick tucker 2 | # written for DailyProgrammerChallenges :-) 3 | # email: nicktucker4@gmail.com 4 | # assumptions: file linked in challenge description is transferred to local .txt file 5 | 6 | words_to_descramble = ('iferkna','mkeart','sleewa','edcudls','iragoge','usrlsle','nalraoci','nsdeuto','amrhat','inknsy') 7 | with open('hard_challenge_3.txt','r') as f: 8 | word_list = [line.replace('\n','') for line in f.readlines()] 9 | 10 | sorted_word_dict = {} 11 | 12 | def unscrambler(): 13 | for word in word_list: 14 | sorted_word_dict[word]=''.join(sorted(word)) 15 | reconstructed_words = [''.join(sorted(word)) for word in words_to_descramble] 16 | for _ in sorted_word_dict.items(): 17 | for word in reconstructed_words: 18 | if word in _: 19 | print _[0] 20 | 21 | unscrambler() 22 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0046 Intermediate/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # tlseabra@github 2 | import random 3 | 4 | def game(): 5 | indices = list(range(8)) 6 | places = [None] * 8 7 | while indices: 8 | d = random.randint(0,9) 9 | i = round(d*7/9) 10 | real_index, c = i, 1 11 | while not real_index in indices: 12 | if all(x in indices for x in (i+c, i-c)): 13 | real_index = i+c if sum(indices)/len(indices) > 3.5 else i-c 14 | elif i+c in indices: 15 | real_index = i+c 16 | elif i-c in indices: 17 | real_index = i-c 18 | c += 1 19 | places[real_index] = str(d) 20 | indices.remove(real_index) 21 | return places == sorted(places) 22 | 23 | print(sum(game() for _ in range(1000000)) / 10000) 24 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0106 Easy - Random Talker, Part 1/challenge_text.md: -------------------------------------------------------------------------------- 1 | Your program will be responsible for analyzing a small chunk of text, the text of this ***entire*** dailyprogrammer description. Your task is to output the distinct words in this description, from highest to lowest count with the number of occurrences for each. Punctuation will be considered as separate words where they are not a part of the word. 2 | 3 | The following will be considered their own words: **"** **.** **,** **:** **;** **!** **?** **(** **)** **[** **]** **{** **}** 4 | 5 | For anything else, consider it as part of a word. 6 | 7 | Extra Credit: 8 | 9 | Process the text of the ebook [Metamorphosis, by Franz Kafka](http://www.gutenberg.org/cache/epub/5200/pg5200.txt) and determine the top 10 most frequently used words and their counts. (This will help for part 2) -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0065 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | A magic square is a square of size NxN with the numbers 1 through n^2 put in so that all rows, all columns and both diagonals sum to the same number. For instance, this is a 3x3 magic square: 2 | 3 | 8 1 6 4 | 3 5 7 5 | 4 9 2 6 | 7 | As you can see all rows, all columns and both diagonals (8+5+2 and 4+5+6) sum to the same number, 15. 8 | 9 | Write a program that draws a magic square of size 18x18. 10 | 11 | *** 12 | 13 | * Thanks to [SwimmingPastaDevil](http://www.reddit.com/user/SwimmingPastaDevil) for submitting this problem in /r/dailyprogrammer_ideas! And on behalf of the moderators, I'd like to thank everyone who submitted problems the last couple of days, it's been really helpful, and there are some great problems there! Keep it up, it really helps us out a lot! 14 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0028 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | The idea is simple. Use the [pastebin](http://pastebin.com/login.php?ref=L2FwaQ==) API (wrappers should not be allowed) in the most creative way to create a cool command line tool. A simple example that's very easy to implement in most modern programming languages is a program that posts to pastebin the contents of a given file. A few ideas for extra features: 2 | 3 | * The ability to post a whole directory to pastebin with one command. 4 | * The option to post only a part of a file 5 | * Tweeting the link to twitter when posting 6 | * Language recognition for the filename 7 | * A history of recent pastes with their links 8 | * Automatic pasting every few minutes (or after a file changes) for backup 9 | 10 | Thanks to chris_p for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 11 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0059 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | Given a binary matrix like this: 2 | 3 | 0 1 1 1 1 0 4 | 1 0 0 1 1 1 5 | 1 0 1 1 1 1 6 | 1 1 1 1 1 1 7 | 0 1 1 1 1 0 8 | 9 | Output the clues for a [nonogram puzzle](http://en.wikipedia.org/wiki/Nonogram) in the format of "top clues, empty line, bottom clues", with clues separated by spaces: 10 | 11 | 3 12 | 1 2 13 | 1 3 14 | 5 15 | 5 16 | 3 17 | 18 | 4 19 | 1 3 20 | 1 4 21 | 6 22 | 4 23 | 24 | That is, count the contiguous groups of "1" bits and their sizes, first in columns, then in rows. 25 | 26 | * Thanks to [nooodl](http://www.reddit.com/user/nooodl) for suggesting this problem at /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, why not head over there and post it! 27 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0298 Intermediate - Too many or too few Parentheses/challenge_text.md: -------------------------------------------------------------------------------- 1 | this challenge is about spotting where parentheses are unbalanced. 2 | 3 | **find the index in string where the first extra `)` or `(` parentheses is, or return the length of string if parentheses are balanced.** 4 | 5 | for flashiness, insert `**` around any index that is found. (will bold in markdown) 6 | 7 | **inputs:** 8 | 9 | )(asdf))) 10 | ((((asdf))) 11 | ((((asdf)) 12 | (ab)((cd)(asdf))) 13 | (ab)((cd)(asdf)()) 14 | (ab)(((cd)(asdf) 15 | (ab)(((cd)(asdf 16 | (ab)(((cd)(asdf))))) 17 | 18 | **outputs:** 19 | 20 | **)**(asdf))) 21 | **(**(((asdf))) 22 | (**(**((asdf)) 23 | (ab)((cd)(asdf))**)** 24 | (ab)((cd)(asdf)()) 25 | (ab)(**(**(cd)(asdf) 26 | (ab)((**(**cd)(asdf NB. may argue it should be 1 left. 27 | (ab)(((cd)(asdf)))**)**) -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0100 Intermediate - (Bad Word Filter)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program called 'censor' that takes in one argument on the command line. This argument is the filename of a newline-separated wordlist of profanity such as 2 | 3 | http://urbanoalvarez.es/blog/2008/04/04/bad-words-list/ or 4 | 5 | http://www.bannedwordlist.com/SwearWordResources.htm 6 | 7 | The program should then read a text from standard in, and print it out again, but replacing every instance of a word in the wordlist with a 'censored' version. 8 | The censored version of a word has the same first character as the word, and the rest of the characters are replaced with '*'. 9 | 10 | For example, the 'censored' version of 'peter' would be 'p****' 11 | 12 | Example: 13 | 14 | >echo 'You jerkface!' | censor badwords.txt 15 | You j***face! 16 | 17 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0267 Easy - All the places your dog didn't win/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # Author: Lim Yao Jie 2 | # Description: Show placement of doggo 3 | # Github: www.github.com/causztic 4 | 5 | def show_placements(x, total=100): 6 | start = 1 7 | result = "" 8 | 9 | dictionary = { 10 | 1: "st", 11 | 2: "nd", 12 | 3: "rd", 13 | 11: "th", 14 | 12: "th", 15 | 13: "th" 16 | } 17 | 18 | while total >= start: 19 | # if it exists, take the suffix. 20 | # if the first time it doesn't exist, take the modulus and search again. 21 | # defaults to th in the end. 22 | if start != x: 23 | result += "{}{}\t".format(start, dictionary.get(start, dictionary.get(start % 10, "th"))) 24 | 25 | start = start + 1 26 | 27 | print(result) 28 | 29 | show_placements(5) -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0019 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Challenge #19 will use [The Adventures of Sherlock Holmes](http://www.gutenberg.org/cache/epub/1661/pg1661.txt) from [Project Gutenberg](http://www.gutenberg.org). 2 | 3 | Write a program that will build and output a word index for The Adventures of Sherlock Holmes. Assume one page contains 40 lines of text as formatted from Project Gutenberg's site. There are common words like "the", "a", "it" that will probably appear on almost every page, so do not display words that occur more than 100 times. 4 | 5 | Example Output: the word "abhorrent" appears once on page 1, and the word "medical" appears on multiple pages, so the output for this word would look like: 6 | 7 | abhorrent: 1 8 | 9 | medical: 34, 97, 98, 130, 160 10 | 11 | Exclude the Project Gutenberg header and footer, book title, story titles, and chapters. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0049 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | 3 | function montyHall(n){ 4 | var smart = 0, dumb = 0; 5 | for(var i = 0; i < n; i++){ 6 | var doors = ["goat", "goat", "goat"]; 7 | doors[Math.floor(Math.random()*3)] = "car"; 8 | var smartPick = Math.floor(Math.random()*3); 9 | var dumbPick = smartPick; 10 | var doorShow = doors.indexOf("goat") == smartPick ? 11 | doors.reduce((a, b, i) => b == "goat" ? i : a) : 12 | doors.indexOf("goat"); 13 | smartPick = [0, 1, 2].filter(a => a != dumbPick && a != doorShow)[0]; 14 | dumb += doors[dumbPick] == "car"; 15 | smart += doors[smartPick] == "car"; 16 | } 17 | console.log("The smart player won the car " + smart + " times.\nThe dumb player won the car " + dumb + " times."); 18 | } 19 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0093 Hard - (15-puzzle)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that can solve a standard ['15-puzzle'](http://en.wikipedia.org/wiki/Fifteen_puzzle). 2 | 3 | The program should read in a hex string describing the puzzle state from left to right top to bottom, where F is a blank...for example,: 4 | 5 | 0FD1C3B648952A7E 6 | 7 | would describe the puzzle 8 | 9 | +----+----+----+----+ 10 | | 0 | | 13 | 1 | 11 | +----+----+----+----+ 12 | | 12 | 3 | 11 | 6 | 13 | +----+----+----+----+ 14 | | 4 | 8 | 9 | 5 | 15 | +----+----+----+----+ 16 | | 2 | 10 | 7 | 14 | 17 | +----+----+----+----+ 18 | 19 | 20 | The program should output the final solution 0123456789ABCDEF, and ALSO output EACH intermediate board state as a string on the way to finding a solution. 21 | Warning: I don't know if the above puzzle is actually solvable. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0104 Easy - Powerplant Simulation/challenge_text.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | A powerplant for the city of Redmond goes offline every third day because of local demands. Ontop of this, the powerplant has to go offline for maintenance every 100 days. Keeping things complicated, on every 14th day, the powerplant is turned off for refueling. Your goal is to write a function which returns the number of days the powerplant is operational given a number of days to simulate. 4 | 5 | **Formal Inputs & Outputs:** 6 | 7 | *Input Description:* 8 | 9 | Integer days - the number of days we want to simulate the powerplant 10 | 11 | *Output Description:* 12 | 13 | Return the number of days the powerplant is operational. 14 | 15 | **Sample Inputs & Outputs:** 16 | 17 | The function, given 10, should return 7 (3 days removed because of maintenance every third day). -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0003 Easy/solutions/solution.m: -------------------------------------------------------------------------------- 1 | %Author Evilk9 (github.com/evilk9) 2 | choice = input('Make A Decision.\n(1) Encrypt\n(2) Decrypt: '); 3 | user_input = input('Enter Text: ', 's'); 4 | offset = input('Enter Offset Number: '); 5 | 6 | if(choice == 1) 7 | 8 | for i = 1:length(user_input) 9 | 10 | encoded_char = int32(user_input(i)); 11 | encoded_char = encoded_char + offset; 12 | encoded_char = char(encoded_char); 13 | 14 | fprintf('%s', encoded_char); 15 | end 16 | 17 | end 18 | 19 | if(choice == 2) 20 | for i = 1:length(user_input) 21 | 22 | decoded_char = int32(user_input(i)); 23 | decoded_char = decoded_char - offset; 24 | decoded_char = char(decoded_char); 25 | 26 | fprintf('%s', decoded_char); 27 | end 28 | end 29 | 30 | 31 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0089 Easy - Simple statistical functions/challenge_text.md: -------------------------------------------------------------------------------- 1 | For today's challenge, you should calculate some simple statistical values based on a list of values. Given [this data set](http://pastebin.com/vqzTrVK2), write functions that will calculate: 2 | 3 | * [The mean value](http://en.wikipedia.org/wiki/Arithmetic_mean) 4 | * [The variance](http://en.wikipedia.org/wiki/Variance) 5 | * [The standard deviation](http://en.wikipedia.org/wiki/Standard_deviation) 6 | 7 | 8 | Obviously, many programming languages and environments have standard functions for these (this problem is one of the few that is *really* easy to solve in Excel!), but you are not allowed to use those! The point of this problem is to write the functions yourself. 9 | 10 | * Thanks to [Cosmologicon](http://www.reddit.com/user/Cosmologicon) for suggesting this problem at /r/dailyprogrammer_ideas! 11 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0197 Hard - Crazy Professor/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description 2 | 3 | He's at it again, the professor at the department of Computer Science has posed a question to all his students knowing that they can't brute-force it. He wants them all to think about the efficiency of their algorithms and how they could possibly reduce the execution time. 4 | 5 | He posed the problem to his students and then smugly left the room in the mindset that none of his students would complete the task on time (maybe because the program would still be running!). 6 | 7 | #The problem 8 | 9 | What is the 1000000th number that is not divisble by any prime greater than 20? 10 | 11 | #Acknowledgements 12 | 13 | Thanks to /u/raluralu for this submission! 14 | 15 | 16 | #NOTE 17 | 18 | counting will start from 1. Meaning that the 1000000th number is the 1000000th number and not the 999999th number. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0058 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | For the easy part of today's challenge, we considered numbers that are palindromes in different bases. For this problem, lets only concern ourselves with numbers that are palindromes in base 10. 2 | 3 | Define a function P(N) that takes as input a number N, and returns the smallest base 10 palindrome larger than N (i.e. it returns the "next" palindrome after N). So, for instance: 4 | 5 | P(808) = 818 6 | P(999) = 1001 7 | P(2133) = 2222 8 | 9 | What is P( 3^39 )? 10 | 11 | *** 12 | 13 | BONUS: What is P( 7^100 ) 14 | 15 | * Thanks to [ashashwat](http://www.reddit.com/user/ashashwat) for suggesting this problem at /r/dailyprogrammer_ideas! (problem originally from [here](http://www.spoj.pl/problems/PALIN/)) If you have a problem that you think would be good for this subreddit, why not head over there and suggest it? -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0086 Easy - Run-length encoding/challenge_text.md: -------------------------------------------------------------------------------- 1 | Run-Length encoding is a simple form of compression that detects 'runs' of repeated instances of a symbol in a string and compresses them to a list of pairs of 'symbol' 'length'. For example, the string 2 | 3 | "Heeeeelllllooooo nurse!" 4 | 5 | Could be compressed using run-length encoding to the list of pairs 6 | [(1,'H'),(5,'e'),(5,'l'),(5,'o'),(1,'n'),(1,'u'),(1,'r'),(1,'s'),(1,'e')] 7 | 8 | Which seems to not be compressed, but if you represent it as an array of 18bytes (each pair is 2 bytes), then we save 5 bytes of space compressing this string. 9 | 10 | Write a function that takes in a string and returns a run-length-encoding of that string. (either as a list of pairs or as a 2-byte-per pair array) 11 | 12 | BONUS: Write a decompression function that takes in the RLE representation and returns the original string -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0322 Intermediate - Largest Palindrome/challenge_text.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | Write a program that, given an integer input n, prints the largest integer that is a palindrome and has two factors both of string length n. 4 | 5 | # Input Description 6 | 7 | An integer 8 | 9 | # Output Description 10 | 11 | The largest integer palindrome who has factors each with string length of the input. 12 | 13 | # Sample Input: 14 | 15 | 1 16 | 17 | 2 18 | 19 | # Sample Output: 20 | 21 | 9 22 | 23 | 9009 24 | 25 | (9 has factors 3 and 3. 9009 has factors 99 and 91) 26 | 27 | # Challenge inputs/outputs 28 | 29 | 3 => 906609 30 | 31 | 4 => 99000099 32 | 33 | 5 => 9966006699 34 | 35 | 6 => ? 36 | 37 | # Credit 38 | 39 | This challenge was suggested by /u/ruby-solve, many thanks! If you have a challenge idea, please share it in /r/dailyprogrammer_ideas and there's a good chance we'll use it. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0175 Easy - Bogo!/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void shuffle(char arr[], int size){ 8 | char *fixed = malloc(size * sizeof(char)); 9 | memcpy(fixed, arr, size * sizeof(char)); 10 | for(int i = size; i > 0; i--){ 11 | int index = rand()%i; 12 | arr[size - i] = fixed[index]; 13 | fixed[index] = fixed[i - 1]; 14 | } 15 | } 16 | 17 | int bogoSort(char arr[], char sorted[], int size){ 18 | int count = 0; 19 | while(!(strcmp(arr, sorted) == 0)){ 20 | shuffle(arr, size); 21 | count++; 22 | } 23 | return count; 24 | } 25 | 26 | int main(void){ 27 | srand(time(NULL)); 28 | char a[] = "lolhe", b[] = "hello"; 29 | int num = bogoSort(a, b, sizeof(a)/sizeof(a[0])); 30 | printf("Number of iterations: %d\n%s", num, a); 31 | } 32 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0193 Easy - A Cube, Ball, Cylinder, Cone walk into a warehouse/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description: 2 | 3 | An international shipping company is trying to figure out how to manufacture various types of containers. Given a volume they want to figure out the dimensions of various shapes that would all hold the same volume. 4 | 5 | #Input: 6 | 7 | A volume in cubic meters. 8 | 9 | #Output: 10 | 11 | Dimensions of containers of various types that would hold the volume. 12 | The following containers are possible. 13 | 14 | * Cube 15 | * Ball (Sphere) 16 | * Cylinder 17 | * Cone 18 | 19 | #Example Input: 20 | 21 | 27 22 | 23 | #Example Output: 24 | 25 | Cube: 3.00m width, 3.00m, high, 3.00m tall 26 | Cylinder: 3.00m tall, Diameter of 3.38m 27 | Sphere: 1.86m Radius 28 | Cone: 9.00m tall, 1.69m Radius 29 | 30 | #Some Inputs to test. 31 | 32 | 27, 42, 1000, 2197 -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0004 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | today, your challenge is to create a program that will take a series of numbers (5, 3, 15), and find how those numbers can add, subtract, multiply, or divide in various ways to relate to eachother. This string of numbers should result in 5 * 3 = 15, or 15 /3 = 5, or 15/5 = 3. When you are done, test your numbers with the following strings: 2 | 3 | 4 | 4, 2, 8 5 | 6 | 6, 2, 12 7 | 8 | 6, 2, 3 9 | 10 | 9, 12, 108 11 | 12 | 4, 16, 64 13 | 14 | For extra credit, have the program list all possible combinations. 15 | 16 | for even more extra credit, allow the program to deal with strings of greater than three numbers. For example, an input of (3, 5, 5, 3) would be 3 * 5 = 15, 15/5 = 3. When you are finished, test them with the following strings. 17 | 18 | 2, 4, 6, 3 19 | 20 | 1, 1, 2, 3 21 | 22 | 4, 4, 3, 4 23 | 24 | 8, 4, 3, 6 25 | 26 | 9, 3, 1, 7 27 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0044 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a function that takes two arguments a and b, and finds all primes that are between a and a + b (specifically, find all primes p such that a ≤ p < a + b). So for instance, for a = 1234 and b = 100, it should return the following 15 primes: 2 | 3 | 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327 4 | 5 | The sum of those primes are 19339. The number of primes for a = 9! and b = 8! is 3124 and the sum of those primes is 1196464560. 6 | 7 | How many primes are there for a = 16! and b = 10!, and what is their sum? 8 | 9 | *** 10 | 11 | Note 1: In this problem, n! refers to the [factorial](http://en.wikipedia.org/wiki/Factorial) of n, 1\*2\*3\*...\*(n-1)\*n, so 9! is equal to 362880. 12 | 13 | Note 2: All numbers and solutions in this problem fit into 64-bit integers. 14 | 15 | EDIT: changed some incorrect numbers, thanks ixid! -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0081 Intermediate - (Local Minimization)/challenge_text.md: -------------------------------------------------------------------------------- 1 | For a lot of the questions today we are going to be doing some simple numerical calculus. Don't worry, its not too terrifying. 2 | 3 | Write a function fmin that can take in a real-valued function f(x) where x is a vector in 3D space (bonus points for N-D). 4 | 5 | xout=fmin(f,x0) should return a local minimum of f close to x0. 6 | 7 | Example in Python 8 | 9 | %f is a function with 1 3-vector 10 | def f(x): 11 | return x[0]**2+x[1]**2+x[2]**2 12 | 13 | %find the local minimum of f, starting at (1,1,1) 14 | print fmin(f,[1.0,1.0,1.0]) 15 | 16 | should print out 17 | 18 | [0.0,0.0,0.0] %because (0,0,0) is the global minimum of f(x,y,z)=x^2+y^2+z^2 19 | 20 | EDIT: To make this a little easier, I decided that it is acceptable for your implementation to require that fmin have additional arguments for the derivatives of f -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0092 Easy - Digital number display/challenge_text.md: -------------------------------------------------------------------------------- 1 | Today's easy challenge is to write a program that draws a number in the terminal that looks like one of those old school [seven segment displays](http://en.wikipedia.org/wiki/Seven-segment_display) you find in alarm clocks and VCRs. For instance, if you wanted to draw the number 5362, it would look somthing like: 2 | 3 | +--+ +--+ +--+ +--+ 4 | | | | | 5 | | | | | 6 | +--+ +--+ +--+ +--+ 7 | | | | | | 8 | | | | | | 9 | +--+ +--+ +--+ +--+ 10 | 11 | I've added some +'s to the joints to make it a bit more readable, but that's optional. 12 | 13 | Bonus: Write the program so that the numbers are scalable. In other words, that example would have a scale of 2 (since every line is two terminal characters long), but your program should also be able to draw them in a scale of 3, 4, 5, etc. 14 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0149 Easy - Disemvoweler/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define MAXBUFFER 128 8 | 9 | int isVowel(char ch){ 10 | if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') 11 | return 1; 12 | else 13 | return 0; 14 | } 15 | 16 | int main(){ 17 | char *line = (char*) calloc(MAXBUFFER, sizeof(char)); 18 | char *outConsonants = (char*) calloc(MAXBUFFER, sizeof(char)); 19 | char *outVowels = (char*) calloc(MAXBUFFER, sizeof(char)); 20 | int c = 0, v = 0; 21 | 22 | fgets(line, MAXBUFFER, stdin); 23 | for(int i = 0; i < strlen(line); i++){ 24 | if(isVowel(line[i])) 25 | outVowels[v++] = line[i]; 26 | else if(isalpha(line[i])) 27 | outConsonants[c++] = line[i]; 28 | } 29 | 30 | printf("%s\n%s", outConsonants, outVowels); 31 | } 32 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0017 Easy/solutions/solution2.py: -------------------------------------------------------------------------------- 1 | ############################################## 2 | ## Python 2. Build triangle and reverse it. ## 3 | ############################################## 4 | 5 | def request(): 6 | "Request triangle's height" 7 | height = int(raw_input('> ')) 8 | return height 9 | 10 | def build(height): 11 | "Build normal triangle" 12 | x = 1 13 | for i in range(0, height): 14 | print '@' * x 15 | x *= 2 16 | return x #for reverse loop 17 | 18 | def reverse(height, last): 19 | "Build upside-down triangle" 20 | x = last/2 21 | for i in xrange(height, 0, -1): 22 | print '@' * x 23 | x /= 2 24 | 25 | def main(): 26 | try: 27 | print "Hello. Type the height of the triangle." 28 | height = request() 29 | last = build(height) 30 | print "Done. Reverse it? ENTER for yes. CTRL^C for no." 31 | raw_input('> ') 32 | reverse(height, last) 33 | print "Done." 34 | except: 35 | pass 36 | 37 | main() 38 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0048 Easy/solution/solution.c: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Jack Zheng 3 | Github: jackzheng2496 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | void even_odd(int array[], int size) { 10 | int i, j, k, m; 11 | 12 | i = 0; 13 | k = m = -1; 14 | j = size - 1; 15 | 16 | while (i < j) { 17 | if (array[i] % 2 == 1) 18 | k = (k != -1) ? k : i; 19 | 20 | if (array[j] % 2 == 0) 21 | m = (m != -1) ? m : j; 22 | 23 | if (k != -1 && m != -1) { 24 | int temp = array[k]; 25 | array[k] = array[m]; 26 | array[m] = temp; 27 | k = m = -1; 28 | } 29 | 30 | i = (k == -1) ? ++i : i; 31 | j = (m == -1) ? --j : j; 32 | } 33 | } 34 | 35 | int main(int argc, char *argv[]) { 36 | int array[] = {2,1,11,12,4,17,6,12,1,14,10,19,2}; 37 | 38 | even_odd(array, 13); 39 | 40 | for (int i = 0; i < 13; i++) { 41 | printf("%d ", array[i]); 42 | } 43 | 44 | printf("\n"); 45 | 46 | return EXIT_SUCCESS; 47 | } 48 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0109 Easy - Digits Check/challenge_text.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | Write a function, where given a string, return true if it only contains the digits from 0 (zero) to 9 (nine). Else, return false. 4 | 5 | **Formal Inputs & Outputs:** 6 | 7 | *Input Description:* 8 | 9 | string data - a given string that may or may not contains digits; will never be empty 10 | 11 | *Output Description:* 12 | 13 | Return True or False - true if the given string only contains digits, false otherwise 14 | 15 | **Sample Inputs & Outputs:** 16 | 17 | "123" should return true. "123.123" should return a false. "abc" should return a false. 18 | 19 | **Notes:** 20 | 21 | This is a trivial programming exercise, but a real challenge would be to optimize this function for your language and/or environment. As a recommended reading, look into how [fast string-searching](http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm) works. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0027 Easy/solutions/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | /** 4 | * Created by Matej Gazda on 3/24/2016. 5 | */ 6 | public class Solution { 7 | public static void main(String[] args){ 8 | Scanner textScan = new Scanner(System.in); 9 | System.out.println("Please enter a year"); 10 | String text = textScan.nextLine(); 11 | int year = Integer.parseInt(text); 12 | if(year%100 != 0) { 13 | System.out.println((Integer.parseInt(text.substring(0, 2)) + 1) + "th century"); 14 | } 15 | else{ 16 | System.out.println(Integer.parseInt(text.substring(0, 2)) + "th century"); 17 | } 18 | if((year % 4 == 0 && year % 100 != 0) || (year % 4 == 0 && year % 100 == 0 & year % 400 == 0)){ 19 | System.out.println("Leap year!"); 20 | } 21 | else{ 22 | System.out.println("Not a Leap year!"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0114 Intermediate - Shortest word ladder/challenge_text.md: -------------------------------------------------------------------------------- 1 | Given any two words from [this list of 3,807 four-letter words](http://pastebin.com/zY4Xt7iB), output a [word ladder](http://www.reddit.com/r/dailyprogrammer/comments/149kec/1242012_challenge_114_easy_word_ladder_steps/) between them that's as short as possible, using words from the list. (Note that the word list was chosen so that it's possible to form a ladder between any pair of words in the list.) Sample input: 2 | 3 | look 4 | leap 5 | 6 | Sample output (any valid ladder of 5 words from `look` to `leap` would also work): 7 | 8 | look 9 | loon 10 | loan 11 | lean 12 | leap 13 | 14 | __Bonus__: There are 8 pairs of words that require a ladder of 18 words to join. Find these 8 pairs of words. (Hint: a certain word appears in each of the 8 pairs.) 15 | 16 | _Thanks to **Thomas1122** for suggesting this challenge on /r/dailyprogrammer_ideas!_ -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0034 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Inspired by the restaurant I ate at the other day. This is the puzzle: You have a wooden triangle, roughly equilateral with 5 rows of holes. The top row has one hole, and the bottom has 5, increasing by one hole with each successive row. 2 | 3 | One hole of the triangle is empty and the rest are filled with golf tees. To make a move, you jump a golf tee over another adjacent golf tee into a hole immediately beyond it, removing that second golf tee from the game. Your goal is to find a solution set of jumps such that all of the golf tees but one are removed from the board. The notation of such a solution is at your discretion. 4 | 5 | Bonus: Investigate if the choice of initial empty hole influences the solvability of the problem, and if so, what is the maximum number of pegs that can be removed given each starting hole. 6 | 7 | * thanks to luxgladius for the challenge at [/r/dailyprogrammer_ideas](/r/dailyprogrammer_ideas) 8 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0063 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a procedure called reverse(N, A), where N is an integer and A is an array which reverses the N first items in the array and leaves the rest intact. 2 | 3 | For instance, if N = 3 and A = [1,2,3,4,5], then reverse(N,A) will modify A so that it becomes [3,2,1,4,5], because the three first items, [1,2,3], have been reversed. Here are a few other examples: 4 | 5 | reverse(1, [1, 2, 3, 4, 5]) -> A = [1, 2, 3, 4, 5] 6 | reverse(2, [1, 2, 3, 4, 5]) -> A = [2, 1, 3, 4, 5] 7 | reverse(5, [1, 2, 3, 4, 5]) -> A = [5, 4, 3, 2, 1] 8 | reverse(3, [51, 41, 12, 62, 74]) -> A = [12, 41, 51, 62, 74] 9 | 10 | So if N is equal to 0 or 1, A remains unchanged, and if N is equal to the size of A, all of A gets flipped. 11 | 12 | Try to write reverse() so that it works *in-place*; that is, it uses only a constant amount of memory in addition to the list A itself. This isn't necessary, but it is recommended. -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0047 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | If you were to generate all permutations of the first three letters of the alphabet ("a", "b" and "c") and then sort them, you would get the following list of 6 permutations: 2 | 3 | 1. abc 4 | 2. acb 5 | 3. bac 6 | 4. bca 7 | 5. cab 8 | 6. cba 9 | 10 | As you can see, the fourth permutation in a sorted list of all the permutations of "a", "b" and "c" is "bca". 11 | 12 | Similarly, if we wanted the 30th permutation in a sorted list of all permutations of the first five letters of the alphabet (i.e. "abcde"), you get "baedc". 13 | 14 | Define a function f(n,p) that generates the permutation number p in a sorted list of all permutations of the n first letters of the alphabet. So, for instance: 15 | 16 | f(3, 4) = "bca" 17 | f(5, 30) = "baedc" 18 | f(7, 1000) = "bdcfega" 19 | f(8, 20000) = "dhfebagc" 20 | 21 | Find f(11, 20000000) 22 | 23 | *** 24 | 25 | Bonus: 26 | 27 | Find f(20, 10^18 ) -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0077 Hard - (Boggle solver)/challenge_text.md: -------------------------------------------------------------------------------- 1 | Write a program that is able to find all words in a [Boggle](http://en.wikipedia.org/wiki/Boggle) board. For a word list, you can [use this file](http://code.google.com/p/dotnetperls-controls/downloads/detail?name=enable1.txt). 2 | 3 | How many words can you find in the following 10x10 Boggle board? 4 | 5 | T N L E P I A C N M 6 | T R E H O C F E I W 7 | S C E R E D A M E A 8 | A O M O G O O F I E 9 | G A C M H N L E R X 10 | T D E R J T F O A S 11 | I T A R T I N H N T 12 | R N L Y I V S C R T 13 | A X E P S S H A C F 14 | I U I I I A I W T T 15 | 16 | *** 17 | 18 | * Thanks to [Medicalizawhat](http://www.reddit.com/user/Medicalizawhat) for suggesting this problem (and to Cosmologicon for providing a word list and some commentary) at /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, why not head over there and suggest it? -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0020 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function findPrimes(input){ 4 | var primes = [2]; 5 | var flag; 6 | 7 | for(var i = 3; i < input; i += 2){ 8 | flag = true; 9 | for(var j = 3; j < i/2 ; j += 2 ){ 10 | if(i%j == 0){flag = false; break;} 11 | } 12 | 13 | if(flag) 14 | primes.push(i); 15 | } 16 | 17 | return primes; 18 | } 19 | 20 | 21 | function sieve(input){ 22 | var primes = [], i, p = 2, flag = true; 23 | 24 | for(i=2; i <= input; i++){ 25 | primes[i-2] = i; 26 | } 27 | 28 | while(flag){ 29 | flag = false; 30 | for(i = 2*p; i <= input; i += p) 31 | primes[i-2] = - 1; 32 | 33 | for(i = p + 1; i <= input; i++){ 34 | if(primes[i-2] > 0){ flag = true; p = i; break;} 35 | } 36 | } 37 | 38 | var output = []; 39 | for(i=0; i < primes.length; i++){ 40 | if(primes[i] > 0) output.push(primes[i]); 41 | } 42 | 43 | return output; 44 | } 45 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0169 Easy - 90 Degree 2D Array Rotate/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description: 2 | 3 | Given a NxN size 2D array of numbers. Develop a way to rotate the data as if you rotated the data by 90 degrees clockwise. 4 | 5 | #Example: 6 | 7 | N = 3 8 | 9 | Data: 10 | 11 | 1 2 3 12 | 4 5 6 13 | 7 8 9 14 | 15 | Rotate 90 degrees: 16 | 17 | 7 4 1 18 | 8 5 2 19 | 9 6 3 20 | 21 | Rotate it again 90 degrees: 22 | 23 | 9 8 7 24 | 6 5 4 25 | 3 2 1 26 | 27 | #Challenge Input: 28 | 29 | N = 10 30 | 31 | 1 2 3 4 5 6 7 8 9 0 32 | 0 9 8 7 6 5 4 3 2 1 33 | 1 3 5 7 9 2 4 6 8 0 34 | 0 8 6 4 2 9 7 5 3 1 35 | 0 1 2 3 4 5 4 3 2 1 36 | 9 8 7 6 5 6 7 8 9 0 37 | 1 1 1 1 1 1 1 1 1 1 38 | 2 2 2 2 2 2 2 2 2 2 39 | 9 8 7 6 7 8 9 8 7 6 40 | 0 0 0 0 0 0 0 0 0 0 41 | 42 | #Optional: 43 | 44 | Show the 2D array at 90, 180, 270 degree clockwise from the original position. 45 | 46 | 47 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0323 Easy - 3SUM/challenge_text.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | In computational complexity theory, the 3SUM problem asks if a given set of *n* real numbers contains three elements that sum to zero. A naive solution works in O(N^2) time, and research efforts have been exploring the lower complexity bound for some time now. 4 | 5 | # Input Example 6 | 7 | You will be given a list of integers, one set per line. Example: 8 | 9 | 9 -6 -5 9 8 3 -4 8 1 7 -4 9 -9 1 9 -9 9 4 -6 -8 10 | 11 | # Output Example 12 | 13 | Your program should emit triplets of numbers that sum to 0. Example: 14 | 15 | -9 1 8 16 | -8 1 7 17 | -5 -4 9 18 | -5 1 4 19 | -4 1 3 20 | -4 -4 8 21 | 22 | # Challenge Input 23 | 24 | 4 5 -1 -2 -7 2 -5 -3 -7 -3 1 25 | -1 -6 -3 -7 5 -8 2 -8 1 26 | -5 -1 -4 2 9 -9 -6 -1 -7 27 | 28 | # Challenge Output 29 | 30 | -7 2 5 31 | -5 1 4 32 | -3 -2 5 33 | -3 -1 4 34 | -3 1 2 35 | 36 | -7 2 5 37 | -6 1 5 38 | -3 1 2 39 | 40 | -5 -4 9 41 | -1 -1 2 42 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0109 Hard - (Steiner Inellipse)/challenge_text.md: -------------------------------------------------------------------------------- 1 | For the difficult challenge, you must find the [Steiner Inellipse](http://en.wikipedia.org/wiki/Steiner_inellipse) of a triangle. The Steiner Inellipse is the ellipse within a triangle that has the maximum area, without exceeding the bounds of the triangle. 2 | 3 | For example: [here is an image of a typical inellipse.](http://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Steiner_Inellipse.svg/250px-Steiner_Inellipse.svg.png) 4 | 5 | For your input, you will be given the three coordinates of a triangle. They are: 6 | 7 | * Coord 1: (0,2) 8 | * Coord 2: (0,7) 9 | * Coord 3: (7,0) 10 | 11 | For your output, you have two options: either use some sort of graphical implementation to draw the found ellipse, or output the equation of that elipse. 12 | 13 | Any further information can be found [here](http://projecteuler.net/problem=385) at a similar problem on projecteuler.net. 14 | 15 | Good luck, and have fun! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0203 Easy - The Start of Something Big/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description 2 | All great things start with something small. Sometimes people [don't even realise what goes into making a 'small' thing](http://rampantgames.com/blog/?p=7745). 3 | 4 | A popular story is linked above about a group of graphics programmers who create a rendering engine in some amount of time. After some time HR came to see what the programmers had accomplished. They responded by showing a black triangle on a tv. 5 | 6 | HR was less than impressed (understandle for a non techie) but it goes to show the natural evolution of a program. What they didn't realise is that the programmers have created their base engine and can now easily add and extend on top of it. 7 | 8 | Maybe you can follow similar steps? 9 | 10 | #Challenge 11 | 12 | On your screen, display a square. 13 | 14 | You may use any libraries available to you. 15 | 16 | The square may be of any size and of any colour. 17 | 18 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0101 Hard - (Boolean Minimization)/challenge_text.md: -------------------------------------------------------------------------------- 1 | For difficult 101, I thought I'd do something with binary in it. 2 | 3 | Write a program that reads in a file containing 2^n 0s and 1s as ascii characters. You will have to solve for N given the number of 0s and 1s in the file, 4 | as it will not be given in the file. These 0s and 1s are to be interpreted as the outputs of a truth table in N variables. 5 | 6 | Given this truth table, output a minimal boolean expression of the function in some form. ( 7 | [Hint1](http://en.wikipedia.org/wiki/Quine%E2%80%93McCluskey_algorithm), [hint2](http://en.wikipedia.org/wiki/Karnaugh_map)) 8 | 9 | For example, one implementation could read in this input file 10 | 11 | 0000010111111110 12 | 13 | This is a 4-variable boolean function with the given truth table. The program could minimize the formula, and could output 14 | 15 | f(abcd)=ac'+ab'+bcd' 16 | 17 | or 18 | 19 | f(0123)=02'+01'+123' -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0004 Easy/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # generates random passwords / hexstrings 2 | # works on Python 3. written by kbrgl. 3 | import string 4 | from random import randint 5 | 6 | class PasswordGenerator: 7 | """generates a random password""" 8 | def __init__(self, acceptable_characters=string.hexdigits): 9 | self.acceptable_characters = acceptable_characters 10 | 11 | def generate(self, length=4, n=1): 12 | return [self.random_blob(length) for _ in range(n)] 13 | 14 | def random_blob(self, length): 15 | result = [] 16 | for _ in range(length): 17 | result.append(self.acceptable_characters[randint(0, (len(self.acceptable_characters) - 1))]) 18 | return ''.join(result) 19 | 20 | 21 | if __name__ == '__main__': 22 | generator = PasswordGenerator() 23 | n = input("number of passwords: ") 24 | length = input("how long: ") 25 | for password in generator.generate(int(length), int(n)): 26 | print(password) 27 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0002 Easy/solutions/solution.m: -------------------------------------------------------------------------------- 1 | %Author: Evilk9 (github.com/evilk9) 2 | 3 | fprintf('Newtons Second Law Of Motion Calculator\n'); 4 | fprintf('What do you need to calculate?'); 5 | decision = input('\n (1)Force \n (2) Mass \n (3) Acceleration: '); 6 | 7 | if(decision == 1) 8 | mass = input('Enter Mass(kg): '); 9 | acceleration = input('Enter Acceleration(m/s^2): '); 10 | 11 | force = mass * acceleration; 12 | fprintf('The Force is: %d N', force); 13 | end 14 | 15 | if(decision ==2) 16 | force = input('Enter Force(N): '); 17 | acceleration = input('Enter Acceleration(m/s^2): '); 18 | mass = force/acceleration; 19 | fprintf('The Mass is: %d Kg', mass); 20 | end 21 | 22 | if(decision ==3) 23 | force = input('Enter Force(N): '); 24 | mass = input('Enter Mass(kg): '); 25 | acceleration = force/mass; 26 | fprintf('The Acceleration is: %d m/s^2', acceleration); 27 | end 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0111 Hard - The Josephus Problem/challenge_text.md: -------------------------------------------------------------------------------- 1 | Flavius Josephus was a roman historian of Jewish origin. During the Jewish-Roman wars of the first century AD, he was in a cave with fellow soldiers, 41 men in all, surrounded by enemy Roman troops. They decided to commit suicide by standing in a ring and counting off each third man. Each man so designated was to commit suicide. (When the count came back around the ring, soldiers who had already committed suicide were skipped in the counting.) Josephus, not wanting to die, placed himself in position #31, which was the last position to be chosen. 2 | 3 | In the general version of the problem, there are n soldiers numbered from 1 to n and each k-th soldier will be eliminated. The count starts from the first soldier. Write a function to find, given n and k, the number of the last survivor. For example, `josephus(41, 3) = 31`. Find `josephus(123456789101112, 13)`. 4 | 5 | Thanks to user __zebuilin__ for suggesting this problem in /r/dailyprogrammer_ideas! -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0122 Easy - Words With Ordered Vowels/challenge_text.md: -------------------------------------------------------------------------------- 1 | 2 | # [](#EasyIcon) *(Easy)*: Words With Ordered Vowels 3 | Find words in a word list that contain all the vowels in alphabetical 4 | order, non-repeated, where vowels are defined as A E I O U Y. 5 | 6 | *Author: ikea_riot* 7 | # Formal Inputs & Outputs 8 | ## Input Description 9 | A text file with one word on each line. 10 | ## Output Description 11 | All words in the list that contains all the vowels A E I O U Y in alphabetical order. 12 | # Sample Inputs & Outputs 13 | ## Sample Input 14 | Use [this word list](http://code.google.com/p/dotnetperls-controls/downloads/detail?name=enable1.txt) 15 | ## Sample Output 16 | abstemiously 17 | ... 18 | # Challenge Input 19 | Nothing special, see sample input 20 | ## Challenge Input Solution 21 | Nothing special, see sample output 22 | # Note 23 | We are starting to fill the queue with new challenges! Please help out by posting suggestions to /r/dailyprogrammer_ideas 24 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0321 Easy - Talking Clock/challenge_text.md: -------------------------------------------------------------------------------- 1 | 2 | **Description** 3 | 4 | No more hiding from your alarm clock! You've decided you want your computer to keep you updated on the time so you're never late again. A talking clock takes a 24-hour time and translates it into words. 5 | 6 | 7 | **Input Description** 8 | 9 | An hour (0-23) followed by a colon followed by the minute (0-59). 10 | 11 | 12 | **Output Description** 13 | 14 | The time in words, using 12-hour format followed by am or pm. 15 | 16 | 17 | **Sample Input data** 18 | 19 | 00:00 20 | 01:30 21 | 12:05 22 | 14:01 23 | 20:29 24 | 21:00 25 | 26 | 27 | **Sample Output data** 28 | 29 | It's twelve am 30 | It's one thirty am 31 | It's twelve oh five pm 32 | It's two oh one pm 33 | It's eight twenty nine pm 34 | It's nine pm 35 | 36 | 37 | **Extension challenges (optional)** 38 | 39 | Use the audio clips [found here](http://steve-audio.net/voices/) to give your clock a voice. 40 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0006 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | create a program that can remove all duplicate strings from a .txt. file. for example, "bdbdb" -> "bd" 2 | _______________________________________________________________________________________________ 3 | 4 | **we are really sorry about this :(** .. I just woke up now and am looking at this disaster. We promise to give a bonus question soon ... 5 | 6 | for those who still have time, here is the modified question: 7 | 8 | remove duplicate substrings. 9 | 10 | Ex: aaajtestBlaBlatestBlaBla ---> aaajtestBlaBla 11 | 12 | another example: 13 | 14 | aaatestBlaBlatestBlaBla 15 | aaathisBlaBlathisBlaBla 16 | aaathatBlaBlathatBlaBla 17 | aaagoodBlaBlagoodBlaBla 18 | aaagood1BlaBla123good1BlaBla123 19 | 20 | output desired: 21 | aaatestBlaBla 22 | aaathisBlaBla 23 | aaathatBlaBla 24 | aaagoodBlaBla 25 | aaagood1BlaBla123 26 | 27 | I am really sorry for the vagueness. Hopefully will not be repeated again :( 28 | 29 | 30 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0262 Hard - 4x4 puzzle swapper/challenge_text.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | You have a 4x4 grid containing pieces numbered 1 to 16, of which you choose the order. To move the pieces you swap the positions of 2 pieces (this is not a slider puzzle - there's no open space). Tiles must be swapped with adjacent tiles. The goal to to solve the puzzle in as few moves as possible, showing all steps. The steps are which 2 pieces swap positions for each move. Pieces could be referred to by their position or their number. 4 | 5 | **Input #1** 6 | 7 | 8 | 9 | 4 6 2 14 10 | 11 | 15 8 13 1 12 | 13 | 10 5 9 12 14 | 15 | 7 11 16 3 16 | 17 | **the solved puzzle is:** 18 | 19 | 1 2 3 4 20 | 21 | 5 6 7 8 22 | 23 | 9 10 11 12 24 | 25 | 13 14 15 16 26 | 27 | It may be too hard to guarantee a solution in the fewest possible moves. You may instead use a strategy that is quick enough, if you want. 28 | 29 | # thanks 30 | 31 | thanks to /u/purpledesertowl for this idea that was submitted at /r/dailyprogrammer_ideas. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0114 Easy - Word ladder steps/challenge_text.md: -------------------------------------------------------------------------------- 1 | A word ladder is a sequence of words made by changing one letter at a time. For example: 2 | `cold → cord → card → ward → warm` 3 | Given a word, list all the words that can appear next to it in a word ladder, using [this list of 3,807 four-letter words][link1]. Sample input: 4 | ``` 5 | puma 6 | ``` 7 | Sample output: 8 | 9 | ``` 10 | duma 11 | pima 12 | puja 13 | pula 14 | pump 15 | puna 16 | pupa 17 | ``` 18 | How many words from the list can appear next to the word `best` in a word ladder? 19 | 20 | **Bonus 1:** One word in the list has 33 other words that can appear next to it. What is this word? 21 | 22 | **Bonus 2:** How many different words can be reached, starting from best, in 3 or fewer steps? 23 | 24 | Thanks to **Thomas1122** for suggesting this challenge on [/r/dailyprogrammer_ideas][link2]! 25 | 26 | [//]: # (reference links) 27 | [link1]: 28 | [link2]: 29 | 30 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0008 Easy/solutions/Solution.java: -------------------------------------------------------------------------------- 1 | 2 | public class Solution { 3 | 4 | 5 | public static void main(String[] args){ 6 | int count = 99; 7 | 8 | for(int i=count;i>0;i--){ 9 | if(count == 1){ 10 | System.out.println(count + " bottle of beer on the wall," + count + " bottle of beer.\nTake one down and pass it around, no more bottles of beer on the wall.\n"); 11 | } 12 | else if(count == 2){ 13 | System.out.println(count + " bottles of beer on the wall," + count + " bottles of beer.\nTake one down and pass it around, " + (count-1) + " bottle of beer on the wall.\n"); 14 | } 15 | else{ 16 | System.out.println(count + " bottles of beer on the wall," + count + " bottles of beer.\nTake one down and pass it around, " + (count-1) + " bottles of beer on the wall.\n"); 17 | } 18 | count--; 19 | } 20 | System.out.println("No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall."); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0045 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* 18/12/2016 */ 2 | 3 | function drawBoard(rows, cols, width, height){ 4 | var output = ""; 5 | 6 | for(var i = 0; i < rows; i++){ 7 | for(var j = 0; j < (width + 1) * cols + 1; j++){ 8 | output += "*"; 9 | } 10 | output += "\n"; 11 | for(var j = 0; j < height; j++){ 12 | for(var k = 0; k < cols; k++){ 13 | output += "*"; 14 | if( (!(i%2) && k%2) || (i%2 && !(k%2)) ){ 15 | for(l = 0; l < width; l++){ 16 | output += "#"; 17 | } 18 | }else{ 19 | for(l = 0; l < width; l++){ 20 | output += " "; 21 | } 22 | } 23 | } 24 | output += "*\n"; 25 | } 26 | } 27 | 28 | for(var j = 0; j < (width + 1) * cols + 1; j++){ 29 | output += "*"; 30 | } 31 | 32 | console.log(output); 33 | } 34 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0275 Easy - Splurthian Chemistry 101/solutions/solution.c: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | #include 3 | #include 4 | 5 | unsigned char validSymbol(char *n, char *s){ 6 | if(strlen(s) != 2) return 0; 7 | 8 | char name[50], symbol[3]; 9 | strcpy(name, n); 10 | strcpy(symbol, s); 11 | name[0] += 32; //making the first letter 12 | symbol[0] += 32; //of each string lowercase; 13 | for(int i=0, index=0, flag; i < 2; i++){ 14 | flag = 0; 15 | for(int j=index; j < strlen(name); j++){ 16 | if(symbol[i] == name[j]){ 17 | index = j+1; 18 | flag++; 19 | break; 20 | } 21 | } 22 | if(!flag) return 0; 23 | } 24 | return 1; 25 | } 26 | 27 | int main(int argc, char* argv[]){ 28 | printf("%s, %s -> %s\n", argv[1], 29 | argv[2], 30 | validSymbol(argv[1], argv[2]) ? "true" : "false"); 31 | } 32 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0058 Easy/solutions/solution.rs: -------------------------------------------------------------------------------- 1 | //tlseabra @github 2 | use std::env; 3 | 4 | static ASCII_UPPER: [char; 36] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 5 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 6 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 7 | 'U', 'V', 'W', 'X', 'Y', 'Z']; 8 | 9 | fn int_to_string(mut input: u64, radix: u64) -> String { 10 | if input == 0 { return String::from("0"); } 11 | 12 | let mut output = String::new(); 13 | 14 | while input > 0 { 15 | let c: char = *ASCII_UPPER.get((input%radix) as usize).unwrap(); 16 | output.push(c); 17 | input /= radix; 18 | } 19 | output.as_str().chars().rev().collect() 20 | } 21 | 22 | fn main() { 23 | let num: u64 = env::args().nth(1).unwrap().parse().unwrap(); 24 | let radix: u64 = env::args().nth(2).unwrap().parse().unwrap(); 25 | println!("{}", int_to_string(num, radix)); 26 | } 27 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0208 Easy - Culling Numbers/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Description: 2 | 3 | Numbers surround us. Almost too much sometimes. It would be good to just cut these numbers down and cull out the repeats. 4 | 5 | Given some numbers let us do some number "culling". 6 | 7 | #Input: 8 | 9 | You will be given many unsigned integers. 10 | 11 | #Output: 12 | 13 | Find the repeats and remove them. Then display the numbers again. 14 | 15 | #Example: 16 | 17 | Say you were given: 18 | 19 | * 1 1 2 2 3 3 4 4 20 | 21 | Your output would simply be: 22 | 23 | * 1 2 3 4 24 | 25 | #Challenge Inputs: 26 | 27 | ##1: 28 | 29 | 3 1 3 4 4 1 4 5 2 1 4 4 4 4 1 4 3 2 5 5 2 2 2 4 2 4 4 4 4 1 30 | 31 | ##2: 32 | 33 | 65 36 23 27 42 43 3 40 3 40 23 32 23 26 23 67 13 99 65 1 3 65 13 27 36 4 65 57 13 7 89 58 23 74 23 50 65 8 99 86 23 78 89 54 89 61 19 85 65 19 31 52 3 95 89 81 13 46 89 59 36 14 42 41 19 81 13 26 36 18 65 46 99 75 89 21 19 67 65 16 31 8 89 63 42 47 13 31 23 10 42 63 42 1 13 51 65 31 23 28 34 | 35 | -------------------------------------------------------------------------------- /Extra-Bonus Challenges/[Weekly] #1 -- Handling Console Input/challenge_text.md: -------------------------------------------------------------------------------- 1 | #Weekly Topic #1 2 | 3 | Often part of the challenges is getting the data into memory to solve the problem. A very easy way to handle it is hard code the challenge data. Another way is read from a file. 4 | 5 | 6 | For this week lets look at reading from a console. The user entered input. How do you go about it? Posting examples of languages and what your approach is to handling this. I would suggest start a thread on a language. And posting off that language comment. 7 | 8 | 9 | Some key points to keep in mind. 10 | 11 | * There are many ways to do things. 12 | * Keep an open mind 13 | * The key with this week topic is sharing insight/strategy to using console input in solutions. 14 | 15 | #Suggested Input to handle: 16 | 17 | Lets read in strings. we will give n the number of strings then the strings. 18 | 19 | ##Example: 20 | 21 | 5 22 | Huey 23 | Dewey 24 | Louie 25 | Donald 26 | Scrooge 27 | 28 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0081 Hard - (Matrix Exponential)/challenge_text.md: -------------------------------------------------------------------------------- 1 | For a lot of the questions today we are going to be doing some simple numerical calculus. Don't worry, its not too terrifying. 2 | 3 | Write a function that can calculate the [Matrix Exponential](http://en.wikipedia.org/wiki/Matrix_exponential) for a 4x4 (or nxn) matrix. This function is extremely valuable for lots of different scientific areas. 4 | 5 | There are [LOTS of ways to do it!](http://www.cs.cornell.edu/cv/researchpdf/19ways+.pdf) 6 | 7 | For testing, here is a matrix. 8 | 9 | 0.00000 -1.00000 3.00000 0.50000 10 | 1.00000 0.00000 0.45000 0.10000 11 | -3.00000 -0.45000 0.00000 0.40000 12 | -0.50000 -0.10000 -0.40000 0.00000 13 | 14 | And the resulting matrix exponential (as computed by GNU Octave) 15 | 16 | -0.9276446 -0.2437849 -0.2285533 0.1667568 17 | -0.2809791 0.7661246 0.5148905 0.2626626 18 | -0.0150871 0.5946104 -0.7613132 -0.2580951 19 | 0.2455577 -0.0077772 -0.3210194 0.9146516 -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0038 Intermediate/challenge_text.md: -------------------------------------------------------------------------------- 1 | # *(Intermediate):* Challenge #38 2 | [Reverse Polish Notation(RPN)](http://en.wikipedia.org/wiki/Reverse_Polish_notation) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand; so the expression written "3 − 4 + 5" would be written "3 4 − 5 +" first subtract 4 from 3, then add 5 to that. 3 | 4 | Transform the algebraic expression with brackets into RPN form. 5 | 6 | You can assume that for the test cases below only single letters will be used, brackets [ ] will not be used and each expression has only one RPN form (no expressions like abc) 7 | 8 | # Sample input 9 | ``` 10 | (a+(b*c)) 11 | ((a+b)*(z+x)) 12 | ((a+t)*((b+(a+c)) ^ (c+d))) 13 | ``` 14 | 15 | # Sample output 16 | ``` 17 | abc*+ 18 | ab+zx+* 19 | at+bac++cd+ ^ * 20 | ``` 21 | 22 | ### Credits 23 | *Author: rya11111* 24 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0021 Easy/solutions/solution.js: -------------------------------------------------------------------------------- 1 | /* https://github.com/tlseabra */ 2 | 3 | function strPerm(rest, soFar, total) { 4 | var next, 5 | remaining, 6 | i; 7 | 8 | if (rest == "") 9 | total.push(parseInt(soFar)); 10 | 11 | else { 12 | for (i = 0; i < rest.length; i++) { 13 | remaining = rest.substr(0,i) + rest.substr(i+1,rest.length-1); 14 | next = soFar + rest[i]; 15 | strPerm(remaining, next, total); //recursion is weird 16 | } 17 | } 18 | } 19 | 20 | function nextInteger(input){ 21 | var numberStr = input.toString(); 22 | var total = [], uniques = []; 23 | 24 | strPerm(numberStr,"", total); 25 | total.sort(function(a, b){return a-b}); 26 | 27 | for(var i=0; i < total.length; i++){ 28 | if( uniques.indexOf(total[i]) === -1) 29 | uniques.push(total[i]); 30 | } 31 | 32 | if(uniques.indexOf(input) + 1 == uniques.length) 33 | return input; 34 | else 35 | return uniques[ uniques.indexOf(input) + 1 ]; 36 | } 37 | -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0104 Intermediate - (Bracket Racket)/challenge_text.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | Write a function, where given a string of arbitrary characters, returns true if all brackets ([defined as parentheses, square-brackets, curly-braces, and chevrons](http://en.wikipedia.org/wiki/Bracket)) are correctly paired and ordered. This is to say that all brackets, if they enclose other brackets, enclose both the paired opening and closing characters. 4 | 5 | **Formal Inputs & Outputs:** 6 | 7 | *Input Description:* 8 | 9 | string data - a given string that may or may not have correctly formed brackets. 10 | 11 | *Output Description:* 12 | 13 | Return True or False - true if the given string is correctly bracket formed. 14 | 15 | **Sample Inputs & Outputs:** 16 | 17 | "123", "(abc)", "()abc()", and "([<{abc123abc}>])" should return true, but "(abc[123)abc]" (wrong pairing) and "(abc>" (not closed) should return false. 18 | 19 | **Notes:** 20 | 21 | This is a very easy problem if you use a specific primitive data-structure. -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0018 Easy/solutions/solution2.py: -------------------------------------------------------------------------------- 1 | ########################################### 2 | ## Python 2. Uses multi-key-dict module. ## 3 | ########################################### 4 | 5 | from multi_key_dict import multi_key_dict 6 | 7 | two = three = four = five = six = seven = eight = nine = multi_key_dict() 8 | 9 | two['A', 'B', 'C'] = '2' 10 | three['D', 'E', 'F'] = '3' 11 | four['G', 'H', 'I'] = '4' 12 | five['J','K' 'L'] = '5' 13 | six['M', 'N', 'O'] = '6' 14 | seven['P', 'Q', 'R', 'S'] = '7' 15 | eight['T', 'U', 'V'] = '8' 16 | nine['W','X','Y', 'Z'] = '9' 17 | 18 | def request(): 19 | print "Enter telephone number (7 letters)" 20 | number = raw_input('1-800-') 21 | return number.upper() 22 | 23 | def decrypt(number): 24 | d = '1-800-' 25 | for i in range(0,7): 26 | d = d + two[number[i]] 27 | if i == 2: #add dash 28 | d = d + '-' 29 | 30 | return d 31 | 32 | def main(): 33 | try: 34 | number = request() 35 | decrypted = decrypt(number) 36 | print "Decrypted: %s" % decrypted 37 | except: 38 | pass 39 | main() 40 | -------------------------------------------------------------------------------- /Easy Challenges/Challenge 0052 Easy/challenge_text.md: -------------------------------------------------------------------------------- 1 | Imagine each letter and its position within the alphabet. Now assign each letter its corresponding value ie a=1, b=2,... z=26. When given a list of words, order the words by the sum of the values of the letters in their names. 2 | 3 | Example: Shoe and Hat 4 | 5 | Hat: 8+1+20 = 29 6 | 7 | Shoe: 19+8+15+5 = 47 8 | 9 | So the order would be Hat, Shoe. 10 | 11 | For extra points, divide by the sum by the number of letters in that word and then rank them. 12 | 13 | thanks to SpontaneousHam for the challenge at /r/dailyprogrammer_ideas .. [link](http://www.reddit.com/r/dailyprogrammer_ideas/comments/smqa2/intermediate_organising_words_in_a_specific_way/) 14 | 15 | __________________________________________________________________________________ 16 | 17 | Please note that [difficult] challenge has been changed since it was already asked 18 | 19 | http://www.reddit.com/r/dailyprogrammer/comments/tmnfn/5142012_challenge_52_difficult/ 20 | 21 | fortunately, someone informed it very early :) 22 | -------------------------------------------------------------------------------- /Easy Challenges/[Easy] Longest Two-Character Sub-String/challenge_text.md: -------------------------------------------------------------------------------- 1 | # [](#EasyIcon) *(Easy)*: Longest Two-Character Sub-String 2 | 3 | This programming challenge is a [classic](http://en.wikipedia.org/wiki/Longest_common_substring_problem) interview question for software engineers: given a string, find the longest sub-string that contains, at most, two characters. 4 | 5 | *Author: /u/Regul* 6 | 7 | # Formal Inputs & Outputs 8 | ## Input Description 9 | 10 | Through standard console input, you will be given a string to search, which only contains lower-case alphabet letters. 11 | 12 | ## Output Description 13 | 14 | Simply print the longest sub-string of the given string that contains, at most, two unique characters. If you find multiple sub-strings that match the description, print the last sub-string (furthest to the right). 15 | 16 | # Sample Inputs & Outputs 17 | ## Sample Inputs 18 | 19 | abbccc 20 | abcabcabcabccc 21 | qwertyytrewq 22 | 23 | ## Sample Outputs 24 | 25 | bbccc 26 | bccc 27 | tyyt 28 | -------------------------------------------------------------------------------- /Extra-Bonus Challenges/Weekly #26 - Mini Challenges/challenge_text.md: -------------------------------------------------------------------------------- 1 | So this week, let's do some mini challenges. Too small for an easy but great for a mini challenge. Here is your chance to post some good warm up mini challenges. How it works. Start a new main thread in here. 2 | 3 | if you post a challenge, here's a template from /u/lengau for anyone wanting to post challenges (you can copy/paste this text rather than having to get the source): 4 | 5 | `**[CHALLENGE NAME]** - [CHALLENGE DESCRIPTION]` 6 | 7 | ` ` 8 | 9 | `**Given:** [INPUT DESCRIPTION]` 10 | 11 | ` ` 12 | 13 | `**Output:** [EXPECTED OUTPUT DESCRIPTION]` 14 | 15 | ` ` 16 | 17 | `**Special:** [ANY POSSIBLE SPECIAL INSTRUCTIONS]` 18 | 19 | ` ` 20 | 21 | `**Challenge input:** [SAMPLE INPUT]` 22 | 23 | ` ` 24 | 25 | If you want to solve a mini challenge you reply in that thread. Simple. Keep checking back all week as people will keep posting challenges and solve the ones you want. 26 | 27 | Please check other mini challenges before posting one to avoid duplications within a certain reason. 28 | -------------------------------------------------------------------------------- /Hard Challenges/Challenge 0051 Hard/challenge_text.md: -------------------------------------------------------------------------------- 1 | Take a 7x7 grid of cells and remove the central cell (like a chessboard, but slightly smaller and with a hole in the middle), and it would look something [like this](http://i.imgur.com/UXtTA.png). The number of cells is 7*7 - 1 = 48 because we removed the central cell. 2 | 3 | Now, lets start tiling this grid with dominoes. Each domino covers exactly two cells that are either horizontally or vertically next to each other, so if you are going to tile the whole 4 | thing with dominoes, you would need 24 of them (48 over 2). [Here is an example](http://i.imgur.com/NmD8m.png) of the grid being perfectly tiled by dominoes. There are exactly 75272 ways you can use dominoes to tile a 7x7 grid with the central cell removed. 5 | 6 | Find the last 8 digits of the number of ways you can use dominoes to tile a 15x15 grid with the central cell removed. 7 | 8 | Note: rotations and reflections of tilings count as distinct tilings. I.e. if two tilings differ only by rotation or reflection, they are still considered to be different. -------------------------------------------------------------------------------- /Intermediate Challenges/Challenge 0139 Intermediate - Telephone Keypads/solutions/solution.py: -------------------------------------------------------------------------------- 1 | # @Author: Ouss4 2 | # @Github: github.com/Ouss4 3 | # @Date: 14/05/2016 4 | # @Description: Solution for Intermediate 0139. 5 | 6 | def T9ToText(text): 7 | """ 8 | 1) Take one element (They are all the same ex. 7777 = 7). 9 | 2) Take times the number was pressed (ex. 7777 = 4). 10 | 3) Translate it (ex. 7777: from (1) & (2) => translator[7][4] = 's') 11 | """ 12 | translator = {2:'abc', 3:'def', 4:'ghi', 5:'jkl', 13 | 6:'mno', 7:'pqrs', 8:'tuv', 9:'wxyz'} 14 | 15 | return "".join([translator[int(i[0])][len(i) - 1] for i in text.split()]) 16 | 17 | theWord = T9ToText("7777 666 555 3") 18 | fileName = "dict.txt" 19 | 20 | with open(fileName, "r") as inputFile: 21 | # Read the file and remove the last \n 22 | fileContent = inputFile.read().split("\n")[:-1] 23 | 24 | for text in fileContent: 25 | if text.lower().startswith(theWord): 26 | print(text) 27 | 28 | --------------------------------------------------------------------------------