├── .gitignore ├── .gitmodules ├── .hr_conf.yaml ├── .travis.yml ├── .vscode ├── .cmaketools.json ├── bashrc ├── c_cpp_properties.json ├── launch.json ├── settings.json └── tasks.json ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── _config.yml ├── algorithms ├── CMakeLists.txt ├── README.md ├── algo-debugging │ ├── CMakeLists.txt │ ├── README.md │ ├── prime-date.cpp │ ├── prime-date.java │ ├── prime-date.py │ ├── zig-zag-sequence.cpp │ ├── zig-zag-sequence.java │ └── zig-zag-sequence.py ├── arrays-and-sorting │ ├── CMakeLists.txt │ ├── README.md │ ├── big-sorting.py │ ├── closest-numbers.py │ ├── correctness-invariant.py │ ├── countingsort1.py │ ├── countingsort2.py │ ├── countingsort4.py │ ├── find-the-median.py │ ├── insertion-sort.cpp │ ├── insertion-sort.py │ ├── insertionsort1.py │ ├── insertionsort2.py │ ├── quicksort1.py │ ├── runningtime.py │ └── tutorial-intro.py ├── bit-manipulation │ ├── CMakeLists.txt │ ├── README.md │ ├── aorb.py │ ├── counter-game.py │ ├── flipping-bits.cpp │ ├── hamming-distance.cpp │ ├── lonely-integer.py │ ├── maximizing-xor.py │ └── the-great-xor.cpp ├── constructive-algorithms │ ├── CMakeLists.txt │ ├── README.md │ └── new-year-chaos.py ├── dynamic-programming │ ├── CMakeLists.txt │ ├── README.md │ ├── dorsey-thief.cpp │ ├── fibonacci-modified.py │ └── longest-increasing-subsequent.cpp ├── game-theory │ ├── CMakeLists.txt │ ├── README.md │ └── game-of-stones-1.py ├── greedy │ ├── CMakeLists.txt │ ├── README.md │ ├── beautiful-pairs.py │ ├── grid-challenge.py │ ├── marcs-cakewalk.py │ ├── maximum-perimeter-triangle.cpp │ ├── minimum-absolute-difference-in-an-array.py │ └── sherlock-and-the-beast.py ├── implementation │ ├── CMakeLists.txt │ ├── README.md │ ├── absolute-permutation.py │ ├── acm-icpc-team.py │ ├── almost-sorted.py │ ├── angry-professor.py │ ├── append-and-delete.py │ ├── apple-and-orange.py │ ├── beautiful-days-at-the-movies.py │ ├── beautiful-triplets.py │ ├── between-two-sets.py │ ├── bigger-is-greater.py │ ├── bon-appetit.py │ ├── breaking-best-and-worst-records.py │ ├── cats-and-a-mouse.py │ ├── cavity-map.cpp │ ├── chocolate-feast.py │ ├── circular-array-rotation.py │ ├── climbing-the-leaderboard.py │ ├── counting-valleys.cpp │ ├── cut-the-sticks.py │ ├── day-of-the-programmer.py │ ├── designer-pdf-viewer.py │ ├── divisible-sum-pairs.py │ ├── drawing-book.py │ ├── electronics-shop.cpp │ ├── encryption.py │ ├── equality-in-a-array.py │ ├── extra-long-factorials.hs │ ├── extra-long-factorials.py │ ├── fair-rations.py │ ├── find-digits.py │ ├── flatland-space-stations.py │ ├── grading.py │ ├── halloween-sale.py │ ├── happy-ladybugs.py │ ├── jumping-on-the-clouds-revisited.py │ ├── jumping-on-the-clouds.py │ ├── kangaroo.py │ ├── kaprekar-numbers.py │ ├── larrys-array.py │ ├── library-fine.py │ ├── lisa-workbook.py │ ├── magic-square-forming.py │ ├── manasa-and-stones.py │ ├── matrix-rotation-algo.py │ ├── migratory-birds.py │ ├── minimum-distances.py │ ├── non-divisible-subset.py │ ├── organizing-containers-of-balls.py │ ├── permutation-equation.py │ ├── picking-numbers.py │ ├── queens-attack-2.py │ ├── repeated-string.py │ ├── save-the-prisoner.py │ ├── service-lane.py │ ├── sherlock-and-squares.py │ ├── sock-merchant.py │ ├── strange-advertising.py │ ├── strange-code.py │ ├── taum-and-bday.py │ ├── the-birthday-bar.py │ ├── the-grid-search.py │ ├── the-hurdle-race.py │ ├── the-time-in-words.py │ ├── two-pluses.cpp │ └── utopian-tree.py ├── search │ ├── CMakeLists.txt │ ├── README.md │ ├── hackerland-radio-transmitters.py │ ├── icecream-parlor.py │ ├── missing-numbers.py │ ├── pairs.py │ └── sherlock-and-array.py ├── strings │ ├── CMakeLists.txt │ ├── README.md │ ├── alternating-characters.py │ ├── anagram.py │ ├── beautiful-binary-string.py │ ├── caesar-cipher-1.py │ ├── camelcase.py │ ├── common-child.cpp │ ├── common-child.py │ ├── determining-dna-health.py │ ├── funny-string.py │ ├── game-of-thrones.py │ ├── gem-stones.py │ ├── hackerrank-in-a-string.py │ ├── making-anagrams.py │ ├── mars-exploration.py │ ├── morgan-and-a-string.c │ ├── palindrome-index.py │ ├── pangrams.py │ ├── reduced-string.py │ ├── richie-rich.py │ ├── separate-the-numbers.py │ ├── sherlock-and-anagrams.py │ ├── sherlock-and-valid-string.py │ ├── string-construction.py │ ├── strong-password.py │ ├── the-love-letter-mystery.py │ ├── two-characters.py │ ├── two-strings.py │ └── weighted-uniform-string.py └── warmup │ ├── CMakeLists.txt │ ├── README.md │ ├── a-very-big-sum.py │ ├── birthday-cake-candles.py │ ├── compare-the-triplets.cpp │ ├── compare-the-triplets.py │ ├── diagonal-difference.py │ ├── mini-max-sum.py │ ├── plus-minus.py │ ├── simple-array-sum.cpp │ ├── simple-array-sum.py │ ├── solve-me-first.cpp │ ├── solve-me-first.hs │ ├── solve-me-first.java │ ├── solve-me-first.js │ ├── solve-me-first.py │ ├── solve-me-first.sh │ ├── staircase.py │ └── time-conversion.py ├── c ├── CMakeLists.txt ├── README.md ├── c-arrays-and-strings │ ├── 1d-arrays-in-c.c │ ├── CMakeLists.txt │ ├── README.md │ ├── dynamic-array-in-c.c │ ├── frequency-of-digits-1.c │ ├── printing-tokens-.c │ └── reverse-array-c.c ├── c-conditionals-and-loops │ ├── CMakeLists.txt │ ├── README.md │ ├── bitwise-operators-in-c.c │ ├── conditional-statements-in-c.c │ ├── for-loop-in-c.c │ ├── printing-pattern-2.c │ └── sum-of-digits-of-a-five-digit-number.c ├── c-functions │ ├── CMakeLists.txt │ ├── README.md │ ├── permutations-of-strings.c │ ├── querying-the-document.c │ ├── recursion-in-c.c │ ├── sorting-array-of-strings.c │ ├── students-marks-sum.c │ └── variadic-functions-in-c.c ├── c-introduction │ ├── CMakeLists.txt │ ├── README.md │ ├── functions-in-c.c │ ├── hello-world-c.c │ ├── playing-with-characters.c │ ├── pointer-in-c.c │ └── sum-numbers-c.c └── c-structs-and-enums │ ├── CMakeLists.txt │ ├── README.md │ ├── post-transition.c │ ├── small-triangles-large-triangles.c │ ├── structuring-the-document.c │ └── too-high-boxes.c ├── coding-dojo ├── CoderDojo_Logo.png ├── README.md ├── README.md.in ├── bitset-1.cpp ├── detect-whether-a-linked-list-contains-a-cycle.cpp ├── detecting-valid-latitude-and-longitude.py ├── equal-stacks.py ├── ip-address-validation.py ├── largest-rectangle.py ├── maximum-element.cpp ├── missing-numbers.py ├── tree-huffman-decoding.cpp └── validating-credit-card-number.py ├── compare.py ├── contests ├── CMakeLists.txt ├── README.md ├── infinitum11 │ ├── CMakeLists.txt │ ├── README.md │ ├── fibonacci-gcd-again.cpp │ └── fibonacci-gcd-again.py ├── openbracket-2017 │ ├── CMakeLists.txt │ ├── README.md │ └── because-owlery-is-too-lazy.py ├── projecteuler │ ├── CMakeLists.txt │ ├── README.md │ ├── euler001.py │ ├── euler002.cpp │ ├── euler003.cpp │ ├── euler004.cpp │ ├── euler005.py │ ├── euler006.py │ ├── euler007.py │ ├── euler008.py │ ├── euler009.cpp │ ├── euler009.py │ ├── euler010.py │ ├── euler011.py │ ├── euler012.py │ ├── euler013.py │ ├── euler015.py │ ├── euler016.py │ ├── euler017.py │ ├── euler018.py │ ├── euler020.py │ ├── euler021.cpp │ ├── euler028.py │ ├── euler031.py │ ├── euler054.py │ ├── euler071.py │ ├── euler072.py │ ├── euler074.cpp │ ├── euler081.cpp │ ├── euler108.py │ └── euler110.py ├── rookierank │ ├── CMakeLists.txt │ ├── README.md │ └── antiprime-numbers.py └── womens-codesprint-3 │ ├── CMakeLists.txt │ ├── README.md │ └── ascii-flower.py ├── cpp ├── CMakeLists.txt ├── README.md ├── classes │ ├── CMakeLists.txt │ ├── README.md │ ├── abstract-classes-polymorphism.cpp │ ├── box-it.cpp │ ├── c-tutorial-class.cpp │ ├── c-tutorial-struct.cpp │ ├── classes-objects.cpp │ ├── exceptional-server.cpp │ ├── inherited-code.cpp │ └── virtual-functions.cpp ├── cpp-debugging │ ├── CMakeLists.txt │ ├── README.md │ ├── cpp-exception-handling.cpp │ ├── hotel-prices.cpp │ ├── messages-order.cpp │ └── overloading-ostream-operator.cpp ├── cpp-introduction │ ├── CMakeLists.txt │ ├── README.md │ ├── arrays-introduction.cpp │ ├── c-tutorial-basic-data-types.cpp │ ├── c-tutorial-conditional-if-else.cpp │ ├── c-tutorial-for-loop.cpp │ ├── c-tutorial-functions.cpp │ ├── c-tutorial-pointer.cpp │ ├── cpp-hello-world.cpp │ ├── cpp-input-and-output.cpp │ └── variable-sized-arrays.cpp ├── cpp-strings │ ├── CMakeLists.txt │ ├── README.md │ ├── attribute-parser.cpp │ ├── c-tutorial-strings.cpp │ └── c-tutorial-stringstream.cpp ├── inheritance │ ├── CMakeLists.txt │ ├── README.md │ ├── accessing-inherited-functions.cpp │ ├── inheritance-introduction.cpp │ ├── magic-spells.cpp │ ├── multi-level-inheritance-cpp.cpp │ └── rectangle-area.cpp ├── other-concepts │ ├── CMakeLists.txt │ ├── README.md │ ├── attending-workshops.cpp │ ├── bitset-1.cpp │ ├── c-class-templates.cpp │ ├── cpp-class-template-specialization.cpp │ ├── cpp-variadics.cpp │ ├── operator-overloading.cpp │ ├── overload-operators.cpp │ └── preprocessor-solution.cpp └── stl │ ├── CMakeLists.txt │ ├── README.md │ ├── cpp-lower-bound.cpp │ ├── cpp-maps.cpp │ ├── cpp-sets.cpp │ ├── deque-stl.cpp │ ├── prettyprint.cpp │ ├── vector-erase.cpp │ └── vector-sort.cpp ├── data-structures ├── CMakeLists.txt ├── README.md ├── arrays │ ├── 2d-array.py │ ├── CMakeLists.txt │ ├── README.md │ ├── array-left-rotation.py │ ├── arrays-ds.cpp │ ├── arrays-ds.py │ ├── crush.py │ ├── dynamic-array.py │ └── sparse-arrays.py ├── heap │ ├── CMakeLists.txt │ ├── README.md │ ├── find-the-running-median.py │ ├── jesse-and-cookies.py │ └── qheap1.py ├── linked-lists │ ├── CMakeLists.txt │ ├── README.md │ ├── compare-two-linked-lists.cpp │ ├── delete-a-node-from-a-linked-list.cpp │ ├── delete-duplicate-value-nodes-from-a-sorted-linked-list.cpp │ ├── detect-whether-a-linked-list-contains-a-cycle.cpp │ ├── find-the-merge-point-of-two-joined-linked-lists.cpp │ ├── get-the-value-of-the-node-at-a-specific-position-from-the-tail.py │ ├── insert-a-node-at-a-specific-position-in-a-linked-list.cpp │ ├── insert-a-node-at-the-head-of-a-linked-list.cpp │ ├── insert-a-node-at-the-tail-of-a-linked-list.cpp │ ├── insert-a-node-into-a-sorted-doubly-linked-list.cpp │ ├── linked-list.hpp │ ├── merge-two-sorted-linked-lists.cpp │ ├── print-the-elements-of-a-linked-list-in-reverse.cpp │ ├── print-the-elements-of-a-linked-list.cpp │ ├── reverse-a-doubly-linked-list.py │ └── reverse-a-linked-list.cpp ├── queues │ ├── CMakeLists.txt │ ├── README.md │ └── queue-using-two-stacks.py ├── stacks │ ├── CMakeLists.txt │ ├── README.md │ ├── balanced-brackets.py │ ├── equal-stacks.py │ ├── largest-rectangle.py │ ├── maximum-element.cpp │ └── simple-text-editor.py ├── trees │ ├── CMakeLists.txt │ ├── README.md │ ├── array-pairs.py │ ├── binary-search-tree-insertion.cpp │ ├── binary-search-tree-insertion.hpp │ ├── binary-search-tree-lowest-common-ancestor.cpp │ ├── tree-height-of-a-binary-tree.cpp │ ├── tree-height-of-a-binary-tree.py │ ├── tree-huffman-decoding.cpp │ ├── tree-inorder-traversal.cpp │ ├── tree-level-order-traversal.cpp │ ├── tree-postorder-traversal.cpp │ ├── tree-preorder-traversal.cpp │ ├── tree-top-view.cpp │ └── tree.hpp └── trie │ ├── CMakeLists.txt │ ├── README.md │ ├── contacts.py │ └── no-prefix-set.py ├── databases ├── README.md ├── database-normalization │ ├── README.md │ └── database-normalization-1-1nf.txt └── relational-algebra │ ├── README.md │ ├── basics-of-sets-and-relational-algebra-1.txt │ ├── basics-of-sets-and-relational-algebra-2.txt │ ├── basics-of-sets-and-relational-algebra-3.txt │ ├── basics-of-sets-and-relational-algebra-4.txt │ ├── basics-of-sets-and-relational-algebra-5.txt │ ├── basics-of-sets-and-relational-algebra-6.txt │ ├── basics-of-sets-and-relational-algebra-7.txt │ ├── database-query-languages.txt │ ├── procedural-language.txt │ ├── relational-algebra-3.txt │ ├── relational-algebra-4.txt │ ├── relations-1.txt │ └── relations-2.txt ├── distributed-systems ├── README.md └── distributed-mcq │ ├── CMakeLists.txt │ ├── README.md │ ├── mcq-challenge-10.txt │ ├── mcq-challenge-11.txt │ ├── mcq-challenge-13.txt │ ├── mcq-challenge-14.txt │ ├── mcq-challenge-7.txt │ ├── mcq-challenge-8.txt │ └── mcq-challenge-9.txt ├── fp ├── CMakeLists.txt ├── README.md └── intro │ ├── CMakeLists.txt │ ├── README.md │ ├── fp-hello-world-n-times.hs │ ├── fp-hello-world.erl │ ├── fp-hello-world.hs │ └── fp-solve-me-first.hs ├── hr_count.py ├── hr_db.py ├── hr_github.sh ├── hr_interview.py ├── hr_menu.py ├── hr_offline.py ├── hr_table.py ├── hrinit.py ├── hrtc2.py ├── interview-preparation-kit ├── CMakeLists.txt ├── README.md ├── arrays │ ├── 2d-array.py │ ├── CMakeLists.txt │ ├── README.md │ ├── crush.py │ ├── ctci-array-left-rotation.py │ ├── minimum-swaps-2.py │ └── new-year-chaos.py ├── dictionaries-hashmaps │ ├── CMakeLists.txt │ ├── README.md │ ├── ctci-ransom-note.cpp │ ├── sherlock-and-anagrams.py │ └── two-strings.py ├── graphs │ ├── README.md │ ├── ctci-bfs-shortest-reach.cpp │ └── ctci-connected-cell-in-a-grid.cpp ├── greedy-algorithms │ ├── README.md │ └── minimum-absolute-difference-in-an-array.py ├── linked-lists │ ├── README.md │ ├── ctci-linked-list-cycle.cpp │ ├── find-the-merge-point-of-two-joined-linked-lists.cpp │ ├── insert-a-node-at-a-specific-position-in-a-linked-list.cpp │ ├── insert-a-node-into-a-sorted-doubly-linked-list.cpp │ └── reverse-a-doubly-linked-list.py ├── miscellaneous │ ├── CMakeLists.txt │ ├── README.md │ ├── ctci-big-o.cpp │ ├── flipping-bits.cpp │ ├── friend-circle-queries.py │ └── maximum-xor.cpp ├── recursion-backtracking │ ├── README.md │ ├── ctci-fibonacci-numbers.cpp │ └── ctci-recursive-staircase.cpp ├── search │ ├── README.md │ ├── ctci-ice-cream-parlor.py │ └── pairs.py ├── sorting │ ├── README.md │ ├── ctci-bubble-sort.py │ ├── ctci-comparator-sorting.cpp │ └── ctci-merge-sort.py ├── stacks-queues │ ├── README.md │ ├── balanced-brackets.py │ ├── ctci-queue-using-two-stacks.cpp │ └── largest-rectangle.py ├── strings │ ├── README.md │ ├── alternating-characters.py │ ├── common-child.cpp │ ├── common-child.py │ ├── ctci-making-anagrams.py │ └── sherlock-and-valid-string.py └── trees │ ├── README.md │ ├── binary-search-tree-lowest-common-ancestor.cpp │ ├── ctci-is-binary-search-tree.py │ ├── tree-height-of-a-binary-tree.cpp │ ├── tree-height-of-a-binary-tree.py │ └── tree-huffman-decoding.cpp ├── java ├── CMakeLists.txt ├── README.md └── java-introduction │ ├── CMakeLists.txt │ ├── README.md │ ├── java-currency-formatter.java │ ├── java-datatypes.java │ ├── java-date-and-time.java │ ├── java-end-of-file.java │ ├── java-if-else.java │ ├── java-int-to-string.java │ ├── java-loops-i.java │ ├── java-loops.java │ ├── java-output-formatting.java │ ├── java-static-initializer-block.java │ ├── java-stdin-and-stdout-1.java │ ├── java-stdin-stdout.java │ └── welcome-to-java.java ├── mathematics ├── CMakeLists.txt ├── README.md ├── algebra │ ├── CMakeLists.txt │ ├── README.md │ ├── combo-meal.py │ ├── difference-and-product.py │ ├── easy-sum.py │ ├── little-gaurav-and-sequence.py │ ├── manasa-and-sub-sequences.py │ ├── number-groups.py │ ├── pythagorean-triple.py │ ├── shashank-and-list.py │ ├── sherlock-and-square.py │ ├── simple-one.py │ ├── stepping-stones-game.py │ ├── tell-the-average.py │ ├── triangle-numbers.py │ └── wet-shark-and-42.py ├── combinatorics │ ├── CMakeLists.txt │ ├── README.md │ ├── a-chocolate-fiesta.py │ ├── building-a-list.py │ ├── coinage.py │ ├── merge-list.py │ ├── ncr-table.cpp │ ├── ncr-table.py │ ├── picking-cards.py │ └── sherlock-and-pairs.py ├── fundamentals │ ├── CMakeLists.txt │ ├── README.md │ ├── best-divisor.py │ ├── bus-station.py │ ├── connecting-towns.py │ ├── die-hard-3.py │ ├── diwali-lights.py │ ├── even-odd-query.cpp │ ├── even-odd-query.py │ ├── filling-jars.py │ ├── find-point.cpp │ ├── game-with-cells.py │ ├── halloween-party.py │ ├── handshake.py │ ├── harry-potter-and-the-floating-rocks.py │ ├── is-fibo.py │ ├── jim-and-the-jokes.py │ ├── k-candy-store.py │ ├── leonardo-and-prime.py │ ├── lowest-triangle.py │ ├── matrix-tracing.py │ ├── maximum-draws.py │ ├── most-distant.py │ ├── mutual-recurrences.cpp │ ├── mutual-recurrences.py │ ├── p1-paper-cutting.py │ ├── possible-path.py │ ├── restaurant.py │ ├── reverse-game.py │ ├── russian-peasant-exponentiation.py │ ├── sherlock-and-divisors.py │ ├── sherlock-and-moving-tiles.py │ ├── sherlock-and-permutations.py │ ├── special-multiple.c │ ├── special-multiple.py │ ├── strange-grid.py │ └── summing-the-n-series.py ├── geometry │ ├── CMakeLists.txt │ ├── README.md │ ├── a-circle-and-a-square.cpp │ ├── baby-step-giant-step.py │ ├── circle-city.py │ ├── points-on-a-line.py │ ├── points-on-rectangle.py │ ├── rectangular-game.py │ ├── sherlock-and-counting.py │ ├── sherlock-and-planes.py │ └── xrange-and-pizza.py ├── linear-algebra-foundations │ ├── CMakeLists.txt │ ├── README.md │ ├── determinant-of-the-matrix-1.py │ ├── determinant-of-the-matrix-2.txt │ ├── determinant-of-the-matrix-3.txt │ ├── eigenvalue-of-matrix-1.py │ ├── eigenvalue-of-matrix-2.py │ ├── eigenvalues-of-matrix-3.py │ ├── eigenvalues-of-matrix-4.py │ ├── linear-algebra-foundations-1-matrix-subtraction.txt │ ├── linear-algebra-foundations-1.txt │ ├── linear-algebra-foundations-3-matrix-multiplication.py │ ├── linear-algebra-foundations-3-matrix-multiplication.txt │ ├── linear-algebra-foundations-4-matrix-multiplication.py │ ├── linear-algebra-foundations-5-the-100th-power-of-a-matrix.py │ ├── linear-algebra-foundations-6-the-nsupthsup-power-of-a-matrix.txt │ ├── linear-algebra-foundations-7-the-1000th-power-of-a-matrix.py │ ├── linear-algebra-foundations-7-the-1000th-power-of-a-matrix.txt │ ├── linear-algebra-fundamentals-10-eigenvectors.py │ ├── linear-algebra-fundamentals-8-systems-of-equations.py │ └── linear-algebra-fundamentals-9-eigenvalues.txt ├── number-theory │ ├── CMakeLists.txt │ ├── README.md │ ├── akhil-and-gf.py │ ├── binomial-coefficients.py │ ├── breaking-sticks.cpp │ ├── cheese-and-random-toppings.py │ ├── closest-number.py │ ├── constructing-a-number.py │ ├── dance-class.py │ ├── devu-police.py │ ├── divisibility-of-power.py │ ├── divisor-exploration-2.py │ ├── divisor-exploration-3.cpp │ ├── divisor-exploration-3.py │ ├── divisor-exploration.py │ ├── easy-gcd-1.py │ ├── easy-math.py │ ├── equations.py │ ├── eulers-criterion.py │ ├── fibonacci-finding-easy.py │ ├── fibonacci-gcd.py │ ├── help-mike.py │ ├── identify-smith-numbers.py │ ├── john-and-gcd-list.py │ ├── largest-coprime-submatrix.cpp │ ├── little-chammys-huge-donation.cpp │ ├── littlepandapower.py │ ├── long-permutation.py │ ├── lucy-and-flowers.cpp │ ├── manasa-and-factorials.py │ ├── manasa-loves-maths.py │ ├── megaprime-numbers.py │ ├── mehta-and-his-laziness.py │ ├── minimal-distance-to-pi.py │ ├── ncr.py │ ├── number-of-subsets.py │ ├── pairs-again.cpp │ ├── power-of-large-numbers.py │ ├── prime-sum.py │ ├── primitive-problem.py │ ├── salary-blues.py │ ├── sherlock-and-gcd.py │ ├── sherlock-puzzle.py │ ├── strange-numbers.py │ ├── superpowers.py │ ├── the-chosen-one.py │ └── twins.py └── probability │ ├── CMakeLists.txt │ ├── README.md │ ├── bday-gift.py │ ├── binomial-distribution-1.py │ ├── binomial-distribution-2.py │ ├── binomial-distribution-3.py │ ├── extremely-dangerous-virus.py │ ├── normal-distribution-1.py │ ├── normal-distribution-2.py │ ├── normal-distribution-3.py │ ├── random-number-generator.py │ └── sherlock-and-probability.py ├── python ├── CMakeLists.txt ├── README.md ├── closures-and-decorators │ ├── CMakeLists.txt │ ├── README.md │ ├── decorators-2-name-directory.py │ └── standardize-mobile-number-using-decorators.py ├── errors-exceptions │ ├── CMakeLists.txt │ ├── README.md │ ├── exceptions.py │ └── incorrect-regex.py ├── numpy │ ├── CMakeLists.txt │ ├── README.md │ ├── floor-ceil-and-rint.py │ ├── np-array-mathematics.py │ ├── np-arrays.py │ ├── np-concatenate.py │ ├── np-dot-and-cross.py │ ├── np-eye-and-identity.py │ ├── np-inner-and-outer.py │ ├── np-linear-algebra.py │ ├── np-mean-var-and-std.py │ ├── np-min-and-max.py │ ├── np-polynomials.py │ ├── np-shape-reshape.py │ ├── np-sum-and-prod.py │ ├── np-transpose-and-flatten.py │ └── np-zeros-and-ones.py ├── py-basic-data-types │ ├── CMakeLists.txt │ ├── README.md │ ├── find-second-maximum-number-in-a-list.py │ ├── finding-the-percentage.py │ ├── list-comprehensions.py │ ├── nested-list.py │ ├── python-lists.py │ └── python-tuples.py ├── py-built-ins │ ├── CMakeLists.txt │ ├── README.md │ ├── any-or-all.py │ ├── ginorts.py │ ├── input.py │ ├── python-eval.py │ ├── python-sort-sort.py │ └── zipped.py ├── py-classes │ ├── CMakeLists.txt │ ├── README.md │ ├── class-1-dealing-with-complex-numbers.py │ └── class-2-find-the-torsional-angle.py ├── py-collections │ ├── CMakeLists.txt │ ├── README.md │ ├── collections-counter.py │ ├── defaultdict-tutorial.py │ ├── most-commons.py │ ├── piling-up.py │ ├── py-collections-deque.py │ ├── py-collections-namedtuple.py │ ├── py-collections-ordereddict.py │ └── word-order.py ├── py-date-time │ ├── CMakeLists.txt │ ├── README.md │ ├── calendar-module.py │ └── python-time-delta.py ├── py-debugging │ ├── CMakeLists.txt │ ├── README.md │ ├── default-arguments.py │ └── words-score.py ├── py-functionals │ ├── CMakeLists.txt │ ├── README.md │ ├── map-and-lambda-expression.py │ ├── reduce-function.py │ └── validate-list-of-email-address-with-filter.py ├── py-introduction │ ├── CMakeLists.txt │ ├── README.md │ ├── py-hello-world.py │ ├── py-if-else.py │ ├── python-arithmetic-operators.py │ ├── python-division.py │ ├── python-loops.py │ ├── python-print.py │ └── write-a-function.py ├── py-itertools │ ├── CMakeLists.txt │ ├── README.md │ ├── compress-the-string.py │ ├── iterables-and-iterators.py │ ├── itertools-combinations-with-replacement.py │ ├── itertools-combinations.py │ ├── itertools-permutations.py │ ├── itertools-product.py │ └── maximize-it.py ├── py-math │ ├── CMakeLists.txt │ ├── README.md │ ├── find-angle.py │ ├── polar-coordinates.py │ ├── python-integers-come-in-all-sizes.py │ ├── python-mod-divmod.py │ ├── python-power-mod-power.py │ ├── python-quest-1.py │ └── triangle-quest-2.py ├── py-regex │ ├── CMakeLists.txt │ ├── README.md │ ├── detect-html-tags-attributes-and-attribute-values.py │ ├── hex-color-code.py │ ├── html-parser-part-1.py │ ├── html-parser-part-2.py │ ├── introduction-to-regex.py │ ├── matrix-script.py │ ├── re-findall-re-finditer.py │ ├── re-group-groups.py │ ├── re-split.py │ ├── re-start-re-end.py │ ├── re-sub-regex-substitution.py │ ├── validate-a-roman-number.py │ ├── validating-credit-card-number.py │ ├── validating-named-email-addresses.py │ ├── validating-postalcode.py │ ├── validating-the-phone-number.py │ └── validating-uid.py ├── py-sets │ ├── CMakeLists.txt │ ├── README.md │ ├── no-idea.py │ ├── py-check-strict-superset.py │ ├── py-check-subset.py │ ├── py-introduction-to-sets.py │ ├── py-set-add.py │ ├── py-set-difference-operation.py │ ├── py-set-discard-remove-pop.py │ ├── py-set-intersection-operation.py │ ├── py-set-mutations.py │ ├── py-set-symmetric-difference-operation.py │ ├── py-set-union.py │ ├── py-the-captains-room.py │ └── symmetric-difference.py ├── py-strings │ ├── CMakeLists.txt │ ├── README.md │ ├── alphabet-rangoli.py │ ├── capitalize.py │ ├── designer-door-mat.py │ ├── find-a-string.py │ ├── merge-the-tools.py │ ├── python-mutations.py │ ├── python-string-formatting.py │ ├── python-string-split-and-join.py │ ├── string-validators.py │ ├── swap-case.py │ ├── text-alignment.py │ ├── text-wrap.py │ ├── the-minion-game.py │ └── whats-your-name.py └── xml │ ├── CMakeLists.txt │ ├── README.md │ ├── xml-1-find-the-score.py │ └── xml2-find-the-maximum-depth.py ├── regex ├── CMakeLists.txt ├── README.md ├── assertions │ ├── CMakeLists.txt │ ├── README.md │ ├── negative-lookahead.py │ ├── negative-lookbehind.py │ ├── positive-lookahead.py │ └── positive-lookbehind.py ├── backreferences │ ├── CMakeLists.txt │ ├── README.md │ ├── backreferences-to-failed-groups.py │ ├── branch-reset-groups.pl │ ├── forward-references.java │ └── matching-same-text-again-again.py ├── grouping-and-capturing │ ├── CMakeLists.txt │ ├── README.md │ ├── alternative-matching.py │ ├── capturing-non-capturing-groups.py │ └── matching-word-boundaries.py ├── re-applications │ ├── CMakeLists.txt │ ├── README.md │ ├── alien-username.py │ ├── detect-html-links.py │ ├── detect-html-tags.py │ ├── detect-the-domain-name.py │ ├── detect-the-email-addresses.py │ ├── detecting-valid-latitude-and-longitude.py │ ├── find-a-word.py │ ├── find-hackerrank.py │ ├── find-substring.py │ ├── hackerrank-language.py │ ├── hackerrank-tweets.py │ ├── html-attributes.py │ ├── ide-identifying-comments.py │ ├── ip-address-validation.py │ ├── programming-language-detection.py │ ├── saying-hi.py │ ├── split-number.py │ ├── stack-exchange-scraper.py │ ├── uk-and-us-2.py │ ├── uk-and-us.py │ ├── utopian-identification-number.py │ └── valid-pan-format.py ├── re-character-class │ ├── CMakeLists.txt │ ├── README.md │ ├── excluding-specific-characters.py │ ├── matching-range-of-characters.py │ └── matching-specific-characters.py ├── re-introduction │ ├── CMakeLists.txt │ ├── README.md │ ├── matching-anything-but-new-line.py │ ├── matching-digits-non-digit-character.py │ ├── matching-specific-string.py │ ├── matching-start-end.py │ ├── matching-whitespace-non-whitespace-character.py │ └── matching-word-non-word.py └── re-repetitions │ ├── CMakeLists.txt │ ├── README.md │ ├── matching-ending-items.py │ ├── matching-one-or-more-repititions.py │ ├── matching-x-repetitions.py │ ├── matching-x-y-repetitions.py │ └── matching-zero-or-more-repetitions.py ├── requirements.txt ├── runtest.sh ├── security ├── CMakeLists.txt ├── README.md ├── concepts │ ├── CMakeLists.txt │ ├── README.md │ ├── security-encryption-scheme.cpp │ ├── security-key-spaces.cpp │ └── security-message-space-and-ciphertext-space.cpp ├── cryptography │ ├── CMakeLists.txt │ ├── README.md │ ├── basic-cryptanalysis.py │ ├── dictionary.lst │ ├── keyword-transposition-cipher.py │ └── prng-sequence-guessing.cpp └── functions │ ├── CMakeLists.txt │ ├── README.md │ ├── security-bijective-functions.cpp │ ├── security-function-ii.cpp │ ├── security-inverse-of-a-function.cpp │ ├── security-involution.cpp │ ├── security-tutorial-functions.cpp │ └── security-tutorial-permutations.cpp ├── setup.cfg ├── shell ├── CMakeLists.txt ├── README.md ├── arrays-in-bash │ ├── CMakeLists.txt │ ├── README.md │ ├── bash-tutorials-concatenate-an-array-with-itself.sh │ ├── bash-tutorials-count-the-number-of-elements-in-an-array.sh │ ├── bash-tutorials-display-the-third-element-of-an-array.sh │ ├── bash-tutorials-filter-an-array-with-patterns.sh │ ├── bash-tutorials-read-in-an-array.sh │ ├── bash-tutorials-remove-the-first-capital-letter-from-each-array-element.sh │ ├── bash-tutorials-slice-an-array.sh │ └── lonely-integer-2.sh ├── bash │ ├── CMakeLists.txt │ ├── README.md │ ├── bash-tutorials---a-personalized-echo.sh │ ├── bash-tutorials---arithmetic-operations.sh │ ├── bash-tutorials---comparing-numbers.sh │ ├── bash-tutorials---compute-the-average.sh │ ├── bash-tutorials---getting-started-with-conditionals.sh │ ├── bash-tutorials---looping-and-skipping.sh │ ├── bash-tutorials---looping-with-numbers.sh │ ├── bash-tutorials---more-on-conditionals.sh │ ├── bash-tutorials---the-world-of-numbers.sh │ ├── bash-tutorials-lets-echo.sh │ └── fractal-trees-all.sh ├── grep-sed-awk │ ├── CMakeLists.txt │ ├── README.md │ ├── awk-1.sh │ ├── awk-2.sh │ ├── awk-3.sh │ ├── awk-4.sh │ ├── sed-command-4.sh │ ├── sed-command-5.sh │ ├── text-processing-in-linux-the-grep-command-1.sh │ ├── text-processing-in-linux-the-grep-command-2.sh │ ├── text-processing-in-linux-the-grep-command-3.sh │ ├── text-processing-in-linux-the-grep-command-4.sh │ ├── text-processing-in-linux-the-grep-command-5.sh │ ├── text-processing-in-linux-the-sed-command-1.sh │ ├── text-processing-in-linux-the-sed-command-2.sh │ └── text-processing-in-linux-the-sed-command-3.sh └── textpro │ ├── CMakeLists.txt │ ├── README.md │ ├── paste-1.sh │ ├── paste-2.sh │ ├── paste-3.sh │ ├── paste-4.sh │ ├── text-processing-cut-1.sh │ ├── text-processing-cut-2.sh │ ├── text-processing-cut-3.sh │ ├── text-processing-cut-4.sh │ ├── text-processing-cut-5.sh │ ├── text-processing-cut-6.sh │ ├── text-processing-cut-7.sh │ ├── text-processing-cut-8.sh │ ├── text-processing-cut-9.sh │ ├── text-processing-head-1.sh │ ├── text-processing-head-2.sh │ ├── text-processing-in-linux---the-middle-of-a-text-file.sh │ ├── text-processing-in-linux-the-uniq-command-1.sh │ ├── text-processing-in-linux-the-uniq-command-2.sh │ ├── text-processing-in-linux-the-uniq-command-3.sh │ ├── text-processing-in-linux-the-uniq-command-4.sh │ ├── text-processing-sort-1.sh │ ├── text-processing-sort-2.sh │ ├── text-processing-sort-3.sh │ ├── text-processing-sort-4.sh │ ├── text-processing-sort-5.sh │ ├── text-processing-sort-6.sh │ ├── text-processing-sort-7.sh │ ├── text-processing-tail-1.sh │ ├── text-processing-tail-2.sh │ ├── text-processing-tr-1.sh │ ├── text-processing-tr-2.sh │ └── text-processing-tr-3.sh ├── sql ├── README.md ├── advanced-select │ ├── README.md │ ├── occupations.sql │ ├── the-pads.sql │ └── what-type-of-triangle.sql └── select │ ├── README.md │ ├── japanese-cities-attributes.sql │ ├── japanese-cities-name.sql │ ├── more-than-75-marks.sql │ ├── name-of-employees.sql │ ├── revising-the-select-query-2.sql │ ├── revising-the-select-query.sql │ ├── salary-of-employees.sql │ ├── select-all-sql.sql │ ├── select-by-id.sql │ ├── weather-observation-station-1.sql │ ├── weather-observation-station-10.sql │ ├── weather-observation-station-11.sql │ ├── weather-observation-station-12.sql │ ├── weather-observation-station-3.sql │ ├── weather-observation-station-4.sql │ ├── weather-observation-station-5.sql │ ├── weather-observation-station-6.sql │ ├── weather-observation-station-7.sql │ ├── weather-observation-station-8.sql │ └── weather-observation-station-9.sql ├── stdc++.h.in ├── testcases.tar.xz └── tutorials ├── 10-days-of-javascript ├── CMakeLists.txt ├── README.md ├── js10-arithmetic-operators.js ├── js10-arrays.js ├── js10-arrows.js ├── js10-binary-calculator.html ├── js10-binary-calculator │ ├── css │ │ └── binaryCalculator.css │ ├── index.html │ └── js │ │ └── binaryCalculator.js ├── js10-bitwise.js ├── js10-buttons-container.html ├── js10-buttons-container │ ├── css │ │ └── buttonsGrid.css │ ├── index.html │ └── js │ │ └── buttonsGrid.js ├── js10-class.js ├── js10-count-objects.js ├── js10-create-a-button.html ├── js10-create-a-button │ ├── css │ │ └── button.css │ ├── index.html │ └── js │ │ └── button.js ├── js10-data-types.js ├── js10-date.js ├── js10-function.js ├── js10-hello-world.js ├── js10-if-else.js ├── js10-inheritance.js ├── js10-let-and-const.js ├── js10-loops.js ├── js10-objects.js ├── js10-regexp-1.js ├── js10-regexp-2.js ├── js10-regexp-3.js ├── js10-switch.js ├── js10-template-literals.js ├── js10-throw.js └── js10-try-catch-and-finally.js ├── 10-days-of-statistics ├── CMakeLists.txt ├── README.md ├── s10-basic-statistics.py ├── s10-binomial-distribution-1.py ├── s10-binomial-distribution-2.py ├── s10-geometric-distribution-1.py ├── s10-geometric-distribution-2.py ├── s10-interquartile-range.py ├── s10-least-square-regression-line.py ├── s10-mcq-1.py ├── s10-mcq-2.py ├── s10-mcq-3.py ├── s10-mcq-4.txt ├── s10-mcq-5.txt ├── s10-mcq-6.txt ├── s10-mcq-7.txt ├── s10-multiple-linear-regression.py ├── s10-normal-distribution-1.py ├── s10-normal-distribution-2.py ├── s10-pearson-correlation-coefficient.py ├── s10-poisson-distribution-1.py ├── s10-poisson-distribution-2.py ├── s10-quartiles.py ├── s10-spearman-rank-correlation-coefficient.py ├── s10-standard-deviation.py ├── s10-the-central-limit-theorem-1.py ├── s10-the-central-limit-theorem-2.py ├── s10-the-central-limit-theorem-3.py └── s10-weighted-mean.py ├── 30-days-of-code ├── 30-2d-arrays.cpp ├── 30-2d-arrays.py ├── 30-abstract-classes.cpp ├── 30-abstract-classes.py ├── 30-arrays.cpp ├── 30-arrays.py ├── 30-binary-numbers.cpp ├── 30-binary-numbers.py ├── 30-binary-search-trees.py ├── 30-binary-trees.cpp ├── 30-binary-trees.py ├── 30-bitwise-and.cpp ├── 30-class-vs-instance.py ├── 30-conditional-statements.cpp ├── 30-data-types.cpp ├── 30-data-types.py ├── 30-dictionaries-and-maps.py ├── 30-exceptions-string-to-integer.cpp ├── 30-exceptions-string-to-integer.py ├── 30-generics.cpp ├── 30-hello-world.c ├── 30-hello-world.py ├── 30-inheritance.cpp ├── 30-interfaces.cpp ├── 30-linked-list-deletion.cpp ├── 30-linked-list.cpp ├── 30-linked-list.py ├── 30-loops.py ├── 30-more-exceptions.cpp ├── 30-nested-logic.cpp ├── 30-operators.cpp ├── 30-operators.py ├── 30-queues-stacks.py ├── 30-recursion.py ├── 30-regex-patterns.py ├── 30-review-loop.cpp ├── 30-review-loop.py ├── 30-running-time-and-complexity.cpp ├── 30-running-time-and-complexity.py ├── 30-scope.cpp ├── 30-scope.py ├── 30-sorting.cpp ├── 30-testing.py ├── CMakeLists.txt └── README.md ├── CMakeLists.txt ├── README.md └── cracking-the-coding-interview ├── CMakeLists.txt ├── README.md ├── ctci-array-left-rotation.py ├── ctci-balanced-brackets.cpp ├── ctci-bfs-shortest-reach.cpp ├── ctci-big-o.cpp ├── ctci-bubble-sort.py ├── ctci-coin-change.cpp ├── ctci-comparator-sorting.cpp ├── ctci-connected-cell-in-a-grid.cpp ├── ctci-contacts.py ├── ctci-fibonacci-numbers.cpp ├── ctci-find-the-running-median.cpp ├── ctci-ice-cream-parlor.py ├── ctci-is-binary-search-tree.py ├── ctci-linked-list-cycle.cpp ├── ctci-linked-list-cycle.hpp ├── ctci-lonely-integer.cpp ├── ctci-making-anagrams.py ├── ctci-merge-sort.py ├── ctci-queue-using-two-stacks.cpp ├── ctci-ransom-note.cpp └── ctci-recursive-staircase.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .cache.db 3 | 4 | .vscode/.ropeproject/ 5 | testcases/ 6 | testcases2/ 7 | 8 | build/ 9 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "cmake-haskell"] 2 | path = cmake-haskell 3 | url = https://github.com/donkeybonks/cmake-haskell.git 4 | -------------------------------------------------------------------------------- /.hr_conf.yaml: -------------------------------------------------------------------------------- 1 | # configuration file 2 | 3 | # how to load the file in Python: 4 | # domains = yaml.load(open(os.path.join(os.path.dirname(__file__), ".hr_conf.yaml")))["domains"] 5 | 6 | domains: 7 | - algorithms 8 | - data-structures 9 | - mathematics 10 | - cpp 11 | - c 12 | - python 13 | - shell 14 | - fp 15 | - java 16 | - tutorials 17 | - contests 18 | - security 19 | - sql 20 | - databases 21 | - regex 22 | - interview-preparation-kit 23 | - distributed-systems 24 | -------------------------------------------------------------------------------- /.vscode/.cmaketools.json: -------------------------------------------------------------------------------- 1 | { 2 | "variant": null, 3 | "activeEnvironments": [], 4 | "codeModel": null 5 | } -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /algorithms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(warmup) 2 | add_subdirectory(implementation) 3 | add_subdirectory(strings) 4 | add_subdirectory(greedy) 5 | add_subdirectory(arrays-and-sorting) 6 | add_subdirectory(search) 7 | add_subdirectory(dynamic-programming) 8 | add_subdirectory(bit-manipulation) 9 | add_subdirectory(game-theory) 10 | add_subdirectory(algo-debugging) 11 | -------------------------------------------------------------------------------- /algorithms/algo-debugging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(prime-date prime-date.cpp) 2 | add_hackerrank_py(prime-date.py) 3 | add_hackerrank_java(prime-date.java CLASS Main) 4 | 5 | add_hackerrank(zig-zag-sequence zig-zag-sequence.cpp) 6 | add_hackerrank_py(zig-zag-sequence.py) 7 | add_hackerrank_java(zig-zag-sequence.java CLASS Main) 8 | 9 | dirty_cpp(prime-date) 10 | dirty_cpp(zig-zag-sequence) 11 | -------------------------------------------------------------------------------- /algorithms/arrays-and-sorting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(big-sorting.py) 2 | add_hackerrank_py(find-the-median.py) 3 | add_hackerrank_py(insertion-sort.py) 4 | add_hackerrank_py(countingsort1.py) 5 | add_hackerrank_py(insertionsort2.py) 6 | add_hackerrank_py(countingsort4.py) 7 | add_hackerrank_py(tutorial-intro.py) 8 | add_hackerrank_py(runningtime.py) 9 | add_hackerrank(insertion-sort insertion-sort.cpp) 10 | add_hackerrank_py(countingsort2.py) 11 | add_hackerrank_py(insertionsort1.py) 12 | add_hackerrank_py(closest-numbers.py) 13 | add_hackerrank_py(quicksort1.py) 14 | -------------------------------------------------------------------------------- /algorithms/arrays-and-sorting/big-sorting.py: -------------------------------------------------------------------------------- 1 | # Big Sorting 2 | # Sort an array of very long numeric strings. 3 | # 4 | # https://www.hackerrank.com/challenges/big-sorting/problem 5 | # 6 | 7 | import functools 8 | 9 | def entier(a, b): 10 | la, lb = len(a), len(b) 11 | if la < lb: return -1 12 | if la > lb: return +1 13 | if a < b: return -1 14 | if a > b: return +1 15 | return 0 16 | 17 | if __name__ == "__main__": 18 | n = int(input()) 19 | arr = list(input() for i in range(n)) 20 | for i in sorted(arr, key=functools.cmp_to_key(entier)): 21 | print(i) 22 | -------------------------------------------------------------------------------- /algorithms/arrays-and-sorting/countingsort1.py: -------------------------------------------------------------------------------- 1 | # Counting Sort 1 2 | # Count the number of times each value appears. 3 | # 4 | # https://www.hackerrank.com/challenges/countingsort1/problem 5 | # 6 | 7 | 8 | def countingSort(arr): 9 | # compte les occurences de arr[i] ∈ [0, 99] 10 | counts = [0] * 100 11 | for i in arr: 12 | counts[i] += 1 13 | return counts 14 | 15 | if __name__ == "__main__": 16 | n = int(input().strip()) 17 | arr = list(map(int, input().strip().split(' '))) 18 | result = countingSort(arr) 19 | print (" ".join(map(str, result))) 20 | -------------------------------------------------------------------------------- /algorithms/arrays-and-sorting/find-the-median.py: -------------------------------------------------------------------------------- 1 | # Find the Median 2 | # Find the Median in a list of numbers. 3 | # 4 | # https://www.hackerrank.com/challenges/find-the-median/problem 5 | # 6 | 7 | def findMedian(arr): 8 | # la valeur médiane est celle qui partage la liste triée en 2 9 | return sorted(arr)[len(arr) // 2] 10 | 11 | if __name__ == "__main__": 12 | n = int(input().strip()) 13 | arr = list(map(int, input().strip().split(' '))) 14 | result = findMedian(arr) 15 | print(result) 16 | -------------------------------------------------------------------------------- /algorithms/bit-manipulation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(lonely-integer.py) 2 | add_hackerrank(hamming-distance hamming-distance.cpp) 3 | add_hackerrank_py(maximizing-xor.py) 4 | add_hackerrank_py(aorb.py) 5 | add_hackerrank_py(counter-game.py) 6 | add_hackerrank(flipping-bits flipping-bits.cpp) 7 | add_hackerrank(the-great-xor the-great-xor.cpp) 8 | -------------------------------------------------------------------------------- /algorithms/bit-manipulation/flipping-bits.cpp: -------------------------------------------------------------------------------- 1 | // Algorithms > Bit Manipulation > Flipping bits 2 | // Flip bits in its binary representation. 3 | // 4 | // https://www.hackerrank.com/challenges/flipping-bits/problem 5 | // https://www.hackerrank.com/contests/101hack20/challenges/flipping-bits 6 | // challenge id: 5529 7 | // 8 | 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | int t; 16 | cin >> t; 17 | while (t--) 18 | { 19 | uint32_t a; 20 | cin >> a; 21 | cout << ~a << endl; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /algorithms/constructive-algorithms/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(new-year-chaos.py) 2 | -------------------------------------------------------------------------------- /algorithms/constructive-algorithms/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [Algorithms](https://www.hackerrank.com/domains/algorithms) 3 | The true test of problem solving: when one realizes that time and memory aren't infinite. 4 | 5 | 6 | 7 | #### [Constructive Algorithms](https://www.hackerrank.com/domains/algorithms/constructive-algorithms) 8 | 9 | Name | Preview | Code | Difficulty 10 | ---- | ------- | ---- | ---------- 11 | [New Year Chaos](https://www.hackerrank.com/challenges/new-year-chaos)|Determine how many bribes took place to get a queue into its current state.|[Python](new-year-chaos.py)|Medium 12 | 13 | -------------------------------------------------------------------------------- /algorithms/dynamic-programming/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(longest-increasing-subsequent longest-increasing-subsequent.cpp) 2 | dirty_cpp(longest-increasing-subsequent) 3 | add_hackerrank(dorsey-thief dorsey-thief.cpp) 4 | add_hackerrank_py(fibonacci-modified.py) 5 | -------------------------------------------------------------------------------- /algorithms/dynamic-programming/fibonacci-modified.py: -------------------------------------------------------------------------------- 1 | # Algorithms > Dynamic Programming > Fibonacci Modified 2 | # Compute the nth term of a Fibonacci sequence. 3 | # 4 | # https://www.hackerrank.com/challenges/fibonacci-modified/problem 5 | # https://www.hackerrank.com/contests/back2school14/challenges/fibonacci-modified 6 | # 7 | 8 | t1, t2, n = map(int, input().split()) 9 | 10 | for i in range(3, n + 1): 11 | t2, t1 = t1 + t2 ** 2, t2 12 | 13 | print(t2) 14 | -------------------------------------------------------------------------------- /algorithms/game-theory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(game-of-stones-1.py) 2 | -------------------------------------------------------------------------------- /algorithms/game-theory/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [Algorithms](https://www.hackerrank.com/domains/algorithms) 3 | The true test of problem solving: when one realizes that time and memory aren't infinite. 4 | 5 | 6 | 7 | #### [Game Theory](https://www.hackerrank.com/domains/algorithms/game-theory) 8 | 9 | Name | Preview | Code | Difficulty 10 | ---- | ------- | ---- | ---------- 11 | [Game of Stones](https://www.hackerrank.com/challenges/game-of-stones-1)|A Game of Stones|[Python](game-of-stones-1.py)|Easy 12 | 13 | -------------------------------------------------------------------------------- /algorithms/greedy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(marcs-cakewalk.py) 2 | add_hackerrank_py(grid-challenge.py) 3 | add_hackerrank_py(beautiful-pairs.py) 4 | add_hackerrank(maximum-perimeter-triangle maximum-perimeter-triangle.cpp) 5 | add_hackerrank_py(sherlock-and-the-beast.py) 6 | add_hackerrank_py(minimum-absolute-difference-in-an-array.py) 7 | -------------------------------------------------------------------------------- /algorithms/implementation/beautiful-days-at-the-movies.py: -------------------------------------------------------------------------------- 1 | # Beautiful Days at the Movies 2 | # Find the number of beautiful days. 3 | # 4 | # https://www.hackerrank.com/challenges/beautiful-days-at-the-movies/problem 5 | # 6 | 7 | def beautifulDays(i, j, k): 8 | # Complete this function 9 | return sum(1 for n in range(i, j + 1) 10 | if abs(n - int(''.join(reversed(str(n))))) % k == 0) 11 | 12 | 13 | if __name__ == "__main__": 14 | i, j, k = input().strip().split(' ') 15 | i, j, k = [int(i), int(j), int(k)] 16 | result = beautifulDays(i, j, k) 17 | print(result) 18 | -------------------------------------------------------------------------------- /algorithms/implementation/bon-appetit.py: -------------------------------------------------------------------------------- 1 | # Bon Appétit 2 | # Determine whether or not Brian overcharged Anna for their split bill. 3 | # 4 | # https://www.hackerrank.com/challenges/bon-appetit/problem 5 | # 6 | 7 | n, k = map(int, input().split()) 8 | b = list(map(int, input().split())) 9 | p = int(input()) 10 | 11 | cc = sum(v for i, v in enumerate(b) if i != k) 12 | brian = cc / 2 + b[k - 1] 13 | anna = cc / 2 14 | 15 | if p == anna: 16 | print('Bon Appetit') 17 | else: 18 | print(round(p - anna)) 19 | -------------------------------------------------------------------------------- /algorithms/implementation/circular-array-rotation.py: -------------------------------------------------------------------------------- 1 | # Circular Array Rotation 2 | # Print the elements in an array after 'm' right circular rotation operations. 3 | # 4 | # https://www.hackerrank.com/challenges/circular-array-rotation/problem 5 | # 6 | 7 | if __name__ == "__main__": 8 | n, k, q = map(int, input().split()) 9 | a = list(map(int, input().split())) 10 | 11 | # fait la rotation circulaire 12 | # en Python, c'est ultra-simple 13 | k = n - k % n 14 | a = a[k:] + a[:k] 15 | 16 | for _ in range(q): 17 | i = int(input()) 18 | print(a[i]) 19 | -------------------------------------------------------------------------------- /algorithms/implementation/designer-pdf-viewer.py: -------------------------------------------------------------------------------- 1 | # Designer PDF Viewer 2 | # Help finding selection area in PDF Viewer. 3 | # 4 | # https://www.hackerrank.com/challenges/designer-pdf-viewer/problem 5 | # 6 | 7 | def designerPdfViewer(h, word): 8 | # Complete this function 9 | return max(h[ord(c) - ord('a')] for c in word) * len(word) 10 | 11 | if __name__ == "__main__": 12 | h = list(map(int, input().strip().split(' '))) 13 | word = input().strip() 14 | result = designerPdfViewer(h, word) 15 | print(result) 16 | -------------------------------------------------------------------------------- /algorithms/implementation/extra-long-factorials.hs: -------------------------------------------------------------------------------- 1 | -- Extra Long Factorials 2 | -- Calculate a very large factorial that doesn't fit in the conventional numeric data types. 3 | -- 4 | -- https://www.hackerrank.com/challenges/extra-long-factorials/problem 5 | -- 6 | import Control.Applicative 7 | import Control.Monad 8 | import System.IO 9 | 10 | fac :: Integer -> Integer 11 | fac 1 = 1 12 | fac n = n * fac (n - 1) 13 | 14 | main :: IO () 15 | main = do 16 | n_temp <- getLine 17 | let n = read n_temp :: Integer 18 | let result = fac n 19 | print result 20 | -------------------------------------------------------------------------------- /algorithms/implementation/find-digits.py: -------------------------------------------------------------------------------- 1 | # Find Digits 2 | # Calculate the number of digits in an integer that evenly divide it. 3 | # 4 | # https://www.hackerrank.com/challenges/find-digits/problem 5 | # 6 | 7 | 8 | def findDigits(n): 9 | # Complete this function 10 | return sum(1 for d in str(n) if d != "0" and n % int(d) == 0) 11 | 12 | if __name__ == "__main__": 13 | t = int(input().strip()) 14 | for a0 in range(t): 15 | n = int(input().strip()) 16 | result = findDigits(n) 17 | print(result) 18 | -------------------------------------------------------------------------------- /algorithms/implementation/service-lane.py: -------------------------------------------------------------------------------- 1 | # Service Lane 2 | # Calculate the maximum width of the vehicle that can pass through a service lane. 3 | # 4 | # https://www.hackerrank.com/challenges/service-lane/problem 5 | # 6 | 7 | 8 | def serviceLane(width, a, b): 9 | # euh? comment dire... 10 | print(min(width[a:b + 1])) 11 | 12 | if __name__ == "__main__": 13 | n, t = map(int, input().split()) 14 | width = list(map(int, input().split())) 15 | for _ in range(t): 16 | a, b = map(int, input().split()) 17 | serviceLane(width, a, b) 18 | -------------------------------------------------------------------------------- /algorithms/implementation/the-birthday-bar.py: -------------------------------------------------------------------------------- 1 | # Birthday Chocolate 2 | # Given an array of integers, find the number of subarrays of length k having sum s. 3 | # 4 | # https://www.hackerrank.com/challenges/the-birthday-bar/problem 5 | # 6 | 7 | def solve(n, s, d, m): 8 | # Complete this function 9 | return sum(1 for i in range(len(s) - m + 1) if sum(s[i:i + m]) == d) 10 | 11 | 12 | n = int(input().strip()) 13 | s = list(map(int, input().strip().split(' '))) 14 | d, m = input().strip().split(' ') 15 | d, m = [int(d), int(m)] 16 | result = solve(n, s, d, m) 17 | print(result) 18 | -------------------------------------------------------------------------------- /algorithms/implementation/the-hurdle-race.py: -------------------------------------------------------------------------------- 1 | # The Hurdle Race 2 | # Can you help Dan determine the minimum number of magic beverages he must drink to jump all the hurdles? 3 | # 4 | # https://www.hackerrank.com/challenges/the-hurdle-race/problem 5 | # 6 | 7 | def hurdleRace(k, height): 8 | # Complete this function 9 | return max(0, max(height) - k) 10 | 11 | 12 | if __name__ == "__main__": 13 | n, k = map(int, input().split()) 14 | height = list(map(int, input().split(' '))) 15 | result = hurdleRace(k, height) 16 | print(result) 17 | -------------------------------------------------------------------------------- /algorithms/implementation/utopian-tree.py: -------------------------------------------------------------------------------- 1 | # Utopian Tree 2 | # Predict the height of the tree after N growth cycles. 3 | # 4 | # https://www.hackerrank.com/challenges/utopian-tree/problem 5 | # 6 | 7 | 8 | def utopianTree(n): 9 | # Complete this function 10 | H = 1 11 | for i in range(n): 12 | if i % 2 == 0: 13 | H *= 2 14 | else: 15 | H += 1 16 | return H 17 | 18 | 19 | if __name__ == "__main__": 20 | t = int(input()) 21 | for a0 in range(t): 22 | n = int(input()) 23 | result = utopianTree(n) 24 | print(result) 25 | -------------------------------------------------------------------------------- /algorithms/search/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(pairs.py) 2 | add_hackerrank_py(icecream-parlor.py) 3 | add_hackerrank_py(missing-numbers.py) 4 | add_hackerrank_py(hackerland-radio-transmitters.py) 5 | add_hackerrank_py(sherlock-and-array.py) 6 | -------------------------------------------------------------------------------- /algorithms/strings/alternating-characters.py: -------------------------------------------------------------------------------- 1 | # Alternating Characters 2 | # Calculate the minimum number of deletions required to convert a string into a string in which consecutive characters are different. 3 | # 4 | # https://www.hackerrank.com/challenges/alternating-characters/problem 5 | # 6 | 7 | import itertools 8 | 9 | def alternatingCharacters(s): 10 | return sum(len(list(g)) - 1 for k, g in itertools.groupby(s)) 11 | 12 | q = int(input().strip()) 13 | for a0 in range(q): 14 | s = input().strip() 15 | result = alternatingCharacters(s) 16 | print(result) 17 | -------------------------------------------------------------------------------- /algorithms/strings/camelcase.py: -------------------------------------------------------------------------------- 1 | # CamelCase 2 | # 3 | # 4 | # https://www.hackerrank.com/challenges/camelcase/problem 5 | # 6 | 7 | import sys 8 | 9 | def camelcase(s): 10 | # Complete this function 11 | # +1 pour le premier mot, après il suffit de compter les majuscules 12 | return 1 + sum(1 for c in s if c.upper() == c) 13 | 14 | if __name__ == "__main__": 15 | s = input().strip() 16 | result = camelcase(s) 17 | print(result) 18 | -------------------------------------------------------------------------------- /algorithms/strings/gem-stones.py: -------------------------------------------------------------------------------- 1 | # Gemstones 2 | # Find the number of different gem-elements present. 3 | # 4 | # https://www.hackerrank.com/challenges/gem-stones/problem 5 | # 6 | 7 | # les minéraux de chaque pierre 8 | minerals = [set(input()) for _ in range(int(input()))] 9 | 10 | # minéraux présents dans toutes les pierres 11 | minerals = set.intersection(*minerals) 12 | 13 | # le résultat... 14 | print(len(minerals)) 15 | -------------------------------------------------------------------------------- /algorithms/strings/mars-exploration.py: -------------------------------------------------------------------------------- 1 | # Mars Exploration 2 | # Save Our Ship! 3 | # 4 | # https://www.hackerrank.com/challenges/mars-exploration/problem 5 | # 6 | 7 | 8 | def marsExploration(s): 9 | # Complete this function 10 | nb = 0 11 | i = 0 12 | while i < len(s): 13 | c = s[i] 14 | if c != "SOS"[i % 3]: 15 | nb += 1 16 | i += 1 17 | return nb 18 | 19 | 20 | if __name__ == "__main__": 21 | s = input().strip() 22 | result = marsExploration(s) 23 | print(result) 24 | -------------------------------------------------------------------------------- /algorithms/strings/pangrams.py: -------------------------------------------------------------------------------- 1 | # Pangrams 2 | # Check whether a given string is a panagram or not. 3 | # 4 | # https://www.hackerrank.com/challenges/pangrams/problem 5 | # 6 | 7 | 8 | def pangrams(s): 9 | # si le set() a 26 éléments, on y a stocké les 26 lettres de l'alphabet 10 | letters = set() 11 | for c in s: 12 | c = c.lower() 13 | if c.isalpha(): letters.add(c) 14 | if len(letters) == 26: 15 | print("pangram") 16 | else: 17 | print("not pangram") 18 | 19 | 20 | if __name__ == '__main__': 21 | s = input() 22 | pangrams(s) 23 | -------------------------------------------------------------------------------- /algorithms/strings/string-construction.py: -------------------------------------------------------------------------------- 1 | # String Construction 2 | # Find the minimum cost of copying string s. 3 | # 4 | # https://www.hackerrank.com/challenges/string-construction/problem 5 | # 6 | 7 | # aucun intérêt: la réponse est: le nombre de caractères différents! 8 | 9 | def stringConstruction(s): 10 | return len(set(s)) 11 | 12 | if __name__ == "__main__": 13 | q = int(input().strip()) 14 | for a0 in range(q): 15 | s = input().strip() 16 | result = stringConstruction(s) 17 | print(result) 18 | -------------------------------------------------------------------------------- /algorithms/strings/the-love-letter-mystery.py: -------------------------------------------------------------------------------- 1 | # The Love-Letter Mystery 2 | # Find the minimum number of operations required to convert a given string into a palindrome under certain conditions 3 | # 4 | # https://www.hackerrank.com/challenges/the-love-letter-mystery/problem 5 | # 6 | 7 | def theLoveLetterMystery(s): 8 | return sum(abs(ord(s[i]) - ord(s[-i - 1])) for i in range(len(s) // 2)) 9 | 10 | q = int(input()) 11 | for a0 in range(q): 12 | s = input() 13 | result = theLoveLetterMystery(s) 14 | print(result) 15 | -------------------------------------------------------------------------------- /algorithms/strings/two-strings.py: -------------------------------------------------------------------------------- 1 | # Two Strings 2 | # Given two strings, you find a common substring of non-zero length. 3 | # 4 | # https://www.hackerrank.com/challenges/two-strings/problem 5 | # 6 | 7 | def twoStrings(s1, s2): 8 | # Complete this function 9 | return "YES" if len(set.intersection(set(s1), set(s2))) > 0 else "NO" 10 | 11 | q = int(input().strip()) 12 | for a0 in range(q): 13 | s1 = input().strip() 14 | s2 = input().strip() 15 | result = twoStrings(s1, s2) 16 | print(result) 17 | -------------------------------------------------------------------------------- /algorithms/warmup/a-very-big-sum.py: -------------------------------------------------------------------------------- 1 | """ 2 | A Very Big Sum 3 | 4 | https://www.hackerrank.com/challenges/a-very-big-sum/problem 5 | """ 6 | 7 | def aVeryBigSum(n, ar): 8 | return sum(ar) 9 | 10 | 11 | n = int(input().strip()) 12 | ar = list(map(int, input().strip().split(' '))) 13 | result = aVeryBigSum(n, ar) 14 | print(result) 15 | -------------------------------------------------------------------------------- /algorithms/warmup/compare-the-triplets.py: -------------------------------------------------------------------------------- 1 | # Algorithms > Warmup > Compare the Triplets 2 | # Compare the elements in two triplets. 3 | # 4 | # https://www.hackerrank.com/challenges/compare-the-triplets/problem 5 | # 6 | 7 | a = map(int, input().split()) 8 | b = map(int, input().split()) 9 | alice, bob = 0, 0 10 | for i, j in zip(a, b): 11 | if i > j: 12 | alice += 1 13 | elif i < j: 14 | bob += 1 15 | print(alice, bob) 16 | -------------------------------------------------------------------------------- /algorithms/warmup/mini-max-sum.py: -------------------------------------------------------------------------------- 1 | """ 2 | Mini-Max Sum 3 | 4 | https://www.hackerrank.com/challenges/mini-max-sum/problem 5 | """ 6 | 7 | def miniMaxSum(arr): 8 | # Complete this function 9 | arr = sorted(arr) 10 | print(sum(arr[0:4]), sum(arr[1:5])) 11 | 12 | if __name__ == "__main__": 13 | arr = list(map(int, input().strip().split(' '))) 14 | miniMaxSum(arr) 15 | -------------------------------------------------------------------------------- /algorithms/warmup/solve-me-first.hs: -------------------------------------------------------------------------------- 1 | -- Algorithms > Warmup > Solve Me First 2 | -- This is an easy challenge to help you start coding in your favorite languages! 3 | -- 4 | -- https://www.hackerrank.com/challenges/solve-me-first/problem 5 | -- challenge id: 2532 6 | -- 7 | 8 | solveMeFirst a b = a + b 9 | 10 | -- (template_tail) ---------------------------------------------------------------------- 11 | main = do 12 | val1 <- readLn 13 | val2 <- readLn 14 | let sum = solveMeFirst val1 val2 15 | print sum 16 | -------------------------------------------------------------------------------- /algorithms/warmup/solve-me-first.py: -------------------------------------------------------------------------------- 1 | # Algorithms > Warmup > Solve Me First 2 | # This is an easy challenge to help you start coding in your favorite languages! 3 | # 4 | # https://www.hackerrank.com/challenges/solve-me-first/problem 5 | # challenge id: 2532 6 | # 7 | 8 | def solveMeFirst(a, b): 9 | return a + b 10 | 11 | num1 = int(input()) 12 | num2 = int(input()) 13 | res = solveMeFirst(num1, num2) 14 | print(res) 15 | -------------------------------------------------------------------------------- /algorithms/warmup/solve-me-first.sh: -------------------------------------------------------------------------------- 1 | # Algorithms > Warmup > Solve Me First 2 | # This is an easy challenge to help you start coding in your favorite languages! 3 | # 4 | # https://www.hackerrank.com/challenges/solve-me-first/problem 5 | # challenge id: 2532 6 | # 7 | 8 | read a 9 | read b 10 | echo $(($a + $b)) 11 | -------------------------------------------------------------------------------- /algorithms/warmup/staircase.py: -------------------------------------------------------------------------------- 1 | """ 2 | Staircase 3 | 4 | https://www.hackerrank.com/challenges/staircase/problem 5 | """ 6 | 7 | import sys 8 | 9 | def staircase(n): 10 | # Complete this function 11 | for i in range(1, n + 1): 12 | print(" " * (n - i) + "#" * i) 13 | 14 | if __name__ == "__main__": 15 | n = int(input().strip()) 16 | staircase(n) 17 | -------------------------------------------------------------------------------- /c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(c-introduction) 2 | add_subdirectory(c-conditionals-and-loops) 3 | add_subdirectory(c-arrays-and-strings) 4 | add_subdirectory(c-functions) 5 | add_subdirectory(c-structs-and-enums) 6 | -------------------------------------------------------------------------------- /c/c-arrays-and-strings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(1d-arrays-in-c 1d-arrays-in-c.c) 2 | add_hackerrank(reverse-array-c reverse-array-c.c) 3 | add_hackerrank(printing-tokens- printing-tokens-.c) 4 | add_hackerrank(frequency-of-digits-1 frequency-of-digits-1.c) 5 | add_hackerrank(dynamic-array-in-c dynamic-array-in-c.c) 6 | -------------------------------------------------------------------------------- /c/c-arrays-and-strings/printing-tokens-.c: -------------------------------------------------------------------------------- 1 | // C > Arrays and Strings > Printing Tokens 2 | // Given a sentence, print each word in a new line. 3 | // 4 | // https://www.hackerrank.com/challenges/printing-tokens-/problem 5 | // 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() { 13 | 14 | char s[1001]; 15 | 16 | while (scanf("%s", s) == 1) 17 | { 18 | printf("%s\n", s); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /c/c-conditionals-and-loops/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(conditional-statements-in-c conditional-statements-in-c.c) 2 | add_hackerrank(printing-pattern-2 printing-pattern-2.c) 3 | add_hackerrank(sum-of-digits-of-a-five-digit-number sum-of-digits-of-a-five-digit-number.c) 4 | add_hackerrank(for-loop-in-c for-loop-in-c.c) 5 | add_hackerrank(bitwise-operators-in-c bitwise-operators-in-c.c) 6 | -------------------------------------------------------------------------------- /c/c-functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(recursion-in-c recursion-in-c.c) 2 | add_hackerrank(students-marks-sum students-marks-sum.c) 3 | add_hackerrank(sorting-array-of-strings sorting-array-of-strings.c) 4 | add_hackerrank(variadic-functions-in-c variadic-functions-in-c.c) 5 | add_hackerrank(permutations-of-strings permutations-of-strings.c) 6 | add_hackerrank(querying-the-document querying-the-document.c) 7 | 8 | target_compile_options(querying-the-document PRIVATE "-Wno-conversion") 9 | -------------------------------------------------------------------------------- /c/c-introduction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(hello-world-c hello-world-c.c) 2 | add_hackerrank(sum-numbers-c sum-numbers-c.c) 3 | add_hackerrank(functions-in-c functions-in-c.c) 4 | add_hackerrank(pointer-in-c pointer-in-c.c) 5 | add_hackerrank(playing-with-characters playing-with-characters.c) 6 | -------------------------------------------------------------------------------- /c/c-introduction/hello-world-c.c: -------------------------------------------------------------------------------- 1 | // C > Introduction > "Hello World!" in C 2 | // This challenge will help you to learn to input some data and then output some data. 3 | // 4 | // https://www.hackerrank.com/challenges/hello-world-c/problem 5 | // 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | 15 | char s[100]; 16 | scanf("%[^\n]%*c", s); 17 | 18 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 19 | puts("Hello, World!"); 20 | puts(s); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /c/c-introduction/sum-numbers-c.c: -------------------------------------------------------------------------------- 1 | // C > Introduction > Sum and Difference of Two Numbers 2 | // Get started with data types. 3 | // 4 | // https://www.hackerrank.com/challenges/sum-numbers-c/problem 5 | // 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | int main() 13 | { 14 | int i, j; 15 | float f, g; 16 | 17 | if (scanf("%d %d", &i, &j) == 2 && scanf("%f %f", &f, &g) == 2) 18 | { 19 | printf("%d %d\n", i + j, i - j); 20 | printf("%.1f %.1f\n", f + g, f - g); 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /coding-dojo/CoderDojo_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rene-d/hackerrank/1bfdbc63de5d0f94cd9e6ae250476b4a267662f2/coding-dojo/CoderDojo_Logo.png -------------------------------------------------------------------------------- /coding-dojo/bitset-1.cpp: -------------------------------------------------------------------------------- 1 | ../cpp/other-concepts/bitset-1.cpp -------------------------------------------------------------------------------- /coding-dojo/detect-whether-a-linked-list-contains-a-cycle.cpp: -------------------------------------------------------------------------------- 1 | ../data-structures/linked-lists/detect-whether-a-linked-list-contains-a-cycle.cpp -------------------------------------------------------------------------------- /coding-dojo/detecting-valid-latitude-and-longitude.py: -------------------------------------------------------------------------------- 1 | ../regex/re-applications/detecting-valid-latitude-and-longitude.py -------------------------------------------------------------------------------- /coding-dojo/equal-stacks.py: -------------------------------------------------------------------------------- 1 | ../data-structures/stacks/equal-stacks.py -------------------------------------------------------------------------------- /coding-dojo/ip-address-validation.py: -------------------------------------------------------------------------------- 1 | ../regex/re-applications/ip-address-validation.py -------------------------------------------------------------------------------- /coding-dojo/largest-rectangle.py: -------------------------------------------------------------------------------- 1 | ../data-structures/stacks/largest-rectangle.py -------------------------------------------------------------------------------- /coding-dojo/maximum-element.cpp: -------------------------------------------------------------------------------- 1 | ../data-structures/stacks/maximum-element.cpp -------------------------------------------------------------------------------- /coding-dojo/missing-numbers.py: -------------------------------------------------------------------------------- 1 | ../algorithms/search/missing-numbers.py -------------------------------------------------------------------------------- /coding-dojo/tree-huffman-decoding.cpp: -------------------------------------------------------------------------------- 1 | ../data-structures/trees/tree-huffman-decoding.cpp -------------------------------------------------------------------------------- /coding-dojo/validating-credit-card-number.py: -------------------------------------------------------------------------------- 1 | ../python/py-regex/validating-credit-card-number.py -------------------------------------------------------------------------------- /contests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(projecteuler) 2 | add_subdirectory(openbracket-2017) 3 | add_subdirectory(womens-codesprint-3) 4 | 5 | #add_subdirectory(infinitum11) 6 | -------------------------------------------------------------------------------- /contests/infinitum11/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(fibonacci-gcd-again.py) 2 | add_hackerrank(fibonacci-gcd-again fibonacci-gcd-again.cpp) 3 | -------------------------------------------------------------------------------- /contests/infinitum11/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [Ad Infinitum 11 - Math Programming Contest](https://www.hackerrank.com/contests/infinitum11) 3 | Welcome to Ad Infinitum (To Infinity) a programming competition, purely in the mathematics domain. 4 | 5 | 6 | Name | Preview | Code | Difficulty 7 | ---- | ------- | ---- | ---------- 8 | [Fibonacci GCD Again](https://www.hackerrank.com/contests/infinitum11/challenges/fibonacci-gcd-again)|Compute GCDs involving Fibonacci numbers... again.|[C++](fibonacci-gcd-again.cpp) [Python](fibonacci-gcd-again.py)|Advanced 9 | 10 | -------------------------------------------------------------------------------- /contests/openbracket-2017/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HACKERRANK_CONTEST openbracket-2017) 2 | 3 | add_hackerrank_py(because-owlery-is-too-lazy.py) 4 | -------------------------------------------------------------------------------- /contests/openbracket-2017/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [OpenBracket Delaware - Online Trials](https://www.hackerrank.com/contests/openbracket-2017) 3 | Participate and win in OpenBracket's CodeSprint to qualify for the championships! 4 | 5 | 6 | Name | Preview | Code | Difficulty 7 | ---- | ------- | ---- | ---------- 8 | [Hogwarts Email Address](https://www.hackerrank.com/contests/openbracket-2017/challenges/because-owlery-is-too-lazy)|You have to determine whether the given string is a valid email address or not.|[Python](because-owlery-is-too-lazy.py)|Easy 9 | 10 | -------------------------------------------------------------------------------- /contests/openbracket-2017/because-owlery-is-too-lazy.py: -------------------------------------------------------------------------------- 1 | # 2 | # https://www.hackerrank.com/contests/openbracket-2017/challenges/because-owlery-is-too-lazy 3 | # 4 | 5 | import re 6 | 7 | def isValid(email): 8 | # Complete this function 9 | if bool(re.match(r"^[a-z]{5}@hogwarts\.com$", email)): 10 | return "Yes" 11 | else: 12 | return "No" 13 | 14 | if __name__ == "__main__": 15 | s = input().strip() 16 | result = isValid(s) 17 | print(result) 18 | -------------------------------------------------------------------------------- /contests/projecteuler/euler008.py: -------------------------------------------------------------------------------- 1 | # ProjectEuler+ > Project Euler #8: Largest product in a series 2 | # Playing with really really long numbers. 3 | # 4 | # https://www.hackerrank.com/contests/projecteuler/challenges/euler008 5 | # challenge id: 2634 6 | # 7 | 8 | for _ in range(int(input())): 9 | n, k = map(int, input().split()) 10 | num = list(map(int, input())) 11 | 12 | m = 0 13 | 14 | for i in range(n - k): 15 | p = 1 16 | for j in range(i, i + k): 17 | p *= num[j] 18 | if p > m: 19 | m = p 20 | 21 | print(m) 22 | -------------------------------------------------------------------------------- /contests/projecteuler/euler013.py: -------------------------------------------------------------------------------- 1 | # ProjectEuler+ > Project Euler #13: Large sum 2 | # Summing up big things. 3 | # 4 | # https://www.hackerrank.com/contests/projecteuler/challenges/euler013 5 | # challenge id: 2639 6 | # 7 | 8 | # absolument aucun intérêt quand on utilise un langage adéquat 9 | 10 | resultat = sum(int(input()) for _ in range(int(input()))) 11 | print(str(resultat)[0:10]) 12 | -------------------------------------------------------------------------------- /contests/projecteuler/euler016.py: -------------------------------------------------------------------------------- 1 | # Project Euler #16: Power digit sum 2 | # 3 | # https://www.hackerrank.com/contests/projecteuler/challenges/euler016/problem 4 | 5 | for _ in range(int(input())): 6 | print(sum(int(c) for c in str(2 ** int(input())))) 7 | -------------------------------------------------------------------------------- /contests/projecteuler/euler020.py: -------------------------------------------------------------------------------- 1 | # ProjectEuler+ > Project Euler #20: Factorial digit sum 2 | # When complexities go from one extreme to the other. 3 | # 4 | # https://www.hackerrank.com/contests/projecteuler/challenges/euler020 5 | # challenge id: 2646 6 | # 7 | 8 | from math import factorial 9 | 10 | for _ in range(int(input())): 11 | n = int(input()) 12 | 13 | print(sum(int(d) for d in str(factorial(n)))) 14 | -------------------------------------------------------------------------------- /contests/projecteuler/euler028.py: -------------------------------------------------------------------------------- 1 | """ 2 | Project Euler #28: Number spiral diagonals 3 | 4 | https://www.hackerrank.com/contests/projecteuler/challenges/euler028/ 5 | """ 6 | 7 | 8 | # http://oeis.org/A114254 9 | def A114254(n): 10 | return 1 + 10 * n ** 2 + (16 * n ** 3 + 26 * n) // 3 11 | 12 | 13 | nb = int(input()) 14 | for i in range(nb): 15 | n = int(input()) // 2 16 | print(A114254(n) % 1000000007) 17 | -------------------------------------------------------------------------------- /contests/rookierank/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(antiprime-numbers.py) 2 | -------------------------------------------------------------------------------- /contests/womens-codesprint-3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HACKERRANK_CONTEST womens-codesprint-3) 2 | 3 | add_hackerrank_py(ascii-flower.py) 4 | -------------------------------------------------------------------------------- /contests/womens-codesprint-3/ascii-flower.py: -------------------------------------------------------------------------------- 1 | # Women's CodeSprint 3 > ASCII Flower 2 | # Help Julie design draw an ASCII flower pattern spanning a given number of rows and columns. 3 | # 4 | # https://www.hackerrank.com/contests/womens-codesprint-3/challenges/ascii-flower 5 | # 6 | 7 | flower = ['..O..', 8 | 'O.o.O', 9 | '..O..'] 10 | r, c = map(int, input().split()) 11 | for _ in range(r): 12 | for i in range(3): 13 | print(flower[i] * c) 14 | -------------------------------------------------------------------------------- /cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(classes) 2 | add_subdirectory(cpp-introduction) 3 | add_subdirectory(cpp-strings) 4 | add_subdirectory(inheritance) 5 | add_subdirectory(other-concepts) 6 | add_subdirectory(stl) 7 | add_subdirectory(cpp-debugging) 8 | -------------------------------------------------------------------------------- /cpp/classes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(box-it box-it.cpp) 2 | add_hackerrank(c-tutorial-class c-tutorial-class.cpp) 3 | add_hackerrank(classes-objects classes-objects.cpp) 4 | add_hackerrank(c-tutorial-struct c-tutorial-struct.cpp) 5 | add_hackerrank(abstract-classes-polymorphism abstract-classes-polymorphism.cpp) 6 | add_hackerrank(virtual-functions virtual-functions.cpp) 7 | add_hackerrank(inherited-code inherited-code.cpp) 8 | #add_hackerrank(exceptional-server exceptional-server.cpp) 9 | 10 | dirty_cpp(inherited-code) 11 | dirty_cpp(classes-objects) 12 | dirty_cpp(abstract-classes-polymorphism) 13 | -------------------------------------------------------------------------------- /cpp/cpp-debugging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(hotel-prices hotel-prices.cpp) 2 | add_hackerrank(cpp-exception-handling cpp-exception-handling.cpp) 3 | add_hackerrank(messages-order messages-order.cpp) 4 | add_hackerrank(overloading-ostream-operator overloading-ostream-operator.cpp) 5 | -------------------------------------------------------------------------------- /cpp/cpp-introduction/c-tutorial-basic-data-types.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/c-tutorial-basic-data-types/problem 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | // Complete the code. 9 | int a; 10 | long b; 11 | char c; 12 | float f; 13 | double d; 14 | if (5 == scanf("%d %ld %c %f %lf", &a, &b, &c, &f, &d)) 15 | printf("%d\n%ld\n%c\n%.3f\n%.9lf\n", a, b, c, f, d); 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /cpp/cpp-introduction/c-tutorial-pointer.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/c-tutorial-pointer/problem 2 | 3 | #include 4 | 5 | void update(int *a,int *b) { 6 | // Complete this function 7 | int c = *a + *b; 8 | int d = *a - *b; 9 | 10 | *a = c; 11 | *b = d >= 0 ? d : -d; 12 | } 13 | 14 | int main() { 15 | int a, b; 16 | int *pa = &a, *pb = &b; 17 | 18 | scanf("%d %d", &a, &b); 19 | update(pa, pb); 20 | printf("%d\n%d", a, b); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /cpp/cpp-introduction/cpp-hello-world.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/cpp-hello-world/problem 2 | 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int main() { 8 | std::cout << "Hello, World!" << std::endl; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /cpp/cpp-introduction/cpp-input-and-output.cpp: -------------------------------------------------------------------------------- 1 | // https://www.hackerrank.com/challenges/cpp-input-and-output/problem 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | 11 | int main() { 12 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 13 | int a,b,c; scanf("%d %d %d",&a,&b,&c); printf("%d\n",a+b+c); 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /cpp/cpp-strings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(attribute-parser attribute-parser.cpp) 2 | add_hackerrank(c-tutorial-stringstream c-tutorial-stringstream.cpp) 3 | add_hackerrank(c-tutorial-strings c-tutorial-strings.cpp) 4 | -------------------------------------------------------------------------------- /cpp/cpp-strings/c-tutorial-strings.cpp: -------------------------------------------------------------------------------- 1 | // Strings 2 | // 3 | // https://www.hackerrank.com/challenges/c-tutorial-strings/problem 4 | 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int main() { 11 | // Complete the program 12 | string a, b; 13 | 14 | cin >> a; 15 | cin >> b; 16 | cout << a.size() << " " << b.size() << endl; 17 | cout << a + b << endl; 18 | 19 | std::swap(a[0], b[0]); 20 | cout << a << " " << b << endl; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /cpp/inheritance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(rectangle-area rectangle-area.cpp) 2 | add_hackerrank(inheritance-introduction inheritance-introduction.cpp) 3 | add_hackerrank(accessing-inherited-functions accessing-inherited-functions.cpp) 4 | add_hackerrank(magic-spells magic-spells.cpp) 5 | add_hackerrank(multi-level-inheritance-cpp multi-level-inheritance-cpp.cpp) 6 | -------------------------------------------------------------------------------- /cpp/stl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(vector-erase vector-erase.cpp) 2 | add_hackerrank(cpp-sets cpp-sets.cpp) 3 | add_hackerrank(cpp-lower-bound cpp-lower-bound.cpp) 4 | add_hackerrank(deque-stl deque-stl.cpp) 5 | add_hackerrank(vector-sort vector-sort.cpp) 6 | add_hackerrank(prettyprint prettyprint.cpp) 7 | add_hackerrank(cpp-maps cpp-maps.cpp) 8 | 9 | dirty_cpp(deque-stl) -------------------------------------------------------------------------------- /data-structures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/data-structures 2 | 3 | add_subdirectory(arrays) 4 | add_subdirectory(trees) 5 | add_subdirectory(linked-lists) 6 | add_subdirectory(trie) 7 | add_subdirectory(heap) 8 | add_subdirectory(stacks) 9 | add_subdirectory(queues) 10 | -------------------------------------------------------------------------------- /data-structures/arrays/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(sparse-arrays.py) 2 | add_hackerrank_py(2d-array.py) 3 | add_hackerrank_py(crush.py) 4 | add_hackerrank_py(array-left-rotation.py) 5 | add_hackerrank_py(dynamic-array.py) 6 | add_hackerrank(arrays-ds arrays-ds.cpp) 7 | add_hackerrank_py(arrays-ds.py) 8 | -------------------------------------------------------------------------------- /data-structures/arrays/array-left-rotation.py: -------------------------------------------------------------------------------- 1 | # Left Rotation 2 | # Given an array and a number, d, perform d left rotations on the array. 3 | # 4 | # https://www.hackerrank.com/challenges/array-left-rotation/problem 5 | # 6 | 7 | def rotate(l, n): 8 | n = n % len(l) 9 | return l[n:] + l[:n] 10 | 11 | 12 | if __name__ == '__main__': 13 | nd = input().split() 14 | n = int(nd[0]) 15 | d = int(nd[1]) 16 | a = list(map(int, input().split())) 17 | a = rotate(a, d) 18 | print(' '.join(map(str, a))) 19 | -------------------------------------------------------------------------------- /data-structures/arrays/arrays-ds.py: -------------------------------------------------------------------------------- 1 | # Arrays - DS 2 | # Accessing and using arrays. 3 | # 4 | # https://www.hackerrank.com/challenges/arrays-ds/problem 5 | # 6 | 7 | # avec certains langages, c'est peut-être plus challengant qu'en Python... 8 | 9 | input() 10 | print(' '.join(map(str, reversed(list(map(int, input().split())))))) -------------------------------------------------------------------------------- /data-structures/arrays/sparse-arrays.py: -------------------------------------------------------------------------------- 1 | # Sparse Arrays 2 | # Determine the number of times a string has previously appeared. 3 | # 4 | # https://www.hackerrank.com/challenges/sparse-arrays/problem 5 | # 6 | 7 | from collections import defaultdict 8 | 9 | strings = defaultdict(lambda: 0) 10 | 11 | for _ in range(int(input())): 12 | strings[input()] += 1 13 | 14 | for _ in range(int(input())): 15 | print(strings[input()]) 16 | -------------------------------------------------------------------------------- /data-structures/heap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(find-the-running-median.py) 2 | add_hackerrank_py(qheap1.py) 3 | add_hackerrank_py(jesse-and-cookies.py) 4 | -------------------------------------------------------------------------------- /data-structures/heap/find-the-running-median.py: -------------------------------------------------------------------------------- 1 | # Find the Running Median 2 | # Find the median of the elements after inputting each element. 3 | # 4 | # https://www.hackerrank.com/challenges/find-the-running-median/problem 5 | # 6 | 7 | import bisect 8 | 9 | a = [] 10 | for _ in range(int(input())): 11 | n = int(input()) 12 | bisect.insort(a, n) 13 | m = (a[(len(a) - 1) // 2] + a[len(a) // 2]) / 2 14 | print("%.1f" % m) 15 | -------------------------------------------------------------------------------- /data-structures/queues/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(queue-using-two-stacks.py) 2 | -------------------------------------------------------------------------------- /data-structures/queues/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [Data Structures](https://www.hackerrank.com/domains/data-structures) 3 | Data Structures help in elegant representation of data for algorithms 4 | 5 | 6 | #### [Queues](https://www.hackerrank.com/domains/data-structures/queues) 7 | 8 | Name | Preview | Code | Difficulty 9 | ---- | ------- | ---- | ---------- 10 | [Queue using Two Stacks](https://www.hackerrank.com/challenges/queue-using-two-stacks)|Create a queue data structure using two stacks.|[Python](queue-using-two-stacks.py)|Medium 11 | 12 | -------------------------------------------------------------------------------- /data-structures/stacks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(maximum-element maximum-element.cpp) 2 | add_hackerrank_py(balanced-brackets.py) 3 | add_hackerrank_py(equal-stacks.py) 4 | add_hackerrank_py(largest-rectangle.py) 5 | add_hackerrank_py(simple-text-editor.py) 6 | -------------------------------------------------------------------------------- /data-structures/trees/array-pairs.py: -------------------------------------------------------------------------------- 1 | """ 2 | Array Pairs 3 | 4 | https://www.hackerrank.com/challenges/array-pairs/problem 5 | """ 6 | 7 | n = int(input()) 8 | a = list(map(int, input().split())) 9 | 10 | #import random 11 | #a = [1,1,2,4,2,1,1,2,4,36,1,2,4,21,1,2,4,2] 12 | #n = len(a) 13 | 14 | """ BRUTE FORCE """ 15 | nb = 0 16 | for i in range(n - 1): 17 | for j in range(i + 1, n): 18 | m = max(a[i:j + 1]) 19 | if a[i] * a[j] <= m: 20 | nb += 1 21 | print(nb) 22 | -------------------------------------------------------------------------------- /data-structures/trie/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(contacts.py) 2 | add_hackerrank_py(no-prefix-set.py) 3 | -------------------------------------------------------------------------------- /databases/database-normalization/README.md: -------------------------------------------------------------------------------- 1 | 2 | ### [Databases](https://www.hackerrank.com/domains/databases) 3 | Check your Database skills 4 | 5 | 6 | #### [Database Normalization](https://www.hackerrank.com/domains/databases/database-normalization) 7 | 8 | Name | Preview | Code | Difficulty 9 | ---- | ------- | ---- | ---------- 10 | [Database Normalization #1 - 1NF](https://www.hackerrank.com/challenges/database-normalization-1-1nf)|The first normal form.|[text](database-normalization-1-1nf.txt)|Easy 11 | 12 | -------------------------------------------------------------------------------- /databases/database-normalization/database-normalization-1-1nf.txt: -------------------------------------------------------------------------------- 1 | # Databases > Database Normalization > Database Normalization #1 - 1NF 2 | # The first normal form. 3 | # 4 | # https://www.hackerrank.com/challenges/database-normalization-1-1nf/problem 5 | # 6 | 7 | 3 8 | 5 9 | 2 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-1.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #1 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-1/problem 5 | # 6 | 7 | # union: résultat de l'union: 1,2,3,4,5,6,7,8 8 | 9 | 8 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-2.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #2 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-2/problem 5 | # 6 | 7 | # intersection: les éléments 2,3,4,5,6 sont présents dans les deux listes 8 | 9 | 5 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-3.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #3 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-3/problem 5 | # 6 | 7 | # les éléments de A moins les éléments de B: il ne reste que 1 8 | 9 | 1 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-4.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #4 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-4/problem 5 | # 6 | 7 | # c'est le nombre de combinaisons entre A et B: 6 éléments de A avec 7 éléments de B 8 | 9 | 42 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-5.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #5 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-5/problem 5 | # 6 | 7 | 2 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-6.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #6 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-6/problem 5 | # 6 | 7 | 2 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/basics-of-sets-and-relational-algebra-7.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Basics of Sets and Relations #7 2 | # Problems based on the basics of sets and relations. 3 | # 4 | # https://www.hackerrank.com/challenges/basics-of-sets-and-relational-algebra-7/problem 5 | # 6 | 7 | 2 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/database-query-languages.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Database Query Languages 2 | 3 | # 4 | # https://www.hackerrank.com/challenges/database-query-languages/problem 5 | # 6 | 7 | Query 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/procedural-language.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Procedural Language 2 | 3 | # 4 | # https://www.hackerrank.com/challenges/procedural-language/problem 5 | # 6 | 7 | Relational algebra 8 | 9 | # (question vaseuse) 10 | -------------------------------------------------------------------------------- /databases/relational-algebra/relational-algebra-3.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Relational Algebra - 3 2 | 3 | # 4 | # https://www.hackerrank.com/challenges/relational-algebra-3/problem 5 | # 6 | 7 | Equijoins 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/relational-algebra-4.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Relational Algebra - 4 2 | # 3 | # https://www.hackerrank.com/challenges/relational-algebra-4/problem 4 | # 5 | 6 | Left to right 7 | -------------------------------------------------------------------------------- /databases/relational-algebra/relations-1.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Relations - 1 2 | 3 | # 4 | # https://www.hackerrank.com/challenges/relations-1/problem 5 | # 6 | 7 | Join 8 | -------------------------------------------------------------------------------- /databases/relational-algebra/relations-2.txt: -------------------------------------------------------------------------------- 1 | # Databases > Relational Algebra > Relations - 2 2 | 3 | # 4 | # https://www.hackerrank.com/challenges/relations-2/problem 5 | # 6 | 7 | Cartesian product 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/distributed-systems?filters%5Bsubdomains%5D%5B%5D=distributed-mcq 2 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-10.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > Distributed Objects - 4 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-10/problem 4 | # challenge id: 8461 5 | # 6 | 7 | JavaSpaces 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-11.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > Distributed Objects - 5 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-11/problem 4 | # challenge id: 8462 5 | # 6 | 7 | Pyro 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-13.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > MapReduce - 2 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-13/problem 4 | # challenge id: 8464 5 | # 6 | 7 | True 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-14.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > MapReduce - 3 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-14/problem 4 | # challenge id: 8465 5 | # 6 | 7 | False 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-7.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > Distributed Objects - 1 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-7/problem 4 | # challenge id: 8458 5 | # 6 | 7 | DCOM 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-8.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > Distributed Objects - 2 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-8/problem 4 | # challenge id: 8459 5 | # 6 | 7 | DDObjects 8 | -------------------------------------------------------------------------------- /distributed-systems/distributed-mcq/mcq-challenge-9.txt: -------------------------------------------------------------------------------- 1 | # Distributed Systems > Multiple Choice > Distributed Objects - 3 2 | # 3 | # https://www.hackerrank.com/challenges/mcq-challenge-9/problem 4 | # challenge id: 8460 5 | # 6 | 7 | Jt 8 | -------------------------------------------------------------------------------- /fp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(intro) 2 | -------------------------------------------------------------------------------- /fp/intro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(fp Haskell) 2 | 3 | add_executable(fp-solve-me-first fp-solve-me-first.hs) 4 | add_executable(fp-hello-world fp-hello-world.hs) 5 | add_executable(fp-hello-world-n-times fp-hello-world-n-times.hs) 6 | 7 | add_test_hackerrank(fp-solve-me-first) 8 | add_test_hackerrank(fp-hello-world) 9 | add_test_hackerrank(fp-hello-world-n-times) 10 | -------------------------------------------------------------------------------- /fp/intro/fp-hello-world.erl: -------------------------------------------------------------------------------- 1 | % Hello World 2 | % Write code to print the 'Hello World' program. 3 | % 4 | % https://www.hackerrank.com/challenges/fp-hello-world/problem 5 | % 6 | 7 | % Enter your code here. Read input from STDIN. Print output to STDOUT 8 | % Your class should be named solution 9 | 10 | -module(solution). 11 | -export([main/0]). 12 | 13 | hello() -> 14 | io:fwrite("Hello World\n"). 15 | 16 | main() -> 17 | hello(). 18 | -------------------------------------------------------------------------------- /fp/intro/fp-hello-world.hs: -------------------------------------------------------------------------------- 1 | -- Hello World 2 | -- Write code to print the 'Hello World' program. 3 | -- 4 | -- https://www.hackerrank.com/challenges/fp-hello-world/problem 5 | -- 6 | 7 | -- Enter your code here. Read input from STDIN. Print output to STDOUT 8 | 9 | hello_world = -- Fill up this function 10 | putStrLn "Hello World" 11 | 12 | -- This part relates to Input/Output and can be used as it is. Do not modify this section 13 | main = do 14 | hello_world 15 | -------------------------------------------------------------------------------- /fp/intro/fp-solve-me-first.hs: -------------------------------------------------------------------------------- 1 | -- Solve Me First FP 2 | -- This is a special challenge to make you familiar with IO. 3 | -- 4 | -- https://www.hackerrank.com/challenges/fp-solve-me-first/problem 5 | -- 6 | 7 | solveMeFirst a b = a + b 8 | 9 | -- (template_tail) ---------------------------------------------------------------------- 10 | main = do 11 | val1 <- readLn 12 | val2 <- readLn 13 | let sum = solveMeFirst val1 val2 14 | print sum 15 | -------------------------------------------------------------------------------- /interview-preparation-kit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(arrays) 2 | add_subdirectory(dictionaries-hashmaps) 3 | 4 | add_subdirectory(miscellaneous) 5 | -------------------------------------------------------------------------------- /interview-preparation-kit/arrays/2d-array.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/arrays/2d-array.py -------------------------------------------------------------------------------- /interview-preparation-kit/arrays/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #add_hackerrank_py(2d-array.py) 2 | #add_hackerrank_py(ctci-array-left-rotation.py) 3 | #add_hackerrank_py(crush.py) 4 | #add_hackerrank_py(new-year-chaos.py) 5 | add_hackerrank_py(minimum-swaps-2.py) 6 | -------------------------------------------------------------------------------- /interview-preparation-kit/arrays/crush.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/arrays/crush.py -------------------------------------------------------------------------------- /interview-preparation-kit/arrays/ctci-array-left-rotation.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-array-left-rotation.py -------------------------------------------------------------------------------- /interview-preparation-kit/arrays/new-year-chaos.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/constructive-algorithms/new-year-chaos.py -------------------------------------------------------------------------------- /interview-preparation-kit/dictionaries-hashmaps/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rene-d/hackerrank/1bfdbc63de5d0f94cd9e6ae250476b4a267662f2/interview-preparation-kit/dictionaries-hashmaps/CMakeLists.txt -------------------------------------------------------------------------------- /interview-preparation-kit/dictionaries-hashmaps/ctci-ransom-note.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-ransom-note.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/dictionaries-hashmaps/sherlock-and-anagrams.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/sherlock-and-anagrams.py -------------------------------------------------------------------------------- /interview-preparation-kit/dictionaries-hashmaps/two-strings.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/two-strings.py -------------------------------------------------------------------------------- /interview-preparation-kit/graphs/ctci-bfs-shortest-reach.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-bfs-shortest-reach.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/graphs/ctci-connected-cell-in-a-grid.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-connected-cell-in-a-grid.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/greedy-algorithms/minimum-absolute-difference-in-an-array.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/greedy/minimum-absolute-difference-in-an-array.py -------------------------------------------------------------------------------- /interview-preparation-kit/linked-lists/ctci-linked-list-cycle.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-linked-list-cycle.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/linked-lists/find-the-merge-point-of-two-joined-linked-lists.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/linked-lists/find-the-merge-point-of-two-joined-linked-lists.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/linked-lists/insert-a-node-at-a-specific-position-in-a-linked-list.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/linked-lists/insert-a-node-at-a-specific-position-in-a-linked-list.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/linked-lists/insert-a-node-into-a-sorted-doubly-linked-list.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/linked-lists/insert-a-node-into-a-sorted-doubly-linked-list.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/linked-lists/reverse-a-doubly-linked-list.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/linked-lists/reverse-a-doubly-linked-list.py -------------------------------------------------------------------------------- /interview-preparation-kit/miscellaneous/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(friend-circle-queries.py) 2 | add_hackerrank(maximum-xor maximum-xor.cpp) 3 | -------------------------------------------------------------------------------- /interview-preparation-kit/miscellaneous/ctci-big-o.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-big-o.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/miscellaneous/flipping-bits.cpp: -------------------------------------------------------------------------------- 1 | ../../algorithms/bit-manipulation/flipping-bits.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/recursion-backtracking/ctci-fibonacci-numbers.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-fibonacci-numbers.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/recursion-backtracking/ctci-recursive-staircase.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-recursive-staircase.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/search/ctci-ice-cream-parlor.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-ice-cream-parlor.py -------------------------------------------------------------------------------- /interview-preparation-kit/search/pairs.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/search/pairs.py -------------------------------------------------------------------------------- /interview-preparation-kit/sorting/ctci-bubble-sort.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-bubble-sort.py -------------------------------------------------------------------------------- /interview-preparation-kit/sorting/ctci-comparator-sorting.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-comparator-sorting.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/sorting/ctci-merge-sort.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-merge-sort.py -------------------------------------------------------------------------------- /interview-preparation-kit/stacks-queues/balanced-brackets.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/stacks/balanced-brackets.py -------------------------------------------------------------------------------- /interview-preparation-kit/stacks-queues/ctci-queue-using-two-stacks.cpp: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-queue-using-two-stacks.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/stacks-queues/largest-rectangle.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/stacks/largest-rectangle.py -------------------------------------------------------------------------------- /interview-preparation-kit/strings/alternating-characters.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/alternating-characters.py -------------------------------------------------------------------------------- /interview-preparation-kit/strings/common-child.cpp: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/common-child.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/strings/common-child.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/common-child.py -------------------------------------------------------------------------------- /interview-preparation-kit/strings/ctci-making-anagrams.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-making-anagrams.py -------------------------------------------------------------------------------- /interview-preparation-kit/strings/sherlock-and-valid-string.py: -------------------------------------------------------------------------------- 1 | ../../algorithms/strings/sherlock-and-valid-string.py -------------------------------------------------------------------------------- /interview-preparation-kit/trees/binary-search-tree-lowest-common-ancestor.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/trees/binary-search-tree-lowest-common-ancestor.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/trees/ctci-is-binary-search-tree.py: -------------------------------------------------------------------------------- 1 | ../../tutorials/cracking-the-coding-interview/ctci-is-binary-search-tree.py -------------------------------------------------------------------------------- /interview-preparation-kit/trees/tree-height-of-a-binary-tree.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/trees/tree-height-of-a-binary-tree.cpp -------------------------------------------------------------------------------- /interview-preparation-kit/trees/tree-height-of-a-binary-tree.py: -------------------------------------------------------------------------------- 1 | ../../data-structures/trees/tree-height-of-a-binary-tree.py -------------------------------------------------------------------------------- /interview-preparation-kit/trees/tree-huffman-decoding.cpp: -------------------------------------------------------------------------------- 1 | ../../data-structures/trees/tree-huffman-decoding.cpp -------------------------------------------------------------------------------- /java/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(java-introduction) 2 | -------------------------------------------------------------------------------- /java/java-introduction/welcome-to-java.java: -------------------------------------------------------------------------------- 1 | // Java > Introduction > Welcome to Java! 2 | // Practice printing to stdout. 3 | // 4 | // https://www.hackerrank.com/challenges/welcome-to-java/problem 5 | // challenge id: 7875 6 | // 7 | 8 | public class Solution { 9 | 10 | public static void main(String[] args) { 11 | System.out.println("Hello, World."); 12 | System.out.println("Hello, Java."); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mathematics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/mathematics 2 | 3 | add_subdirectory(fundamentals) 4 | add_subdirectory(number-theory) 5 | add_subdirectory(combinatorics) 6 | add_subdirectory(geometry) 7 | add_subdirectory(algebra) 8 | add_subdirectory(probability) 9 | -------------------------------------------------------------------------------- /mathematics/algebra/sherlock-and-square.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Algebra > Sherlock and Square 2 | # Help Sherlock in finding the total side lengths of squares. 3 | # 4 | # https://www.hackerrank.com/challenges/sherlock-and-square/problem 5 | # https://www.hackerrank.com/contests/w11/challenges/sherlock-and-square 6 | # challenge id: 4429 7 | # 8 | 9 | MOD = 1000000007 10 | 11 | for _ in range(int(input())): 12 | n = int(input()) 13 | print((pow(2, n + 1, MOD) + 2) % MOD) 14 | -------------------------------------------------------------------------------- /mathematics/algebra/wet-shark-and-42.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Algebra > Wet Shark and 42 2 | # Help Wet Shark escape the gods of 42. 3 | # 4 | # https://www.hackerrank.com/challenges/wet-shark-and-42/problem 5 | # https://www.hackerrank.com/contests/infinitum9/challenges/wet-shark-and-42 6 | # 7 | 8 | def distance(n): 9 | return (n * 21 - 1) // 20 * 2 10 | 11 | for _ in range(int(input())): 12 | n = int(input()) 13 | print(distance(n) % 1000000007) 14 | -------------------------------------------------------------------------------- /mathematics/combinatorics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(merge-list.py) 2 | add_hackerrank_py(a-chocolate-fiesta.py) 3 | add_hackerrank_py(ncr-table.py) 4 | add_hackerrank_py(building-a-list.py) 5 | add_hackerrank_py(coinage.py) 6 | add_hackerrank(ncr-table ncr-table.cpp) 7 | add_hackerrank_py(sherlock-and-pairs.py) 8 | add_hackerrank_py(picking-cards.py) 9 | -------------------------------------------------------------------------------- /mathematics/combinatorics/merge-list.py: -------------------------------------------------------------------------------- 1 | # Merge List 2 | # Help Shashank in merging two list. 3 | # 4 | # https://www.hackerrank.com/challenges/merge-list/problem 5 | # 6 | 7 | from math import factorial 8 | 9 | 10 | def C(n, r): 11 | return factorial(n) // factorial(r) // factorial(n - r) 12 | 13 | 14 | for i in range(int(input())): 15 | n, m = map(int, input().split()) 16 | print(C(n + m, n) % 1000000007) 17 | -------------------------------------------------------------------------------- /mathematics/combinatorics/ncr-table.py: -------------------------------------------------------------------------------- 1 | # nCr table 2 | # Help Jim calculating nCr values 3 | # 4 | # https://www.hackerrank.com/challenges/ncr-table/problem 5 | # 6 | 7 | from math import factorial 8 | 9 | 10 | def C(n, r): 11 | return factorial(n) // factorial(r) // factorial(n - r) 12 | 13 | 14 | for i in range(int(input())): 15 | n = int(input()) 16 | print(' '.join(str(C(n, r) % 1000000000) for r in range(n + 1))) 17 | -------------------------------------------------------------------------------- /mathematics/fundamentals/connecting-towns.py: -------------------------------------------------------------------------------- 1 | # Connecting Towns 2 | # Find the Number of ways to in which one can travel from one town to another. 3 | # 4 | # https://www.hackerrank.com/challenges/connecting-towns/problem 5 | # 6 | 7 | # Python gère nativement les big integers, il suffit de lire l'énoncé 8 | 9 | for _ in range(int(input())): 10 | n = int(input()) 11 | r = list(map(int, input().split())) 12 | 13 | p = 1 14 | for i in r: 15 | p = (p * i) % 1234567 16 | print(p) 17 | -------------------------------------------------------------------------------- /mathematics/fundamentals/die-hard-3.py: -------------------------------------------------------------------------------- 1 | # Die Hard 3 2 | # Help Bruce and Samuel save the city by solving their puzzle 3 | # 4 | # https://www.hackerrank.com/challenges/die-hard-3/problem 5 | # 6 | 7 | from math import gcd 8 | 9 | for _ in range(int(input())): 10 | a, b, c = map(int, input().split()) 11 | 12 | print("YES" if c <= max(a, b) and c % gcd(a, b) == 0 else "NO") 13 | -------------------------------------------------------------------------------- /mathematics/fundamentals/diwali-lights.py: -------------------------------------------------------------------------------- 1 | # Diwali Lights 2 | # Number of ways to light the room 3 | # 4 | # https://www.hackerrank.com/challenges/diwali-lights/problem 5 | # 6 | 7 | # chaque lampe peut être allumée ou éteinte 8 | # il y a donc 2^n possibilités pour n lampes 9 | # -1 parce qu'il en faut une allumé 10 | 11 | for n in range(int(input())): 12 | n = int(input()) 13 | print((2 ** n - 1) % 100000) -------------------------------------------------------------------------------- /mathematics/fundamentals/even-odd-query.py: -------------------------------------------------------------------------------- 1 | # Weekly Challenges - Week 5 > Even Odd Query 2 | # Is the number odd or even? 3 | # 4 | # https://www.hackerrank.com/contests/w5/challenges/even-odd-query 5 | # 6 | 7 | input() 8 | A = list(map(int, input().split())) 9 | 10 | for _ in range(int(input())): 11 | x, y = map(int, input().split()) 12 | if A[x - 1] % 2 == 1 or x > y or (x < y and A[x] == 0): 13 | print("Odd") 14 | else: 15 | print("Even") 16 | -------------------------------------------------------------------------------- /mathematics/fundamentals/filling-jars.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Fundamentals > Filling Jars 2 | # Perform the multiple queries on the list. And print average. - 20 Points 3 | # 4 | # https://www.hackerrank.com/challenges/filling-jars/problem 5 | # 6 | 7 | # dans ce challenge, nul besoin de calculer les contenus de chaque jarre 8 | # il suffit de calculer une somme globale 9 | # sinon c'est trop lent 10 | 11 | n, m = map(int, input().split()) 12 | sum_k = 0 13 | for _ in range(m): 14 | a, b, k = map(int, input().split()) 15 | sum_k += k * (b - a + 1) 16 | print(sum_k // n) 17 | -------------------------------------------------------------------------------- /mathematics/fundamentals/find-point.cpp: -------------------------------------------------------------------------------- 1 | // Find the Point 2 | // 3 | // https://www.hackerrank.com/challenges/find-point/problem 4 | 5 | #include 6 | using namespace std; 7 | int main() 8 | { 9 | int n; 10 | cin >> n; 11 | for (auto i = 0; i < n; ++i) 12 | { 13 | int px, py, qx, qy; 14 | cin >> px >> py >> qx >> qy; 15 | cout << (qx + qx - px) << " " << (qy + qy - py) << endl; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /mathematics/fundamentals/game-with-cells.py: -------------------------------------------------------------------------------- 1 | # Army Game 2 | # Find the minimum number of supply packages Luke must drop to supply all of his army bases. 3 | # 4 | # https://www.hackerrank.com/challenges/game-with-cells/problem 5 | # 6 | 7 | 8 | n, m = map(int, input().split()) 9 | r = ((n + 1) // 2) * ((m + 1) // 2) 10 | print(r) 11 | -------------------------------------------------------------------------------- /mathematics/fundamentals/halloween-party.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Fundamentals > Halloween party 2 | # Help Alex give Silvia the maximum number of chocolates 3 | # 4 | # https://www.hackerrank.com/challenges/halloween-party/problem 5 | # 6 | 7 | for _ in range(int(input())): 8 | K = int(input()) 9 | # K pair: on coupe K/2 fois horizontalement et K/2 fois verticalement 10 | # K impair: on coupe une fois de plus horizontalement ou verticalement 11 | print((K // 2) * ((K + 1) // 2)) -------------------------------------------------------------------------------- /mathematics/fundamentals/handshake.py: -------------------------------------------------------------------------------- 1 | # Handshake 2 | # Count the number of Handshakes in a board meeting. 3 | # 4 | # https://www.hackerrank.com/challenges/handshake/problem 5 | # 6 | 7 | T = int(input()) 8 | for a0 in range(T): 9 | N = int(input()) 10 | print(N * (N - 1) // 2) 11 | -------------------------------------------------------------------------------- /mathematics/fundamentals/harry-potter-and-the-floating-rocks.py: -------------------------------------------------------------------------------- 1 | # Sumar and the Floating Rocks 2 | # Count the number of integral rocks between Harry and Hermoine 3 | # 4 | # https://www.hackerrank.com/challenges/harry-potter-and-the-floating-rocks/problem 5 | # 6 | 7 | from math import gcd 8 | 9 | for _ in range(int(input())): 10 | x1, y1, x2, y2 = map(int, input().split()) 11 | 12 | # y = A* x + B 13 | # y1 = A * x1 + B 14 | # y2 = A * x2 + B 15 | # A = (y2-y1) / (x2-x1) 16 | 17 | f = gcd(y2 - y1, x2 - x1) - 1 18 | print(f) 19 | -------------------------------------------------------------------------------- /mathematics/fundamentals/k-candy-store.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Fundamentals > K Candy Store 2 | # In how many ways can you select K candies out of N different types of candies when each of the N candies are infinite in number? 3 | # 4 | # https://www.hackerrank.com/challenges/k-candy-store/problem 5 | # 6 | 7 | from math import factorial 8 | 9 | def C(n, k): 10 | return factorial(n) // factorial(n - k) // factorial(k) 11 | 12 | t = int(input()) 13 | for _ in range(t): 14 | n = int(input()) 15 | k = int(input()) 16 | print(C(n + k - 1, n - 1) % 10 ** 9) 17 | -------------------------------------------------------------------------------- /mathematics/fundamentals/lowest-triangle.py: -------------------------------------------------------------------------------- 1 | # Minimum Height Triangle 2 | # Find the smallest height of a triangle preserving the given constraints. 3 | # 4 | # https://www.hackerrank.com/challenges/lowest-triangle/problem 5 | # 6 | 7 | base, area = map(int, input().split()) 8 | height = (2 * area - 1) // base + 1 9 | print(height) 10 | -------------------------------------------------------------------------------- /mathematics/fundamentals/maximum-draws.py: -------------------------------------------------------------------------------- 1 | # Maximum Draws 2 | # Count the minimum Draws 3 | # 4 | # https://www.hackerrank.com/challenges/maximum-draws/problem 5 | # 6 | 7 | for _ in range(int(input())): 8 | n = int(input()) 9 | 10 | # dans le pire des cas, on retire toutes les chaussettes de chaque paire 11 | # à la suivante, on aura forcément une paire assortie 12 | print(n + 1) 13 | -------------------------------------------------------------------------------- /mathematics/fundamentals/p1-paper-cutting.py: -------------------------------------------------------------------------------- 1 | # Cutting Paper Squares 2 | # Determine the number of cuts needed to cut a paper into $1 \times 1$ squares. 3 | # 4 | # https://www.hackerrank.com/challenges/p1-paper-cutting/problem 5 | # 6 | 7 | import sys 8 | 9 | def solve(n, m): 10 | # Complete this function 11 | return n * m - 1 12 | 13 | 14 | n, m = input().strip().split(' ') 15 | n, m = [int(n), int(m)] 16 | result = solve(n, m) 17 | print(result) 18 | -------------------------------------------------------------------------------- /mathematics/fundamentals/possible-path.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Fundamentals > Possible Path 2 | # Help Adam in reaching at aa particular point. 3 | # 4 | # https://www.hackerrank.com/challenges/possible-path/problem 5 | # 6 | 7 | from math import gcd 8 | 9 | for _ in range(int(input())): 10 | a, b, x, y = map(int, input().split()) 11 | 12 | print(["NO", "YES"][gcd(a, b) == gcd(x, y)]) 13 | 14 | # il faut bien comprendre le phrasé de l'énoncé... 15 | # (a,b) change à chaque déplacement 16 | # print(["NO", "YES"][(x - a) % b == 0 and (y - b) % a == 0]) 17 | -------------------------------------------------------------------------------- /mathematics/fundamentals/restaurant.py: -------------------------------------------------------------------------------- 1 | # Restaurant 2 | # Help Martha with her interview at Subway 3 | # 4 | # https://www.hackerrank.com/challenges/restaurant/problem 5 | # 6 | 7 | from math import gcd 8 | 9 | for _ in range(int(input())): 10 | l, b = map(int, input().split()) 11 | 12 | if l == b: 13 | print(1) 14 | else: 15 | print((l * b) // gcd(l, b) ** 2) 16 | -------------------------------------------------------------------------------- /mathematics/fundamentals/strange-grid.py: -------------------------------------------------------------------------------- 1 | # Strange Grid Again 2 | # find the integer in c-th column in r-th row of the grid. 3 | # 4 | # https://www.hackerrank.com/challenges/strange-grid/problem 5 | # 6 | 7 | r, c = map(int, input().split()) 8 | 9 | r -= 1 10 | c -= 1 11 | print((r // 2) * 10 + c * 2 + r % 2) 12 | -------------------------------------------------------------------------------- /mathematics/fundamentals/summing-the-n-series.py: -------------------------------------------------------------------------------- 1 | # Summing the N series 2 | # Sum the N series. 3 | # 4 | # https://www.hackerrank.com/challenges/summing-the-n-series/problem 5 | # 6 | 7 | # c'est quand même plus facile que les problèmes de Project Euler... 8 | 9 | for _ in range(int(input())): 10 | n = int(input()) 11 | print((n ** 2) % 1000000007) 12 | 13 | -------------------------------------------------------------------------------- /mathematics/geometry/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/mathematics/geometry 2 | 3 | add_hackerrank_py(points-on-a-line.py) 4 | add_hackerrank_py(baby-step-giant-step.py) 5 | add_hackerrank_py(rectangular-game.py) 6 | add_hackerrank_py(sherlock-and-counting.py) 7 | add_hackerrank_py(points-on-rectangle.py) 8 | add_hackerrank_py(sherlock-and-planes.py) 9 | add_hackerrank_py(circle-city.py) 10 | add_hackerrank_py(xrange-and-pizza.py) 11 | add_hackerrank(a-circle-and-a-square a-circle-and-a-square.cpp) 12 | -------------------------------------------------------------------------------- /mathematics/geometry/rectangular-game.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Geometry > Rectangular Game 2 | # What's the largest number in the rectangular grid? 3 | # 4 | # https://www.hackerrank.com/challenges/rectangular-game/problem 5 | # 6 | 7 | # sans forcer, la réponse est clairement min(x) * min(y) 8 | 9 | n = int(input()) 10 | mx, my = map(int, input().split()) 11 | for _ in range(n - 1): 12 | x, y = map(int, input().split()) 13 | mx = min(x, mx) 14 | my = min(y, my) 15 | print(mx * my) 16 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/mathematics/linear-algebra-foundations 2 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/determinant-of-the-matrix-2.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Determinant of the matrix #2 2 | # Basic problems related to determinants. 3 | # 4 | # https://www.hackerrank.com/challenges/determinant-of-the-matrix-2/problem 5 | # 6 | 7 | # det(A) = 5 8 | # det(2A) = 5 * 2^dim(A) = 5 * 2^3 = 40 9 | # det(transpose(A)) = det(A) = 5 10 | 11 | # réponse: 12 | 5 13 | 40 14 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/determinant-of-the-matrix-3.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Determinant of the matrix #3 2 | # Basic problems related to determinants. 3 | # 4 | # https://www.hackerrank.com/challenges/determinant-of-the-matrix-3/problem 5 | # 6 | 7 | # le déterminant d'une matrice d'ordre 3 est a*e*i+b*f*g+c*d*h-g*e*c-h*f*a-i*d*b 8 | # il ne change pas dans la deuxième matrice 9 | 10 | # réponse: 11 | -6 12 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/eigenvalue-of-matrix-1.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Eigenvalue of a Matrix I 2 | # Basic problems related to eigenvalues. 3 | # 4 | # https://www.hackerrank.com/challenges/eigenvalue-of-matrix-1/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | M = np.matrix([[1, -3, 3], 10 | [3, -5, 3], 11 | [6, -6, 4]]) 12 | 13 | print(np.linalg.eigvals(M)) 14 | 15 | I = np.identity(np.linalg.matrix_rank(M)) 16 | 17 | for λ in np.linalg.eigvals(M): 18 | print(np.linalg.det(M - λ * I)) -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/eigenvalue-of-matrix-2.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Eigenvalue of matrix #2 2 | # Basic problems related to eigenvalues. 3 | # 4 | # https://www.hackerrank.com/challenges/eigenvalue-of-matrix-2/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | M = np.matrix([[1, 2], 10 | [2, 4]]) 11 | 12 | print(np.linalg.eigvals(M)) 13 | 14 | I = np.identity(np.linalg.matrix_rank(M)) 15 | 16 | for λ in np.linalg.eigvals(M): 17 | print(np.linalg.det(M - λ * I)) -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/eigenvalues-of-matrix-3.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Eigenvalue of matrix #3 2 | # Basic problems related to eigenvalues. 3 | # 4 | # https://www.hackerrank.com/challenges/eigenvalues-of-matrix-3/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | a = np.matrix([[2, -1], [-1, 2]]) 10 | 11 | print(np.linalg.eigvalsh(a)) 12 | print(np.linalg.eigvalsh(a * a)) 13 | 14 | """ 15 | réponse: 16 | 17 | 1 18 | 3 19 | 1 20 | 9 21 | """ -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/eigenvalues-of-matrix-4.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Eigenvalue of matrix #4 2 | # Basic problems related to eigenvalues. 3 | # 4 | # https://www.hackerrank.com/challenges/eigenvalues-of-matrix-4/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | A = np.matrix([[ 2, -1], 10 | [-1, 2]]) 11 | 12 | I = np.identity(np.linalg.matrix_rank(A)) 13 | 14 | print(np.linalg.eigvals(np.linalg.inv(A))) 15 | 16 | print(np.linalg.eigvals(A - 4 * I)) 17 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-1-matrix-subtraction.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #2 - Matrix Subtraction 2 | # The basics of linear algebra and matrices as required in Machine Learning. 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-1-matrix-subtraction/problem 5 | # 6 | 7 | -3 8 | -3 9 | -3 10 | -5 11 | -5 12 | -5 13 | -3 14 | -4 15 | 1 16 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-1.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #1 - Matrix Addition 2 | # The basics of linear algebra and matrices as required in Machine Learning. 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-1/problem 5 | # 6 | 7 | 5 8 | 7 9 | 9 10 | 9 11 | 11 12 | 13 13 | 5 14 | 6 15 | 8 16 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-3-matrix-multiplication.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #3- Matrix Multiplication 2 | # Matrix Multiplication of 2x2 Matrices 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-3-matrix-multiplication/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | a = np.matrix([[1, 2], [2, 3]]) 10 | b = np.matrix([[4, 5], [7, 8]]) 11 | 12 | p = a * b 13 | print(p) 14 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-3-matrix-multiplication.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #3- Matrix Multiplication 2 | # Matrix Multiplication of 2x2 Matrices 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-3-matrix-multiplication/problem 5 | # 6 | 7 | # 1*4+2*7 = 18 8 | # 1*5+2*8 = 21 9 | # 2*4+3*7 = 29 10 | # 2*5+3*8 = 34 11 | 12 | # réponse: 13 | 14 | 18 15 | 21 16 | 29 17 | 34 18 | -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-4-matrix-multiplication.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #4- Matrix Multiplication 2 | # Matrix Multiplication of 2x2 Matrices 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-4-matrix-multiplication/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | a = np.matrix([[1,2,3], [2,3,4], [1,1,1]]) 10 | b = np.matrix([[4,5,6], [7,8,9], [4,5,7]]) 11 | print(a * b) 12 | 13 | """ 14 | réponse: 15 | 16 | 30 17 | 36 18 | 45 19 | 45 20 | 54 21 | 67 22 | 15 23 | 18 24 | 22 25 | """ -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-5-the-100th-power-of-a-matrix.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #5 - The 100th Power of a Matrix 2 | # Compute the 100the power of a given matrix. 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-5-the-100th-power-of-a-matrix/problem 5 | # 6 | 7 | import numpy as np 8 | 9 | a = np.matrix([[1,1,0],[0,1,0],[0,0,1]]) 10 | print(a ** 100) 11 | 12 | """ 13 | réponse: 14 | 15 | 1 16 | 100 17 | 1 18 | 0 19 | 1 20 | """ -------------------------------------------------------------------------------- /mathematics/linear-algebra-foundations/linear-algebra-foundations-6-the-nsupthsup-power-of-a-matrix.txt: -------------------------------------------------------------------------------- 1 | # Mathematics > Linear Algebra Foundations > Linear Algebra Foundations #6 - An Equation involving Matrices 2 | # Solve an equation involving matrices. 3 | # 4 | # https://www.hackerrank.com/challenges/linear-algebra-foundations-6-the-nsupthsup-power-of-a-matrix/problem 5 | # 6 | 7 | réponse: 8 | -2 9 | 1 10 | 11 | # A^2 = [[ 1 2 0] 12 | # [ 0 1 0] 13 | # [ 0 0 1]] 14 | -------------------------------------------------------------------------------- /mathematics/number-theory/closest-number.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Number Theory > Closest Number 2 | # What is the closest number? 3 | # 4 | # https://www.hackerrank.com/challenges/closest-number/problem 5 | # 6 | 7 | def closestNumber(a, b, x): 8 | p = int(a ** b) 9 | m = (p // x) * x 10 | if p - m > m + x - p: 11 | return m + x 12 | else: 13 | return m 14 | 15 | 16 | if __name__ == '__main__': 17 | for _ in range(int(input())): 18 | a, b, x = map(int, input().split()) 19 | result = closestNumber(a, b, x) 20 | print(result) -------------------------------------------------------------------------------- /mathematics/number-theory/dance-class.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Number Theory > Dancing in Pairs 2 | # Find out if they can dance in pairs? 3 | # 4 | # https://www.hackerrank.com/challenges/dance-class/problem 5 | # https://www.hackerrank.com/contests/infinitum-jun14/challenges/dance-class 6 | # challenge id: 2561 7 | # 8 | 9 | from decimal import Decimal 10 | 11 | for _ in range(int(input())): 12 | n = Decimal(input()) 13 | p = n.sqrt() 14 | print(["even", "odd"][int(p) % 2]) 15 | -------------------------------------------------------------------------------- /mathematics/number-theory/help-mike.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Number Theory > Help Mike 2 | # Help Mike attend the NSA meeting 3 | # 4 | # https://www.hackerrank.com/challenges/help-mike/problem 5 | # https://www.hackerrank.com/contests/sep13/challenges/help-mike 6 | # challenge id: 803 7 | # 8 | 9 | for _ in range(int(input())): 10 | n, k = map(int, input().split()) 11 | q, r = divmod(n, k) 12 | nb_pairs = k * (q - 1) * q // 2 + (r + (k - 1) // 2) * q 13 | if r > k // 2: 14 | nb_pairs += r - k // 2 15 | print(nb_pairs) 16 | -------------------------------------------------------------------------------- /mathematics/number-theory/long-permutation.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Number Theory > Long Permutation 2 | # Determine the n^th element of an infinite permutation! 3 | # 4 | # https://www.hackerrank.com/challenges/long-permutation/problem 5 | # https://www.hackerrank.com/contests/101hack37/challenges/long-permutation 6 | # challenge id: 21494 7 | # 8 | 9 | n, m = map(int, input().split()) 10 | p = list(map(int, input().split())) 11 | 12 | x = 0 13 | while m >= 1: 14 | m -= 1 15 | x = p[x] 16 | if x >= n: 17 | x += m 18 | break 19 | 20 | print(x) 21 | -------------------------------------------------------------------------------- /mathematics/number-theory/sherlock-and-gcd.py: -------------------------------------------------------------------------------- 1 | # Sherlock and GCD 2 | # Help Sherlock in finding the subset. 3 | # 4 | # https://www.hackerrank.com/challenges/sherlock-and-gcd/problem 5 | # 6 | 7 | from math import gcd 8 | 9 | def verif(a): 10 | d = a[0] 11 | for i in range(1, len(a)): 12 | d = gcd(d, a[i]) 13 | 14 | if d == 1: return "YES" 15 | return "NO" 16 | 17 | for i in range(int(input())): 18 | input() 19 | a = list(map(int, input().split())) 20 | print(verif(a)) 21 | -------------------------------------------------------------------------------- /mathematics/number-theory/superpowers.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Number Theory > Superpowers of 2 2 | # Just another numbers problem... 3 | # 4 | # https://www.hackerrank.com/challenges/superpowers/problem 5 | # https://www.hackerrank.com/contests/101hack20/challenges/superpowers 6 | # challenge id: 5505 7 | # 8 | 9 | a, b = map(int, input().split()) 10 | print(pow(2, pow(2, a), b)) 11 | -------------------------------------------------------------------------------- /mathematics/probability/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(bday-gift.py) 2 | add_hackerrank_py(random-number-generator.py) 3 | add_hackerrank_py(normal-distribution-1.py) 4 | add_hackerrank_py(normal-distribution-2.py) 5 | add_hackerrank_py(normal-distribution-3.py) 6 | add_hackerrank_py(binomial-distribution-1.py) 7 | add_hackerrank_py(binomial-distribution-2.py) 8 | add_hackerrank_py(binomial-distribution-3.py) 9 | add_hackerrank_py(sherlock-and-probability.py) 10 | add_hackerrank_py(extremely-dangerous-virus.py) 11 | -------------------------------------------------------------------------------- /mathematics/probability/bday-gift.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Probability > B'day Gift 2 | # Whats the price Isaac has to pay for HackerPhone 3 | # 4 | # https://www.hackerrank.com/challenges/bday-gift/problem 5 | # https://www.hackerrank.com/contests/nov13/challenges/bday-gift 6 | # 7 | 8 | # chaque boule a une probabilité 0.5 d'être ramassée 9 | 10 | n = int(input()) 11 | e = sum(int(input()) for _ in range(n)) 12 | print(e / 2) 13 | -------------------------------------------------------------------------------- /mathematics/probability/extremely-dangerous-virus.py: -------------------------------------------------------------------------------- 1 | # Mathematics > Probability > Extremely Dangerous Virus 2 | # Estimate how large the virus will grow. 3 | # 4 | # https://www.hackerrank.com/challenges/extremely-dangerous-virus/problem 5 | # https://www.hackerrank.com/contests/rookierank/challenges/extremely-dangerous-virus 6 | # challenge id: 22940 7 | # 8 | 9 | a, b, t = map(int, input().split()) 10 | 11 | print(pow((a + b) // 2, t, 1000000007)) 12 | -------------------------------------------------------------------------------- /python/closures-and-decorators/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(decorators-2-name-directory.py) 2 | add_hackerrank_py(standardize-mobile-number-using-decorators.py) 3 | -------------------------------------------------------------------------------- /python/errors-exceptions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(exceptions.py) 2 | add_hackerrank_py(incorrect-regex.py) 3 | -------------------------------------------------------------------------------- /python/errors-exceptions/incorrect-regex.py: -------------------------------------------------------------------------------- 1 | # Python > Errors and Exceptions > Incorrect Regex 2 | # Check whether the regex is valid or not. 3 | # 4 | # https://www.hackerrank.com/challenges/incorrect-regex/problem 5 | # 6 | 7 | import re 8 | 9 | for _ in range(int(input())): 10 | try: 11 | re.compile(input()) 12 | print(True) 13 | except re.error: 14 | print(False) 15 | -------------------------------------------------------------------------------- /python/numpy/floor-ceil-and-rint.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Floor, Ceil and Rint 2 | # Use the floor, ceil and rint tools of NumPy on the given array. 3 | # 4 | # https://www.hackerrank.com/challenges/floor-ceil-and-rint/problem 5 | # 6 | 7 | import numpy 8 | 9 | if numpy.version.version >= '1.14.': 10 | numpy.set_printoptions(legacy='1.13') 11 | 12 | a = numpy.array(input().split(), numpy.float) 13 | print(numpy.floor(a)) 14 | print(numpy.ceil(a)) 15 | print(numpy.rint(a)) 16 | -------------------------------------------------------------------------------- /python/numpy/np-array-mathematics.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Array Mathematics 2 | # Perform basic mathematical operations on arrays in NumPy. 3 | # 4 | # https://www.hackerrank.com/challenges/np-array-mathematics/problem 5 | # 6 | 7 | import numpy 8 | 9 | n, m = map(int, input().split()) 10 | 11 | A = numpy.array([input().split() for i in range(n)], numpy.int) 12 | B = numpy.array([input().split() for i in range(n)], numpy.int) 13 | 14 | print(A + B) 15 | print(A - B) 16 | print(A * B) 17 | print(A // B) 18 | print(A % B) 19 | print(A ** B) 20 | -------------------------------------------------------------------------------- /python/numpy/np-concatenate.py: -------------------------------------------------------------------------------- 1 | # Concatenate 2 | # Use the concatenate function on 2 arrays. 3 | # 4 | # https://www.hackerrank.com/challenges/np-concatenate/problem 5 | # 6 | 7 | import numpy 8 | 9 | n, m, p = map(int, input().split()) 10 | 11 | N = numpy.array([list(map(int, input().split())) for _ in range(n)]) 12 | M = numpy.array([list(map(int, input().split())) for _ in range(m)]) 13 | 14 | print(numpy.concatenate((N, M), axis = 0)) 15 | -------------------------------------------------------------------------------- /python/numpy/np-dot-and-cross.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Dot and Cross 2 | # Use NumPy to find the dot and cross products of arrays. 3 | # 4 | # https://www.hackerrank.com/challenges/np-dot-and-cross/problem 5 | # 6 | 7 | import numpy 8 | 9 | n = int(input()) 10 | 11 | A = numpy.array([input().split() for i in range(n)], numpy.int) 12 | B = numpy.array([input().split() for i in range(n)], numpy.int) 13 | 14 | print(A.dot(B)) 15 | -------------------------------------------------------------------------------- /python/numpy/np-eye-and-identity.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Eye and Identity 2 | # Create an array using the identity or eye tools from the NumPy module. 3 | # 4 | # https://www.hackerrank.com/challenges/np-eye-and-identity/problem 5 | # 6 | 7 | import numpy 8 | 9 | if numpy.version.version >= '1.14.': 10 | numpy.set_printoptions(legacy='1.13') 11 | 12 | n, m = map(int, input().split()) 13 | 14 | print(numpy.eye(n, m)) 15 | -------------------------------------------------------------------------------- /python/numpy/np-inner-and-outer.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Inner and Outer 2 | # Use NumPy to find the inner and outer product of arrays. 3 | # 4 | # https://www.hackerrank.com/challenges/np-inner-and-outer/problem 5 | # 6 | 7 | import numpy 8 | 9 | u = numpy.array(input().split(), numpy.int) 10 | v = numpy.array(input().split(), numpy.int) 11 | 12 | print(numpy.inner(u, v)) 13 | print(numpy.outer(u, v)) 14 | -------------------------------------------------------------------------------- /python/numpy/np-linear-algebra.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Linear Algebra 2 | # NumPy routines for linear algebra calculations. 3 | # 4 | # https://www.hackerrank.com/challenges/np-linear-algebra/problem 5 | # 6 | 7 | import numpy 8 | 9 | if numpy.version.version >= '1.14.': 10 | numpy.set_printoptions(legacy='1.13') 11 | 12 | m = numpy.array([input().split() for i in range(int(input()))], numpy.float) 13 | print(numpy.linalg.det(m)) 14 | -------------------------------------------------------------------------------- /python/numpy/np-mean-var-and-std.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Mean, Var, and Std 2 | # Use the mean, var and std tools in NumPy on the given 2-D array. 3 | # 4 | # https://www.hackerrank.com/challenges/np-mean-var-and-std/problem 5 | # 6 | 7 | import numpy 8 | 9 | if numpy.version.version >= '1.14.': 10 | numpy.set_printoptions(legacy='1.13') 11 | 12 | n, m = map(int, input().split()) 13 | A = numpy.array([input().split() for i in range(n)], numpy.int) 14 | 15 | print(numpy.mean(A, axis=1)) 16 | print(numpy.var(A, axis=0)) 17 | print(numpy.std(A, axis=None)) -------------------------------------------------------------------------------- /python/numpy/np-min-and-max.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Min and Max 2 | # Use the min and max tools of NumPy on the given 2-D array. 3 | # 4 | # https://www.hackerrank.com/challenges/np-min-and-max/problem 5 | # 6 | 7 | import numpy 8 | 9 | n, m = map(int, input().split()) 10 | A = numpy.array([input().split() for i in range(n)], numpy.int) 11 | 12 | print(numpy.max(numpy.min(A, axis=1))) 13 | -------------------------------------------------------------------------------- /python/numpy/np-polynomials.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Polynomials 2 | # Given the coefficients, use polynomials in NumPy. 3 | # 4 | # https://www.hackerrank.com/challenges/np-polynomials/problem 5 | # 6 | 7 | import numpy 8 | 9 | p = list(map(float, input().split())) 10 | print(numpy.polyval(p, float(input()))) 11 | -------------------------------------------------------------------------------- /python/numpy/np-shape-reshape.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Shape and Reshape 2 | # Using the shape and reshape tools available in the NumPy module, configure a list according to the guidelines. 3 | # 4 | # https://www.hackerrank.com/challenges/np-shape-reshape/problem 5 | # 6 | 7 | import numpy 8 | 9 | v = numpy.array(input().split(), numpy.integer) 10 | m = numpy.reshape(v, (3, 3)) 11 | print(m) -------------------------------------------------------------------------------- /python/numpy/np-sum-and-prod.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Sum and Prod 2 | # Perform the sum and prod functions of NumPy on the given 2-D array. 3 | # 4 | # https://www.hackerrank.com/challenges/np-sum-and-prod/problem 5 | # 6 | 7 | import numpy 8 | 9 | n, m = map(int, input().split()) 10 | A = numpy.array([input().split() for i in range(n)], numpy.int) 11 | 12 | print(numpy.prod(numpy.sum(A, axis=0))) 13 | -------------------------------------------------------------------------------- /python/numpy/np-transpose-and-flatten.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Transpose and Flatten 2 | # Use the transpose and flatten tools in the NumPy module to manipulate an array. 3 | # 4 | # https://www.hackerrank.com/challenges/np-transpose-and-flatten/problem 5 | # 6 | 7 | import numpy 8 | 9 | n, m = map(int, input().split()) 10 | 11 | M = numpy.array([input().split() for i in range(n)], numpy.int) 12 | 13 | print(M.transpose()) 14 | print(M.flatten()) 15 | -------------------------------------------------------------------------------- /python/numpy/np-zeros-and-ones.py: -------------------------------------------------------------------------------- 1 | # Python > Numpy > Zeros and Ones 2 | # Print an array using the zeros and ones tools in the NumPy module. 3 | # 4 | # https://www.hackerrank.com/challenges/np-zeros-and-ones/problem 5 | # 6 | 7 | import numpy 8 | 9 | shape = tuple(map(int, input().split())) 10 | 11 | print(numpy.zeros(shape, dtype=numpy.int)) 12 | 13 | print(numpy.ones(shape, dtype=numpy.int)) 14 | -------------------------------------------------------------------------------- /python/py-basic-data-types/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(python-tuples.py) 2 | add_hackerrank_py(finding-the-percentage.py) 3 | add_hackerrank_py(nested-list.py) 4 | add_hackerrank_py(python-lists.py) 5 | add_hackerrank_py(list-comprehensions.py) 6 | add_hackerrank_py(find-second-maximum-number-in-a-list.py) 7 | -------------------------------------------------------------------------------- /python/py-basic-data-types/find-second-maximum-number-in-a-list.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find the Runner-Up Score! 3 | 4 | https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | arr = map(int, input().split()) 10 | 11 | arr = sorted(arr, reverse=True) 12 | m = arr[0] 13 | while arr[0] == m: 14 | del arr[0] 15 | 16 | print(arr[0]) 17 | -------------------------------------------------------------------------------- /python/py-basic-data-types/finding-the-percentage.py: -------------------------------------------------------------------------------- 1 | """ 2 | Finding the percentage 3 | 4 | https://www.hackerrank.com/challenges/finding-the-percentage/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | student_marks = {} 10 | for _ in range(n): 11 | name, *line = input().split() 12 | scores = list(map(float, line)) 13 | student_marks[name] = scores 14 | query_name = input() 15 | 16 | print("%.02f" % (sum(student_marks[query_name]) / 3)) 17 | -------------------------------------------------------------------------------- /python/py-basic-data-types/list-comprehensions.py: -------------------------------------------------------------------------------- 1 | """ 2 | List Comprehensions 3 | 4 | https://www.hackerrank.com/challenges/list-comprehensions/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | x = int(input()) 9 | y = int(input()) 10 | z = int(input()) 11 | n = int(input()) 12 | 13 | print([[i, j, k] for i in range(x + 1) for j in range(y + 1) for k in range(z + 1) if i + j + k != n]) 14 | -------------------------------------------------------------------------------- /python/py-basic-data-types/nested-list.py: -------------------------------------------------------------------------------- 1 | """ 2 | Nested Lists 3 | 4 | https://www.hackerrank.com/challenges/nested-list/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | scores = dict() 9 | for _ in range(int(input())): 10 | name = input() 11 | score = float(input()) 12 | 13 | if score in scores: 14 | scores[score].append(name) 15 | else: 16 | scores[score] = [name] 17 | 18 | for name in sorted(scores[sorted(scores.keys())[1]]): 19 | print(name) 20 | -------------------------------------------------------------------------------- /python/py-basic-data-types/python-tuples.py: -------------------------------------------------------------------------------- 1 | # Tuples 2 | # Learn about tuples and compute hash(T). 3 | # 4 | # https://www.hackerrank.com/challenges/python-tuples/problem 5 | # 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | integer_list = map(int, input().split()) 10 | 11 | print(hash(tuple(integer_list))) 12 | -------------------------------------------------------------------------------- /python/py-built-ins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(input.py) 2 | add_hackerrank_py(zipped.py) 3 | add_hackerrank_py(python-eval.py) 4 | add_hackerrank_py(ginorts.py) 5 | add_hackerrank_py(python-sort-sort.py) 6 | add_hackerrank_py(any-or-all.py) 7 | -------------------------------------------------------------------------------- /python/py-built-ins/any-or-all.py: -------------------------------------------------------------------------------- 1 | # Python > Built-Ins > Any or All 2 | # Return True, if any of the iterable is true or if all of it is true using the any() and all() expressions. 3 | # 4 | # https://www.hackerrank.com/challenges/any-or-all/problem 5 | # 6 | 7 | _, arr = input(), list(map(int, input().split())) 8 | print(all(i >= 0 for i in arr) and any((i < 10 or i % 11 == 0) for i in arr)) 9 | -------------------------------------------------------------------------------- /python/py-built-ins/input.py: -------------------------------------------------------------------------------- 1 | # Python > Built-Ins > Input() 2 | # A Python 2 challenge: Input() is equivalent to eval(raw_input(prompt)). 3 | # 4 | # https://www.hackerrank.com/challenges/input/problem 5 | # 6 | 7 | x, y = map(int, input().split()) 8 | P = input() 9 | print(y == eval(P, {'x':x})) 10 | -------------------------------------------------------------------------------- /python/py-built-ins/python-eval.py: -------------------------------------------------------------------------------- 1 | # Python > Built-Ins > Python Evaluation 2 | # Evaluate the expressions in Python using the expression eval(). 3 | # 4 | # https://www.hackerrank.com/challenges/python-eval/problem 5 | # 6 | 7 | eval(input()) 8 | -------------------------------------------------------------------------------- /python/py-built-ins/python-sort-sort.py: -------------------------------------------------------------------------------- 1 | # Python > Built-Ins > Athlete Sort 2 | # Sort the table on the kth attribute. 3 | # 4 | # https://www.hackerrank.com/challenges/python-sort-sort/problem 5 | # 6 | 7 | import operator 8 | 9 | n, m = map(int, input().split()) 10 | arr = [list(map(int, input().split())) for _ in range(n)] 11 | k = int(input()) 12 | 13 | for i in sorted(arr, key=operator.itemgetter(k)): 14 | print(*i) 15 | -------------------------------------------------------------------------------- /python/py-built-ins/zipped.py: -------------------------------------------------------------------------------- 1 | # Python > Built-Ins > Zipped! 2 | # Compute the average by zipping data. 3 | # 4 | # https://www.hackerrank.com/challenges/zipped/problem 5 | # 6 | 7 | n, x = map(int, input().split()) 8 | a = [] 9 | for _ in range(x): 10 | a.append(list( map(float, input().split()))) 11 | for i in zip(*a): 12 | print(sum(i) / x) -------------------------------------------------------------------------------- /python/py-classes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(class-1-dealing-with-complex-numbers.py) 2 | add_hackerrank_py(class-2-find-the-torsional-angle.py) 3 | -------------------------------------------------------------------------------- /python/py-collections/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/domains/python?filters%5Bsubdomains%5D%5B%5D=py-collections 2 | 3 | add_hackerrank_py(piling-up.py) 4 | add_hackerrank_py(word-order.py) 5 | add_hackerrank_py(collections-counter.py) 6 | add_hackerrank_py(defaultdict-tutorial.py) 7 | add_hackerrank_py(py-collections-ordereddict.py) 8 | add_hackerrank_py(py-collections-namedtuple.py) 9 | add_hackerrank_py(py-collections-deque.py) 10 | add_hackerrank_py(most-commons.py) 11 | -------------------------------------------------------------------------------- /python/py-collections/collections-counter.py: -------------------------------------------------------------------------------- 1 | # Python > Collections > collections.Counter() 2 | # Use a counter to sum the amount of money earned by the shoe shop owner. 3 | # 4 | # https://www.hackerrank.com/challenges/collections-counter/problem 5 | # 6 | 7 | from collections import Counter 8 | 9 | input() 10 | shoes = Counter(input().split()) 11 | earned = 0 12 | for _ in range(int(input())): 13 | shoe, price = input().split() 14 | if shoes[shoe]: 15 | shoes[shoe] -= 1 16 | earned += int(price) 17 | print(earned) 18 | -------------------------------------------------------------------------------- /python/py-collections/defaultdict-tutorial.py: -------------------------------------------------------------------------------- 1 | # Python > Collections > DefaultDict Tutorial 2 | # Create dictionary value fields with predefined data types. 3 | # 4 | # https://www.hackerrank.com/challenges/defaultdict-tutorial/problem 5 | # 6 | 7 | from collections import defaultdict 8 | 9 | n, m = map(int, input().split()) 10 | 11 | A = defaultdict(list) 12 | for i in range(1, n + 1): 13 | A[input()].append(i) 14 | 15 | for _ in range(m): 16 | r = A[input()] 17 | if len(r) == 0: 18 | print(-1) 19 | else: 20 | print(" ".join(map(str, r))) 21 | -------------------------------------------------------------------------------- /python/py-collections/most-commons.py: -------------------------------------------------------------------------------- 1 | # Python > Collections > Company Logo 2 | # Print the number of character occurrences in descending order. 3 | # 4 | # https://www.hackerrank.com/challenges/most-commons/problem 5 | # 6 | 7 | from collections import Counter 8 | from itertools import groupby 9 | 10 | name = input() 11 | 12 | nb = 0 13 | for c, g in groupby(Counter(name).most_common(), key=lambda x: x[1]): 14 | for l in sorted(map(lambda x: x[0], g)): 15 | print(l, c) 16 | nb += 1 17 | if nb == 3: break 18 | if nb == 3: break 19 | -------------------------------------------------------------------------------- /python/py-collections/py-collections-namedtuple.py: -------------------------------------------------------------------------------- 1 | # Python > Collections > Collections.namedtuple() 2 | # You need to turn tuples into convenient containers using collections.namedtuple(). 3 | # 4 | # https://www.hackerrank.com/challenges/py-collections-namedtuple/problem 5 | # 6 | 7 | from collections import namedtuple 8 | n = int(input()) 9 | Student = namedtuple('Student', input()) 10 | print(sum(int(Student(*(input().split())).MARKS) for _ in range(n)) / n) 11 | -------------------------------------------------------------------------------- /python/py-collections/py-collections-ordereddict.py: -------------------------------------------------------------------------------- 1 | # Python > Collections > Collections.OrderedDict() 2 | # Print a dictionary of items that retains its order. 3 | # 4 | # https://www.hackerrank.com/challenges/py-collections-ordereddict/problem 5 | # 6 | 7 | from collections import OrderedDict 8 | 9 | prices = OrderedDict() 10 | 11 | for _ in range(int(input())): 12 | item, price = input().rsplit(maxsplit=1) 13 | prices[item] = prices.get(item, 0) + int(price) 14 | 15 | for item, price in prices.items(): 16 | print(item, price) 17 | -------------------------------------------------------------------------------- /python/py-collections/word-order.py: -------------------------------------------------------------------------------- 1 | """ 2 | Word Order 3 | 4 | https://www.hackerrank.com/challenges/word-order/problem 5 | """ 6 | 7 | from collections import OrderedDict 8 | 9 | dico = OrderedDict() 10 | for _ in range(int(input())): 11 | word = input() 12 | dico[word] = dico.get(word, 0) + 1 13 | 14 | print(len(dico)) 15 | print(' '.join(map(str, dico.values()))) 16 | -------------------------------------------------------------------------------- /python/py-date-time/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(python-time-delta.py) 2 | add_hackerrank_py(calendar-module.py) 3 | -------------------------------------------------------------------------------- /python/py-date-time/calendar-module.py: -------------------------------------------------------------------------------- 1 | # Python > Date and Time > Calendar Module 2 | # Print the day of a given date. 3 | # 4 | # https://www.hackerrank.com/challenges/calendar-module/problem 5 | # 6 | 7 | import calendar 8 | 9 | m, d, y = map(int, input().split()) 10 | 11 | i = calendar.weekday(y, m, d) 12 | print(calendar.day_name[i].upper()) 13 | -------------------------------------------------------------------------------- /python/py-debugging/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(default-arguments.py) 2 | add_hackerrank_py(words-score.py) 3 | -------------------------------------------------------------------------------- /python/py-functionals/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(reduce-function.py) 2 | add_hackerrank_py(validate-list-of-email-address-with-filter.py) 3 | add_hackerrank_py(map-and-lambda-expression.py) 4 | -------------------------------------------------------------------------------- /python/py-introduction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(python-division.py) 2 | add_hackerrank_py(python-loops.py) 3 | add_hackerrank_py(python-print.py) 4 | add_hackerrank_py(py-hello-world.py) 5 | add_hackerrank_py(py-if-else.py) 6 | add_hackerrank_py(write-a-function.py) 7 | add_hackerrank_py(python-arithmetic-operators.py) 8 | -------------------------------------------------------------------------------- /python/py-introduction/py-hello-world.py: -------------------------------------------------------------------------------- 1 | # https://www.hackerrank.com/challenges/py-hello-world/problem 2 | 3 | if __name__ == '__main__': 4 | print("Hello, World!") 5 | -------------------------------------------------------------------------------- /python/py-introduction/py-if-else.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python If-Else 3 | 4 | https://www.hackerrank.com/challenges/py-if-else/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | 10 | if n % 2 == 1 or (n >= 6 and n <= 20): 11 | print("Weird") 12 | else: 13 | print("Not Weird") 14 | -------------------------------------------------------------------------------- /python/py-introduction/python-arithmetic-operators.py: -------------------------------------------------------------------------------- 1 | """ 2 | Arithmetic Operators 3 | 4 | https://www.hackerrank.com/challenges/python-arithmetic-operators/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | a = int(input()) 9 | b = int(input()) 10 | 11 | print(a + b) 12 | print(a - b) 13 | print(a * b) 14 | -------------------------------------------------------------------------------- /python/py-introduction/python-division.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python: Division 3 | 4 | https://www.hackerrank.com/challenges/python-division/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | a = int(input()) 9 | b = int(input()) 10 | 11 | print(a // b) 12 | print(round(a / b, 11)) 13 | -------------------------------------------------------------------------------- /python/py-introduction/python-loops.py: -------------------------------------------------------------------------------- 1 | """ 2 | Loops 3 | 4 | https://www.hackerrank.com/challenges/python-loops/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | 10 | for i in range(n): 11 | print(i ** 2) 12 | -------------------------------------------------------------------------------- /python/py-introduction/python-print.py: -------------------------------------------------------------------------------- 1 | """ 2 | Print Function 3 | 4 | https://www.hackerrank.com/challenges/python-print/problem 5 | """ 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | 10 | print(*[i for i in range(1, n + 1)], sep='') 11 | -------------------------------------------------------------------------------- /python/py-introduction/write-a-function.py: -------------------------------------------------------------------------------- 1 | """ 2 | Write a function 3 | 4 | https://www.hackerrank.com/challenges/write-a-function/problem 5 | """ 6 | 7 | def is_leap(year): 8 | leap = False 9 | 10 | # Write your logic here 11 | leap = year % 4 == 0 and (year % 400 == 0 or year % 100 != 0) 12 | 13 | return leap 14 | 15 | 16 | year = int(input()) 17 | print(is_leap(year)) 18 | -------------------------------------------------------------------------------- /python/py-itertools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(compress-the-string.py) 2 | add_hackerrank_py(maximize-it.py) 3 | add_hackerrank_py(iterables-and-iterators.py) 4 | add_hackerrank_py(itertools-product.py) 5 | add_hackerrank_py(itertools-permutations.py) 6 | add_hackerrank_py(itertools-combinations.py) 7 | add_hackerrank_py(itertools-combinations-with-replacement.py) 8 | -------------------------------------------------------------------------------- /python/py-itertools/compress-the-string.py: -------------------------------------------------------------------------------- 1 | # Compress the String! 2 | # groupby() 3 | # 4 | # https://www.hackerrank.com/challenges/compress-the-string/problem 5 | # 6 | 7 | import itertools 8 | 9 | s = input() 10 | 11 | print(' '.join(str((len(list(g)), int(c))) 12 | for c, g in itertools.groupby(s))) 13 | -------------------------------------------------------------------------------- /python/py-itertools/itertools-combinations-with-replacement.py: -------------------------------------------------------------------------------- 1 | # Python > Itertools > itertools.combinations_with_replacement() 2 | # Find all the combinations of a string with replacements. 3 | # 4 | # https://www.hackerrank.com/challenges/itertools-combinations-with-replacement/problem 5 | # 6 | 7 | from itertools import combinations_with_replacement 8 | 9 | s, n = input().split() 10 | for i in combinations_with_replacement(sorted(s), int(n)): 11 | print("".join(i)) 12 | -------------------------------------------------------------------------------- /python/py-itertools/itertools-combinations.py: -------------------------------------------------------------------------------- 1 | # Python > Itertools > itertools.combinations() 2 | # Print all the combinations of a string using itertools. 3 | # 4 | # https://www.hackerrank.com/challenges/itertools-combinations/problem 5 | # 6 | 7 | from itertools import combinations 8 | 9 | s, n = input().split() 10 | for k in range(1, int(n) + 1): 11 | for i in combinations(sorted(s), k): 12 | print("".join(i)) 13 | -------------------------------------------------------------------------------- /python/py-itertools/itertools-permutations.py: -------------------------------------------------------------------------------- 1 | # Python > Itertools > itertools.permutations() 2 | # Find all permutations of a given size in a given string. 3 | # 4 | # https://www.hackerrank.com/challenges/itertools-permutations/problem 5 | # 6 | 7 | from itertools import permutations 8 | 9 | s, n = input().split() 10 | for i in permutations(sorted(s), int(n)): 11 | print("".join(i)) 12 | -------------------------------------------------------------------------------- /python/py-itertools/itertools-product.py: -------------------------------------------------------------------------------- 1 | # Python > Itertools > itertools.product() 2 | # Find the cartesian product of 2 sets. 3 | # 4 | # https://www.hackerrank.com/challenges/itertools-product/problem 5 | # 6 | 7 | from itertools import product 8 | 9 | A = list(map(int, input().split())) 10 | B = list(map(int, input().split())) 11 | 12 | P = list(product(A, B)) 13 | 14 | print(" ".join(str(x) for x in P)) 15 | -------------------------------------------------------------------------------- /python/py-itertools/maximize-it.py: -------------------------------------------------------------------------------- 1 | """ 2 | Maximize It! 3 | 4 | https://www.hackerrank.com/challenges/maximize-it/problem 5 | """ 6 | 7 | import itertools 8 | 9 | N = [] 10 | K, M = map(int, input().split()) 11 | for _ in range(K): 12 | N.append(list(map(lambda x: int(x) ** 2, input().split()))[1:]) 13 | 14 | Smax = max([sum(i) % M for i in itertools.product(*N)]) 15 | 16 | print(Smax) 17 | -------------------------------------------------------------------------------- /python/py-math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(find-angle.py) 2 | add_hackerrank_py(polar-coordinates.py) 3 | add_hackerrank_py(triangle-quest-2.py) 4 | add_hackerrank_py(python-mod-divmod.py) 5 | add_hackerrank_py(python-power-mod-power.py) 6 | add_hackerrank_py(python-integers-come-in-all-sizes.py) 7 | add_hackerrank_py(python-quest-1.py) 8 | -------------------------------------------------------------------------------- /python/py-math/find-angle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Find Angle MBC 3 | 4 | https://www.hackerrank.com/challenges/find-angle/problem 5 | """ 6 | 7 | from math import atan2, pi 8 | 9 | AB = int(input()) 10 | BC = int(input()) 11 | 12 | print(u"{}°".format(round(atan2(AB, BC) * 180 / pi))) 13 | -------------------------------------------------------------------------------- /python/py-math/polar-coordinates.py: -------------------------------------------------------------------------------- 1 | # Python > Math > Polar Coordinates 2 | # Convert complex numbers to polar coordinates 3 | # 4 | # https://www.hackerrank.com/challenges/polar-coordinates/problem 5 | # 6 | 7 | import cmath 8 | 9 | c = complex(input()) 10 | 11 | print(abs(c)) # 𝑟 12 | print(cmath.phase(c)) # φ 13 | -------------------------------------------------------------------------------- /python/py-math/python-integers-come-in-all-sizes.py: -------------------------------------------------------------------------------- 1 | # Python > Math > Integers Come In All Sizes 2 | # Exercises with big integers in Python. 3 | # 4 | # https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes/problem 5 | # 6 | 7 | 8 | a = int(input()) 9 | b = int(input()) 10 | c = int(input()) 11 | d = int(input()) 12 | print(a ** b + c ** d) -------------------------------------------------------------------------------- /python/py-math/python-mod-divmod.py: -------------------------------------------------------------------------------- 1 | # Python > Math > Mod Divmod 2 | # Get the quotient and remainder using the divmod operator in Python. 3 | # 4 | # https://www.hackerrank.com/challenges/python-mod-divmod/problem 5 | # 6 | 7 | a = int(input()) 8 | b = int(input()) 9 | q, r = divmod(a, b) 10 | print(q) 11 | print(r) 12 | print((q, r)) 13 | -------------------------------------------------------------------------------- /python/py-math/python-quest-1.py: -------------------------------------------------------------------------------- 1 | # Python > Math > Triangle Quest 2 | # Print a numeric triangle of height N-1 using only 2 lines. 3 | # 4 | # https://www.hackerrank.com/challenges/python-quest-1/problem 5 | # 6 | 7 | for i in range(1,int(input())): #More than 2 lines will result in 0 score. Do not leave a blank line also 8 | print(i * (10 ** i // 9)) 9 | -------------------------------------------------------------------------------- /python/py-math/triangle-quest-2.py: -------------------------------------------------------------------------------- 1 | # Python > Math > Triangle Quest 2 2 | # Create a palindromic triangle. 3 | # 4 | # https://www.hackerrank.com/challenges/triangle-quest-2/problem 5 | # 6 | 7 | 8 | # (template_tail) ---------------------------------------------------------------------- 9 | for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also 10 | print(123456789 // (10 ** (9-i)) * (10 ** (i - 1)) + 987654321 % (10 ** (i - 1))) 11 | -------------------------------------------------------------------------------- /python/py-regex/hex-color-code.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Hex Color Code 2 | # Validate Hex color codes in CSS. 3 | # 4 | # https://www.hackerrank.com/challenges/hex-color-code/problem 5 | # 6 | 7 | import re 8 | 9 | for _ in range(int(input())): 10 | s = input() 11 | if re.match(r'^(.*\:|\s)', s, re.I): 12 | for m in re.finditer(r'(\#(?:[0-9a-f]{3}){1,2})', s, re.I): 13 | print(m.group(1)) 14 | -------------------------------------------------------------------------------- /python/py-regex/introduction-to-regex.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Detect Floating Point Number 2 | # Validate a floating point number using the regular expression module for Python. 3 | # 4 | # https://www.hackerrank.com/challenges/introduction-to-regex/problem 5 | # 6 | 7 | import re 8 | 9 | p = re.compile(r'^[+-]?\d*\.\d+$') 10 | for _ in range(int(input())): 11 | print(bool(p.match(input()))) 12 | -------------------------------------------------------------------------------- /python/py-regex/matrix-script.py: -------------------------------------------------------------------------------- 1 | """ 2 | Matrix Script 3 | 4 | https://www.hackerrank.com/challenges/matrix-script/problem 5 | """ 6 | 7 | import itertools 8 | import re 9 | 10 | n, m = input().strip().split(' ') 11 | n, m = [int(n), int(m)] 12 | matrix = [] 13 | matrix_i = 0 14 | for matrix_i in range(n): 15 | matrix_t = str(input()) 16 | matrix.append(matrix_t) 17 | 18 | message = ''.join(itertools.chain.from_iterable(itertools.zip_longest(*matrix, fillvalue=' '))) 19 | 20 | message = re.sub(r"([a-zA-Z0-9])\W+([a-zA-Z0-9])", r"\1 \2", message) 21 | print(message) 22 | -------------------------------------------------------------------------------- /python/py-regex/re-findall-re-finditer.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Re.findall() & Re.finditer() 2 | # Find all the pattern matches using the expressions re.findall() and re.finditer(). 3 | # 4 | # https://www.hackerrank.com/challenges/re-findall-re-finditer/problem 5 | # 6 | 7 | import re 8 | 9 | found = False 10 | s = input() 11 | for i in re.findall("(?<=[^aeiou])([aeiou]{2,})[^aeiou]", s, flags=re.I): 12 | print(i) 13 | found = True 14 | if not found: 15 | print(-1) 16 | -------------------------------------------------------------------------------- /python/py-regex/re-group-groups.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Group(), Groups() & Groupdict() 2 | # Using group(), groups(), and groupdict(), find the subgroup(s) of the match. 3 | # 4 | # https://www.hackerrank.com/challenges/re-group-groups/problem 5 | # 6 | 7 | import re 8 | 9 | s = input() 10 | 11 | # \1 (dans la regex) est la référence au premier groupe 12 | 13 | m = re.search(r"([0-9a-zA-Z])\1+", s) 14 | if m: 15 | print(m.group(1)) 16 | else: 17 | print(-1) 18 | -------------------------------------------------------------------------------- /python/py-regex/re-split.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Re.split() 2 | # Split the string by the pattern occurrence using the re.split() expression. 3 | # 4 | # https://www.hackerrank.com/challenges/re-split/problem 5 | # 6 | 7 | regex_pattern = r"[,.]" # Do not delete 'r'. 8 | 9 | # (skeliton_tail) ---------------------------------------------------------------------- 10 | import re 11 | print("\n".join(re.split(regex_pattern, input()))) 12 | -------------------------------------------------------------------------------- /python/py-regex/re-sub-regex-substitution.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Regex Substitution 2 | # Substitute a string using regex tools. 3 | # 4 | # https://www.hackerrank.com/challenges/re-sub-regex-substitution/problem 5 | # 6 | 7 | import re 8 | 9 | for _ in range(int(input())): 10 | s = input() 11 | s = re.sub(r'(?<= )(&&)(?= )', 'and', s) # (?<= ) et (?= ) pour ne pas consommer les espaces 12 | s = re.sub(r'(?<= )(\|\|)(?= )', 'or', s) 13 | print(s) 14 | -------------------------------------------------------------------------------- /python/py-regex/validating-credit-card-number.py: -------------------------------------------------------------------------------- 1 | """ 2 | Validating Credit Card Numbers 3 | 4 | https://www.hackerrank.com/challenges/validating-credit-card-number/problem 5 | """ 6 | 7 | import re 8 | 9 | 10 | for _ in range(int(input())): 11 | num = input() 12 | 13 | ok1 = bool(re.match(r"^[456]\d{15}$", num)) 14 | ok2 = bool(re.match(r"^[456]\d{3}\-\d{4}\-\d{4}\-\d{4}$", num)) 15 | num = num.replace("-", "") 16 | ok3 = bool(re.match(r"(?!.*(\d)(-?\1){3})", num)) 17 | if (ok1 or ok2) and ok3: 18 | print("Valid") 19 | else: 20 | print("Invalid") 21 | -------------------------------------------------------------------------------- /python/py-regex/validating-named-email-addresses.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Validating and Parsing Email Addresses 2 | # Print valid email addresses according to the constraints. 3 | # 4 | # https://www.hackerrank.com/challenges/validating-named-email-addresses/problem 5 | # 6 | 7 | import re 8 | 9 | for _ in range(int(input())): 10 | s = input().strip() 11 | 12 | if re.match(r'^.*<[a-z][\w\.\-]*@[a-z]+\.[a-z]{1,3}>$', s, re.I): 13 | print(s) 14 | -------------------------------------------------------------------------------- /python/py-regex/validating-postalcode.py: -------------------------------------------------------------------------------- 1 | """ 2 | Validating Postal Codes 3 | 4 | https://www.hackerrank.com/challenges/validating-postalcode/problem 5 | """ 6 | 7 | import re 8 | 9 | def validate(code): 10 | ok = bool(re.match(r"^[1-9][0-9]{5}$", code)) 11 | alternative = sum(int(code[i - 1] == code[i + 1]) for i in range(1, len(code) - 1)) 12 | return ok and alternative < 2 13 | 14 | print(validate(input())) 15 | -------------------------------------------------------------------------------- /python/py-regex/validating-the-phone-number.py: -------------------------------------------------------------------------------- 1 | # Python > Regex and Parsing > Validating phone numbers 2 | # Check whether the given phone number is valid or not. 3 | # 4 | # https://www.hackerrank.com/challenges/validating-the-phone-number/problem 5 | # 6 | 7 | import re 8 | 9 | for _ in range(int(input())): 10 | s = input() 11 | print("YES" if re.match(r'^[789]\d{9}$', s) else "NO") 12 | -------------------------------------------------------------------------------- /python/py-sets/no-idea.py: -------------------------------------------------------------------------------- 1 | """ 2 | No Idea! 3 | 4 | https://www.hackerrank.com/challenges/no-idea/problem 5 | """ 6 | 7 | input() 8 | 9 | N = map(int, input().split()) 10 | A = set(map(int, input().split())) 11 | B = set(map(int, input().split())) 12 | 13 | h = 0 14 | for n in N: 15 | if n in A: h += 1 16 | if n in B: h -= 1 17 | print(h) 18 | -------------------------------------------------------------------------------- /python/py-sets/py-check-strict-superset.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Check Strict Superset 2 | # Check if A is a strict superset of the other given sets. 3 | # 4 | # https://www.hackerrank.com/challenges/py-check-strict-superset/problem 5 | # 6 | 7 | a = set(map(int, input().split())) 8 | strict_superset = True 9 | for _ in range(int(input())): 10 | x = set(map(int, input().split())) 11 | if not ((len(x - a) == 0 and len(a - x) > 0)): 12 | strict_superset = False 13 | break 14 | print(strict_superset) 15 | -------------------------------------------------------------------------------- /python/py-sets/py-check-subset.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Check Subset 2 | # Verify if set A is a subset of set B. 3 | # 4 | # https://www.hackerrank.com/challenges/py-check-subset/problem 5 | # 6 | 7 | for _ in range(int(input())): 8 | _, a = input(), set(map(int, input().split())) 9 | _, b = input(), set(map(int, input().split())) 10 | print(b.intersection(a) == a) 11 | -------------------------------------------------------------------------------- /python/py-sets/py-introduction-to-sets.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Introduction to Sets 2 | # Use the set tool to compute the average. 3 | # 4 | # https://www.hackerrank.com/challenges/py-introduction-to-sets/problem 5 | # 6 | 7 | def average(array): 8 | # your code goes here 9 | a = set(array) 10 | return sum(a) / len(a) 11 | 12 | # (skeliton_tail) ---------------------------------------------------------------------- 13 | if __name__ == '__main__': 14 | n = int(input()) 15 | arr = list(map(int, input().split())) 16 | result = average(arr) 17 | print(result) 18 | -------------------------------------------------------------------------------- /python/py-sets/py-set-add.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .add() 2 | # Add elements to set. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-add/problem 5 | # 6 | 7 | s = set() 8 | for _ in range(int(input())): 9 | s.add(input()) 10 | print(len(s)) 11 | -------------------------------------------------------------------------------- /python/py-sets/py-set-difference-operation.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .difference() Operation 2 | # Use the .difference() operator to check the differences between sets. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-difference-operation/problem 5 | # 6 | 7 | 8 | n = int(input()) 9 | english = set(map(int, input().split())) 10 | 11 | n = int(input()) 12 | french = set(map(int, input().split())) 13 | 14 | print(len(english - french)) 15 | -------------------------------------------------------------------------------- /python/py-sets/py-set-discard-remove-pop.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .discard(), .remove() & .pop() 2 | # Different ways to omit set elements. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem 5 | # 6 | 7 | n = int(input()) 8 | s = set(map(int, input().split())) 9 | 10 | for _ in range(int(input())): 11 | cmd = input().split() 12 | if cmd[0] == "pop": 13 | s.pop() 14 | elif cmd[0] == "remove": 15 | s.remove(int(cmd[1])) 16 | elif cmd[0] == "discard": 17 | s.discard(int(cmd[1])) 18 | 19 | print(sum(s)) -------------------------------------------------------------------------------- /python/py-sets/py-set-intersection-operation.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .intersection() Operation 2 | # Use the .intersection() operator to determine the number of same students in both sets. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-intersection-operation/problem 5 | # 6 | 7 | n = int(input()) 8 | english = set(map(int, input().split())) 9 | 10 | n = int(input()) 11 | french = set(map(int, input().split())) 12 | 13 | print(len(english & french)) 14 | -------------------------------------------------------------------------------- /python/py-sets/py-set-symmetric-difference-operation.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .symmetric_difference() Operation 2 | # Making symmetric difference of sets. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-symmetric-difference-operation/problem 5 | # 6 | 7 | 8 | n = int(input()) 9 | english = set(map(int, input().split())) 10 | 11 | n = int(input()) 12 | french = set(map(int, input().split())) 13 | 14 | print(len(english ^ french)) 15 | -------------------------------------------------------------------------------- /python/py-sets/py-set-union.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Set .union() Operation 2 | # Use the .union() operator to determine the number of students. 3 | # 4 | # https://www.hackerrank.com/challenges/py-set-union/problem 5 | # 6 | 7 | n = int(input()) 8 | english = set(map(int, input().split())) 9 | 10 | n = int(input()) 11 | french = set(map(int, input().split())) 12 | 13 | print(len(english | french)) 14 | -------------------------------------------------------------------------------- /python/py-sets/py-the-captains-room.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > The Captain's Room 2 | # Out of a list of room numbers, determine the number of the captain's room. 3 | # 4 | # https://www.hackerrank.com/challenges/py-the-captains-room/problem 5 | # 6 | 7 | k = int(input()) 8 | rooms = list(map(int, input().split())) 9 | 10 | a = set() 11 | room_group = set() 12 | 13 | for room in rooms: 14 | if room in a: 15 | room_group.add(room) 16 | else: 17 | a.add(room) 18 | 19 | a = a - room_group 20 | print(a.pop()) 21 | -------------------------------------------------------------------------------- /python/py-sets/symmetric-difference.py: -------------------------------------------------------------------------------- 1 | # Python > Sets > Symmetric Difference 2 | # Learn about sets as a data type. 3 | # 4 | # https://www.hackerrank.com/challenges/symmetric-difference/problem 5 | # 6 | 7 | m = int(input()) 8 | M = set(map(int, input().split())) 9 | 10 | n = int(input()) 11 | N = set(map(int, input().split())) 12 | 13 | a = (M - N).union(N - M) 14 | for i in sorted(a): 15 | print(i) 16 | -------------------------------------------------------------------------------- /python/py-strings/capitalize.py: -------------------------------------------------------------------------------- 1 | """ 2 | Capitalize! 3 | 4 | https://www.hackerrank.com/challenges/capitalize/problem 5 | """ 6 | 7 | def capitalize(string): 8 | s = "" 9 | for i in range(len(string)): 10 | if i == 0 or string[i-1] == ' ': 11 | s += string[i].upper() 12 | else: 13 | s += string[i] 14 | return s 15 | 16 | if __name__ == '__main__': 17 | string = input() 18 | capitalized_string = capitalize(string) 19 | print(capitalized_string) 20 | -------------------------------------------------------------------------------- /python/py-strings/python-string-split-and-join.py: -------------------------------------------------------------------------------- 1 | # String Split and Join 2 | # Use Python's split and join methods on the input string. 3 | # 4 | # https://www.hackerrank.com/challenges/python-string-split-and-join/problem 5 | # 6 | 7 | def split_and_join(line): 8 | # write your code here 9 | return '-'.join(line.split()) 10 | 11 | 12 | # (skeliton_tail) ---------------------------------------------------------------------- 13 | if __name__ == '__main__': 14 | line = input() 15 | result = split_and_join(line) 16 | print(result) 17 | -------------------------------------------------------------------------------- /python/py-strings/swap-case.py: -------------------------------------------------------------------------------- 1 | # sWAP cASE 2 | # Swap the letter cases of a given string. 3 | # 4 | # https://www.hackerrank.com/challenges/swap-case/problem 5 | # 6 | 7 | def swap(c): 8 | if c.islower(): 9 | return c.upper() 10 | else: 11 | return c.lower() 12 | 13 | def swap_case(s): 14 | return ''.join([swap(c) for c in s]) 15 | 16 | # (skeliton_tail) ---------------------------------------------------------------------- 17 | if __name__ == '__main__': 18 | s = input() 19 | result = swap_case(s) 20 | print(result) 21 | -------------------------------------------------------------------------------- /python/py-strings/whats-your-name.py: -------------------------------------------------------------------------------- 1 | # What's Your Name? 2 | # Python string practice: Print your name in the console. 3 | # 4 | # https://www.hackerrank.com/challenges/whats-your-name/problem 5 | # 6 | 7 | def print_full_name(a, b): 8 | print("Hello {} {}! You just delved into python.".format(a, b)) 9 | 10 | 11 | # (skeliton_tail) ---------------------------------------------------------------------- 12 | if __name__ == '__main__': 13 | first_name = input() 14 | last_name = input() 15 | print_full_name(first_name, last_name) 16 | -------------------------------------------------------------------------------- /python/xml/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(xml-1-find-the-score.py) 2 | add_hackerrank_py(xml2-find-the-maximum-depth.py) 3 | -------------------------------------------------------------------------------- /regex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(re-introduction) 2 | add_subdirectory(re-character-class) 3 | add_subdirectory(re-repetitions) 4 | add_subdirectory(grouping-and-capturing) 5 | add_subdirectory(backreferences) 6 | add_subdirectory(assertions) 7 | add_subdirectory(re-applications) 8 | -------------------------------------------------------------------------------- /regex/assertions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(positive-lookahead.py) 2 | add_hackerrank_py(negative-lookahead.py) 3 | add_hackerrank_py(positive-lookbehind.py) 4 | add_hackerrank_py(negative-lookbehind.py) 5 | -------------------------------------------------------------------------------- /regex/assertions/negative-lookahead.py: -------------------------------------------------------------------------------- 1 | # Regex > Assertions > Negative Lookahead 2 | # It asserts the regex to match if regexp ahead is not matching. 3 | # 4 | # https://www.hackerrank.com/challenges/negative-lookahead/problem 5 | # challenge id: 14902 6 | # 7 | 8 | Regex_Pattern = r"(.)(?!\1)" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | Test_String = input() 14 | 15 | match = re.findall(Regex_Pattern, Test_String) 16 | 17 | print("Number of matches :", len(match)) 18 | -------------------------------------------------------------------------------- /regex/assertions/negative-lookbehind.py: -------------------------------------------------------------------------------- 1 | # Regex > Assertions > Negative Lookbehind 2 | # It asserts the regex to match if regexp behind is not matching. 3 | # 4 | # https://www.hackerrank.com/challenges/negative-lookbehind/problem 5 | # challenge id: 14904 6 | # 7 | 8 | Regex_Pattern = r"(? Assertions > Positive Lookbehind 2 | # It asserts the regex to match if regexp behind is matching. 3 | # 4 | # https://www.hackerrank.com/challenges/positive-lookbehind/problem 5 | # challenge id: 14903 6 | # 7 | 8 | Regex_Pattern = r"(?<=[13579])\d" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | Test_String = input() 14 | 15 | match = re.findall(Regex_Pattern, Test_String) 16 | 17 | print("Number of matches :", len(match)) 18 | -------------------------------------------------------------------------------- /regex/backreferences/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(matching-same-text-again-again.py) 2 | add_hackerrank_py(backreferences-to-failed-groups.py) 3 | 4 | add_hackerrank_java(forward-references.java) -------------------------------------------------------------------------------- /regex/backreferences/backreferences-to-failed-groups.py: -------------------------------------------------------------------------------- 1 | # Regex > Backreferences > Backreferences To Failed Groups 2 | # Backreference to a capturing group that match nothing. 3 | # 4 | # https://www.hackerrank.com/challenges/backreferences-to-failed-groups/problem 5 | # challenge id: 14743 6 | # 7 | 8 | Regex_Pattern = r"^\d\d(-?)\d\d\1\d\d\1\d\d$" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/backreferences/branch-reset-groups.pl: -------------------------------------------------------------------------------- 1 | # Regex > Backreferences > Branch Reset Groups 2 | # Alternatives having same capturing group 3 | # 4 | # https://www.hackerrank.com/challenges/branch-reset-groups/problem 5 | # challenge id: 14816 6 | # 7 | 8 | $Regex_Pattern = '^\d\d(?|(---)|(-)|(:)|(\.))\d\d\1\d\d\1\d\d$'; 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | $Test_String = ; 12 | if($Test_String =~ /$Regex_Pattern/){ 13 | print "true"; 14 | } else { 15 | print "false"; 16 | } 17 | -------------------------------------------------------------------------------- /regex/grouping-and-capturing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(matching-word-boundaries.py) 2 | add_hackerrank_py(capturing-non-capturing-groups.py) 3 | add_hackerrank_py(alternative-matching.py) 4 | -------------------------------------------------------------------------------- /regex/grouping-and-capturing/alternative-matching.py: -------------------------------------------------------------------------------- 1 | # Regex > Grouping and Capturing > Alternative Matching 2 | # Matching single regex out of several regex. 3 | # 4 | # https://www.hackerrank.com/challenges/alternative-matching/problem 5 | # challenge id: 14623 6 | # 7 | 8 | Regex_Pattern = r'^(Mr|Ms|Mrs|Dr|Er)\.[a-zA-Z]+$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/grouping-and-capturing/capturing-non-capturing-groups.py: -------------------------------------------------------------------------------- 1 | # Regex > Grouping and Capturing > Capturing & Non-Capturing Groups 2 | # Creating capturing and non-capturing group. 3 | # 4 | # https://www.hackerrank.com/challenges/capturing-non-capturing-groups/problem 5 | # challenge id: 14621 6 | # 7 | 8 | Regex_Pattern = r'(?:ok){3,}' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/grouping-and-capturing/matching-word-boundaries.py: -------------------------------------------------------------------------------- 1 | # Regex > Grouping and Capturing > Matching Word Boundaries 2 | # Using \b to match word boundaries. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-word-boundaries/problem 5 | # challenge id: 14619 6 | # 7 | 8 | Regex_Pattern = r'\b[aeiouAEIOU][a-zA-Z]*\b' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-applications/alien-username.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Alien Username 2 | # Validate the usernames from an alien planet. 3 | # 4 | # https://www.hackerrank.com/challenges/alien-username/problem 5 | # challenge id: 720 6 | # 7 | 8 | import re 9 | 10 | for _ in range(int(input())): 11 | s = input() 12 | 13 | ok = re.match(r"^[_\.]\d+[a-z]*_?$", s, re.I) 14 | 15 | print("VALID" if ok else "INVALID") 16 | -------------------------------------------------------------------------------- /regex/re-applications/detect-html-tags.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Detect HTML Tags 2 | # Given N lines of HTML source, print the HTML tags found within it. 3 | # 4 | # https://www.hackerrank.com/challenges/detect-html-tags/problem 5 | # https://www.hackerrank.com/contests/regex-practice-2/challenges/detect-html-tags 6 | # challenge id: 722 7 | # 8 | 9 | import re 10 | 11 | html = ''.join([input() for _ in range(int(input()))]) 12 | 13 | find_tags = r'<\s*(\w+).*?>' 14 | match = re.findall(find_tags, html, re.I) 15 | if bool(match): 16 | print(';'.join(sorted(set(tag for tag in match)))) 17 | -------------------------------------------------------------------------------- /regex/re-applications/detect-the-domain-name.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Detect the Domain Name 2 | # Use Regular Expressions to detect domain names from a chunk of HTML Markup provided to you. 3 | # 4 | # https://www.hackerrank.com/challenges/detect-the-domain-name/problem 5 | # challenge id: 894 6 | # 7 | 8 | import re 9 | 10 | ad = [] 11 | for _ in range(int(input())): 12 | s = input() 13 | a = re.findall(r"""https?://(?:ww[w2]\.){0,1}([\w\d\-\.]*\.\w+)[/?"]""", s) 14 | ad.extend(a) 15 | 16 | print(';'.join(sorted(set(ad)))) 17 | -------------------------------------------------------------------------------- /regex/re-applications/detect-the-email-addresses.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Detect the Email Addresses 2 | # Use Regular Expressions to detect the email addresses embedded in a given chunk of text. 3 | # 4 | # https://www.hackerrank.com/challenges/detect-the-email-addresses/problem 5 | # challenge id: 895 6 | # 7 | 8 | import re 9 | 10 | ad = [] 11 | for _ in range(int(input())): 12 | s = input() 13 | 14 | a = re.findall(r"\b[\w\.]+@(?:\w+\.)+\w+\b", s) 15 | 16 | ad.extend(a) 17 | 18 | print(';'.join(sorted(set(ad)))) 19 | -------------------------------------------------------------------------------- /regex/re-applications/find-a-word.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Find a Word 2 | # Find a given word in a sentence using regex special characters. 3 | # 4 | # https://www.hackerrank.com/challenges/find-a-word/problem 5 | # challenge id: 733 6 | # 7 | 8 | import re 9 | 10 | s = " ".join(input() for _ in range(int(input()))) 11 | 12 | for _ in range(int(input())): 13 | w = input() 14 | print(len(re.findall(r"(^|(?<=\W))" + w + r"(?=\W)", s, re.I))) 15 | -------------------------------------------------------------------------------- /regex/re-applications/find-substring.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Find A Sub-Word 2 | # Use RegEx to count the number of times a sub-word appears in a given set of sentences. 3 | # 4 | # https://www.hackerrank.com/challenges/find-substring/problem 5 | # challenge id: 734 6 | # 7 | 8 | import re 9 | 10 | s = " ".join(input() for _ in range(int(input()))) 11 | 12 | for _ in range(int(input())): 13 | sw = input() 14 | print(len(re.findall(r"\b[\d\w]+" + sw + r"[\d\w]+\b", s))) 15 | -------------------------------------------------------------------------------- /regex/re-applications/hackerrank-tweets.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > HackerRank Tweets 2 | # Write a regex to identify the tweets that has the string *hackerrank* in it 3 | # 4 | # https://www.hackerrank.com/challenges/hackerrank-tweets/problem 5 | # https://www.hackerrank.com/contests/regex-practice-2/challenges/hackerrank-tweets 6 | # challenge id: 714 7 | # 8 | 9 | import re 10 | 11 | n = 0 12 | for _ in range(int(input())): 13 | if re.search(r'\bhackerrank\b', input(), re.I): 14 | n += 1 15 | print(n) 16 | -------------------------------------------------------------------------------- /regex/re-applications/saying-hi.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > Saying Hi 2 | # Use a regex to print all the lines that start with "hi " but are not immediately followed by a 'd' or 'D'. 3 | # 4 | # https://www.hackerrank.com/challenges/saying-hi/problem 5 | # challenge id: 713 6 | # 7 | 8 | import re 9 | 10 | for _ in range(int(input())): 11 | s = input() 12 | if re.match(r"^hi\s[^d]", s, re.I): 13 | print(s) 14 | -------------------------------------------------------------------------------- /regex/re-applications/uk-and-us.py: -------------------------------------------------------------------------------- 1 | # Regex > Applications > The British and American Style of Spelling 2 | # Use regular expression to find the count of a given word that ends with either *ze* or *se* 3 | # 4 | # https://www.hackerrank.com/challenges/uk-and-us/problem 5 | # challenge id: 710 6 | # 7 | 8 | import re 9 | 10 | text = '' 11 | for _ in range(int(input())): 12 | text += input() + ' ' 13 | 14 | for _ in range(int(input())): 15 | w = input() 16 | print(len(re.findall(w[:len(w) - 2] + r'[sz]e\b', text))) 17 | -------------------------------------------------------------------------------- /regex/re-character-class/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(matching-specific-characters.py) 2 | add_hackerrank_py(excluding-specific-characters.py) 3 | add_hackerrank_py(matching-range-of-characters.py) 4 | -------------------------------------------------------------------------------- /regex/re-character-class/excluding-specific-characters.py: -------------------------------------------------------------------------------- 1 | # Regex > Character Class > Excluding Specific Characters 2 | # Use the [^] character class to exclude specific characters. 3 | # 4 | # https://www.hackerrank.com/challenges/excluding-specific-characters/problem 5 | # challenge id: 14273 6 | # 7 | 8 | Regex_Pattern = r'^\D[^aeiou][^bcDF]\S[^AEIOU][^\.,]$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-character-class/matching-range-of-characters.py: -------------------------------------------------------------------------------- 1 | # Regex > Character Class > Matching Character Ranges 2 | # Write a RegEx matching a range of characters. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-range-of-characters/problem 5 | # challenge id: 14274 6 | # 7 | 8 | Regex_Pattern = r'^[a-z][1-9][^a-z][^A-Z][A-Z]' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-character-class/matching-specific-characters.py: -------------------------------------------------------------------------------- 1 | # Regex > Character Class > Matching Specific Characters 2 | # Use the [ ] expression to match specific characters. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-specific-characters/problem 5 | # challenge id: 14272 6 | # 7 | 8 | Regex_Pattern = r'^[123][012][xs0][30Aa][xsu][\.,]$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-introduction/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(matching-specific-string.py) 2 | add_hackerrank_py(matching-anything-but-new-line.py) 3 | add_hackerrank_py(matching-whitespace-non-whitespace-character.py) 4 | add_hackerrank_py(matching-word-non-word.py) 5 | add_hackerrank_py(matching-start-end.py) 6 | add_hackerrank_py(matching-digits-non-digit-character.py) 7 | -------------------------------------------------------------------------------- /regex/re-introduction/matching-digits-non-digit-character.py: -------------------------------------------------------------------------------- 1 | # Regex > Introduction > Matching Digits & Non-Digit Characters 2 | # Use the expression \d to match digits and \D to match non-digit characters. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-digits-non-digit-character/problem 5 | # challenge id: 14186 6 | # 7 | 8 | Regex_Pattern = r"(\d\d\D){2}\d{4}" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-introduction/matching-start-end.py: -------------------------------------------------------------------------------- 1 | # Regex > Introduction > Matching Start & End 2 | # Use the ^ symbol to match the start of a string, and the $ symbol to match the end characters. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-start-end/problem 5 | # challenge id: 14268 6 | # 7 | 8 | Regex_Pattern = r"^\d\w{4}\.$" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-introduction/matching-word-non-word.py: -------------------------------------------------------------------------------- 1 | # Regex > Introduction > Matching Word & Non-Word Character 2 | # Use \w to match any word and \W to match any non-word character. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-word-non-word/problem 5 | # challenge id: 14140 6 | # 7 | 8 | Regex_Pattern = r"\w{3}\W\w{10}\W\w{3}" # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-repetitions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(matching-x-repetitions.py) 2 | add_hackerrank_py(matching-x-y-repetitions.py) 3 | add_hackerrank_py(matching-zero-or-more-repetitions.py) 4 | add_hackerrank_py(matching-one-or-more-repititions.py) 5 | add_hackerrank_py(matching-ending-items.py) 6 | -------------------------------------------------------------------------------- /regex/re-repetitions/matching-ending-items.py: -------------------------------------------------------------------------------- 1 | # Regex > Repetitions > Matching Ending Items 2 | # Match the end of the string using the $ boundary matcher. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-ending-items/problem 5 | # challenge id: 14620 6 | # 7 | 8 | Regex_Pattern = r'^[a-zA-Z]*s$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-repetitions/matching-one-or-more-repititions.py: -------------------------------------------------------------------------------- 1 | # Regex > Repetitions > Matching One Or More Repetitions 2 | # Match zero or more repetitions of character/character class/group with the + symbol. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-one-or-more-repititions/problem 5 | # challenge id: 14524 6 | # 7 | 8 | Regex_Pattern = r'^\d+[A-Z]+[a-z]+$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-repetitions/matching-x-repetitions.py: -------------------------------------------------------------------------------- 1 | # Regex > Repetitions > Matching {x} Repetitions 2 | # Match exactly x repetitions using the tool {x}. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-x-repetitions/problem 5 | # challenge id: 14525 6 | # 7 | 8 | Regex_Pattern = r'^[a-zA-Z02468]{40}[13579\s]{5}$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-repetitions/matching-x-y-repetitions.py: -------------------------------------------------------------------------------- 1 | # Regex > Repetitions > Matching {x, y} Repetitions 2 | # Match between a range of x and y repetitions using the {x,y} tool. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-x-y-repetitions/problem 5 | # challenge id: 14522 6 | # 7 | 8 | Regex_Pattern = r'^\d{1,2}[A-Za-z]{3,}\.{0,3}$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /regex/re-repetitions/matching-zero-or-more-repetitions.py: -------------------------------------------------------------------------------- 1 | # Regex > Repetitions > Matching Zero Or More Repetitions 2 | # Match zero or more repetitions of character/character class/group using the * symbol in regex. 3 | # 4 | # https://www.hackerrank.com/challenges/matching-zero-or-more-repetitions/problem 5 | # challenge id: 14523 6 | # 7 | 8 | Regex_Pattern = r'^\d\d\d*[a-z]*[A-Z]*$' # Do not delete 'r'. 9 | 10 | # (skeliton_tail) ---------------------------------------------------------------------- 11 | import re 12 | 13 | print(str(bool(re.search(Regex_Pattern, input()))).lower()) 14 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyyaml 2 | requests 3 | requests_cache 4 | flake8 5 | numpy 6 | scipy 7 | scikit-learn 8 | #cpp-coveralls 9 | #coveralls 10 | -------------------------------------------------------------------------------- /security/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(concepts) 2 | add_subdirectory(cryptography) 3 | add_subdirectory(functions) 4 | -------------------------------------------------------------------------------- /security/concepts/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(security-message-space-and-ciphertext-space security-message-space-and-ciphertext-space.cpp) 2 | add_hackerrank(security-key-spaces security-key-spaces.cpp) 3 | add_hackerrank(security-encryption-scheme security-encryption-scheme.cpp) 4 | -------------------------------------------------------------------------------- /security/cryptography/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_py(keyword-transposition-cipher.py) 2 | add_hackerrank(prng-sequence-guessing prng-sequence-guessing.cpp) 3 | add_hackerrank_py(basic-cryptanalysis.py) 4 | configure_file(dictionary.lst dictionary.lst COPYONLY @ONLY) 5 | -------------------------------------------------------------------------------- /security/functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank(security-function-ii security-function-ii.cpp) 2 | add_hackerrank(security-tutorial-functions security-tutorial-functions.cpp) 3 | add_hackerrank(security-bijective-functions security-bijective-functions.cpp) 4 | add_hackerrank(security-inverse-of-a-function security-inverse-of-a-function.cpp) 5 | add_hackerrank(security-tutorial-permutations security-tutorial-permutations.cpp) 6 | add_hackerrank(security-involution security-involution.cpp) 7 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | exclude = python/* algorithms/* tutorials/* mathematics/* data-structures/* challenges/* contests/* security/* work/* debug/* build*/* wsl/* regex/* interview-preparation-kit/* 4 | -------------------------------------------------------------------------------- /shell/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(bash) 2 | add_subdirectory(textpro) 3 | add_subdirectory(arrays-in-bash) 4 | add_subdirectory(grep-sed-awk) -------------------------------------------------------------------------------- /shell/arrays-in-bash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_hackerrank_shell(bash-tutorials-read-in-an-array.sh) 2 | add_hackerrank_shell(bash-tutorials-slice-an-array.sh) 3 | add_hackerrank_shell(bash-tutorials-filter-an-array-with-patterns.sh) 4 | add_hackerrank_shell(bash-tutorials-concatenate-an-array-with-itself.sh) 5 | add_hackerrank_shell(bash-tutorials-display-the-third-element-of-an-array.sh) 6 | add_hackerrank_shell(bash-tutorials-count-the-number-of-elements-in-an-array.sh) 7 | add_hackerrank_shell(bash-tutorials-remove-the-first-capital-letter-from-each-array-element.sh) 8 | add_hackerrank_shell(lonely-integer-2.sh) 9 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-concatenate-an-array-with-itself.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Concatenate an array with itself 2 | # Concatenate an array with itself. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-concatenate-an-array-with-itself/problem 5 | # 6 | 7 | declare -a a 8 | a=($(cat)) 9 | b=("${a[@]}" "${a[@]}" "${a[@]}") 10 | echo ${b[@]} 11 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-count-the-number-of-elements-in-an-array.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Count the number of elements in an Array 2 | # Read in an Array - and count the number of elements in it. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-count-the-number-of-elements-in-an-array/problem 5 | # 6 | 7 | a=($(cat)) 8 | echo ${#a[@]} 9 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-display-the-third-element-of-an-array.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Display an element of an array 2 | # Read in an Array - and display the fourth element in it. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-display-the-third-element-of-an-array/problem 5 | # 6 | 7 | a=($(cat)) 8 | echo ${a[3]} -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-filter-an-array-with-patterns.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Filter an Array with Patterns 2 | # Read in an array and filter out certain elements based on a pattern. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-filter-an-array-with-patterns/problem 5 | # 6 | 7 | declare -a a 8 | 9 | a=($(cat)) 10 | 11 | echo ${a[@]/*[aA]*/} 12 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-read-in-an-array.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Read in an Array 2 | # Read in an Array - and display all its elements. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-read-in-an-array/problem 5 | # 6 | 7 | a=($(cat)) 8 | echo ${a[@]} 9 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-remove-the-first-capital-letter-from-each-array-element.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Remove the First Capital Letter from Each Element 2 | # The first capital letter in each element should be replaced with a dot ('.'). 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-remove-the-first-capital-letter-from-each-array-element/problem 5 | # 6 | 7 | a=($(cat)) 8 | echo ${a[@]/#?/.} 9 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/bash-tutorials-slice-an-array.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Slice an Array 2 | # Slice a given array. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-slice-an-array/problem 5 | # 6 | 7 | declare -a a 8 | 9 | a=($(cat)) 10 | echo ${a[*]:3:5} 11 | -------------------------------------------------------------------------------- /shell/arrays-in-bash/lonely-integer-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Arrays in Bash > Lonely Integer - Bash! 2 | # Find the integer that occurs only once in the Array 3 | # 4 | # https://www.hackerrank.com/challenges/lonely-integer-2/problem 5 | # 6 | 7 | # il suffit de faire des XOR avec les nombres 8 | # les nombres en double vont s'annuler 9 | # le nombre isolé va rester 10 | 11 | read n 12 | a=($(cat)) 13 | echo $((0 ${a[@]/#/^})) 14 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---a-personalized-echo.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > A Personalized Echo 2 | # A very gentle on-boarding, to accepting input in Bash. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---a-personalized-echo/problem 5 | # 6 | 7 | read a 8 | echo "Welcome $a" 9 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---arithmetic-operations.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Arithmetic Operations 2 | # Math in shell scripts. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---arithmetic-operations/problem 5 | # 6 | 7 | # mais ce n'est certainement pas la solution attendue... 8 | #python3 -c 'print("%.3f" % eval(input().replace("^","**")))' 9 | 10 | # c'est plus vraisemblalement ça... dommage que scale=3 ne donne pas les bonnes décimales 11 | export LANG=C 12 | read a 13 | printf "%.3f\n" $(echo $a | bc -l) 14 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---comparing-numbers.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Comparing Numbers 2 | # Simple comparisons between numbers: Greater than, less than, equal to. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---comparing-numbers/problem 5 | # 6 | 7 | read X 8 | read Y 9 | [ $X -eq $Y ] && echo "X is equal to Y" 10 | [ $X -lt $Y ] && echo "X is less than Y" 11 | [ $X -gt $Y ] && echo "X is greater than Y" 12 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---compute-the-average.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Compute the Average 2 | # Compute the average of a list of N numbers provided to you. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---compute-the-average/problem 5 | # 6 | 7 | # pas franchement le langage le plus adapté... 8 | 9 | export LANG=C 10 | 11 | read N 12 | a=0 13 | for i in $(seq $N); do 14 | read x 15 | a=$((a+x)) 16 | done 17 | printf "%.3f" $(bc -l <<< "$a / $N") 18 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---getting-started-with-conditionals.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Getting started with conditionals 2 | # - 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---getting-started-with-conditionals/problem 5 | # 6 | 7 | read c 8 | if [ "$c" = "y" -o "$c" = "Y" ] 9 | then 10 | echo YES 11 | else 12 | echo NO 13 | fi 14 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---looping-and-skipping.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Looping and Skipping 2 | # Let's play with for loops, a little more. Let's skip numbers! 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---looping-and-skipping/problem 5 | # 6 | 7 | for ((i=1; i<=99; i+=2)); do echo $i; done 8 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---looping-with-numbers.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Looping with Numbers 2 | # Let's experiment with 'For' loops 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---looping-with-numbers/problem 5 | # 6 | 7 | for ((i=1;i<=50;i+=1)) 8 | do 9 | echo $i 10 | done -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---more-on-conditionals.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > More on Conditionals 2 | # Three sides of a triangle are provided to you. Is the Triangle Scalene, Equilateral or Isosceles? 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---more-on-conditionals/problem 5 | # 6 | 7 | read X 8 | read Y 9 | read Z 10 | if [ $X -eq $Y -a $Y -eq $Z -a $Z -eq $X ] ; then 11 | echo EQUILATERAL 12 | elif [ $X -eq $Y -o $Y -eq $Z -o $Z -eq $X ] ; then 13 | echo ISOSCELES 14 | else 15 | echo SCALENE 16 | fi 17 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials---the-world-of-numbers.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > The World of Numbers 2 | # Let's move on to playing with numbers in Bash. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials---the-world-of-numbers/problem 5 | # 6 | 7 | read X 8 | read Y 9 | echo $((X+Y)) 10 | echo $((X-Y)) 11 | echo $((X*Y)) 12 | echo $((X/Y)) 13 | -------------------------------------------------------------------------------- /shell/bash/bash-tutorials-lets-echo.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Bash > Let's Echo 2 | # Let's get started with the simplest Bash command: echo. 3 | # 4 | # https://www.hackerrank.com/challenges/bash-tutorials-lets-echo/problem 5 | # 6 | 7 | echo HELLO 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/awk-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Awk' - 1 2 | # Introduction to the 'awk' command in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/awk-1/problem 5 | # 6 | 7 | awk '{ if (NF < 4) { print "Not all scores are available for "$1 }}' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/awk-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Awk' - 2 2 | # Let's play around with 'awk'. 3 | # 4 | # https://www.hackerrank.com/challenges/awk-2/problem 5 | # 6 | 7 | awk '{ if ($2 >= 50 && $3 >= 50 && $4 >= 50) print $1,": Pass"; else print $1, ": Fail" }' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/awk-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Awk' - 3 2 | # Let's play around with 'awk'. 3 | # 4 | # https://www.hackerrank.com/challenges/awk-3/problem 5 | # 6 | awk '{ p = int(($2 + $3 + $4) / 3); 7 | if (p >= 80) q = "A"; else if (p >= 60) q = "B"; else if (p >= 50) q = "C"; else q ="FAIL"; 8 | print $1" "$2" " $3" " $4 " : " q ; }' 9 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/awk-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Awk' - 4 2 | # Let's play around with 'awk'. 3 | # 4 | # https://www.hackerrank.com/challenges/awk-4/problem 5 | # 6 | 7 | awk '{if (NR % 2) { printf $0 ";"; } else { printf $0 "\n"; } }' 8 | 9 | # il y a moyen d'écrire beaucoup plus concis 10 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/sed-command-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Sed' command #4 2 | # Let's learn about the 'sed' command. 3 | # 4 | # https://www.hackerrank.com/challenges/sed-command-4/problem 5 | # 6 | 7 | sed 's/\([0-9]\{4\}\) \([0-9]\{4\}\) \([0-9]\{4\}\) \([0-9]\{4\}\)/**** **** **** \4/' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/sed-command-5.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Sed' command #5 2 | # Let's learn about the 'sed' command. 3 | # 4 | # https://www.hackerrank.com/challenges/sed-command-5/problem 5 | # 6 | 7 | sed 's/\([0-9]\{4\}\) \([0-9]\{4\}\) \([0-9]\{4\}\) \([0-9]\{4\}\)/\4 \3 \2 \1/' -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-grep-command-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Grep' #1 2 | # Introduction to 'grep' in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-1/problem 5 | # 6 | 7 | grep "the " 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-grep-command-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Grep' #2 2 | # Introduction to 'grep' in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-2/problem 5 | # 6 | 7 | grep -i "the " -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-grep-command-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Grep' #3 2 | # Introduction to 'grep' in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-3/problem 5 | # 6 | 7 | grep -i -v "that " 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-grep-command-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Grep' - A 2 | # Let's 'grep' out stuff from text files! 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-4/problem 5 | # 6 | 7 | grep -E -i 'the |that |then |those ' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-grep-command-5.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Grep' - B 2 | # Let's 'grep' out stuff from text files! 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-grep-command-5/problem 5 | # 6 | 7 | grep -E '([0-9]) ?\1' 8 | 9 | # -E extended grep 10 | # ([0-9]) = capture un chiffre 11 | # " ?" = un espace ou rien 12 | # \1 = référence à la capture 13 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-sed-command-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Sed' command #1 2 | # Let's learn about the 'sed' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-sed-command-1/problem 5 | # 6 | 7 | sed 's/the /this /' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-sed-command-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Sed' command #2 2 | # Let's learn about the 'sed' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-sed-command-2/problem 5 | # 6 | 7 | sed 's/thy/your/ig' 8 | -------------------------------------------------------------------------------- /shell/grep-sed-awk/text-processing-in-linux-the-sed-command-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Grep Sed Awk > 'Sed' command #3 2 | # Let's learn about the 'sed' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-sed-command-3/problem 5 | # 6 | 7 | sed 's/\(thy\)/{\1}/ig' 8 | -------------------------------------------------------------------------------- /shell/textpro/paste-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Paste - 1 2 | # Getting started with the 'paste' command. 3 | # 4 | # https://www.hackerrank.com/challenges/paste-1/problem 5 | # 6 | 7 | paste -s -d';' - 8 | -------------------------------------------------------------------------------- /shell/textpro/paste-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Paste - 2 2 | # Getting started with the 'paste' command. 3 | # 4 | # https://www.hackerrank.com/challenges/paste-2/problem 5 | # 6 | 7 | paste -d';' - - - 8 | -------------------------------------------------------------------------------- /shell/textpro/paste-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Paste - 3 2 | # Getting started with the 'paste' command. 3 | # 4 | # https://www.hackerrank.com/challenges/paste-3/problem 5 | # 6 | 7 | paste -s - 8 | -------------------------------------------------------------------------------- /shell/textpro/paste-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Paste - 4 2 | # Getting started with the 'paste' command. 3 | # 4 | # https://www.hackerrank.com/challenges/paste-4/problem 5 | # 6 | 7 | paste - - - 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #1 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-1/problem 5 | # 6 | 7 | cut -b3 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #2 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-2/problem 5 | # 6 | 7 | cut -b2,7 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #3 2 | # 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-3/problem 5 | # 6 | 7 | cut -b2-7 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #4 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-4/problem 5 | # 6 | 7 | cut -b-4 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-5.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #5 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-5/problem 5 | # 6 | 7 | cut -f1-3 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-6.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #6 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-6/problem 5 | # 6 | 7 | cut -b13- -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-7.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #7 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-7/problem 5 | # 6 | 7 | cut -d' ' -f4 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-8.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #8 2 | # Playing with the 'cut' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-8/problem 5 | # 6 | 7 | cut -d' ' -f1,2,3 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-cut-9.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Cut #9 2 | # Playing with the 'cut' command and TSV files. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-cut-9/problem 5 | # 6 | 7 | cut -f2- 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-head-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Head of a Text File #1 2 | # Introducing the 'head' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-head-1/problem 5 | # 6 | 7 | head -20 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-head-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Head of a Text File #2 2 | # The 'head' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-head-2/problem 5 | # 6 | 7 | head -c20 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-in-linux---the-middle-of-a-text-file.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Middle of a Text File 2 | # Display lines from the middle of a text file 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux---the-middle-of-a-text-file/problem 5 | # 6 | 7 | sed '12,22p;d' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-in-linux-the-uniq-command-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Uniq' Command #1 2 | # Introduction to the 'uniq' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-uniq-command-1/problem 5 | # 6 | 7 | uniq 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-in-linux-the-uniq-command-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Uniq' Command #2 2 | # Introduction to the 'uniq' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-uniq-command-2/problem 5 | # 6 | 7 | uniq -c | sed 's/^ *//' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-in-linux-the-uniq-command-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Uniq' command #3 2 | # Let's learn about the 'uniq' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-uniq-command-3/problem 5 | # 6 | 7 | uniq -c -i | while read a b ; do 8 | echo $a $b 9 | done 10 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-in-linux-the-uniq-command-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Uniq' command #4 2 | # Let's learn about the 'uniq' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-in-linux-the-uniq-command-4/problem 5 | # 6 | 7 | uniq -u 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Sort Command #1 2 | # Introducing the 'sort' command in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-1/problem 5 | # 6 | 7 | sort 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Sort Command #2 2 | # Introducing the 'sort' command in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-2/problem 5 | # 6 | 7 | sort -r 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Sort Command #3 2 | # Introducing the 'sort' command in Linux. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-3/problem 5 | # 6 | 7 | sort -n 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-4.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Sort Command #4 2 | # Playing around with the 'sort' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-4/problem 5 | # 6 | 7 | sort -nr 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-5.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Sort Command #5 2 | # Playing around with the 'sort' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-5/problem 5 | # 6 | 7 | sort -r -n -k2 -t $'\t' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-6.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Sort' command #6 2 | # Let's learn about the 'sort' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-6/problem 5 | # 6 | 7 | sort -n -t$'\t' -k2 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-sort-7.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Sort' command #7 2 | # Let's learn about the 'sort' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-sort-7/problem 5 | # 6 | 7 | sort -nr -k2 -t'|' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-tail-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Tail of a Text File #1 2 | # Introduction to the 'tail' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-tail-1/problem 5 | # 6 | 7 | tail -20 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-tail-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > Tail of a Text File #2 2 | # The 'tail' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-tail-2/problem 5 | # 6 | 7 | tail -c20 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-tr-1.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Tr' Command #1 2 | # Introduction to the 'tr' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-tr-1/problem 5 | # 6 | 7 | tr '()' '[]' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-tr-2.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Tr' Command #2 2 | # Introduction to the 'tr' command. 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-tr-2/problem 5 | # 6 | 7 | tr -d 'a-z' 8 | -------------------------------------------------------------------------------- /shell/textpro/text-processing-tr-3.sh: -------------------------------------------------------------------------------- 1 | # Linux Shell > Text Processing > 'Tr' Command #3 2 | # 3 | # 4 | # https://www.hackerrank.com/challenges/text-processing-tr-3/problem 5 | # 6 | 7 | tr -s ' ' ' ' 8 | -------------------------------------------------------------------------------- /sql/select/japanese-cities-attributes.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Japanese Cities' Attributes 2 | -- Query the attributes of all the cities in Japan. 3 | -- 4 | -- https://www.hackerrank.com/challenges/japanese-cities-attributes/problem 5 | -- 6 | 7 | select * from city where countrycode='JPN'; -------------------------------------------------------------------------------- /sql/select/japanese-cities-name.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Japanese Cities' Names 2 | -- In this challenge, you will query a list of all the Japanese cities' names. 3 | -- 4 | -- https://www.hackerrank.com/challenges/japanese-cities-name/problem 5 | -- 6 | 7 | select name from city where countrycode='JPN'; 8 | -------------------------------------------------------------------------------- /sql/select/revising-the-select-query-2.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Revising the Select Query II 2 | -- Query the city names for all American cities with populations larger than 120,000. 3 | -- 4 | -- https://www.hackerrank.com/challenges/revising-the-select-query-2/problem 5 | -- 6 | 7 | select name from city where countrycode='USA' and population>=120000; 8 | -------------------------------------------------------------------------------- /sql/select/revising-the-select-query.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Revising the Select Query I 2 | -- Query the data for all American cities with populations larger than 100,000. 3 | -- 4 | -- https://www.hackerrank.com/challenges/revising-the-select-query/problem 5 | -- 6 | 7 | select * from CITY where POPULATION>100000 and COUNTRYCODE='USA'; 8 | -------------------------------------------------------------------------------- /sql/select/select-all-sql.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Select All 2 | -- Query all columns for every row in a table. 3 | -- 4 | -- https://www.hackerrank.com/challenges/select-all-sql/problem 5 | -- challenge id: 8137 6 | -- 7 | 8 | SET FEEDBACK OFF; 9 | SET ECHO OFF; 10 | SET HEADING OFF; 11 | SET WRAP OFF; 12 | SET LINESIZE 10000; 13 | SET TAB OFF; 14 | -- (skeliton_head) ---------------------------------------------------------------------- 15 | 16 | select * from city; 17 | 18 | -- (skeliton_tail) ---------------------------------------------------------------------- 19 | exit; 20 | -------------------------------------------------------------------------------- /sql/select/select-by-id.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Select By ID 2 | -- Query the details of the city with ID 1661. 3 | -- 4 | -- https://www.hackerrank.com/challenges/select-by-id/problem 5 | -- 6 | 7 | select * from city where id=1661; 8 | -------------------------------------------------------------------------------- /sql/select/weather-observation-station-1.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Weather Observation Station 1 2 | -- Write a query to print the CITY and STATE for each attribute in the STATION table. 3 | -- 4 | -- https://www.hackerrank.com/challenges/weather-observation-station-1/problem 5 | -- 6 | 7 | select city,state from station; 8 | -------------------------------------------------------------------------------- /sql/select/weather-observation-station-3.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Weather Observation Station 3 2 | -- Query a list of unique CITY names with even ID numbers. 3 | -- 4 | -- https://www.hackerrank.com/challenges/weather-observation-station-3/problem 5 | -- 6 | 7 | select distinct city from station where mod(id, 2) = 0; 8 | -------------------------------------------------------------------------------- /sql/select/weather-observation-station-4.sql: -------------------------------------------------------------------------------- 1 | -- SQL > Basic Select > Weather Observation Station 4 2 | -- Find the number of duplicate CITY names in STATION. 3 | -- 4 | -- https://www.hackerrank.com/challenges/weather-observation-station-4/problem 5 | -- 6 | 7 | select count(*)-count(distinct city) from station; 8 | -------------------------------------------------------------------------------- /testcases.tar.xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rene-d/hackerrank/1bfdbc63de5d0f94cd9e6ae250476b4a267662f2/testcases.tar.xz -------------------------------------------------------------------------------- /tutorials/10-days-of-javascript/js10-buttons-container/css/buttonsGrid.css: -------------------------------------------------------------------------------- 1 | #btns { 2 | width: 75%; 3 | } 4 | 5 | button { 6 | width: 30%; 7 | height: 48px; 8 | font-size: 24px; 9 | } -------------------------------------------------------------------------------- /tutorials/10-days-of-javascript/js10-create-a-button/css/button.css: -------------------------------------------------------------------------------- 1 | #btn { 2 | width: 96px; 3 | height: 48px; 4 | font-size: 24px; 5 | } 6 | -------------------------------------------------------------------------------- /tutorials/10-days-of-javascript/js10-create-a-button/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tutorials/10-days-of-javascript/js10-create-a-button/js/button.js: -------------------------------------------------------------------------------- 1 | var btn = document.getElementById('btn'); 2 | 3 | btn.innerHTML = 0; 4 | btn.onclick = function() { ++btn.innerHTML; } 5 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-geometric-distribution-1.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 4: Geometric Distribution I 2 | # Problems based on basic statistical distributions. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-geometric-distribution-1/problem 5 | # challenge id: 21244 6 | # 7 | 8 | 9 | def g(n, p): 10 | return p * (1 - p) ** (n - 1) 11 | 12 | ko, total = map(int, input().split()) 13 | n = int(input()) 14 | 15 | r = g(n, ko / total) 16 | print("%.3f" % r) 17 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-geometric-distribution-2.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 4: Geometric Distribution II 2 | # Problems based on basic statistical distributions. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-geometric-distribution-2/problem 5 | # challenge id: 21245 6 | # 7 | 8 | def g(n, p): 9 | return p * (1 - p) ** (n - 1) 10 | 11 | ko, total = map(int, input().split()) 12 | n = int(input()) 13 | 14 | r = sum(g(n, ko / total) for n in range(1, 6)) 15 | print("%.3f" % r) 16 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-1.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 2: Basic Probability 2 | # Calculate the probability that two dice will have a maximum sum of 9. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-1/problem 5 | # challenge id: 21607 6 | # 7 | 8 | from fractions import Fraction 9 | 10 | n = 0 11 | for i in range(1, 7): 12 | for j in range(1, 7): 13 | if i + j <= 9: 14 | n += 1 15 | 16 | print(Fraction(n, 6 * 6)) 17 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-2.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 2: More Dice 2 | # Calculate the probability that two dice will roll two unique values having a sum of 6. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-2/problem 5 | # challenge id: 21608 6 | # 7 | 8 | from fractions import Fraction 9 | 10 | n = 0 11 | for i in range(1, 7): 12 | for j in range(1, 7): 13 | if i + j == 6 and i != j: 14 | n += 1 15 | 16 | print(Fraction(n, 6 * 6)) -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-4.txt: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 3: Conditional Probability 2 | # Find the probability that both children are boys, given that one is a boy. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-4/problem 5 | # challenge id: 21610 6 | # 7 | 8 | 1 / 3 9 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-5.txt: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 3: Cards of the Same Suit 2 | # Find the probability that 2 cards drawn from a deck (without replacement) are of the same suit. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-5/problem 5 | # challenge id: 21611 6 | # 7 | 8 | 12 / 51 9 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-6.txt: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 3: Drawing Marbles 2 | # Find the probability that the second marble drawn is blue. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-6/problem 5 | # challenge id: 21612 6 | # 7 | 8 | 2 / 3 9 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-mcq-7.txt: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 8: Pearson Correlation Coefficient II 2 | # Find the Pearson correlation coefficient 3 | # 4 | # https://www.hackerrank.com/challenges/s10-mcq-7/problem 5 | # challenge id: 21709 6 | # 7 | 8 | # explication: 9 | # 3*x + 4*y + 8 = 0 ⟹ y = -3/4 * x - 2 ⟹ b = -3/4 = ρ σy/σx 10 | # 4*x + 3*y + 7 = 0 ⟹ x = -3/4 * y - 7/4 ⟹ b = -3/4 = ρ σx/σy 11 | # (-3/4)² = ρ² ⟹ ρ = ± 3/4 12 | # b < 0 ⟹ ρ = - 3/4 13 | 14 | -3 / 4 15 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-poisson-distribution-1.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 5: Poisson Distribution I 2 | # Basic problem on Poisson Distribution. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-poisson-distribution-1/problem 5 | # challenge id: 21227 6 | # 7 | 8 | import math 9 | 10 | def poisson(λ, k): 11 | return λ ** k * math.e ** (-λ) / math.factorial(k) 12 | 13 | λ = float(input()) 14 | k = int(input()) 15 | 16 | print("{:.3f}".format(poisson(λ, k))) 17 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-poisson-distribution-2.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 5: Poisson Distribution II 2 | # Basic problem on Poisson Distribution. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-poisson-distribution-2/problem 5 | # challenge id: 21228 6 | # 7 | 8 | import math 9 | 10 | def poisson(λ, k): 11 | return λ ** k * math.e ** (-λ) / math.factorial(k) 12 | 13 | def E(λ): 14 | return λ + λ ** 2 15 | 16 | λ1, λ2 = map(float, input().split()) 17 | 18 | print("{:.3f}".format(160 + 40 * E(λ1))) 19 | print("{:.3f}".format(128 + 40 * E(λ2))) 20 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-standard-deviation.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 1: Standard Deviation 2 | # Compute the standard deviation 3 | # 4 | # https://www.hackerrank.com/challenges/s10-standard-deviation/problem 5 | # challenge id: 21237 6 | # 7 | 8 | n = int(input()) 9 | x = list(map(int, input().split())) 10 | 11 | Σ = sum 12 | 13 | # moyenne (mean) 14 | µ = Σ(x) / n 15 | 16 | # écart-type (standard deviation) 17 | 𝜎 = (Σ((i - µ) ** 2 for i in x) / n) ** 0.5 18 | 19 | print("{:.1f}".format(𝜎)) 20 | -------------------------------------------------------------------------------- /tutorials/10-days-of-statistics/s10-weighted-mean.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 10 Days of Statistics > Day 0: Weighted Mean 2 | # Compute the weighted mean. 3 | # 4 | # https://www.hackerrank.com/challenges/s10-weighted-mean/problem 5 | # challenge id: 21217 6 | # 7 | 8 | n = int(input()) 9 | X = list(map(int, input().split())) 10 | W = list(map(int, input().split())) 11 | 12 | m = sum(x * w for x, w in zip(X, W)) / sum(W) 13 | print("{:.1f}".format(m)) 14 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-arrays.cpp: -------------------------------------------------------------------------------- 1 | // Day 7: Arrays 2 | // Getting started with Arrays. 3 | // 4 | // https://www.hackerrank.com/challenges/30-arrays/problem 5 | // 6 | 7 | #include 8 | 9 | using namespace std; 10 | 11 | 12 | int main() 13 | { 14 | int n; 15 | cin >> n; 16 | vector arr(n); 17 | for(int arr_i = 0;arr_i < n;arr_i++) 18 | { 19 | cin >> arr[arr_i]; 20 | } 21 | 22 | for(int arr_i = n;arr_i > 0;) 23 | { 24 | cout << arr[--arr_i] << " "; 25 | } 26 | cout << endl; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-arrays.py: -------------------------------------------------------------------------------- 1 | # Day 7: Arrays 2 | # Getting started with Arrays. 3 | # 4 | # https://www.hackerrank.com/challenges/30-arrays/problem 5 | # 6 | 7 | input() 8 | print(" ".join(map(str, reversed(list(map(int, input().split())))))) 9 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-binary-numbers.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 30 Days of Code > Day 10: Binary Numbers 2 | # Find the maximum number of consecutive 1's in the base-2 representation of a base-10 number. 3 | # 4 | # https://www.hackerrank.com/challenges/30-binary-numbers/problem 5 | # 6 | 7 | n = int(input()) 8 | 9 | nb = 0 10 | result = 0 11 | 12 | while n != 0: 13 | n, r = divmod(n, 2) 14 | if r == 1: 15 | nb += 1 16 | if nb > result: 17 | result = nb 18 | else: 19 | nb = 0 20 | 21 | print(result) 22 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-conditional-statements.cpp: -------------------------------------------------------------------------------- 1 | // Day 3: Intro to Conditional Statements 2 | // Get started with conditional statements. 3 | // 4 | // https://www.hackerrank.com/challenges/30-conditional-statements/problem 5 | // 6 | 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n; 13 | cin >> n; 14 | 15 | if (n % 2 == 1 or (n >= 6 and n <= 20)) 16 | cout << "Weird" << endl; 17 | else 18 | cout << "Not Weird" << endl; 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-dictionaries-and-maps.py: -------------------------------------------------------------------------------- 1 | # Day 8: Dictionaries and Maps 2 | # Mapping Keys to Values using a Map or Dictionary. 3 | # 4 | # https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem 5 | # 6 | 7 | n = int(input()) 8 | d = {} 9 | 10 | for _ in range(n): 11 | k, v = input().split() 12 | d[k] = v 13 | 14 | for _ in range(n): 15 | k = input() 16 | if k in d: 17 | print("{}={}".format(k, d[k])) 18 | else: 19 | print("Not found") 20 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-exceptions-string-to-integer.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 30 Days of Code > Day 16: Exceptions - String to Integer 2 | # Can you determine if a string can be converted to an integer? 3 | # 4 | # https://www.hackerrank.com/challenges/30-exceptions-string-to-integer/problem 5 | # 6 | 7 | S = input().strip() 8 | 9 | try: 10 | print(int(S)) 11 | except ValueError: 12 | print("Bad String") 13 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-hello-world.py: -------------------------------------------------------------------------------- 1 | # Day 0: Hello, World. 2 | # Tutorials > 30 Days of Code 3 | # Practice reading from stdin and printing to stdout. 4 | # 5 | # https://www.hackerrank.com/challenges/30-hello-world/problem 6 | # 7 | 8 | # Read a full line of input from stdin and save it to our dynamically typed variable, input_string. 9 | input_string = input() 10 | 11 | # Print a string literal saying "Hello, World." to stdout. 12 | print('Hello, World.') 13 | 14 | # TODO: Write a line of code here that prints the contents of input_string to stdout. 15 | print(input_string) 16 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-loops.py: -------------------------------------------------------------------------------- 1 | # Day 5: Loops 2 | # Let's talk about loops. 3 | # 4 | # https://www.hackerrank.com/challenges/30-loops/problem 5 | # 6 | 7 | n = int(input()) 8 | for i in range(1, 11): 9 | print("{} x {} = {}".format(n, i, n * i)) 10 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-operators.py: -------------------------------------------------------------------------------- 1 | # Day 2: Operators 2 | # Start using arithmetic operators. 3 | # 4 | # https://www.hackerrank.com/challenges/30-operators/problem 5 | # 6 | 7 | #!/bin/python3 8 | 9 | import sys 10 | 11 | if __name__ == "__main__": 12 | meal_cost = float(input().strip()) 13 | tip_percent = int(input().strip()) 14 | tax_percent = int(input().strip()) 15 | 16 | cost = meal_cost * (1 + tip_percent / 100 + tax_percent / 100) 17 | 18 | print("The total meal cost is {:.0f} dollars.".format(cost)) 19 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-recursion.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 30 Days of Code > Day 9: Recursion 2 | # Use recursion to compute the factorial of number. 3 | # 4 | # https://www.hackerrank.com/challenges/30-recursion/problem 5 | # 6 | 7 | def factorial(n): 8 | if n < 2: 9 | return 1 10 | return n * factorial(n - 1) 11 | 12 | if __name__ == "__main__": 13 | n = int(input().strip()) 14 | result = factorial(n) 15 | print(result) 16 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-regex-patterns.py: -------------------------------------------------------------------------------- 1 | # Tutorials > 30 Days of Code > Day 28: RegEx, Patterns, and Intro to Databases 2 | # Review Pattern documentation and start using Regular Expressions 3 | # 4 | # https://www.hackerrank.com/challenges/30-regex-patterns/problem 5 | # 6 | 7 | # où sont les regex ?... 8 | 9 | gmail = {} 10 | 11 | for _ in range(int(input())): 12 | firstName, emailID = input().split() 13 | if emailID.endswith("@gmail.com"): 14 | gmail[emailID] = firstName 15 | 16 | for i in sorted(gmail.values()): 17 | print(i) 18 | -------------------------------------------------------------------------------- /tutorials/30-days-of-code/30-review-loop.py: -------------------------------------------------------------------------------- 1 | # Day 6: Let's Review 2 | # Characters and Strings 3 | # 4 | # https://www.hackerrank.com/challenges/30-review-loop/problem 5 | # 6 | 7 | for _ in range(int(input())): 8 | s = input() 9 | # pas tout à fait le but du challenge, mais Python est élégant! 10 | print(s[::2], s[1::2]) 11 | -------------------------------------------------------------------------------- /tutorials/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(30-days-of-code) 2 | add_subdirectory(cracking-the-coding-interview) 3 | add_subdirectory(10-days-of-statistics) 4 | add_subdirectory(10-days-of-javascript) -------------------------------------------------------------------------------- /tutorials/cracking-the-coding-interview/ctci-array-left-rotation.py: -------------------------------------------------------------------------------- 1 | # Arrays: Left Rotation 2 | # Given an array and a number, d, perform d left rotations on the array. 3 | # 4 | # https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem 5 | # 6 | 7 | 8 | def array_left_rotation(a, n, k): 9 | k = k % n 10 | return a[k:] + a[:k] 11 | 12 | 13 | n, k = map(int, input().split()) 14 | a = list(map(int, input().split())) 15 | answer = array_left_rotation(a, n, k) 16 | print(*answer, sep=' ') 17 | -------------------------------------------------------------------------------- /tutorials/cracking-the-coding-interview/ctci-fibonacci-numbers.cpp: -------------------------------------------------------------------------------- 1 | // Recursion: Fibonacci Numbers 2 | // Compute the $n^{th}$ Fibonacci number. 3 | // 4 | // https://www.hackerrank.com/challenges/ctci-fibonacci-numbers/problem 5 | // 6 | 7 | #include 8 | 9 | using namespace std; 10 | 11 | int fibonacci(int n) { 12 | 13 | // Complete the function. 14 | if (n < 2) return n; 15 | 16 | return fibonacci(n - 1) + fibonacci(n - 2); 17 | } 18 | 19 | int main() { 20 | int n; 21 | cin >> n; 22 | cout << fibonacci(n); 23 | return 0; 24 | } 25 | --------------------------------------------------------------------------------