├── .gitignore ├── 3kyu ├── (3 kyu) Base64 Encoding │ ├── (3 kyu) Base64 Encoding.js │ └── (3 kyu) Base64 Encoding.md └── (3 kyu) The soul of wit - reverse an array │ ├── (3 kyu) The soul of wit - reverse an array.js │ ├── (3 kyu) The soul of wit - reverse an array.md │ └── (3 kyu) The soul of wit - reverse an array.ts ├── 4kyu ├── (4 kyu) Decode the Morse code, advanced │ ├── (4 kyu) Decode the Morse code, advanced.js │ ├── (4 kyu) Decode the Morse code, advanced.md │ └── (4 kyu) Decode the Morse code, advanced.ts ├── (4 kyu) Human readable duration format │ ├── (4 kyu) Human readable duration format.js │ └── (4 kyu) Human readable duration format.md ├── (4 kyu) IP Validation │ ├── (4 kyu) IP Validation.js │ └── (4 kyu) IP Validation.md ├── (4 kyu) Range Extraction │ ├── (4 kyu) Range Extraction.js │ └── (4 kyu) Range Extraction.md ├── (4 kyu) Reverse it, quickly │ ├── (4 kyu) Reverse it, quickly.js │ └── (4 kyu) Reverse it, quickly.md ├── (4 kyu) Snail │ ├── (4 kyu) Snail.js │ └── (4 kyu) Snail.md ├── (4 kyu) Strip Comments │ ├── (4 kyu) Strip Comments.js │ ├── (4 kyu) Strip Comments.md │ └── (4 kyu) Strip Comments.py └── (4 kyu) Sum Strings as Numbers │ ├── (4 kyu) Sum Strings as Numbers.js │ └── (4 kyu) Sum Strings as Numbers.md ├── 5kyu ├── (5 kyu) Calculating with Functions │ ├── (5 kyu) Calculating with Functions.js │ └── (5 kyu) Calculating with Functions.md ├── (5 kyu) Count IP Addresses │ ├── (5 kyu) Count IP Addresses.js │ ├── (5 kyu) Count IP Addresses.md │ └── (5 kyu) Count IP Addresses.py ├── (5 kyu) Fibonacci Generator │ ├── (5 kyu) Fibonacci Generator.js │ └── (5 kyu) Fibonacci Generator.md ├── (5 kyu) Human Readable Time │ ├── (5 kyu) Human Readable Time.js │ ├── (5 kyu) Human Readable Time.md │ ├── (5 kyu) Human Readable Time.py │ └── (5 kyu) Human Readable Time.ts ├── (5 kyu) Memoized Fibonacci │ ├── (5 kyu) Memoized Fibonacci.js │ ├── (5 kyu) Memoized Fibonacci.md │ └── (5 kyu) Memoized Fibonacci.py ├── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine │ ├── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.cpp │ ├── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.js │ ├── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.md │ ├── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.py │ └── (5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.ts └── (5 kyu) RGB To Hex Conversion │ ├── (5 kyu) RGB To Hex Conversion.cpp │ ├── (5 kyu) RGB To Hex Conversion.js │ ├── (5 kyu) RGB To Hex Conversion.md │ ├── (5 kyu) RGB To Hex Conversion.py │ └── (5 kyu) RGB To Hex Conversion.rs ├── 6kyu ├── (6 kyu) CamelCase Method │ ├── (6 kyu) CamelCase Method.js │ ├── (6 kyu) CamelCase Method.md │ ├── (6 kyu) CamelCase Method.py │ ├── (6 kyu) CamelCase Method.rs │ └── (6 kyu) CamelCase Method.ts ├── (6 kyu) Count the smiley faces │ ├── (6 kyu) Count the smiley faces.js │ └── (6 kyu) Count the smiley faces.md ├── (6 kyu) Decode the Morse code │ ├── (6 kyu) Decode the Morse code.cpp │ ├── (6 kyu) Decode the Morse code.js │ ├── (6 kyu) Decode the Morse code.md │ ├── (6 kyu) Decode the Morse code.py │ ├── (6 kyu) Decode the Morse code.rs │ └── (6 kyu) Decode the Morse code.ts ├── (6 kyu) Easy Balance Checking │ ├── (6 kyu) Easy Balance Checking.js │ ├── (6 kyu) Easy Balance Checking.md │ ├── (6 kyu) Easy Balance Checking.py │ ├── (6 kyu) Easy Balance Checking.rs │ └── (6 kyu) Easy Balance Checking.ts ├── (6 kyu) Fibonacci Generator Function │ ├── (6 kyu) Fibonacci Generator Function.js │ └── (6 kyu) Fibonacci Generator Function.md ├── (6 kyu) Find the odd int │ ├── (6 kyu) Find the odd int.cpp │ ├── (6 kyu) Find the odd int.js │ ├── (6 kyu) Find the odd int.md │ ├── (6 kyu) Find the odd int.py │ └── (6 kyu) Find the odd int.ts ├── (6 kyu) Follow that Spy │ ├── (6 kyu) Follow that Spy.js │ └── (6 kyu) Follow that Spy.md ├── (6 kyu) Hard Time Bomb │ ├── (6 kyu) Hard Time Bomb.js │ └── (6 kyu) Hard Time Bomb.md ├── (6 kyu) Help the bookseller │ ├── (6 kyu) Help the bookseller.cpp │ ├── (6 kyu) Help the bookseller.js │ ├── (6 kyu) Help the bookseller.md │ ├── (6 kyu) Help the bookseller.py │ ├── (6 kyu) Help the bookseller.rs │ └── (6 kyu) Help the bookseller.ts ├── (6 kyu) IQ Test │ ├── (6 kyu) IQ Test.js │ ├── (6 kyu) IQ Test.md │ ├── (6 kyu) IQ Test.py │ └── (6 kyu) IQ Test.ts ├── (6 kyu) Multiples of 3 or 5 │ ├── (6 kyu) Multiples of 3 or 5.cpp │ ├── (6 kyu) Multiples of 3 or 5.js │ ├── (6 kyu) Multiples of 3 or 5.md │ ├── (6 kyu) Multiples of 3 or 5.py │ ├── (6 kyu) Multiples of 3 or 5.rs │ └── (6 kyu) Multiples of 3 or 5.ts ├── (6 kyu) Playing with digits │ ├── (6 kyu) Playing with digits.cpp │ ├── (6 kyu) Playing with digits.js │ ├── (6 kyu) Playing with digits.md │ ├── (6 kyu) Playing with digits.py │ ├── (6 kyu) Playing with digits.rs │ └── (6 kyu) Playing with digits.ts ├── (6 kyu) Playing with passphrases │ ├── (6 kyu) Playing with passphrases.cpp │ ├── (6 kyu) Playing with passphrases.js │ ├── (6 kyu) Playing with passphrases.md │ ├── (6 kyu) Playing with passphrases.py │ ├── (6 kyu) Playing with passphrases.rs │ └── (6 kyu) Playing with passphrases.ts ├── (6 kyu) Reverse or rotate │ ├── (6 kyu) Reverse or rotate.cpp │ ├── (6 kyu) Reverse or rotate.js │ ├── (6 kyu) Reverse or rotate.md │ ├── (6 kyu) Reverse or rotate.py │ ├── (6 kyu) Reverse or rotate.rs │ └── (6 kyu) Reverse or rotate.ts ├── (6 kyu) Salesman's Travel │ ├── (6 kyu) Salesman's Travel.cpp │ ├── (6 kyu) Salesman's Travel.js │ ├── (6 kyu) Salesman's Travel.md │ ├── (6 kyu) Salesman's Travel.py │ ├── (6 kyu) Salesman's Travel.rs │ └── (6 kyu) Salesman's Travel.ts └── (6 kyu) Square Digits Sequence │ ├── (6 kyu) Square Digits Sequence.js │ ├── (6 kyu) Square Digits Sequence.md │ ├── (6 kyu) Square Digits Sequence.py │ ├── (6 kyu) Square Digits Sequence.rs │ └── (6 kyu) Square Digits Sequence.ts ├── 7kyu ├── (7 kyu) All Inclusive │ ├── (7 kyu) All Inclusive.js │ └── (7 kyu) All Inclusive.md ├── (7 kyu) Build a square │ ├── (7 kyu) Build a square.cpp │ ├── (7 kyu) Build a square.cs │ ├── (7 kyu) Build a square.java │ ├── (7 kyu) Build a square.js │ ├── (7 kyu) Build a square.md │ ├── (7 kyu) Build a square.py │ ├── (7 kyu) Build a square.rs │ └── (7 kyu) Build a square.ts ├── (7 kyu) Canvas Fun 1 - Draw Lines │ ├── (7 kyu) Canvas Fun 1 - Draw Lines.js │ └── (7 kyu) Canvas Fun 1 - Draw Lines.md ├── (7 kyu) Complementary DNA │ ├── (7 kyu) Complementary DNA.cpp │ ├── (7 kyu) Complementary DNA.go │ ├── (7 kyu) Complementary DNA.java │ ├── (7 kyu) Complementary DNA.js │ ├── (7 kyu) Complementary DNA.md │ ├── (7 kyu) Complementary DNA.py │ ├── (7 kyu) Complementary DNA.rs │ └── (7 kyu) Complementary DNA.ts ├── (7 kyu) Even numbers in an array │ ├── (7 kyu) Even numbers in an array.cpp │ ├── (7 kyu) Even numbers in an array.js │ ├── (7 kyu) Even numbers in an array.md │ ├── (7 kyu) Even numbers in an array.py │ ├── (7 kyu) Even numbers in an array.rs │ └── (7 kyu) Even numbers in an array.ts ├── (7 kyu) Exes and Ohs │ ├── 7 kyu Exes and Ohs.cpp │ ├── 7 kyu Exes and Ohs.js │ ├── 7 kyu Exes and Ohs.md │ ├── 7 kyu Exes and Ohs.py │ ├── 7 kyu Exes and Ohs.rs │ └── 7 kyu Exes and Ohs.ts ├── (7 kyu) Form The Largest │ ├── (7 kyu) Form The Largest.cpp │ ├── (7 kyu) Form The Largest.cs │ ├── (7 kyu) Form The Largest.js │ ├── (7 kyu) Form The Largest.md │ ├── (7 kyu) Form The Largest.py │ ├── (7 kyu) Form The Largest.rs │ └── (7 kyu) Form The Largest.ts ├── (7 kyu) Form The Minimum │ ├── (7 kyu) Form The Minimum.cpp │ ├── (7 kyu) Form The Minimum.cs │ ├── (7 kyu) Form The Minimum.java │ ├── (7 kyu) Form The Minimum.js │ ├── (7 kyu) Form The Minimum.md │ ├── (7 kyu) Form The Minimum.py │ ├── (7 kyu) Form The Minimum.rs │ └── (7 kyu) Form The Minimum.ts ├── (7 kyu) Frequency sequence │ ├── (7 kyu) Frequency sequence.go │ ├── (7 kyu) Frequency sequence.js │ ├── (7 kyu) Frequency sequence.md │ ├── (7 kyu) Frequency sequence.py │ ├── (7 kyu) Frequency sequence.rs │ └── (7 kyu) Frequency sequence.ts ├── (7 kyu) Get the Middle Character │ ├── (7 kyu) Get the Middle Character.cpp │ ├── (7 kyu) Get the Middle Character.cs │ ├── (7 kyu) Get the Middle Character.go │ ├── (7 kyu) Get the Middle Character.java │ ├── (7 kyu) Get the Middle Character.js │ ├── (7 kyu) Get the Middle Character.md │ ├── (7 kyu) Get the Middle Character.py │ ├── (7 kyu) Get the Middle Character.rs │ └── (7 kyu) Get the Middle Character.ts ├── (7 kyu) Highest and Lowest │ ├── (7 kyu) Highest and Lowest.cpp │ ├── (7 kyu) Highest and Lowest.cs │ ├── (7 kyu) Highest and Lowest.go │ ├── (7 kyu) Highest and Lowest.java │ ├── (7 kyu) Highest and Lowest.js │ ├── (7 kyu) Highest and Lowest.md │ ├── (7 kyu) Highest and Lowest.py │ ├── (7 kyu) Highest and Lowest.rs │ └── (7 kyu) Highest and Lowest.ts ├── (7 kyu) Jaden Casing Strings │ ├── (7 kyu) Jaden Casing Strings.cpp │ ├── (7 kyu) Jaden Casing Strings.cs │ ├── (7 kyu) Jaden Casing Strings.go │ ├── (7 kyu) Jaden Casing Strings.java │ ├── (7 kyu) Jaden Casing Strings.js │ ├── (7 kyu) Jaden Casing Strings.md │ ├── (7 kyu) Jaden Casing Strings.py │ ├── (7 kyu) Jaden Casing Strings.rs │ └── (7 kyu) Jaden Casing Strings.ts ├── (7 kyu) Last │ ├── (7 kyu) Last.go │ ├── (7 kyu) Last.java │ ├── (7 kyu) Last.js │ ├── (7 kyu) Last.md │ ├── (7 kyu) Last.py │ ├── (7 kyu) Last.rs │ └── (7 kyu) Last.ts ├── (7 kyu) Mumbling │ ├── (7 kyu) Mumbling.cpp │ ├── (7 kyu) Mumbling.cs │ ├── (7 kyu) Mumbling.go │ ├── (7 kyu) Mumbling.java │ ├── (7 kyu) Mumbling.js │ ├── (7 kyu) Mumbling.md │ ├── (7 kyu) Mumbling.py │ ├── (7 kyu) Mumbling.rs │ └── (7 kyu) Mumbling.ts ├── (7 kyu) Number of People in the Bus │ ├── (7 kyu) Number of People in the Bus.cpp │ ├── (7 kyu) Number of People in the Bus.cs │ ├── (7 kyu) Number of People in the Bus.go │ ├── (7 kyu) Number of People in the Bus.java │ ├── (7 kyu) Number of People in the Bus.js │ ├── (7 kyu) Number of People in the Bus.md │ ├── (7 kyu) Number of People in the Bus.py │ ├── (7 kyu) Number of People in the Bus.rs │ └── (7 kyu) Number of People in the Bus.ts ├── (7 kyu) Parts of a list │ ├── (7 kyu) Parts of a list.js │ └── (7 kyu) Parts of a list.md ├── (7 kyu) Recursion 2 - Fibonacci │ ├── (7 kyu) Recursion 2 - Fibonacci.js │ ├── (7 kyu) Recursion 2 - Fibonacci.md │ ├── (7 kyu) Recursion 2 - Fibonacci.py │ ├── (7 kyu) Recursion 2 - Fibonacci.rs │ └── (7 kyu) Recursion 2 - Fibonacci.ts ├── (7 kyu) Remove duplicate words │ ├── (7 kyu) Remove duplicate words.cpp │ ├── (7 kyu) Remove duplicate words.cs │ ├── (7 kyu) Remove duplicate words.go │ ├── (7 kyu) Remove duplicate words.java │ ├── (7 kyu) Remove duplicate words.js │ ├── (7 kyu) Remove duplicate words.md │ ├── (7 kyu) Remove duplicate words.py │ ├── (7 kyu) Remove duplicate words.rs │ └── (7 kyu) Remove duplicate words.ts ├── (7 kyu) Reverse words │ ├── (7 kyu) Reverse words.cpp │ ├── (7 kyu) Reverse words.cs │ ├── (7 kyu) Reverse words.go │ ├── (7 kyu) Reverse words.java │ ├── (7 kyu) Reverse words.js │ ├── (7 kyu) Reverse words.md │ ├── (7 kyu) Reverse words.py │ ├── (7 kyu) Reverse words.rs │ └── (7 kyu) Reverse words.ts ├── (7 kyu) Shortest Word │ ├── (7 kyu) Shortest Word.cpp │ ├── (7 kyu) Shortest Word.cs │ ├── (7 kyu) Shortest Word.go │ ├── (7 kyu) Shortest Word.java │ ├── (7 kyu) Shortest Word.js │ ├── (7 kyu) Shortest Word.md │ ├── (7 kyu) Shortest Word.py │ ├── (7 kyu) Shortest Word.rs │ └── (7 kyu) Shortest Word.ts ├── (7 kyu) Simple beads count │ ├── (7 kyu) Simple beads count.cpp │ ├── (7 kyu) Simple beads count.cs │ ├── (7 kyu) Simple beads count.go │ ├── (7 kyu) Simple beads count.java │ ├── (7 kyu) Simple beads count.js │ ├── (7 kyu) Simple beads count.md │ ├── (7 kyu) Simple beads count.py │ ├── (7 kyu) Simple beads count.rs │ └── (7 kyu) Simple beads count.ts ├── (7 kyu) Sort Numbers │ ├── (7 kyu) Sort Numbers.cs │ ├── (7 kyu) Sort Numbers.go │ ├── (7 kyu) Sort Numbers.java │ ├── (7 kyu) Sort Numbers.js │ ├── (7 kyu) Sort Numbers.md │ ├── (7 kyu) Sort Numbers.py │ ├── (7 kyu) Sort Numbers.rs │ └── (7 kyu) Sort Numbers.ts ├── (7 kyu) Speed Control │ ├── (7 kyu) Speed Control.js │ └── (7 kyu) Speed Control.md ├── (7 kyu) String ends with │ ├── (7 kyu) String ends with.cpp │ ├── (7 kyu) String ends with.cs │ ├── (7 kyu) String ends with.go │ ├── (7 kyu) String ends with.java │ ├── (7 kyu) String ends with.js │ ├── (7 kyu) String ends with.md │ ├── (7 kyu) String ends with.py │ ├── (7 kyu) String ends with.rs │ └── (7 kyu) String ends with.ts ├── (7 kyu) Sum of odd numbers │ ├── (7 kyu) Sum of odd numbers.js │ └── (7 kyu) Sum of odd numbers.md ├── (7 kyu) Thinkful - String Drills. Repeater │ ├── (7 kyu) Thinkful - String Drills. Repeater.cpp │ ├── (7 kyu) Thinkful - String Drills. Repeater.cs │ ├── (7 kyu) Thinkful - String Drills. Repeater.go │ ├── (7 kyu) Thinkful - String Drills. Repeater.java │ ├── (7 kyu) Thinkful - String Drills. Repeater.js │ ├── (7 kyu) Thinkful - String Drills. Repeater.md │ ├── (7 kyu) Thinkful - String Drills. Repeater.py │ ├── (7 kyu) Thinkful - String Drills. Repeater.rs │ └── (7 kyu) Thinkful - String Drills. Repeater.ts └── (7 kyu) Two to One │ ├── (7 kyu) Two to One.cpp │ ├── (7 kyu) Two to One.cs │ ├── (7 kyu) Two to One.go │ ├── (7 kyu) Two to One.java │ ├── (7 kyu) Two to One.js │ ├── (7 kyu) Two to One.md │ ├── (7 kyu) Two to One.py │ ├── (7 kyu) Two to One.rs │ └── (7 kyu) Two to One.ts ├── 8kyu ├── (8 kyu) Abbreviate a Two Word Name │ ├── (8 kyu) Abbreviate a Two Word Name.cpp │ ├── (8 kyu) Abbreviate a Two Word Name.cs │ ├── (8 kyu) Abbreviate a Two Word Name.dart │ ├── (8 kyu) Abbreviate a Two Word Name.go │ ├── (8 kyu) Abbreviate a Two Word Name.java │ ├── (8 kyu) Abbreviate a Two Word Name.js │ ├── (8 kyu) Abbreviate a Two Word Name.md │ ├── (8 kyu) Abbreviate a Two Word Name.py │ ├── (8 kyu) Abbreviate a Two Word Name.rs │ └── (8 kyu) Abbreviate a Two Word Name.ts ├── (8 kyu) Area or Perimeter │ ├── (8 kyu) Area or Perimeter.dart │ ├── (8 kyu) Area or Perimeter.java │ ├── (8 kyu) Area or Perimeter.js │ ├── (8 kyu) Area or Perimeter.md │ ├── (8 kyu) Area or Perimeter.py │ └── (8 kyu) Area or Perimeter.ts ├── (8 kyu) Basic subclasses - Adam and Eve │ ├── (8 kyu) Basic subclasses - Adam and Eve.cs │ ├── (8 kyu) Basic subclasses - Adam and Eve.java │ ├── (8 kyu) Basic subclasses - Adam and Eve.js │ ├── (8 kyu) Basic subclasses - Adam and Eve.md │ ├── (8 kyu) Basic subclasses - Adam and Eve.py │ └── (8 kyu) Basic subclasses - Adam and Eve.ts ├── (8 kyu) Beginner - Lost Without a Map │ ├── (8 kyu) Beginner - Lost Without a Map.go │ ├── (8 kyu) Beginner - Lost Without a Map.js │ ├── (8 kyu) Beginner - Lost Without a Map.md │ └── (8 kyu) Beginner - Lost Without a Map.ts ├── (8 kyu) Bin to Decimal │ ├── (8 kyu) Bin to Decimal.js │ └── (8 kyu) Bin to Decimal.md ├── (8 kyu) Century From Year │ ├── (8 kyu) Century From Year.cpp │ ├── (8 kyu) Century From Year.cs │ ├── (8 kyu) Century From Year.go │ ├── (8 kyu) Century From Year.java │ ├── (8 kyu) Century From Year.js │ ├── (8 kyu) Century From Year.md │ ├── (8 kyu) Century From Year.py │ ├── (8 kyu) Century From Year.rs │ └── (8 kyu) Century From Year.ts ├── (8 kyu) Convert a Boolean to a String │ ├── (8 kyu) Convert a Boolean to a String.js │ └── (8 kyu) Convert a Boolean to a String.md ├── (8 kyu) Convert a String to a Number! │ ├── (8 kyu) Convert a String to a Number!.js │ └── (8 kyu) Convert a String to a Number!.md ├── (8 kyu) Convert a string to an array │ ├── (8 kuy) Convert a string to an array.js │ └── (8 kuy) Convert a string to an array.md ├── (8 kyu) Convert boolean values to strings Yes or No │ ├── (8 kyu) Convert boolean values to strings Yes or No.js │ └── (8 kyu) Convert boolean values to strings Yes or No.md ├── (8 kyu) Convert number to reversed array of digits │ ├── (8 kyu) Convert number to reversed array of digits.js │ ├── (8 kyu) Convert number to reversed array of digits.md │ └── (8 kyu) Convert number to reversed array of digits.ts ├── (8 kyu) Count Odd Numbers below n │ ├── (8 kyu) Count Odd Numbers below n.js │ └── (8 kyu) Count Odd Numbers below n.md ├── (8 kyu) Count of positives - sum of negatives │ ├── (8 kyu) Count of positives - sum of negatives.cpp │ ├── (8 kyu) Count of positives - sum of negatives.cs │ ├── (8 kyu) Count of positives - sum of negatives.go │ ├── (8 kyu) Count of positives - sum of negatives.java │ ├── (8 kyu) Count of positives - sum of negatives.js │ ├── (8 kyu) Count of positives - sum of negatives.md │ ├── (8 kyu) Count of positives - sum of negatives.py │ ├── (8 kyu) Count of positives - sum of negatives.rs │ └── (8 kyu) Count of positives - sum of negatives.ts ├── (8 kyu) Counting sheep │ ├── (8 kyu) Counting sheep.cpp │ ├── (8 kyu) Counting sheep.cs │ ├── (8 kyu) Counting sheep.go │ ├── (8 kyu) Counting sheep.java │ ├── (8 kyu) Counting sheep.js │ ├── (8 kyu) Counting sheep.md │ ├── (8 kyu) Counting sheep.py │ ├── (8 kyu) Counting sheep.rs │ └── (8 kyu) Counting sheep.ts ├── (8 kyu) DNA to RNA Conversion │ ├── (8 kyu) DNA to RNA Conversion.cpp │ ├── (8 kyu) DNA to RNA Conversion.cs │ ├── (8 kyu) DNA to RNA Conversion.go │ ├── (8 kyu) DNA to RNA Conversion.java │ ├── (8 kyu) DNA to RNA Conversion.js │ ├── (8 kyu) DNA to RNA Conversion.md │ ├── (8 kyu) DNA to RNA Conversion.py │ ├── (8 kyu) DNA to RNA Conversion.rs │ └── (8 kyu) DNA to RNA Conversion.ts ├── (8 kyu) Difference of Volumes of Cuboids │ ├── (8 kyu) Difference of Volumes of Cuboids.js │ └── (8 kyu) Difference of Volumes of Cuboids.md ├── (8 kyu) Even or Odd │ ├── (8 kyu) Even or Odd.cpp │ ├── (8 kyu) Even or Odd.cs │ ├── (8 kyu) Even or Odd.go │ ├── (8 kyu) Even or Odd.java │ ├── (8 kyu) Even or Odd.js │ ├── (8 kyu) Even or Odd.md │ ├── (8 kyu) Even or Odd.py │ ├── (8 kyu) Even or Odd.rs │ └── (8 kyu) Even or Odd.ts ├── (8 kyu) Fake Binary │ ├── (8 kyu) Fake Binary.js │ └── (8 kyu) Fake Binary.md ├── (8 kyu) Find the smallest integer in the array │ ├── (8 kyu) Find the smallest integer in the array.cpp │ ├── (8 kyu) Find the smallest integer in the array.cs │ ├── (8 kyu) Find the smallest integer in the array.go │ ├── (8 kyu) Find the smallest integer in the array.java │ ├── (8 kyu) Find the smallest integer in the array.js │ ├── (8 kyu) Find the smallest integer in the array.md │ ├── (8 kyu) Find the smallest integer in the array.py │ ├── (8 kyu) Find the smallest integer in the array.rs │ └── (8 kyu) Find the smallest integer in the array.ts ├── (8 kyu) Function 3 - multiplying two numbers │ ├── (8 kyu) Function 3 - multiplying two numbers.cpp │ ├── (8 kyu) Function 3 - multiplying two numbers.go │ ├── (8 kyu) Function 3 - multiplying two numbers.java │ ├── (8 kyu) Function 3 - multiplying two numbers.js │ ├── (8 kyu) Function 3 - multiplying two numbers.md │ └── (8 kyu) Function 3 - multiplying two numbers.ts ├── (8 kyu) How good are you really │ ├── (8 kyu) How good are you really.js │ ├── (8 kyu) How good are you really.md │ └── (8 kyu) How good are you really.ts ├── (8 kyu) I love you, a little, a lot, passionately, not at all │ ├── (8 kyu) I love you, a little, a lot, passionately, not at all.js │ └── (8 kyu) I love you, a little, a lot, passionately, not at all.md ├── (8 kyu) If you can't sleep, just count sheep │ ├── (8 kyu) If you can't sleep, just count sheep.cpp │ ├── (8 kyu) If you can't sleep, just count sheep.cs │ ├── (8 kyu) If you can't sleep, just count sheep.go │ ├── (8 kyu) If you can't sleep, just count sheep.java │ ├── (8 kyu) If you can't sleep, just count sheep.js │ ├── (8 kyu) If you can't sleep, just count sheep.md │ ├── (8 kyu) If you can't sleep, just count sheep.py │ ├── (8 kyu) If you can't sleep, just count sheep.rs │ └── (8 kyu) If you can't sleep, just count sheep.ts ├── (8 kyu) Is n divisible by x and y │ ├── (8 kyu) Is n divisible by x and y.go │ ├── (8 kyu) Is n divisible by x and y.java │ ├── (8 kyu) Is n divisible by x and y.js │ ├── (8 kyu) Is n divisible by x and y.md │ ├── (8 kyu) Is n divisible by x and y.rs │ └── (8 kyu) Is n divisible by x and y.ts ├── (8 kyu) Is the string uppercase │ ├── (8 kyu) Is the string uppercase.js │ └── (8 kyu) Is the string uppercase.md ├── (8 kyu) Jenny's secret message │ ├── (8 kyu) Jenny's secret message.cpp │ ├── (8 kyu) Jenny's secret message.cs │ ├── (8 kyu) Jenny's secret message.go │ ├── (8 kyu) Jenny's secret message.java │ ├── (8 kyu) Jenny's secret message.js │ ├── (8 kyu) Jenny's secret message.md │ ├── (8 kyu) Jenny's secret message.py │ ├── (8 kyu) Jenny's secret message.rs │ └── (8 kyu) Jenny's secret message.ts ├── (8 kyu) MakeUpperCase │ ├── (8 kyu) MakeUpperCase.js │ ├── (8 kyu) MakeUpperCase.md │ └── (8 kyu) MakeUpperCase.ts ├── (8 kyu) Multiply │ ├── (8 kyu) Multiply.cpp │ ├── (8 kyu) Multiply.cs │ ├── (8 kyu) Multiply.dart │ ├── (8 kyu) Multiply.go │ ├── (8 kyu) Multiply.java │ ├── (8 kyu) Multiply.js │ ├── (8 kyu) Multiply.md │ ├── (8 kyu) Multiply.py │ ├── (8 kyu) Multiply.rs │ └── (8 kyu) Multiply.ts ├── (8 kyu) Name Shuffler │ ├── (8 kyu) Name Shuffler.js │ └── (8 kyu) Name Shuffler.md ├── (8 kyu) Opposite number │ ├── (8 kyu) Opposite number.cpp │ ├── (8 kyu) Opposite number.cs │ ├── (8 kyu) Opposite number.go │ ├── (8 kyu) Opposite number.java │ ├── (8 kyu) Opposite number.js │ ├── (8 kyu) Opposite number.md │ ├── (8 kyu) Opposite number.py │ ├── (8 kyu) Opposite number.rs │ └── (8 kyu) Opposite number.ts ├── (8 kyu) Opposites Attract │ ├── (8 kyu) Opposites Attract.js │ ├── (8 kyu) Opposites Attract.md │ └── (8 kyu) Opposites Attract.ts ├── (8 kyu) Parse nice int from char problem │ ├── (8 kyu) Parse nice int from char problem.js │ └── (8 kyu) Parse nice int from char problem.md ├── (8 kyu) Plural │ ├── (8 kyu) Plural.js │ └── (8 kyu) Plural.md ├── (8 kyu) Powers of 2 │ ├── (8 kyu) Powers of 2.js │ └── (8 kyu) Powers of 2.md ├── (8 kyu) Remove First and Last Character │ ├── (8 kyu) Remove First and Last Character.js │ └── (8 kyu) Remove First and Last Character.md ├── (8 kyu) Remove String Spaces │ ├── (8 kyu) Remove String Spaces.cpp │ ├── (8 kyu) Remove String Spaces.cs │ ├── (8 kyu) Remove String Spaces.go │ ├── (8 kyu) Remove String Spaces.java │ ├── (8 kyu) Remove String Spaces.js │ ├── (8 kyu) Remove String Spaces.md │ ├── (8 kyu) Remove String Spaces.py │ ├── (8 kyu) Remove String Spaces.rs │ └── (8 kyu) Remove String Spaces.ts ├── (8 kyu) Return Negative │ ├── (8 kyu) Return Negative.cpp │ ├── (8 kyu) Return Negative.cs │ ├── (8 kyu) Return Negative.go │ ├── (8 kyu) Return Negative.java │ ├── (8 kyu) Return Negative.js │ ├── (8 kyu) Return Negative.md │ ├── (8 kyu) Return Negative.py │ ├── (8 kyu) Return Negative.rs │ └── (8 kyu) Return Negative.ts ├── (8 kyu) Returning Strings │ ├── (8 kyu) Returning Strings.js │ └── (8 kyu) Returning Strings.md ├── (8 kyu) Reversed Strings │ ├── (8 kyu) Reversed Strings.cpp │ ├── (8 kyu) Reversed Strings.cs │ ├── (8 kyu) Reversed Strings.go │ ├── (8 kyu) Reversed Strings.java │ ├── (8 kyu) Reversed Strings.js │ ├── (8 kyu) Reversed Strings.md │ ├── (8 kyu) Reversed Strings.py │ ├── (8 kyu) Reversed Strings.rs │ └── (8 kyu) Reversed Strings.ts ├── (8 kyu) Reversed Words │ ├── (8 kyu) Reversed Words.cpp │ ├── (8 kyu) Reversed Words.cs │ ├── (8 kyu) Reversed Words.go │ ├── (8 kyu) Reversed Words.java │ ├── (8 kyu) Reversed Words.js │ ├── (8 kyu) Reversed Words.md │ ├── (8 kyu) Reversed Words.py │ ├── (8 kyu) Reversed Words.rs │ └── (8 kyu) Reversed Words.ts ├── (8 kyu) Reversed sequence │ ├── (8 kyu) Reversed sequence.cpp │ ├── (8 kyu) Reversed sequence.cs │ ├── (8 kyu) Reversed sequence.go │ ├── (8 kyu) Reversed sequence.java │ ├── (8 kyu) Reversed sequence.js │ ├── (8 kyu) Reversed sequence.md │ ├── (8 kyu) Reversed sequence.py │ ├── (8 kyu) Reversed sequence.rs │ └── (8 kyu) Reversed sequence.ts ├── (8 kyu) Rock Paper Scissors │ ├── (8 kyu) Rock Paper Scissors.js │ └── (8 kyu) Rock Paper Scissors.md ├── (8 kyu) Sort and Star │ ├── (8 kyu) Sort and Star.cpp │ ├── (8 kyu) Sort and Star.cs │ ├── (8 kyu) Sort and Star.go │ ├── (8 kyu) Sort and Star.java │ ├── (8 kyu) Sort and Star.js │ ├── (8 kyu) Sort and Star.md │ ├── (8 kyu) Sort and Star.py │ ├── (8 kyu) Sort and Star.rs │ └── (8 kyu) Sort and Star.ts ├── (8 kyu) Square(n) Sum │ ├── (8 kyu) Square(n) Sum.cpp │ ├── (8 kyu) Square(n) Sum.cs │ ├── (8 kyu) Square(n) Sum.go │ ├── (8 kyu) Square(n) Sum.java │ ├── (8 kyu) Square(n) Sum.js │ ├── (8 kyu) Square(n) Sum.md │ ├── (8 kyu) Square(n) Sum.py │ ├── (8 kyu) Square(n) Sum.rs │ └── (8 kyu) Square(n) Sum.ts ├── (8 kyu) String cleaning │ ├── (8 kyu) String cleaning.js │ └── (8 kyu) String cleaning.md ├── (8 kyu) String repeat │ ├── (8 kyu) String repeat.cpp │ ├── (8 kyu) String repeat.cs │ ├── (8 kyu) String repeat.dart │ ├── (8 kyu) String repeat.go │ ├── (8 kyu) String repeat.java │ ├── (8 kyu) String repeat.js │ ├── (8 kyu) String repeat.md │ ├── (8 kyu) String repeat.py │ ├── (8 kyu) String repeat.rs │ └── (8 kyu) String repeat.ts ├── (8 kyu) Sum of positive │ ├── (8 kyu) Sum of positive.cpp │ ├── (8 kyu) Sum of positive.cs │ ├── (8 kyu) Sum of positive.dart │ ├── (8 kyu) Sum of positive.go │ ├── (8 kyu) Sum of positive.java │ ├── (8 kyu) Sum of positive.js │ ├── (8 kyu) Sum of positive.md │ ├── (8 kyu) Sum of positive.py │ ├── (8 kyu) Sum of positive.rs │ └── (8 kyu) Sum of positive.ts ├── (8 kyu) The Feast of Many Beasts │ ├── (8 kyu) The Feast of Many Beasts.cpp │ ├── (8 kyu) The Feast of Many Beasts.cs │ ├── (8 kyu) The Feast of Many Beasts.go │ ├── (8 kyu) The Feast of Many Beasts.java │ ├── (8 kyu) The Feast of Many Beasts.js │ ├── (8 kyu) The Feast of Many Beasts.md │ ├── (8 kyu) The Feast of Many Beasts.py │ ├── (8 kyu) The Feast of Many Beasts.rs │ └── (8 kyu) The Feast of Many Beasts.ts ├── (8 kyu) To square or not │ ├── (8 kyu) To square or not.cs │ ├── (8 kyu) To square or not.go │ ├── (8 kyu) To square or not.java │ ├── (8 kyu) To square or not.js │ ├── (8 kyu) To square or not.md │ ├── (8 kyu) To square or not.py │ ├── (8 kyu) To square or not.rs │ └── (8 kyu) To square or not.ts ├── (8 kyu) Total amount of points │ ├── (8 kyu) Total amount of points.cpp │ ├── (8 kyu) Total amount of points.cs │ ├── (8 kyu) Total amount of points.dart │ ├── (8 kyu) Total amount of points.go │ ├── (8 kyu) Total amount of points.java │ ├── (8 kyu) Total amount of points.js │ ├── (8 kyu) Total amount of points.md │ ├── (8 kyu) Total amount of points.py │ ├── (8 kyu) Total amount of points.rs │ └── (8 kyu) Total amount of points.ts ├── (8 kyu) Twice as old │ ├── (8 kyu) Twice as old.cpp │ ├── (8 kyu) Twice as old.cs │ ├── (8 kyu) Twice as old.go │ ├── (8 kyu) Twice as old.java │ ├── (8 kyu) Twice as old.js │ ├── (8 kyu) Twice as old.md │ ├── (8 kyu) Twice as old.py │ └── (8 kyu) Twice as old.ts ├── (8 kyu) Volume of a Cuboid │ ├── (8 kyu) Volume of a Cuboid.cpp │ ├── (8 kyu) Volume of a Cuboid.cs │ ├── (8 kyu) Volume of a Cuboid.dart │ ├── (8 kyu) Volume of a Cuboid.go │ ├── (8 kyu) Volume of a Cuboid.java │ ├── (8 kyu) Volume of a Cuboid.js │ ├── (8 kyu) Volume of a Cuboid.md │ ├── (8 kyu) Volume of a Cuboid.py │ ├── (8 kyu) Volume of a Cuboid.rs │ └── (8 kyu) Volume of a Cuboid.ts ├── (8 kyu) Well of Ideas - Easy Version │ ├── (8 kyu) Well of Ideas - Easy Version.cs │ ├── (8 kyu) Well of Ideas - Easy Version.dart │ ├── (8 kyu) Well of Ideas - Easy Version.go │ ├── (8 kyu) Well of Ideas - Easy Version.java │ ├── (8 kyu) Well of Ideas - Easy Version.js │ ├── (8 kyu) Well of Ideas - Easy Version.md │ ├── (8 kyu) Well of Ideas - Easy Version.py │ ├── (8 kyu) Well of Ideas - Easy Version.rs │ └── (8 kyu) Well of Ideas - Easy Version.ts ├── (8 kyu) What is between │ ├── (8 kyu) What is between.cpp │ ├── (8 kyu) What is between.cs │ ├── (8 kyu) What is between.dart │ ├── (8 kyu) What is between.go │ ├── (8 kyu) What is between.java │ ├── (8 kyu) What is between.js │ ├── (8 kyu) What is between.md │ ├── (8 kyu) What is between.py │ ├── (8 kyu) What is between.rs │ └── (8 kyu) What is between.ts ├── (8 kyu) You Cant Code Under Pressure 1 │ ├── (8 kyu) You Cant Code Under Pressure 1.cpp │ ├── (8 kyu) You Cant Code Under Pressure 1.cs │ ├── (8 kyu) You Cant Code Under Pressure 1.dart │ ├── (8 kyu) You Cant Code Under Pressure 1.go │ ├── (8 kyu) You Cant Code Under Pressure 1.java │ ├── (8 kyu) You Cant Code Under Pressure 1.js │ ├── (8 kyu) You Cant Code Under Pressure 1.md │ ├── (8 kyu) You Cant Code Under Pressure 1.py │ ├── (8 kyu) You Cant Code Under Pressure 1.rs │ └── (8 kyu) You Cant Code Under Pressure 1.ts └── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.cpp │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.cs │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.dart │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.go │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.java │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.js │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.md │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.py │ ├── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.rs │ └── (8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.ts ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | .venv 3 | .dccache 4 | -------------------------------------------------------------------------------- /3kyu/(3 kyu) Base64 Encoding/(3 kyu) Base64 Encoding.md: -------------------------------------------------------------------------------- 1 | # Base64 Encoding (3 kyu) 2 | 3 | https://www.codewars.com/kata/5270f22f862516c686000161 4 | 5 | Extend the String object (JS) or create a function (Python, C#) that converts the value of the String to and from Base64 using the ASCII (UTF-8 for C#) character set. 6 | 7 | Do not use built in functions. 8 | 9 | Usage: 10 | 11 | ``` 12 | // should return 'dGhpcyBpcyBhIHN0cmluZyEh' 13 | 'this is a string!!'.toBase64(); 14 | // should return 'this is a string!!' 15 | 'dGhpcyBpcyBhIHN0cmluZyEh'.fromBase64(); 16 | ``` 17 | 18 | You can learn more about Base64 encoding and decoding here. 19 | -------------------------------------------------------------------------------- /3kyu/(3 kyu) The soul of wit - reverse an array/(3 kyu) The soul of wit - reverse an array.js: -------------------------------------------------------------------------------- 1 | //reverse=a=>a.map(a.pop,[...a]) 2 | reverse = (a) => a.map(a.pop, [...a]); 3 | -------------------------------------------------------------------------------- /3kyu/(3 kyu) The soul of wit - reverse an array/(3 kyu) The soul of wit - reverse an array.md: -------------------------------------------------------------------------------- 1 | # The soul of wit: reverse an array (3 kyu) 2 | 3 | https://www.codewars.com/kata/the-soul-of-wit-reverse-an-array 4 | 5 | No time for stories. Reverse an array, return the result. Do whatever you want with the original array. Don't use Array.prototype.reverse. You have 30 bytes to spare. 6 | 7 | ``` 8 | Example: [1, 2, 3] → [3, 2, 1] 9 | ``` 10 | -------------------------------------------------------------------------------- /3kyu/(3 kyu) The soul of wit - reverse an array/(3 kyu) The soul of wit - reverse an array.ts: -------------------------------------------------------------------------------- 1 | export var reverse=(a:any)=>[...a].map(a.pop,a) 2 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Decode the Morse code, advanced/(4 kyu) Decode the Morse code, advanced.md: -------------------------------------------------------------------------------- 1 | # Decode the Morse code, advanced (4 kyu) 2 | 3 | https://www.codewars.com/kata/decode-the-morse-code-advanced 4 | 5 | In this kata you have to write a Morse code decoder for wired electrical 6 | telegraph. 7 | 8 | Electric telegraph is operated on a 2-wire line with a key that, when pressed, connects the wires together, which can be detected on a remote station. The Morse code encodes every character being transmitted as a sequence of "dots" (short presses on the key) and "dashes" (long presses on the key). 9 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) IP Validation/(4 kyu) IP Validation.js: -------------------------------------------------------------------------------- 1 | const isValidIP = (str) => { 2 | const ip = str.split`.`; 3 | 4 | if ( 5 | ip.length !== 4 || 6 | ip.filter( 7 | (x) => 8 | x > 255 || 9 | (!+x && x !== '0') || 10 | x.trim().length !== x.length || 11 | (x[0] === '0' && x !== '0'), 12 | ).length 13 | ) 14 | return false; 15 | 16 | return true; 17 | }; 18 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Range Extraction/(4 kyu) Range Extraction.js: -------------------------------------------------------------------------------- 1 | const solution = (list, i = 0, j = 1) => { 2 | let [curr, prev, arr] = [list[0], '', []]; 3 | 4 | while (j <= list.length) { 5 | if (list[j] - list[j - 1] !== 1 || j++ === list.length) { 6 | j > 1 && (prev = `${list[i]}-`); 7 | list[j - 1] - list[i] === 1 && (prev = `${list[i]},`); 8 | list[j - 1] === list[i] && (prev = ''); 9 | 10 | arr.push(`${prev}${list[j - 1]}`); 11 | prev = list[(i = j++)]; 12 | } 13 | } 14 | 15 | return arr.join`,`; 16 | }; 17 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Reverse it, quickly/(4 kyu) Reverse it, quickly.js: -------------------------------------------------------------------------------- 1 | weirdReverse = (a) => a.sort((_) => 1); 2 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Snail/(4 kyu) Snail.md: -------------------------------------------------------------------------------- 1 | # Snail Sort (4 kyu) 2 | 3 | https://www.codewars.com/kata/snail/javascript 4 | 5 | Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise. 6 | 7 | ``` 8 | array = [[1,2,3], 9 | [4,5,6], 10 | [7,8,9]] 11 | snail(array) #=> [1,2,3,6,9,8,7,4,5] 12 | ``` 13 | 14 | For better understanding, please follow the numbers of the next array consecutively: 15 | 16 | ``` 17 | array = [[1,2,3], 18 | [8,9,4], 19 | [7,6,5]] 20 | snail(array) #=> [1,2,3,4,5,6,7,8,9] 21 | ``` 22 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Strip Comments/(4 kyu) Strip Comments.js: -------------------------------------------------------------------------------- 1 | const solution = (input, markers) => 2 | input 3 | .split('\n') 4 | .map((s) => markers.reduce((t, m) => t.split(m)[0].trim(), s)) 5 | .join('\n'); 6 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Strip Comments/(4 kyu) Strip Comments.md: -------------------------------------------------------------------------------- 1 | # Strip Comments (4 kyu) 2 | 3 | https://www.codewars.com/kata/51c8e37cee245da6b40000bd 4 | 5 | Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. 6 | 7 | ### Example: 8 | 9 | Given an input string of: 10 | 11 | ``` 12 | apples, pears # and bananas 13 | grapes 14 | bananas !apples 15 | ``` 16 | 17 | The output expected would be: 18 | 19 | ``` 20 | apples, pears 21 | grapes 22 | bananas 23 | ``` 24 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Sum Strings as Numbers/(4 kyu) Sum Strings as Numbers.js: -------------------------------------------------------------------------------- 1 | const sumStrings = (a, b) => { 2 | // try a simple case 3 | let sum = String(+a + +b); 4 | if (!sum.includes`e+`) { 5 | return sum; 6 | } 7 | 8 | // perform BigInteger 9 | sum = ''; 10 | let $ = 0; 11 | [a, b] = [a.split``, b.split``]; 12 | while (a.length || b.length || $) { 13 | $ += ~~a.pop() + ~~b.pop(); 14 | sum = ($ % 10) + sum; 15 | $ = $ > 9; 16 | } 17 | return sum.replace(/^0+/, ''); 18 | }; 19 | -------------------------------------------------------------------------------- /4kyu/(4 kyu) Sum Strings as Numbers/(4 kyu) Sum Strings as Numbers.md: -------------------------------------------------------------------------------- 1 | # Sum Strings as Numbers (4 kyu) 2 | 3 | https://www.codewars.com/kata/5324945e2ece5e1f32000370 4 | 5 | Given the string representations of two integers, return the string representation of the sum of those integers. 6 | 7 | ### For example: 8 | 9 | ``` 10 | sumStrings('1','2') // => '3' 11 | ``` 12 | 13 | A string representation of an integer will contain no characters besides the ten numerals "0" to "9". 14 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Count IP Addresses/(5 kyu) Count IP Addresses.js: -------------------------------------------------------------------------------- 1 | const ipsBetween = (start, end) => { 2 | const calc = (n, m = 1) => (end.split`.`[n] - start.split`.`[n]) * m; 3 | 4 | return calc(0, 256 * 256 * 256) + calc(1, 256 * 256) + calc(2, 256) + calc(3); 5 | }; 6 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Count IP Addresses/(5 kyu) Count IP Addresses.py: -------------------------------------------------------------------------------- 1 | def ips_between(start, end): 2 | calc = lambda n, m: (int(end.split(".")[n]) - int(start.split(".")[n])) * m 3 | return calc(0, 256 * 256 * 256) + calc(1, 256 * 256) + calc(2, 256) + calc(3, 1) 4 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Fibonacci Generator/(5 kyu) Fibonacci Generator.js: -------------------------------------------------------------------------------- 1 | function* fibonacci(current = 0, next = 1) { 2 | while (true) { 3 | yield current; 4 | [current, next] = [next, current + next]; 5 | } 6 | } 7 | 8 | function genfib() { 9 | const sequence = fibonacci(); 10 | 11 | return function fib() { 12 | return sequence.next().value; 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Fibonacci Generator/(5 kyu) Fibonacci Generator.md: -------------------------------------------------------------------------------- 1 | # Fibonacci Generator (5 kyu) 2 | 3 | https://www.codewars.com/kata/522498c9906b0cfcb40001fc 4 | 5 | Create a function generator genfib() that returns a function fib() which always returns the next fibonacci number on each invocation (and returns 0 when being called the first time). 6 | 7 | ### Example: 8 | 9 | ``` 10 | var fib = genfib(); 11 | fib(); // -> returns 0 12 | fib(); // -> returns 1 13 | fib(); // -> returns 1 14 | fib(); // -> returns 2 15 | ``` 16 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Human Readable Time/(5 kyu) Human Readable Time.js: -------------------------------------------------------------------------------- 1 | const humanReadable = (seconds) => 2 | [ 3 | ('0' + Math.floor(seconds / 3600)).slice(-2), 4 | ('0' + Math.floor((seconds % 3600) / 60)).slice(-2), 5 | ('0' + (seconds % 60)).slice(-2), 6 | ].join(':'); 7 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Human Readable Time/(5 kyu) Human Readable Time.md: -------------------------------------------------------------------------------- 1 | # Human Readable Time (5 kyu) 2 | 3 | https://www.codewars.com/kata/human-readable-time 4 | 5 | Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS) 6 | 7 | ``` 8 | HH = hours, padded to 2 digits, range: 00 - 99 9 | MM = minutes, padded to 2 digits, range: 00 - 59 10 | SS = seconds, padded to 2 digits, range: 00 - 59 11 | ``` 12 | 13 | The maximum time never exceeds 359999 (99:59:59) 14 | 15 | You can find some examples in the test fixtures. 16 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Human Readable Time/(5 kyu) Human Readable Time.py: -------------------------------------------------------------------------------- 1 | # #1 2 | #def make_readable(seconds): 3 | # hours = seconds/60**2 4 | # minutes = (seconds%60**2)/60 5 | # seconds = (seconds%60**2%60) 6 | # return "%02d:%02d:%02d" % (hours, minutes, seconds) 7 | 8 | # #2 9 | #def make_readable(seconds): 10 | # hours, seconds = divmod(seconds, 60 ** 2) 11 | # minutes, seconds = divmod(seconds, 60) 12 | # return '{:02}:{:02}:{:02}'.format(hours, minutes, seconds) 13 | 14 | # #3 15 | def make_readable(seconds): 16 | return '{:02}:{:02}:{:02}'.format(seconds / 3600, seconds / 60 % 60, seconds % 60) 17 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Human Readable Time/(5 kyu) Human Readable Time.ts: -------------------------------------------------------------------------------- 1 | export function humanReadable(seconds:number):string { 2 | return [ 3 | ('0' + Math.floor(seconds / 3600)).slice(-2), 4 | ('0' + Math.floor((seconds % 3600) / 60)).slice(-2), 5 | ('0' + (seconds % 60)).slice(-2), 6 | ].join(':'); 7 | } 8 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Memoized Fibonacci/(5 kyu) Memoized Fibonacci.js: -------------------------------------------------------------------------------- 1 | const cache = [0, 1]; 2 | 3 | const fibonacci = (n) => 4 | cache[n] !== undefined 5 | ? cache[n] 6 | : (cache[n] = fibonacci(n - 1) + fibonacci(n - 2)); 7 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Memoized Fibonacci/(5 kyu) Memoized Fibonacci.py: -------------------------------------------------------------------------------- 1 | cache = {0:0, 1:1} 2 | 3 | def fibonacci(n): 4 | if n not in cache: 5 | cache[n] = fibonacci(n - 1) + fibonacci(n - 2) 6 | return cache[n] 7 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine/(5 kyu) Ninety Nine Thousand Nine Hundred Ninety Nine.md: -------------------------------------------------------------------------------- 1 | # Ninety Nine Thousand Nine Hundred Ninety Nine (5 kyu) 2 | 3 | https://www.codewars.com/kata/ninety-nine-thousand-nine-hundred-ninety-nine 4 | 5 | Write a method that takes a number and returns a string of that number in English. 6 | 7 | For example: 8 | 9 | ``` 10 | numberToEnglish(27) // => 'twenty seven' 11 | ``` 12 | 13 | Your method should be able to handle any number between 0 and 99999. If given numbers outside of that range or non-Integer numbers, the method should return an empty string. 14 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) RGB To Hex Conversion/(5 kyu) RGB To Hex Conversion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class RGBToHex 5 | { 6 | static inline std::string dec_to_hex(int c) 7 | { 8 | if (c < 0) return "00"; 9 | else if (c > 255) return "FF"; 10 | std::ostringstream oss; 11 | oss << std::uppercase << std::setfill('0') << std::hex << std::setw(2) << c; 12 | return oss.str(); 13 | } 14 | 15 | public: 16 | static std::string rgb(int r, int g, int b) 17 | { 18 | return dec_to_hex(r) + dec_to_hex(g) + dec_to_hex(b); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) RGB To Hex Conversion/(5 kyu) RGB To Hex Conversion.py: -------------------------------------------------------------------------------- 1 | def rgb(r, g, b): 2 | def decToHex(c): 3 | if (c > 255): 4 | return "FF" 5 | if (c < 0): 6 | return "00" 7 | else: 8 | return hex(c)[2:].zfill(2).upper() 9 | 10 | return decToHex(r) + decToHex(g) + decToHex(b) 11 | -------------------------------------------------------------------------------- /5kyu/(5 kyu) RGB To Hex Conversion/(5 kyu) RGB To Hex Conversion.rs: -------------------------------------------------------------------------------- 1 | fn rgb(r: i32, g: i32, b: i32) -> String { 2 | fn dec_to_hex(c: i32) -> String { 3 | if c < 0 { String::from("00") } 4 | else if c > 255 { String::from("FF") } 5 | else { format!("{:02X}", c) } 6 | } 7 | 8 | format!("{}{}{}", dec_to_hex(r), dec_to_hex(g), dec_to_hex(b)) 9 | } 10 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) CamelCase Method/(6 kyu) CamelCase Method.md: -------------------------------------------------------------------------------- 1 | # CamelCase Method (6 kyu) 2 | 3 | https://www.codewars.com/kata/camelcase-method/ 4 | 5 | Write simple .camelcase method (camel_case function in PHP) for strings. All words must have their first letter capitalized without spaces. 6 | 7 | Example: 8 | 9 | ```js 10 | "hello case".camelCase() => HelloCase 11 | "camel case word".camelCase() => CamelCaseWord 12 | ``` 13 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) CamelCase Method/(6 kyu) CamelCase Method.py: -------------------------------------------------------------------------------- 1 | def camel_case(string): 2 | # #1 3 | # return "".join(c.capitalize() for c in string.split()) 4 | # #2 5 | return string.title().replace(" ", "") 6 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) CamelCase Method/(6 kyu) CamelCase Method.rs: -------------------------------------------------------------------------------- 1 | fn camel_case(str: &str) -> String { 2 | str.split_whitespace() 3 | .collect::>() 4 | .iter() 5 | .map(|&s| [&s[..1].to_uppercase(), &s[1..]].join("")) 6 | .collect::>() 7 | .join("") 8 | } 9 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) CamelCase Method/(6 kyu) CamelCase Method.ts: -------------------------------------------------------------------------------- 1 | export function camelCase(str: string): string { 2 | return str 3 | .split(' ') 4 | .map((s: string): string => s.charAt(0).toUpperCase() + s.slice(1)) 5 | .join(''); 6 | } 7 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Count the smiley faces/(6 kyu) Count the smiley faces.js: -------------------------------------------------------------------------------- 1 | //return the total number of smiling faces in the array 2 | const countSmileys = (arr) => 3 | // regExp#1 /^((:|;))\s*[-~]{0,1}\s*((\)|D))$/ 4 | // regExp#2 /^[:;][-~]{0,1}[)D]$/ 5 | arr.filter((el) => el.match(/^[:;][-~]?[)D]$/)).length; 6 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Decode the Morse code/(6 kyu) Decode the Morse code.js: -------------------------------------------------------------------------------- 1 | decodeMorse = function(morseCode) { 2 | return morseCode 3 | .trim() //remove extra spaces 4 | .split(' ') //devide by words 5 | .map(( 6 | str, //parse each word 7 | ) => 8 | str 9 | .split(' ') //devide by symbols 10 | .map((s) => MORSE_CODE[s]) //return Char 11 | .join(''), 12 | ) 13 | .join(' '); 14 | }; 15 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Decode the Morse code/(6 kyu) Decode the Morse code.py: -------------------------------------------------------------------------------- 1 | def decodeMorse(morse_code): 2 | result = [] 3 | for word in morse_code.strip().split(" "): 4 | decoded_word = "" 5 | for letter in word.split(): 6 | decoded_word += MORSE_CODE[letter] 7 | result.append(decoded_word) 8 | return " ".join(result) 9 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Decode the Morse code/(6 kyu) Decode the Morse code.rs: -------------------------------------------------------------------------------- 1 | impl MorseDecoder { 2 | 3 | fn decode_morse(&self, encoded: &str) -> String { 4 | encoded 5 | .trim() 6 | .split(" ") 7 | .map(|x| x.split(' ') 8 | .filter_map(|y| { self.morse_code.get(y) }) 9 | .cloned() 10 | .collect()) 11 | .collect::>() 12 | .join(" ") 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Decode the Morse code/(6 kyu) Decode the Morse code.ts: -------------------------------------------------------------------------------- 1 | export function decodeMorse(morseCode: string): string { 2 | return morseCode 3 | .trim() 4 | .split(' ') 5 | .map((str: string) => 6 | str 7 | .split(' ') 8 | .map((s: string) => MORSE_CODE[s]) 9 | .join(''), 10 | ) 11 | .join(' '); 12 | } 13 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Fibonacci Generator Function/(6 kyu) Fibonacci Generator Function.js: -------------------------------------------------------------------------------- 1 | function* fibonacci(fn1 = 1, fn2 = 0, current = 0) { 2 | while (true) { 3 | [current, fn2, fn1] = [fn2, fn1, fn1 + fn2]; 4 | 5 | yield current; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Find the odd int/(6 kyu) Find the odd int.md: -------------------------------------------------------------------------------- 1 | # Find the odd int (6 kyu) 2 | 3 | https://www.codewars.com/kata/find-the-odd-int/ 4 | 5 | Given an array, find the int that appears an odd number of times. There will always be only one integer that appears an odd number of times. 6 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Find the odd int/(6 kyu) Find the odd int.py: -------------------------------------------------------------------------------- 1 | def find_it(seq): 2 | digits = {} 3 | num = 0 4 | 5 | for n in seq: 6 | if str(n) not in digits: 7 | digits[str(n)] = n 8 | num += n 9 | else: 10 | del digits[str(n)] 11 | num -= n 12 | 13 | return num 14 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Find the odd int/(6 kyu) Find the odd int.ts: -------------------------------------------------------------------------------- 1 | export const findOdd = (xs: number[]): number => { 2 | let digits = {}; 3 | let num: number = 0; 4 | xs.forEach((n: number) => { 5 | if (!digits[n]) { 6 | num += digits[n] = n; 7 | } else { 8 | delete digits[n]; 9 | num -= n; 10 | } 11 | }); 12 | 13 | return num; 14 | }; 15 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Hard Time Bomb/(6 kyu) Hard Time Bomb.md: -------------------------------------------------------------------------------- 1 | # Hard Time Bomb (6 kyu) 2 | 3 | https://www.codewars.com/kata/hard-time-bomb 4 | 5 | A bomb has been set to go off! You have to find the wire and cut it in order to stop the timer. There is a global `var` that holds the numeric ID to which wire to cut. Find that and then you can `Bomb.CutTheWire(wireKey);` 6 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Help the bookseller/(6 kyu) Help the bookseller.ts: -------------------------------------------------------------------------------- 1 | export class G964 { 2 | public static stockList = (listOfArt: string[], listOfCat: string[]) => { 3 | if (!listOfArt.length || !listOfCat.length) { 4 | return ''; 5 | } 6 | const books = {}; 7 | const result = []; 8 | listOfArt.forEach((book: string) => { 9 | const [title, num] = book.split(' '); 10 | books[title[0]] = (books[title[0]] | 0) + +num; 11 | }); 12 | return listOfCat 13 | .map((letter: string) => `(${letter} : ${books[letter] | 0})`) 14 | .join(' - '); 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) IQ Test/(6 kyu) IQ Test.py: -------------------------------------------------------------------------------- 1 | def iq_test(numbers): 2 | sequence = numbers.split() 3 | evens = [] 4 | odds = [] 5 | for i in range(len(sequence)): 6 | odds.append(i + 1) if int(sequence[i]) & 1 else evens.append(i + 1) 7 | return evens[0] if len(evens) == 1 else odds[0] 8 | 9 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) IQ Test/(6 kyu) IQ Test.ts: -------------------------------------------------------------------------------- 1 | export function iqTest(numbers: string): number { 2 | const nums = numbers.split(' ').map((el: string) => +el); 3 | const odd = nums.filter((el: number) => el % 2 === 1); 4 | const even = nums.filter((el: number) => el % 2 === 0); 5 | 6 | return odd.length < even.length 7 | ? nums.indexOf(odd[0]) + 1 8 | : nums.indexOf(even[0]) + 1; 9 | } 10 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Multiples of 3 or 5/(6 kyu) Multiples of 3 or 5.cpp: -------------------------------------------------------------------------------- 1 | int solution(int number) 2 | { 3 | int result = 0; 4 | int i; 5 | for (i = 1; i < number; i++) 6 | { 7 | if (i % 3 == 0 || i % 5 == 0) 8 | { 9 | result += i; 10 | } 11 | } 12 | return result; 13 | } -------------------------------------------------------------------------------- /6kyu/(6 kyu) Multiples of 3 or 5/(6 kyu) Multiples of 3 or 5.md: -------------------------------------------------------------------------------- 1 | # Multiples of 3 and 5 (6 kyu) 2 | 3 | https://www.codewars.com/kata/multiples-of-3-or-5 4 | 5 | If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. 6 | 7 | Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. 8 | 9 | > Note: If the number is a multiple of both 3 and 5, only count it once. 10 | 11 | _Courtesy of ProjectEuler.net_ 12 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Multiples of 3 or 5/(6 kyu) Multiples of 3 or 5.py: -------------------------------------------------------------------------------- 1 | def solution(number): 2 | # #1 3 | # result = 0 4 | # for i in range(1, number): 5 | # result += i if 0 == i % 3 or 0 == i % 5 else 0 6 | # return result 7 | # #2 8 | return sum(x for x in range(number) if x % 3 == 0 or x % 5 == 0) 9 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Multiples of 3 or 5/(6 kyu) Multiples of 3 or 5.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn solution(num: i32) -> i32 { 3 | // let mut result = 0; 4 | // for i in 1..num { 5 | // result += if 0 == i % 3 || 0 == i % 5 {i} else {0} 6 | // } 7 | // result 8 | // } 9 | // #2 10 | fn solution(num: i32) -> i32 { 11 | (1..num).filter(|i| 0 == i % 3 || 0 == i % 5).sum() 12 | } 13 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Multiples of 3 or 5/(6 kyu) Multiples of 3 or 5.ts: -------------------------------------------------------------------------------- 1 | export class Challenge { 2 | static solution(number) { 3 | let result = 0; 4 | for (let i = 1; i < number; i++) { 5 | result += 0 === i % 3 || 0 === i % 5 ? i : 0; 6 | } 7 | return result; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Playing with digits/(6 kyu) Playing with digits.cpp: -------------------------------------------------------------------------------- 1 | #include // std::string 2 | #include // pow 3 | 4 | class DigPow 5 | { 6 | public: 7 | static int digPow(int n, int p) 8 | { 9 | std::string str = std::to_string(n); 10 | int res = 0; 11 | 12 | for(char& c: str) 13 | { 14 | res += pow((int)(c) - 48, p++); 15 | } 16 | 17 | return res % n == 0 ? res / n : -1; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Playing with digits/(6 kyu) Playing with digits.py: -------------------------------------------------------------------------------- 1 | def dig_pow(n, p): # #1 2 | string = str(n) 3 | res = 0 4 | for s in string: 5 | res += int(s) ** p 6 | p += 1 7 | return res / n if res % n == 0 else -1 8 | 9 | 10 | def dig_pow(n, p): # #2 11 | res = 0 12 | for i, s in enumerate(str(n)): 13 | res += int(s) ** (p + i) 14 | return res / n if res % n == 0 else -1 15 | 16 | 17 | def dig_pow(n, p): # #3 18 | res = sum(int(s) ** (p + i) for i, s in enumerate(str(n))) 19 | return res // n if res % n == 0 else -1 20 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Playing with digits/(6 kyu) Playing with digits.rs: -------------------------------------------------------------------------------- 1 | fn dig_pow(n: i64, p: i32) -> i64 { 2 | let n: u64 = n as u64; 3 | let p: u32 = p as u32; 4 | let mut res: u64 = 0; 5 | let mut string: Vec = Vec::new(); 6 | let mut temp = n; 7 | while temp > 0 { 8 | string.push(temp as u32 % 10); 9 | temp /= 10; 10 | } 11 | string.reverse(); 12 | let mut i = p; 13 | for c in string { 14 | res += (c as u64).pow(i); 15 | i += 1; 16 | } 17 | if res % n == 0 { (res / n) as i64 } else { -1 } 18 | } 19 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Playing with digits/(6 kyu) Playing with digits.ts: -------------------------------------------------------------------------------- 1 | export class G964 { 2 | public static digPow = (n: number, p: number): number => { 3 | let t: number = 0; 4 | let k: number = 0; 5 | 6 | n.toString() 7 | .split('') 8 | .forEach( 9 | (el: string, i: number): void => { 10 | t += Math.pow(parseInt(el), p + i); 11 | }, 12 | ); 13 | 14 | while (k <= 0xffff) { 15 | if (n * k++ == t) { 16 | return k - 1; 17 | } 18 | } 19 | 20 | return -1; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Playing with passphrases/(6 kyu) Playing with passphrases.rs: -------------------------------------------------------------------------------- 1 | fn play_pass(s: &str, n: u32) -> String { 2 | s 3 | .char_indices() 4 | .map(|(i, a)| match a { 5 | a if a.is_digit(10) => std::char::from_u32(105 - (a as u32)).unwrap(), 6 | a if a.is_alphabetic() => { 7 | let mut x = std::char::from_u32(((a as u32 + n - 65) % 26 + 65)).unwrap(); 8 | if i % 2 == 1 { x = x.to_ascii_lowercase() } 9 | x 10 | }, 11 | _ => a 12 | }) 13 | .rev() 14 | .collect::() 15 | } 16 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Reverse or rotate/(6 kyu) Reverse or rotate.py: -------------------------------------------------------------------------------- 1 | def revrot(s, n, res=""): 2 | if not s or n < 1 or n > len(s): 3 | return "" 4 | 5 | while len(s) >= n: 6 | group = s[:n] 7 | if sum([int(d)**3 for d in group]) % 2 == 0: 8 | res += group[::-1] 9 | else: 10 | res += group[1:] + group[0] 11 | s = s[n:] 12 | 13 | return res 14 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Reverse or rotate/(6 kyu) Reverse or rotate.rs: -------------------------------------------------------------------------------- 1 | fn revrot(s: &str, c: usize) -> String { 2 | if s.is_empty() || c == 0 || c > s.len() { 3 | return "".to_string(); 4 | } 5 | let mut v: Vec = s.chars().collect(); 6 | v 7 | .chunks_exact_mut(c) 8 | .flat_map(|x| { 9 | let sum: u32 = x 10 | .iter() 11 | .map(|n| n.to_digit(10).unwrap().pow(3)) 12 | .sum(); 13 | 14 | if sum % 2 == 0 { x.reverse(); } 15 | else { x.rotate_left(1); } 16 | 17 | x.iter() 18 | }) 19 | .collect::() 20 | } 21 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Square Digits Sequence/(6 kyu) Square Digits Sequence.py: -------------------------------------------------------------------------------- 1 | def square_digits_sequence(n): 2 | s = set() 3 | while n not in s: 4 | s.add(n) 5 | n = sum(int(d)**2 for d in str(n)) 6 | return len(s)+1 7 | -------------------------------------------------------------------------------- /6kyu/(6 kyu) Square Digits Sequence/(6 kyu) Square Digits Sequence.ts: -------------------------------------------------------------------------------- 1 | export function squareDigitsSequence(a: number): number { 2 | const nums: number[] = []; 3 | while (-1 === nums.indexOf(a)) { 4 | nums.push(a); 5 | a = String(a) 6 | .split('') 7 | .reduce((s: number, n: string) => s + Math.pow(Number(n), 2), 0); 8 | } 9 | return nums.length + 1; 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | std::string generate_shape(int n) 7 | { 8 | std::string res; 9 | for (int i = 0; i < n; i++) 10 | { 11 | for (int j = 0; j < n; j++) 12 | res += "+"; 13 | if (i < n - 1) 14 | res += "\n"; 15 | } 16 | return res; 17 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static string GenerateShape(int n) 6 | { 7 | string[] res = new string[n]; 8 | for (int i = 0; i < n; i++) 9 | { 10 | res[i] = new string('+', n); 11 | } 12 | return String.Join("\n", res); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Kata { 4 | public static final String generateShape(int n) { 5 | List res = new ArrayList<>(); 6 | for (int i = 0; i < n; i++) { 7 | res.add("+".repeat(n)); 8 | } 9 | return String.join("\n", res); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.md: -------------------------------------------------------------------------------- 1 | # Build a square (7 kuy) 2 | 3 | https://www.codewars.com/kata/build-a-square/ 4 | 5 | I will give you an integer. Give me back a shape that is as long and wide as the integer. The integer will be a whole number between 0 and 50. 6 | 7 | Example: Integer = 3; I expect a 3x3 square back just like below as a string. 8 | 9 | Solution: 10 | 11 | ``` 12 | +++ 13 | +++ 14 | +++ 15 | ``` 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def generateShape(int): 3 | # str = [] 4 | # for i in range(int): 5 | # str.append('+' * int) 6 | # return "\n".join(str) 7 | # #2 8 | # def generateShape(n): 9 | # return "\n".join("+" * n for i in range(n)) 10 | 11 | 12 | def generateShape(int): # 3 13 | return (("+" * int + "\n") * int)[:-1] 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn generate_shape(n: i32) -> String { 3 | // let mut str = vec![]; 4 | // for _ in 0..n { 5 | // str.push("+".repeat(n as usize)); 6 | // } 7 | // str.join("\n") 8 | // } 9 | // #2 10 | // fn generate_shape(n: i32) -> String { 11 | // vec!["+".repeat(n as usize); n as usize].join("\n") 12 | // } 13 | // #3 14 | fn generate_shape(n: usize) -> String { 15 | vec!["+".repeat(n); n].join("\n") 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Build a square/(7 kyu) Build a square.ts: -------------------------------------------------------------------------------- 1 | export function generateShape(int: number): string { 2 | let string = ''; 3 | for (let i = 0; i < int * int; i++) { 4 | if (i % int === 0 && i !== 0) { 5 | string += '\n'; 6 | } 7 | string += '+'; 8 | } 9 | return string; 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Canvas Fun 1 - Draw Lines/(7 kyu) Canvas Fun 1 - Draw Lines.md: -------------------------------------------------------------------------------- 1 | # Canvas Fun #1: Draw Lines (7 kyu) 2 | 3 | http://www.codewars.com/kata/canvas-fun-number-1-draw-lines 4 | 5 | Given some points, your task is to draw lines between two adjacent points. 6 | 7 | `points` is given by a 2D integer array. Each subarray has two elements, means the x-coordinate, y-coordinate of each point. 8 | 9 | The basic canvas(width 100 x height 100), background color(white) and pen's color(red) are already defined in the initial code(please don't delete or modify them). 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func DNAStrand(dna string) string { 4 | var dict = map[string]string{ 5 | "A": "T", "T": "A", "C": "G", "G": "C", 6 | } 7 | res := "" 8 | 9 | for _, v := range dna { 10 | res = res + dict[string(v)] 11 | } 12 | 13 | return res 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.java: -------------------------------------------------------------------------------- 1 | public class DnaStrand { 2 | public static String makeComplement(String dna) { 3 | return dna 4 | .replaceAll("A", "t") 5 | .replaceAll("T", "a") 6 | .replaceAll("C", "g") 7 | .replaceAll("G", "c") 8 | .toUpperCase(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function DNAStrand(dna) { 3 | // const dictionary = { A: 'T', T: 'A', C: 'G', G: 'C' }; 4 | // return dna 5 | // .split('') 6 | // .map((c) => dictionary[c]) 7 | // .join(''); 8 | // } 9 | // #2 10 | // const DNAStrand = (dna) => { 11 | // return dna 12 | // .replace(/A/g, 't') 13 | // .replace(/T/g, 'a') 14 | // .replace(/C/g, 'g') 15 | // .replace(/G/g, 'c') 16 | // .toUpperCase(); 17 | // }; 18 | // #3 19 | const DNAStrand = (dna) => 20 | dna.replace(/./g, (c) => ({ A: 'T', T: 'A', G: 'C', C: 'G' }[c])); 21 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.py: -------------------------------------------------------------------------------- 1 | def DNA_strand(dna): 2 | # #1 3 | # dna = dna.replace("A", "t") 4 | # dna = dna.replace("T", "a") 5 | # dna = dna.replace("C", "g") 6 | # dna = dna.replace("G", "c") 7 | 8 | # return dna.upper() 9 | # #2 10 | # Python 3.4 11 | return dna.translate(str.maketrans("ATCG","TAGC")) 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.rs: -------------------------------------------------------------------------------- 1 | fn DNA_strand(dna: &str) -> String { 2 | dna.chars() 3 | .map(|x| match x { 4 | 'A' => 'T', 5 | 'T' => 'A', 6 | 'C' => 'G', 7 | 'G' => 'C', 8 | _ => panic!("Mutant detected"), 9 | }) 10 | .collect() 11 | } 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Complementary DNA/(7 kyu) Complementary DNA.ts: -------------------------------------------------------------------------------- 1 | export class Kata { 2 | static dnaStrand(dna: string) { 3 | return dna 4 | .replace(/A/g, 't') 5 | .replace(/T/g, 'a') 6 | .replace(/C/g, 'g') 7 | .replace(/G/g, 'c') 8 | .toUpperCase(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Even numbers in an array/(7 kyu) Even numbers in an array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | std::vector evenNumbers(vector arr, int n) 6 | { 7 | vector result; 8 | 9 | for (auto x : arr) 10 | if (x % 2 == 0) 11 | result.push_back(x); 12 | 13 | return vector(result.end() - n, result.end()); 14 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Even numbers in an array/(7 kyu) Even numbers in an array.md: -------------------------------------------------------------------------------- 1 | # Even numbers in an array (7 kyu) 2 | 3 | https://www.codewars.com/kata/even-numbers-in-an-array/ 4 | 5 | Given an `array` of digitals numbers, return a new array of length `number` containing the last even numbers from the original array (in the same order). The original array will be not empty and will contain at least "number" even numbers. 6 | 7 | For example: 8 | 9 | ```js 10 | ([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) => [4, 6, 8] 11 | ([-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2) => [-8, 26] 12 | ([6, -25, 3, 7, 5, 5, 7, -3, 23], 1) => [6] 13 | ``` 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Even numbers in an array/(7 kyu) Even numbers in an array.py: -------------------------------------------------------------------------------- 1 | def even_numbers(arr, n): 2 | return list(filter(lambda x: x % 2 == 0, arr))[-n::] 3 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Even numbers in an array/(7 kyu) Even numbers in an array.rs: -------------------------------------------------------------------------------- 1 | fn even_numbers(array: Vec, number: usize) -> Vec { 2 | let arr = array.into_iter().filter(|&i|i % 2 == 0).collect::>(); 3 | let from = arr.len() - number; 4 | arr[from..].to_vec() 5 | } 6 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Even numbers in an array/(7 kyu) Even numbers in an array.ts: -------------------------------------------------------------------------------- 1 | export function evenNumbers(array: number[], n: number): number[] { 2 | const result = []; 3 | 4 | for (let i = 0; i <= array.length; i++) { 5 | if (array[i] % 2 == 0) result.push(array[i]); 6 | } 7 | 8 | return result.splice(result.length - n, n); 9 | } 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Exes and Ohs/7 kyu Exes and Ohs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | bool XO(const std::string &str) 8 | { 9 | string res = ""; 10 | for (int i = 0; i < str.length(); i++) 11 | res += tolower(str[i]); 12 | int x = std::count(res.begin(), res.end(), 'x'); 13 | int o = std::count(res.begin(), res.end(), 'o'); 14 | return x == o; 15 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Exes and Ohs/7 kyu Exes and Ohs.md: -------------------------------------------------------------------------------- 1 | # Exes and Ohs (7 kyu) 2 | 3 | https://www.codewars.com/kata/exes-and-ohs/ 4 | 5 | Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char. 6 | 7 | Examples input/output: 8 | 9 | ```js 10 | XO("ooxx") => true 11 | XO("xooxx") => false 12 | XO("ooxXm") => true 13 | XO("zpzpzpp") => true // when no 'x' and 'o' is present should return true 14 | XO("zzoo") => false 15 | ``` 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Exes and Ohs/7 kyu Exes and Ohs.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def xo(s): 3 | # equal = 0 4 | # for c in s: 5 | # if c.lower() == 'x': equal += 1 6 | # if c.lower() == 'o': equal -= 1 7 | # return equal == 0 8 | #2 9 | def xo(s): 10 | return s.lower().count('x') == s.lower().count('o') 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Exes and Ohs/7 kyu Exes and Ohs.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn xo(string: &'static str) -> bool { 3 | // let mut equal = 0; 4 | // for c in string.to_lowercase().chars() { 5 | // equal += match c { 6 | // 'x' => 1, 7 | // 'o' => -1, 8 | // _ => 0, 9 | // } 10 | // } 11 | // equal == 0 12 | // } 13 | // #2 14 | fn xo(string: &'static str) -> bool { 15 | string.to_lowercase().chars().fold(0, |a, c| match c { 16 | 'x' => a + 1, 17 | 'o' => a - 1, 18 | _ => a, 19 | }) == 0 20 | } 21 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Exes and Ohs/7 kyu Exes and Ohs.ts: -------------------------------------------------------------------------------- 1 | export class Kata { 2 | static xo(str: string) { 3 | let equal = 0; 4 | str.split('').forEach((c) => { 5 | if ('x' === c.toLowerCase()) { 6 | equal += 1; 7 | } 8 | if ('o' === c.toLowerCase()) { 9 | equal -= 1; 10 | } 11 | }); 12 | return equal === 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Largest/(7 kyu) Form The Largest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long long int maxNumber(long long int n) 4 | { 5 | auto str = std::to_string(n); 6 | std::sort(str.begin(), str.end(), std::greater<>()); 7 | return std::stoll(str); 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Largest/(7 kyu) Form The Largest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | class Kata 4 | { 5 | public static int MaxNumber(int n) 6 | { 7 | char[] res = n.ToString().ToCharArray(); 8 | 9 | Array.Sort(res); 10 | Array.Reverse(res); 11 | 12 | return int.Parse(new string(res)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Largest/(7 kyu) Form The Largest.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def max_number(n): 3 | # s = list(str(n)) 4 | # s.sort() 5 | # res = s[::-1] 6 | # return int("".join(res)) 7 | # #2 8 | # def max_number(n): 9 | # s = list(str(n)) 10 | # return int(''.join(sorted(s, reverse=True))) 11 | #3 12 | def max_number(n): 13 | return int(''.join(sorted(str(n), reverse=True))) 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Largest/(7 kyu) Form The Largest.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn max_number(n: u32) -> u32 { 3 | // let str = n.to_string(); 4 | // let mut temp = str.chars().collect::>(); 5 | // temp.sort(); 6 | // let res = temp.into_iter().rev().collect::(); 7 | // res.parse::().unwrap() 8 | // } 9 | // #2 10 | fn max_number(n: u32) -> u32 { 11 | let str = n.to_string().chars().collect::>(); 12 | str.sort(); 13 | str.iter().rev().collect::().parse::().unwrap() 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Largest/(7 kyu) Form The Largest.ts: -------------------------------------------------------------------------------- 1 | export function maxNumber(n: number): number { 2 | const str = String(n); 3 | const arr = str.split('').map(Number); 4 | arr.sort((a: number, b: number): number => b - a); 5 | const res = arr.join(''); 6 | return parseInt(res); 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Minimum/(7 kyu) Form The Minimum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned long long minValue(const std::vector& v) { 5 | std::set s (v.begin(), v.end()); 6 | unsigned long long result = 0; 7 | for (std::set::iterator i = s.begin(); i != s.end(); i++) 8 | result = 10 * result + *i; 9 | return result; 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Minimum/(7 kyu) Form The Minimum.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | class Kata 5 | { 6 | public static long MinValue(int[] a) 7 | { 8 | var res = string.Concat(a.OrderBy(x => x).Distinct()); 9 | return Convert.ToInt64(res); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Minimum/(7 kyu) Form The Minimum.java: -------------------------------------------------------------------------------- 1 | import java.util.stream.Collectors; 2 | import java.util.*; 3 | 4 | public class Minimum { 5 | public static int minValue(int[] values) { 6 | List array = new ArrayList<>(); 7 | for (int n : values) { 8 | array.add(n); 9 | } 10 | var res = array.stream().distinct().sorted().map(x->String.valueOf(x)); 11 | return Integer.parseInt(res.collect(Collectors.joining())); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Minimum/(7 kyu) Form The Minimum.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def min_value(digits): 3 | # s = set(digits) 4 | # l = list(s) 5 | # l.sort() 6 | # r = [] 7 | # for x in l: 8 | # r.append(str(x)) 9 | # res = ''.join(r) 10 | # return int(res) 11 | #2 12 | def min_value(digits): 13 | l = sorted(list(set(digits))) 14 | return int(''.join(str(x) for x in l)) 15 | #3 16 | def min_value(digits): 17 | return int("".join(map(str,sorted(set(digits))))) 18 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Form The Minimum/(7 kyu) Form The Minimum.ts: -------------------------------------------------------------------------------- 1 | export const minValue = (values: number[]): number => { 2 | const arr = [...values].sort(); 3 | const dedupe = arr.filter( 4 | (x: number, i: number, a: number[]): boolean => i === a.indexOf(x), 5 | ); 6 | return +dedupe.join(''); 7 | }; 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Frequency sequence/(7 kyu) Frequency sequence.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import ( 4 | "strconv" 5 | "strings" 6 | ) 7 | 8 | func FreqSeq(str string, sep string) string { 9 | frq := make(map[string]int) 10 | res := make([]string, len(str)) 11 | 12 | for _, s := range str { 13 | l := string(s) 14 | frq[l] = frq[l] + 1 15 | } 16 | for i, _ := range res { 17 | x := string(str[i]) 18 | res[i] = strconv.Itoa(frq[x]) 19 | } 20 | 21 | return strings.Join(res, sep) 22 | } 23 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Frequency sequence/(7 kyu) Frequency sequence.md: -------------------------------------------------------------------------------- 1 | # Frequency sequence (7 kyu) 2 | 3 | https://www.codewars.com/kata/frequency-sequence/ 4 | 5 | Return an output string that translates an input string `s/$s` by replacing each character in `s/$s` with a number representing the number of times that character occurs in `s/$s` and separating each number with the character(s) `sep/$sep`. 6 | 7 | Example: 8 | 9 | ```js 10 | freqSeq('hello world', '-'); // => '1-1-3-3-2-1-1-2-1-3-1' 11 | freqSeq('^^^**$', 'x'); // => '3x3x3x2x2x1' 12 | freqSeq('19999999', ':'); // => '1:7:7:7:7:7:7:7' 13 | ``` 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Frequency sequence/(7 kyu) Frequency sequence.rs: -------------------------------------------------------------------------------- 1 | fn freq_seq(s: &str, sep: &str) -> String { 2 | s.chars() 3 | .map(|c| s.matches(c).count().to_string()) 4 | .collect::>() 5 | .join(sep) 6 | } 7 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Frequency sequence/(7 kyu) Frequency sequence.ts: -------------------------------------------------------------------------------- 1 | export function freqSeq(str: string, sep: string): string { 2 | type FreqType = { 3 | [key: string]: number 4 | } 5 | const freq: FreqType = {}; 6 | let newStr = ''; 7 | 8 | for (let i = 0; i < str.length; i++) { 9 | const n = String(str[i]); 10 | freq[n] = freq[n] ? freq[n] += 1 : 1; 11 | } 12 | 13 | for (let i = 0; i < str.length; i++) { 14 | const n = String(str[i]); 15 | newStr += i ? sep + String(freq[n]) : String(freq[n]); 16 | } 17 | 18 | return newStr; 19 | } 20 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | std::string get_middle(std::string input) 7 | { 8 | int middle = input.length() / 2; 9 | string res = ""; 10 | if (input.length() % 2 == 0) 11 | res += input[middle - 1]; 12 | res += input[middle]; 13 | return res; 14 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.cs: -------------------------------------------------------------------------------- 1 | public class Kata 2 | { 3 | public static string GetMiddle(string s) 4 | { 5 | int middle = (s.Length - 1)/ 2; 6 | int len = 1; 7 | 8 | if (s.Length % 2 == 0) 9 | len = 2; 10 | 11 | return s.Substring(middle, len); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func GetMiddle(s string) string { 4 | if len(s) == 0 { 5 | return "" 6 | } 7 | return s[(len(s)-1)/2:len(s)/2+1] 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.java: -------------------------------------------------------------------------------- 1 | class Kata { 2 | public static String getMiddle(String word) { 3 | int mid = word.length() / 2; 4 | 5 | if (word.length() % 2 != 0) { 6 | return word.substring(mid, mid+1); 7 | } else { 8 | return word.substring(mid-1, mid+1); 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.md: -------------------------------------------------------------------------------- 1 | # (7 kyu) Get the Middle Character 2 | 3 | https://www.codewars.com/kata/get-the-middle-character/ 4 | 5 | You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. 6 | 7 | Examples: 8 | 9 | ```js 10 | Kata.getMiddle("test") should return "es" 11 | Kata.getMiddle("testing") should return "t" 12 | Kata.getMiddle("middle") should return "dd" 13 | Kata.getMiddle("A") should return "A" 14 | ``` 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.py: -------------------------------------------------------------------------------- 1 | def get_middle(s): 2 | return s[(len(s) - 1) / 2:len(s) / 2 + 1] -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.rs: -------------------------------------------------------------------------------- 1 | fn get_middle(s: &str) -> &str { 2 | // #1 3 | // let even = s.len() % 2 == 0; 4 | // let middle = s.len() / 2; 5 | // &s[if even { middle - 1 } else { middle }..middle + 1] 6 | // #2 7 | s[(s.len() - 1) / 2..s.len() / 2 + 1] 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Get the Middle Character/(7 kyu) Get the Middle Character.ts: -------------------------------------------------------------------------------- 1 | export class Challenge { 2 | static getMiddle(s: string) { 3 | const middle = s.length / 2; 4 | if (s.length % 2) { 5 | return s.charAt(Math.floor(middle)); 6 | } else { 7 | return s.slice(middle - 1, middle + 1); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | std::string highAndLow(const std::string &numbers) 10 | { 11 | std::vector v; 12 | std::stringstream ss(numbers); 13 | std::string x; 14 | while (ss >> x) 15 | v.push_back(std::stoi(x)); 16 | auto result = std::minmax_element(v.begin(), v.end()); 17 | int low = result.first - v.begin(); 18 | int high = result.second - v.begin(); 19 | return std::to_string(v[high]) + " " + std::to_string(v[low]); 20 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "strings" 7 | "strconv" 8 | ) 9 | 10 | func HighAndLow(in string) string { 11 | min := math.MaxInt32 12 | max := math.MinInt32 13 | nums := strings.Fields(in) 14 | 15 | for _, n := range nums { 16 | x, _ := strconv.Atoi(n) 17 | if x > max { 18 | max = x 19 | } 20 | if x < min { 21 | min = x 22 | } 23 | } 24 | 25 | return fmt.Sprintf("%d %d", max, min) 26 | } 27 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.java: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | public static String highAndLow(String numbers) { 3 | String[] str = numbers.split(" "); 4 | int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE; 5 | 6 | for(String s: str) { 7 | int x = Integer.parseInt(s); 8 | if(x < min) min = x; 9 | if(x > max) max = x; 10 | } 11 | 12 | return max + " " + min; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function highAndLow(numbers) { 3 | // const arr = numbers.split(' ').map(Number); 4 | // const min = Math.min.apply(null, arr); 5 | // const max = Math.max.apply(null, arr); 6 | // 7 | // return max + ' ' + min; 8 | // } 9 | // #2 10 | // function highAndLow(numbers) { 11 | // const arr = numbers.split(' ').map(Number); 12 | // return Math.max(...arr) + ' ' + Math.min(...arr); 13 | // } 14 | // #3 15 | const highAndLow = (numbers) => 16 | `${Math.max(...numbers.split(' '))} ${Math.min(...numbers.split(' '))}`; 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.py: -------------------------------------------------------------------------------- 1 | def high_and_low(numbers): 2 | arr = list(map(int, numbers.split())) 3 | return str(max(arr)) + ' ' + str(min(arr)) 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Highest and Lowest/(7 kyu) Highest and Lowest.ts: -------------------------------------------------------------------------------- 1 | export class Kata { 2 | static highAndLow(numbers: string) { 3 | const max = Math.max(...numbers.split(' ').map((i) => +i)); 4 | const min = Math.min(...numbers.split(' ').map((i) => +i)); 5 | 6 | return `${max} ${min}`; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Jaden Casing Strings/(7 kyu) Jaden Casing Strings.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func ToJadenCase(str string) string { 6 | return strings.Title(str) 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Jaden Casing Strings/(7 kyu) Jaden Casing Strings.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.stream.Collectors; 3 | 4 | public class JadenCase { 5 | public String toJadenCase(String phrase) { 6 | if (null == phrase || phrase.length() == 0) { 7 | return null; 8 | } 9 | 10 | return Arrays.stream(phrase.split(" ")) 11 | .map(i -> i.substring(0, 1).toUpperCase() + i.substring(1, i.length())) 12 | .collect(Collectors.joining(" ")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Jaden Casing Strings/(7 kyu) Jaden Casing Strings.py: -------------------------------------------------------------------------------- 1 | def toJadenCase(string): 2 | # #1 3 | # return " ".join([c[0].upper() + c[1::] for c in string.split()]) 4 | # 2 5 | return " ".join(c.capitalize() for c in string.split()) 6 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Jaden Casing Strings/(7 kyu) Jaden Casing Strings.rs: -------------------------------------------------------------------------------- 1 | fn to_jaden_case(str: &str) -> String { 2 | str.split_whitespace() 3 | .collect::>() 4 | .iter() 5 | .map(|&s| [&s[..1].to_uppercase(), &s[1..]].join("")) 6 | .collect::>() 7 | .join(" ") 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Jaden Casing Strings/(7 kyu) Jaden Casing Strings.ts: -------------------------------------------------------------------------------- 1 | String.prototype.toJadenCase = function() { 2 | return this.split(' ') 3 | .map(function(s: string): string { 4 | return s.charAt(0).toUpperCase() + s.slice(1); 5 | }) 6 | .join(' '); 7 | }; 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.go: -------------------------------------------------------------------------------- 1 | package kata; 2 | 3 | import "reflect"; 4 | 5 | func Last(xs interface{}) interface{} { 6 | r := reflect.ValueOf(xs); 7 | 8 | if r.Kind() == reflect.String { 9 | var s = xs.(string); 10 | return s[len(s)-1:] 11 | } 12 | 13 | return r.Index(r.Len()-1).Interface(); 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function last(list) { 3 | // if (arguments.length > 1) { 4 | // return arguments[arguments.length - 1]; 5 | // } else if (list.length > 1) { 6 | // return list[list.length - 1]; 7 | // } else { 8 | // return list; 9 | // } 10 | // } 11 | // #2 12 | function last(list) { 13 | return arguments.length > 1 14 | ? arguments[arguments.length - 1] 15 | : list[list.length - 1] || arguments[arguments.length - 1]; 16 | } 17 | // #3 18 | function last(list) { 19 | const last = arguments[arguments.length - 1]; 20 | return last[last.length - 1] || last; 21 | } 22 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.md: -------------------------------------------------------------------------------- 1 | # Last (7 kyu) 2 | 3 | https://www.codewars.com/kata/541629460b198da04e000bb9 4 | 5 | Find the last element of the given argument(s). 6 | 7 | Examples: 8 | 9 | ```js 10 | last([1, 2, 3, 4]); // => 4 11 | last('xyz'); // => "z" 12 | last(1, 2, 3, 4); // => 4 13 | ``` 14 | 15 | In `javascript` and `CoffeeScript` a list will be an array, a string or the list of arguments. 16 | 17 | (courtesy of haskell.org) 18 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def last(*args): 3 | # last = args[-1] 4 | # try: 5 | # return last[-1] 6 | # except TypeError: 7 | # return last 8 | #2 9 | def last(*args): 10 | try: 11 | return args[-1][-1] 12 | except: 13 | return args[-1] 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn last(slice: &[T]) -> T { 3 | // let n = slice.len() - 1; 4 | 5 | // return slice[n].to_owned(); 6 | // } 7 | // #2 8 | // fn last(slice: &[T]) -> T { 9 | // slice.last().unwrap().to_owned() 10 | // } 11 | // #3 12 | fn last(slice: &[T]) -> T { 13 | let l = slice.last(); 14 | match l { 15 | None => panic!("empty"), 16 | Some(x) => x.clone(), 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Last/(7 kyu) Last.ts: -------------------------------------------------------------------------------- 1 | export function last(list: Array): T { 2 | const last = arguments[arguments.length - 1]; 3 | return last[last.length - 1] || last; 4 | } 5 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Mumbling/(7 kyu) Mumbling.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func Accum(s string) string { 6 | var sb []string 7 | letters := strings.Split(s, "") 8 | 9 | for i, letter := range letters { 10 | s := strings.Title(strings.Repeat(strings.ToLower(letter), i+1)) 11 | sb = append(sb, s) 12 | } 13 | 14 | return strings.Join(sb, "-") 15 | } 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Mumbling/(7 kyu) Mumbling.java: -------------------------------------------------------------------------------- 1 | import java.lang.*; 2 | 3 | public class Accumul { 4 | 5 | public static String accum(String s) { 6 | String[] array = s.split(""); 7 | 8 | for(int i = 0; i < array.length; i++){ 9 | String s1 = array[i].toUpperCase(); 10 | String s2 = array[i].toLowerCase().repeat(i); 11 | array[i] = s1 + s2; 12 | } 13 | 14 | return String.join("-", array); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Mumbling/(7 kyu) Mumbling.md: -------------------------------------------------------------------------------- 1 | # Mumbling (7 kyu) 2 | 3 | https://www.codewars.com/kata/mumbling/ 4 | 5 | This time no story, no theory. The examples below show you how to write function accum: 6 | 7 | Examples: 8 | 9 | ```js 10 | accum('abcd'); // "A-Bb-Ccc-Dddd" 11 | accum('RqaEzty'); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" 12 | accum('cwAt'); // "C-Ww-Aaa-Tttt" 13 | ``` 14 | 15 | The parameter of accum is a string which includes only letters from `a..z` and `A..Z`. 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Mumbling/(7 kyu) Mumbling.py: -------------------------------------------------------------------------------- 1 | def accum(s): 2 | # #1 3 | #return "-".join([c.upper() + c.lower() * i for i, c in enumerate(s)]) 4 | 5 | #2 6 | return '-'.join((c * i).title() for i, c in enumerate(s, 1)) -------------------------------------------------------------------------------- /7kyu/(7 kyu) Mumbling/(7 kyu) Mumbling.ts: -------------------------------------------------------------------------------- 1 | export class G964 { 2 | public static accum(s: string): string { 3 | return s 4 | .split('') 5 | .map((el, i) => 6 | /^[a-zA-Z]$/ ? el.toUpperCase() + el.repeat(i).toLowerCase() : '', 7 | ) 8 | .join('-'); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class Kata 5 | { 6 | public static int Number(List peopleListInOut) 7 | { 8 | int totalPeople = 0; 9 | 10 | foreach (var stop in peopleListInOut) { 11 | totalPeople += stop[0] - stop[1]; 12 | } 13 | 14 | return totalPeople; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Number(busStops [][]int) int { 4 | totalPeople := 0 5 | 6 | for _, stop := range busStops { 7 | totalPeople += stop[0] 8 | totalPeople -= stop[1] 9 | } 10 | 11 | return totalPeople 12 | } 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class Metro { 4 | 5 | public int countPassengers(ArrayList stops) { 6 | int totalPeople = 0; 7 | 8 | for(int[] stop : stops) { 9 | totalPeople += stop[0] - stop[1]; 10 | } 11 | 12 | return totalPeople; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function number(busStops) { 3 | // let totalPeople = 0; 4 | // for (let i = 0; i < busStops.length; i++) { 5 | // totalPeople += busStops[i][0]; 6 | // totalPeople -= busStops[i][1]; 7 | // } 8 | // return totalPeople; 9 | // } 10 | // #2 11 | // function number(busStops) { 12 | // return busStops.reduce((people, next) => { 13 | // const [on, off] = next; 14 | // return people + on - off; 15 | // }, 0); 16 | // } 17 | // #3 18 | const number = (busStops) => busStops.reduce((a, c) => a + c[0] - c[1], 0); 19 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # from functools import reduce 3 | # def number(stops): 4 | # nums = [a[0] - a[1] for a in stops] 5 | # return reduce(lambda a, b: a + b, nums) 6 | #2 7 | def number(bus_stops): 8 | return sum([a[0] - a[1] for a in bus_stops]) 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn number(stops: &[(i32,i32)]) -> i32 { 3 | // stops.iter().map(|c| c.0 - c.1).sum() 4 | // } 5 | // #2 6 | fn number(stops: &[(i32, i32)]) -> i32 { 7 | stops.iter().fold(0, |a, c| a + c.0 - c.1) 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Number of People in the Bus/(7 kyu) Number of People in the Bus.ts: -------------------------------------------------------------------------------- 1 | export function number(busStops: number[][]): number { 2 | return busStops.reduce((a, c) => (a += c[0] - c[1]), 0); 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Recursion 2 - Fibonacci/(7 kyu) Recursion 2 - Fibonacci.md: -------------------------------------------------------------------------------- 1 | # Recursion #2 - Fibonacci (7 kyu) 2 | 3 | https://www.codewars.com/kata/recursion-number-2-fibonacci/ 4 | 5 | ## 2 - Fibonacci number 6 | 7 | In mathematical terms, the sequence `f(n)` of [fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number) numbers is defined by the recurrence relation 8 | 9 | ```js 10 | f(n) = f(n-1) + f(n-2) 11 | ``` 12 | 13 | with seed values 14 | 15 | ```js 16 | f(1) = 1 and f(2) = 1 17 | ``` 18 | 19 | ## Your task 20 | 21 | You have to create the function fibonacci that receives n and returns `f(n)`. You have to use recursion. 22 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Recursion 2 - Fibonacci/(7 kyu) Recursion 2 - Fibonacci.py: -------------------------------------------------------------------------------- 1 | def fibonacci(n): 2 | return 1 if n < 3 else fibonacci(n - 1) + fibonacci(n - 2) 3 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Recursion 2 - Fibonacci/(7 kyu) Recursion 2 - Fibonacci.rs: -------------------------------------------------------------------------------- 1 | fn fibonacci(n: u32) -> u32 { 2 | match n { 3 | 0...2 => 1, 4 | _ => fibonacci(n - 1) + fibonacci(n - 2), 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Recursion 2 - Fibonacci/(7 kyu) Recursion 2 - Fibonacci.ts: -------------------------------------------------------------------------------- 1 | export function fibonacci(n: number): number { 2 | if (n < 3) { 3 | return 1; 4 | } else { 5 | return fibonacci(n - 1) + fibonacci(n - 2); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public static class Kata 5 | { 6 | public static string RemoveDuplicateWords(string s) { 7 | return String.Join(" ", s.Split(' ').Distinct()); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func RemoveDuplicateWords(str string) string { 6 | words := strings.Split(str, " ") 7 | res := "" 8 | 9 | for _, w := range words { 10 | if !strings.Contains(res, w) { 11 | res = res + " " + w 12 | } 13 | } 14 | 15 | return res 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function removeDuplicateWords(s) { 3 | // let cleanArr = []; 4 | // s.split(' ').forEach((current) => { 5 | // if (!cleanArr.includes(current)) { 6 | // cleanArr.push(current); 7 | // } 8 | // }); 9 | // return cleanArr.join(' '); 10 | // } 11 | // #2 12 | // function removeDuplicateWords(s) { 13 | // return s 14 | // .split(' ') 15 | // .filter((el, index, arr) => arr.indexOf(el) == index) 16 | // .join(' '); 17 | // } 18 | // #3 19 | const removeDuplicateWords = (s) => [...new Set(s.split` `)].join` `; 20 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.md: -------------------------------------------------------------------------------- 1 | # Remove duplicate words (7 kyu) 2 | 3 | http://www.codewars.com/kata/remove-duplicate-words 4 | 5 | Your task is to remove all duplicate words from string, leaving only single words entries. 6 | 7 | Input: `'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'` 8 | 9 | Output: `'alpha beta gamma delta'` 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.py: -------------------------------------------------------------------------------- 1 | # #1 py 3.4.3 2 | # from collections import OrderedDict 3 | # def remove_duplicate_words(s): 4 | # str = s.split(' ') 5 | # return ' '.join(list(OrderedDict((x, True) for x in str).keys())) 6 | #2 py 3.6.0 7 | def remove_duplicate_words(s): 8 | return ' '.join(dict.fromkeys(s.split())) 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Remove duplicate words/(7 kyu) Remove duplicate words.ts: -------------------------------------------------------------------------------- 1 | export function removeDuplicateWords(s: string): string { 2 | return s 3 | .split(' ') 4 | .filter((el, index, arr) => arr.indexOf(el) == index) 5 | .join(' '); 6 | } 7 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static string ReverseWords(string str) 6 | { 7 | string[] words = str.Split(' '); 8 | string result = String.Empty; 9 | foreach(string w in words) { 10 | char[] array = w.ToCharArray(); 11 | Array.Reverse(array); 12 | result = String.Concat(result, new string(array), " "); 13 | } 14 | return result.Trim(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func ReverseWords(str string) string { 6 | words := strings.Split(str, " ") 7 | res := "" 8 | for _, w := range words { 9 | r := "" 10 | for _, s := range w { 11 | r = string(s) + r 12 | } 13 | res = res + " " + r 14 | } 15 | return res[1:] 16 | } 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function reverseWords(str) { 3 | // const spaces = str.match(/\s+/g); 4 | // const space = spaces ? spaces[0] : ''; 5 | // const words = str.split(/\s+/g); 6 | 7 | // return words.map((x) => x.split``.reverse().join``).join(space); 8 | // } 9 | // #2 10 | // function reverseWords(str) { 11 | // return str.split` `.map((w) => w.split``.reverse().join``).join` `; 12 | // } 13 | // #3 14 | const reverseWords = (str) => 15 | str.split` `.map((w) => w.split``.reverse().join``).join` `; 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.md: -------------------------------------------------------------------------------- 1 | # Reverse words (7 kyu) 2 | 3 | https://www.codewars.com/kata/reverse-words 4 | 5 | Complete the function that accepts a string parameter, and reverses each word in the string. All spaces in the string should be retained. 6 | 7 | ### Examples 8 | 9 | ``` 10 | "This is an example!" ==> "sihT si na !elpmaxe" 11 | "double spaces" ==> "elbuod secaps" 12 | ``` 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def reverse_words(text): 3 | # words = text.split(" ") 4 | # result = [] 5 | # for w in words: 6 | # result.append(w[::-1]) 7 | # return " ".join(result) 8 | 9 | # #2 10 | 11 | 12 | def reverse_words(text): 13 | return " ".join(text[::-1].split(" ")[::-1]) 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.rs: -------------------------------------------------------------------------------- 1 | fn reverse_words(str: &str) -> String { 2 | let words = str.split(" ").collect::>(); 3 | let mut res = "".to_string(); 4 | for w in words { 5 | let mut x = w.to_string(); 6 | x += " "; 7 | x = x.chars().rev().collect(); 8 | res.push_str(&x); 9 | } 10 | res[1..].to_string() 11 | } 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Reverse words/(7 kyu) Reverse words.ts: -------------------------------------------------------------------------------- 1 | export function reverseWords(str: string): string { 2 | return str 3 | .split(' ') 4 | .map( 5 | (w: string): string => 6 | w 7 | .split('') 8 | .reverse() 9 | .join(''), 10 | ) 11 | .join(' '); 12 | } 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.cs: -------------------------------------------------------------------------------- 1 | // #1 Plain Solution 2 | public class Kata 3 | { 4 | public static int FindShort(string s) 5 | { 6 | string[] words = s.Split(' '); 7 | int min = s.Length; 8 | foreach (string word in words) 9 | { 10 | min = word.Length < min ? word.Length : min; 11 | } 12 | return min; 13 | } 14 | } 15 | 16 | // #2 Optimized solution 17 | using System.Linq; 18 | 19 | public class Kata 20 | { 21 | public static int FindShort(string s) 22 | { 23 | return s.Split(' ').Min(x => x.Length); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func FindShort(s string) int { 6 | maxLen := len(s) 7 | words := strings.Fields(s) 8 | for _, word := range(words) { 9 | if len(word) <= maxLen { 10 | maxLen = len(word) 11 | } 12 | } 13 | 14 | return maxLen 15 | } 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function findShort(s) { 3 | // const arr = s.split(' '); 4 | // let smallest = arr[0]; 5 | // for (let i = 0; i < arr.length; i++) { 6 | // if (arr[i].length < smallest.length) { 7 | // smallest = arr[i]; 8 | // } 9 | // } 10 | // return smallest.length; 11 | // } 12 | // #2 13 | // const findShort = (s) => 14 | // s 15 | // .split(' ') 16 | // .sort((a, b) => b.length - a.length) 17 | // .pop().length; 18 | // #3 19 | const findShort = (s) => Math.min(...s.split` `.map((w) => w.length)); 20 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.md: -------------------------------------------------------------------------------- 1 | # Shortest Word (7 kyu) 2 | 3 | https://www.codewars.com/kata/shortest-word/ 4 | 5 | Simple, given a string of words, return the length of the shortest word(s). 6 | 7 | String will never be empty and you do not need to account for different data types. 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def find_short(s): 3 | # lengths = [] 4 | # for word in s.split(" "): 5 | # lengths.append(len(word)) 6 | # return min(lengths) 7 | # #2 8 | def find_short(s): 9 | return min(len(x) for x in s.split()) -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn find_short(s: &str) -> u32 { 3 | // let words = s.split(" ").collect::>(); 4 | // let mut min = ::max_value(); 5 | // for w in words { 6 | // if w.len() < min { 7 | // min = w.len() 8 | // } 9 | // } 10 | // min as u32 11 | // } 12 | // #2 13 | // fn find_short(s: &str) -> u32 { 14 | // s 15 | // .split_whitespace() 16 | // .min_by_key(|s| s.len()) 17 | // .unwrap() 18 | // .len() as u32 19 | // } 20 | // #3 21 | fn find_short(s: &str) -> usize { 22 | s.split_whitespace().map(str::len).min().unwrap() 23 | } 24 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Shortest Word/(7 kyu) Shortest Word.ts: -------------------------------------------------------------------------------- 1 | export function findShort(s: string): number { 2 | return Math.min(...s.split(' ').map((w) => w.length)); 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.cpp: -------------------------------------------------------------------------------- 1 | unsigned int countRedBeads(unsigned int n) 2 | { 3 | return n < 2 ? 0 : (n - 1) * 2; 4 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static int CountRedBeads(int n) 6 | { 7 | return n > 0 ? (n - 1) * 2 : 0; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func CountRedBeads(n int) int { 4 | if n < 2 { 5 | return 0 6 | } else { 7 | return (n - 1) * 2 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function countRedBeads(n) { 3 | // if (n < 2) { 4 | // return 0; 5 | // } else { 6 | // return (n - 1) * 2; 7 | // } 8 | // } 9 | // #2 10 | // function countRedBeads(n) { 11 | // return n < 2 ? 0 : (n - 1) * 2; 12 | // } 13 | // #3 14 | // const countRedBeads = (n) => (n < 2 ? 0 : (n - 1) * 2); 15 | // #4 16 | // const countRedBeads = (n) => ((n || 1) - 1) * 2; 17 | // #5 18 | // maximum value -> two for every two beads times number of blue beads - 1 19 | const countRedBeads = (n) => Math.max(0, (n - 1) * 2); 20 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.md: -------------------------------------------------------------------------------- 1 | # Simple beads count (7 kyu) 2 | 3 | https://www.codewars.com/kata/simple-beads-count 4 | 5 | Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads. 6 | 7 | **@** @@ **@** @@ **@** @@ **@** @@ **@** @@ **@** 8 | 9 | Implement `count_red_beads(n)` (in PHP `count_red_beads($n)`; in Java, Javascript, C, C++ `countRedBeads(n)`) so that it returns the number of _red_ beads. 10 | If there are less than 2 blue beads return 0. 11 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def count_red_beads(n): 3 | # return 0 if n < 2 else (n - 1) * 2 4 | 5 | 6 | def count_red_beads(n): # 2 7 | return max(0, 2 * (n-1)) 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn count_red_beads(n: u32) -> u32 { 3 | // match n { 4 | // 0...1 => 0, 5 | // _ => (n - 1) * 2, 6 | // } 7 | // } 8 | // #2 9 | fn count_red_beads(n: u32) -> u32 { 10 | 2 * n.checked_sub(1).unwrap_or(0) 11 | } 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Simple beads count/(7 kyu) Simple beads count.ts: -------------------------------------------------------------------------------- 1 | export function countRedBeads(n: number): number { 2 | return n < 2 ? 0 : (n - 1) * 2; 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Kata 4 | { 5 | public static int[] SortNumbers(int[] nums) 6 | { 7 | if(nums == null) 8 | nums = new int[0]; 9 | 10 | Array.Sort(nums); 11 | return nums; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "sort" 4 | 5 | func SortNumbers(numbers []int) []int { 6 | sort.Ints(numbers) 7 | return numbers 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.java: -------------------------------------------------------------------------------- 1 | import java.util.stream.*; 2 | 3 | public class Kata { 4 | public static int[] solution(final int[] nums) { 5 | if (nums == null || nums.length == 0) return new int[0]; 6 | return IntStream.of(nums).sorted().toArray(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function solution(nums) { 3 | // if (nums) { 4 | // return nums.sort((a, b) => a - b); 5 | // } else { 6 | // return []; 7 | // } 8 | // } 9 | // #2 10 | // function solution(nums) { 11 | // return nums ? nums.sort((a, b) => a - b) : []; 12 | // } 13 | // #3 14 | // const solution = (nums) => (nums ? nums.sort((a, b) => a - b) : []); 15 | // #4 16 | const solution = (nums) => (nums || []).sort((a, b) => a - b); 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.md: -------------------------------------------------------------------------------- 1 | # Sort Numbers (7 kyu) 2 | 3 | https://www.codewars.com/kata/sort-numbers/ 4 | 5 | Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array. 6 | 7 | For example: 8 | 9 | ```rust 10 | sort_numbers(&vec![1, 2, 3, 10, 5]); // should return vec![1, 2, 3, 5, 10] 11 | sort_numbers(&vec![]); // should return !vec[] 12 | ``` 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.py: -------------------------------------------------------------------------------- 1 | # #1 2 | def solution(nums): 3 | return [] if not nums else sorted(nums) 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | fn sort_numbers(arr: &Vec) -> Vec { 3 | let mut res = arr.clone(); 4 | res.sort(); 5 | res 6 | } 7 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sort Numbers/(7 kyu) Sort Numbers.ts: -------------------------------------------------------------------------------- 1 | export function solution(nums: number[]): number[] { 2 | return nums ? nums.sort((a, b) => a - b) : []; 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | bool solution(std::string const &str, std::string const &ending) 7 | { 8 | if (str.length() >= ending.length()) 9 | { 10 | return (0 == str.compare(str.length() - ending.length(), ending.length(), ending)); 11 | } 12 | else 13 | { 14 | return false; 15 | } 16 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.cs: -------------------------------------------------------------------------------- 1 | public class Kata 2 | { 3 | public static bool Solution(string str, string ending) 4 | { 5 | return str.EndsWith(ending); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func solution(str, ending string) bool { 6 | return strings.HasSuffix(str, ending) 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.java: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | public class Kata { 3 | public static boolean solution(String str, String ending) { 4 | return str.length() >= ending.length() 5 | ? str.substring(str.length() - ending.length()).equals(ending) 6 | : false; 7 | } 8 | } 9 | 10 | // 2 Clever solution 11 | public class Kata { 12 | public static boolean solution(String str, String ending) { 13 | return str.endsWith(ending); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function solution(str, ending) { 3 | // const result = str.substr(str.length - ending.length, str.length); 4 | // return ending === result; 5 | // } 6 | // #2 7 | // function solution(str, ending) { 8 | // return ending === str.substr(-ending.length); 9 | // } 10 | // #3 11 | const solution = (str, ending) => str.endsWith(ending); 12 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.md: -------------------------------------------------------------------------------- 1 | # String ends with (7 kyu) 2 | 3 | https://www.codewars.com/kata/string-ends-with/ 4 | 5 | Complete the solution so that it returns true if the first argument(string) passed in ends with the 2nd argument (also a string). 6 | 7 | Examples: 8 | 9 | ```rust 10 | solution("abc", "bc") //returns true 11 | solution("abc", "d") //returns false 12 | ``` 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.py: -------------------------------------------------------------------------------- 1 | def solution(string, ending): 2 | return string.endswith(ending) 3 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.rs: -------------------------------------------------------------------------------- 1 | fn solution(word: &str, ending: &str) -> bool { 2 | word.ends_with(ending) 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) String ends with/(7 kyu) String ends with.ts: -------------------------------------------------------------------------------- 1 | export function solution(str: string, ending: string): boolean { 2 | return str.substr(-ending.length) === ending; 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sum of odd numbers/(7 kyu) Sum of odd numbers.js: -------------------------------------------------------------------------------- 1 | function rowSumOddNumbers(n) { 2 | return Math.pow(n, 3); 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Sum of odd numbers/(7 kyu) Sum of odd numbers.md: -------------------------------------------------------------------------------- 1 | # Sum of odd numbers 2 | 3 | https://www.codewars.com/kata/55fd2d567d94ac3bc9000064 4 | 5 | Given the triangle of consecutive odd numbers: 6 | 7 | ``` 8 | 1 9 | 3 5 10 | 7 9 11 11 | 13 15 17 19 12 | 21 23 25 27 29 13 | ... 14 | ``` 15 | 16 | Calculate the sum of the numbers in the nth row of this triangle (starting at index 1) e.g.: (Input --> Output) 17 | 18 | ``` 19 | 1 --> 1 20 | 2 --> 3 + 5 = 8 21 | ``` 22 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | std::string repeater(std::string str, int n) 7 | { 8 | std::string res; 9 | for (int i = 0; i < n; i++) 10 | res += str; 11 | return res; 12 | } -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | public class Kata 4 | { 5 | public static string Repeater(string s, int n) 6 | { 7 | return string.Concat(Enumerable.Repeat(s, n)); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func Repeater(s string, n int) string { 6 | return strings.Repeat(s, n) 7 | } 8 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.js: -------------------------------------------------------------------------------- 1 | //#1 2 | // function repeater(string, n) { 3 | // var res = ''; 4 | // while (n > 0) { 5 | // res += string; 6 | // n--; 7 | // } 8 | // return res; 9 | // } 10 | // #2 11 | // function repeater(string, n) { 12 | // return new Array(n + 1).join(string); 13 | // } 14 | const repeater = (string, n) => string.repeat(n); 15 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.md: -------------------------------------------------------------------------------- 1 | # Thinkful - String Drills. Repeater (7 kyu) 2 | 3 | https://www.codewars.com/kata/thinkful-string-drills-repeater/ 4 | 5 | Write a class function named `repeat()` that takes two arguments (a string and a long integer), and returns a new string where the input string is repeated that many times. For example: 6 | 7 | ```js 8 | Repeater.repeat('a', 5); 9 | ``` 10 | 11 | should return 12 | 13 | ```js 14 | 'aaaaa'; 15 | ``` 16 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.py: -------------------------------------------------------------------------------- 1 | def repeater(string, n): 2 | return string * n 3 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.rs: -------------------------------------------------------------------------------- 1 | fn repeater(string: &str, n: u32) -> String { 2 | string.repeat(n as usize) 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Thinkful - String Drills. Repeater/(7 kyu) Thinkful - String Drills. Repeater.ts: -------------------------------------------------------------------------------- 1 | export function repeater(str: string, n: number): string { 2 | return new Array(n + 1).join(str); 3 | } 4 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class TwoToOne 6 | { 7 | public: 8 | static string longest(const string &s1, const string &s2) 9 | { 10 | string word = s1 + s2; 11 | sort(word.begin(), word.end()); 12 | auto ip = unique(word.begin(), word.end()); 13 | return string(word.begin(), ip); 14 | }; 15 | }; -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import ( 4 | "strings" 5 | "sort" 6 | ) 7 | 8 | func TwoToOne(s1 string, s2 string) string { 9 | str := s1 + s2 10 | s := strings.Split(str, "") 11 | sort.Strings(s) 12 | 13 | keys := make(map[string]bool) 14 | list := []string{} 15 | for _, entry := range s { 16 | if _, value := keys[entry]; !value { 17 | keys[entry] = true 18 | list = append(list, entry) 19 | } 20 | } 21 | 22 | return strings.Join(list, "") 23 | } 24 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function longest(s1, s2) { 3 | // let res = s1 + s2; 4 | // res = res.split(''); 5 | // res = [...new Set(res)]; 6 | // res = res.sort(); 7 | // return res.join(''); 8 | // } 9 | // #2 10 | // const longest = (s1, s2) => [...new Set([...(s1 + s2)])].sort().join(''); 11 | // #3 12 | const longest = (s1, s2) => [...new Set(s1 + s2)].sort().join``; 13 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.md: -------------------------------------------------------------------------------- 1 | # Two to One (7 kyu) 2 | 3 | https://www.codewars.com/kata/two-to-one/ 4 | 5 | Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, each taken only once - coming from s1 or s2. 6 | 7 | ## Examples: 8 | 9 | ```js 10 | a = "xyaabbbccccdefww" 11 | b = "xxxxyyyyabklmopq" 12 | longest(a, b) -> "abcdefklmopqwxy" 13 | 14 | a = "abcdefghijklmnopqrstuvwxyz" 15 | longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" 16 | ``` 17 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def longest(s1, s2): 3 | # res = s1 + s2 4 | # res = list(res) 5 | # res = dict.fromkeys(res) 6 | # res = sorted(res) 7 | # res = ''.join(res) 8 | # return res 9 | # #2 10 | # def longest(s1, s2): 11 | # return ''.join(sorted(dict.fromkeys(s1 + s2))) 12 | 13 | # #3 14 | 15 | 16 | def longest(s1, s2): 17 | return ''.join(sorted((set(s1 + s2)))) 18 | -------------------------------------------------------------------------------- /7kyu/(7 kyu) Two to One/(7 kyu) Two to One.ts: -------------------------------------------------------------------------------- 1 | export class G964 { 2 | public static longest = (s1, s2) => { 3 | let res = s1 + s2; 4 | res = res.split(''); 5 | res = [...new Set(res)]; 6 | res = res.sort(); 7 | return res.join(''); 8 | }; 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.cs: -------------------------------------------------------------------------------- 1 | public class Kata 2 | { 3 | public static string AbbrevName(string name) 4 | { 5 | string[] words = name.Split(' '); 6 | string res = ""; 7 | res += words[0][0]; 8 | res += '.'; 9 | res += words[1][0]; 10 | return res.ToUpper(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func AbbrevName(name string) string{ 6 | words := strings.Split(name, " ") 7 | res := "" 8 | res += string(words[0][0]) 9 | res += "." 10 | res += string(words[1][0]) 11 | return strings.ToUpper(res) 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.java: -------------------------------------------------------------------------------- 1 | public class AbbreviateTwoWords { 2 | 3 | public static String abbrevName(String name) { 4 | String[] fullName = name.split(" "); 5 | String firstname = fullName[0]; 6 | String lastname = fullName[1]; 7 | return (firstname.charAt(0) + "." + lastname.charAt(0)).toUpperCase(); 8 | } 9 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.md: -------------------------------------------------------------------------------- 1 | # Abbreviate a Two Word Name (8 kyu) 2 | 3 | https://www.codewars.com/kata/abbreviate-a-two-word-name 4 | 5 | Write a function to convert a name into initials. This kata strictly takes two words with one space in between them. 6 | 7 | The output should be two capital letters with a dot seperating them. 8 | 9 | It should look like this: 10 | 11 | ``` 12 | Sam Harris => S.H 13 | Patrick Feeney => P.F 14 | ``` 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.py: -------------------------------------------------------------------------------- 1 | def abbrevName(name): 2 | # #1 3 | # return ".".join(list(map(lambda c: c[0].upper(), name.split(" ")))) 4 | #2 5 | return ".".join(w[0] for w in name.split()).upper() -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.rs: -------------------------------------------------------------------------------- 1 | fn abbrev_name(name: &str) -> String { 2 | let mut result = String::new(); 3 | let arr: Vec<&str> = name.split_whitespace().collect(); 4 | 5 | result.push_str(&arr[0][..1].to_uppercase()); 6 | result.push_str("."); 7 | result.push_str(&arr[1][..1].to_uppercase()); 8 | 9 | result 10 | } 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Abbreviate a Two Word Name/(8 kyu) Abbreviate a Two Word Name.ts: -------------------------------------------------------------------------------- 1 | export function abbrevName(name: string): string { 2 | return name 3 | .split(' ') 4 | .map((s) => s[0].toUpperCase()) 5 | .join('.'); 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Area or Perimeter/(8 kyu) Area or Perimeter.dart: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | int area_or_perimeter(int l, int w) { 3 | if (l == w) { 4 | return l * w; 5 | } else { 6 | return l * 2 + w * 2; 7 | } 8 | } 9 | 10 | // 2 Optimized solution 11 | int area_or_perimeter(int l, int w) => l == w ? l * w : l * 2 + w * 2; 12 | 13 | // 3 Clever solution 14 | int area_or_perimeter(int l, int w) => l == w ? l * w : (l + w) * 2; 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Area or Perimeter/(8 kyu) Area or Perimeter.js: -------------------------------------------------------------------------------- 1 | // 1 Plain Solution 2 | const areaOrPerimeter = function (l, w) { 3 | const isSquare = l === w; 4 | 5 | if (isSquare) { 6 | return l * w; 7 | } else { 8 | return l * 2 + w * 2; 9 | } 10 | }; 11 | // 2 Optimized solution 12 | const areaOrPerimeter = function (l, w) { 13 | return l === w 14 | ? l * w 15 | : l * 2 + w * 2; 16 | }; 17 | // 3 Coding golf 18 | const areaOrPerimeter = (l, w) => 19 | l === w 20 | ? l * w 21 | : 2 * (l + w); 22 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Area or Perimeter/(8 kyu) Area or Perimeter.md: -------------------------------------------------------------------------------- 1 | # Area or Perimeter (8 kuy) 2 | 3 | https://www.codewars.com/kata/5ab6538b379d20ad880000ab/ 4 | 5 | You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square. 6 | If it is a square, return its area. If it is a rectangle, return its perimeter. 7 | 8 | ``` 9 | area_or_perimeter(6, 10) --> 32 10 | area_or_perimeter(3, 3) --> 9 11 | ``` 12 | 13 | Note: for the purposes of this kata you will assume that it is a square if its length and width are equal, otherwise it is a rectangle. 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Area or Perimeter/(8 kyu) Area or Perimeter.py: -------------------------------------------------------------------------------- 1 | def area_or_perimeter(l , w): 2 | isSquare = l == w; 3 | 4 | if isSquare: 5 | return l * w; 6 | else: 7 | return l * 2 + w * 2; 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Area or Perimeter/(8 kyu) Area or Perimeter.ts: -------------------------------------------------------------------------------- 1 | // 1 Plain Solution 2 | export const areaOrPerimeter = (l: number, w: number): number => { 3 | const isSquare = l === w; 4 | 5 | if (isSquare) { 6 | return l * w; 7 | } else { 8 | return l * 2 + w * 2; 9 | } 10 | }; 11 | // 2 Optimized solution 12 | export const areaOrPerimeter = (l: number, w: number): number => { 13 | return l === w 14 | ? l * w 15 | : l * 2 + w * 2; 16 | }; 17 | // 3 Coding golf 18 | export const areaOrPerimeter = (l: number, w: number): number => 19 | l === w 20 | ? l * w 21 | : 2 * (l + w); 22 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Basic subclasses - Adam and Eve/(8 kyu) Basic subclasses - Adam and Eve.cs: -------------------------------------------------------------------------------- 1 | public class God 2 | { 3 | public static Human[] Create() 4 | { 5 | return new Human[]{new Man(), new Woman()}; 6 | } 7 | } 8 | 9 | public class Human { } 10 | public class Man : Human { } 11 | public class Woman : Human { } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Basic subclasses - Adam and Eve/(8 kyu) Basic subclasses - Adam and Eve.java: -------------------------------------------------------------------------------- 1 | public class God { 2 | public static Human[] create() { 3 | Human Adam = new Man(); 4 | Human Eve = new Woman(); 5 | return new Human[] { Adam, Eve }; 6 | } 7 | } 8 | 9 | class Human { 10 | public Human() { 11 | } 12 | } 13 | 14 | class Man extends Human { 15 | public Man() { 16 | } 17 | } 18 | 19 | class Woman extends Man { 20 | public Woman() { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Basic subclasses - Adam and Eve/(8 kyu) Basic subclasses - Adam and Eve.js: -------------------------------------------------------------------------------- 1 | class God { 2 | /** 3 | * @returns Human[] 4 | */ 5 | static create() { 6 | const Adam = new Man(); 7 | const Eve = new Woman(); 8 | return [Adam, Eve]; 9 | } 10 | } 11 | 12 | class Human { 13 | constructor() {} 14 | } 15 | 16 | class Man extends Human { 17 | constructor() { 18 | super(); 19 | } 20 | } 21 | 22 | class Woman extends Human { 23 | constructor() { 24 | super(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Basic subclasses - Adam and Eve/(8 kyu) Basic subclasses - Adam and Eve.ts: -------------------------------------------------------------------------------- 1 | export class God { 2 | /** 3 | * @returns Human[] 4 | */ 5 | static create(): Human[] { 6 | const Adam = new Man(); 7 | const Eve = new Woman(); 8 | return [Adam, Eve]; 9 | } 10 | } 11 | 12 | export class Human {} 13 | export class Woman extends Human {} 14 | export class Man extends Human {} 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Beginner - Lost Without a Map/(8 kyu) Beginner - Lost Without a Map.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Maps(x []int) []int { 4 | res := make([]int, len(x)) 5 | 6 | for i, y := range x { 7 | res[i] = y * 2 8 | } 9 | 10 | return res 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Beginner - Lost Without a Map/(8 kyu) Beginner - Lost Without a Map.js: -------------------------------------------------------------------------------- 1 | // 1 Plain Solution 2 | function maps(x) { 3 | const res = []; 4 | 5 | for (let i = 0; i < x.length; i++) { 6 | res[i] = x[i] * 2; 7 | } 8 | 9 | return res; 10 | } 11 | 12 | // 2 Optimized solution 13 | function maps(x) { 14 | const res = []; 15 | 16 | x.forEach((y, i) => res[i] = y * 2); 17 | 18 | return res; 19 | } 20 | 21 | // 3 Clever solution 22 | function maps(x) { 23 | return x.map(y => y * 2); 24 | } 25 | 26 | // 4 Coding golf 27 | const maps = x => x.map(y => y*2) 28 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Beginner - Lost Without a Map/(8 kyu) Beginner - Lost Without a Map.md: -------------------------------------------------------------------------------- 1 | # Beginner - Lost Without a Map (8 kyu) 2 | 3 | Given an array of integers, return a new array with each value doubled. 4 | 5 | For example: 6 | 7 | `[1, 2, 3] --> [2, 4, 6]` 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Beginner - Lost Without a Map/(8 kyu) Beginner - Lost Without a Map.ts: -------------------------------------------------------------------------------- 1 | export function maps(x: number[]): number[] { 2 | return x.map(y => y + y); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Bin to Decimal/(8 kyu) Bin to Decimal.md: -------------------------------------------------------------------------------- 1 | # Bin to Decimal 2 | 3 | https://www.codewars.com/kata/57a5c31ce298a7e6b7000334 4 | 5 | Complete the function which converts a binary number (given as a string) to a decimal number. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.cpp: -------------------------------------------------------------------------------- 1 | int centuryFromYear(int year) 2 | { 3 | return (year - 1) / 100 + 1; 4 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.cs: -------------------------------------------------------------------------------- 1 | public static class Kata 2 | { 3 | public static int СenturyFromYear(int year) 4 | { 5 | return (year - 1 ) / 100 + 1; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func century(year int) int { 4 | return (year - 1) / 100 + 1 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.java: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | public class Solution { 3 | public static int century(int number) { 4 | return number % 100 == 0 5 | ? number / 100 6 | : (number / 100) + 1; 7 | } 8 | } 9 | 10 | // 2 Optimized solution 11 | public class Solution { 12 | public static int century(int year) { 13 | return (year + 99) / 100; 14 | } 15 | } 16 | 17 | // 3 Clever solution 18 | public class Solution { 19 | public static int century(int number) { 20 | return (int) Math.ceil((double) number / 100); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // const century = (year) => Math.floor(year / 100) + (year % 100 ? 1 : 0); 3 | // #2 4 | // const century = (year) => Math.ceil(year / 100); 5 | // #3 6 | // Bitwise OR a | b 7 | // Returns a 1 in each bit position for which 8 | // the corresponding bits of either or both operands are 1s. 9 | const century = (year) => ((year + 99) / 100) | 0; 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.py: -------------------------------------------------------------------------------- 1 | def century(year): 2 | return year // 100 + (0 if year % 100 == 0 else 1) 3 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn century(year: u32) -> u32 { 3 | // year / 100 + if year % 100 == 0 { 0 } else { 1 } 4 | // } 5 | // #2 6 | fn century(year: u32) -> u32 { 7 | (year - 1) / 100 + 1 8 | } 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Century From Year/(8 kyu) Century From Year.ts: -------------------------------------------------------------------------------- 1 | export const centuryFromYear = (year: number): number => { 2 | return Math.ceil(year / 100); 3 | }; 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert a Boolean to a String/(8 kyu) Convert a Boolean to a String.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function booleanToString(b) { 3 | if (b === true) { 4 | return "true"; 5 | } else { 6 | return "false"; 7 | } 8 | } 9 | 10 | // 2 Optimized solution 11 | function booleanToString(b) { 12 | return b 13 | ? "true" 14 | : "false"; 15 | } 16 | 17 | // 3 Clever solution 18 | const booleanToString = b => b.toString(); 19 | 20 | // 4 Coding golf 21 | booleanToString=b=>`${b}` 22 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert a Boolean to a String/(8 kyu) Convert a Boolean to a String.md: -------------------------------------------------------------------------------- 1 | # Convert a Boolean to a String (8 kyu) 2 | 3 | https://www.codewars.com/kata/551b4501ac0447318f0009cd 4 | 5 | Implement a function which convert the given boolean value into its string representation. 6 | 7 | Note: Only valid inputs will be given. 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert a string to an array/(8 kuy) Convert a string to an array.md: -------------------------------------------------------------------------------- 1 | Write a function to split a string and convert it into an array of words. For example: 2 | 3 | ```js 4 | "Robin Singh" ==> ["Robin", "Singh"] 5 | 6 | "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] 7 | ``` 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert boolean values to strings Yes or No/(8 kyu) Convert boolean values to strings Yes or No.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function boolToWord (bool) { 3 | if (bool === true) { 4 | return "Yes"; 5 | } else { 6 | return "No"; 7 | } 8 | } 9 | 10 | // 2 Optimized solution 11 | function boolToWord (bool) { 12 | return bool ? "Yes" : "No" 13 | } 14 | 15 | // 3 Clever solution 16 | const boolToWord = b => ["No", "Yes"][+b] -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert boolean values to strings Yes or No/(8 kyu) Convert boolean values to strings Yes or No.md: -------------------------------------------------------------------------------- 1 | # Convert boolean values to strings 'Yes' or 'No'. (8 kyu) 2 | 3 | https://www.codewars.com/kata/53369039d7ab3ac506000467 4 | 5 | Complete the method that takes a boolean value and return a `"Yes"` string for `true`, or a `"No"` string for `false`. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert number to reversed array of digits/(8 kyu) Convert number to reversed array of digits.md: -------------------------------------------------------------------------------- 1 | # Convert number to reversed array of digits (8 kyu) 2 | 3 | https://www.codewars.com/kata/5583090cbe83f4fd8c000051 4 | 5 | Given a random non-negative number, you have to return the digits of this number within an array in reverse order. 6 | 7 | Example: 8 | 9 | ``` 10 | 348597 => [7,9,5,8,4,3] 11 | 0 => [0] 12 | ``` 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Convert number to reversed array of digits/(8 kyu) Convert number to reversed array of digits.ts: -------------------------------------------------------------------------------- 1 | export const digitize = (n: number): number[] => { 2 | const res: number[] = []; 3 | const str = [...String(n)]; 4 | str.forEach(x => res.unshift(+x)); 5 | return res; 6 | }; 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Count Odd Numbers below n/(8 kyu) Count Odd Numbers below n.js: -------------------------------------------------------------------------------- 1 | // 1 Strightforward solution 2 | function oddCount(n) { 3 | return Math.floor(n / 2); 4 | } 5 | 6 | // 2 Optimized solution 7 | function oddCount(n) { 8 | return parseInt(n / 2); 9 | } 10 | 11 | // 3 Coding golf 12 | const oddCount = n => parseInt(n / 2) 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Count Odd Numbers below n/(8 kyu) Count Odd Numbers below n.md: -------------------------------------------------------------------------------- 1 | # Count Odd Numbers below n (8 kyu) 2 | 3 | https://www.codewars.com/kata/59342039eb450e39970000a6 4 | 5 | Given a number `n`, return the number of positive odd numbers below n, EASY! 6 | 7 | ```js 8 | oddCount(7) //=> 3, i.e [1, 3, 5] 9 | oddCount(15) //=> 7, i.e [1, 3, 5, 7, 9, 11, 13] 10 | ``` 11 | 12 | Expect large Inputs! 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Count of positives - sum of negatives/(8 kyu) Count of positives - sum of negatives.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func CountPositivesSumNegatives(input []int) []int { 4 | res := []int{0, 0} 5 | 6 | for i := 0; i < len(input); i++ { 7 | if input[i] > 0 { 8 | res[0]++ 9 | } else { 10 | res[1] += input[i] 11 | } 12 | } 13 | 14 | return res 15 | } 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Count of positives - sum of negatives/(8 kyu) Count of positives - sum of negatives.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def count_positives_sum_negatives(arr): 3 | # if len(arr) == 0: 4 | # return [] 5 | # res = [0, 0] 6 | # for x in arr: 7 | # if x > 0: 8 | # res[0] += 1 9 | # else: 10 | # res[1] += x 11 | # return res 12 | # #2 13 | def count_positives_sum_negatives(arr): 14 | pos = sum(1 for x in arr if x > 0) 15 | neg = sum(x for x in arr if x < 0) 16 | return [pos, neg] if len(arr) else [] 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Count of positives - sum of negatives/(8 kyu) Count of positives - sum of negatives.ts: -------------------------------------------------------------------------------- 1 | export function countPositivesSumNegatives(input: any) { 2 | return input && input.length 3 | ? [ 4 | input.filter((p: number) => p > 0).length, 5 | input 6 | .filter((n: number) => n < 0) 7 | .reduce((a: number, b: number) => a + b, 0), 8 | ] 9 | : []; 10 | } 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // #1 5 | // int count_sheep(vector arr) 6 | // { 7 | // int res = 0; 8 | // for (auto i : arr) 9 | // { 10 | // if (i) 11 | // res++; 12 | // } 13 | // return res; 14 | // } 15 | 16 | // #2 17 | #include 18 | int count_sheep(std::vector arr) 19 | { 20 | return std::count(arr.begin(), arr.end(), true); 21 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static int CountSheeps(bool[] sheeps) 6 | { 7 | int res = 0; 8 | for (int i = 0; i < sheeps.Length; i++) 9 | { 10 | if (sheeps[i] == true) 11 | { 12 | res++; 13 | } 14 | } 15 | return res; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func CountSheeps(arrayOfSheep []bool) int { 4 | var res int 5 | 6 | for i := 0; i < len(arrayOfSheep); i++ { 7 | if arrayOfSheep[i] == true { 8 | res += 1 9 | } 10 | } 11 | 12 | return res 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function countSheeps(arrayOfSheep) { 3 | // return arrayOfSheep.filter((x) => x === true).length; 4 | // } 5 | // #2 6 | // const countSheeps = (arrayOfSheep) => arrayOfSheep.filter((x) => x).length; 7 | // #3 8 | const countSheeps = (arrayOfSheep) => arrayOfSheep.filter(Boolean).length; 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def count_sheeps(arrayOfSheeps): 3 | # return len([x for x in arrayOfSheeps if x is True]) 4 | # #2 5 | # def count_sheeps(arrayOfSheeps): 6 | # return len([x for x in arrayOfSheeps if x]) 7 | # #3 8 | def count_sheeps(arrayOfSheeps): 9 | return arrayOfSheeps.count(True) 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn count_sheep(sheep: &[bool]) -> u8 { 3 | // sheep.into_iter().filter(|&&x| x).collect::>().len() as u8 4 | // } 5 | // #2 6 | fn count_sheep(sheep: &[bool]) -> u8 { 7 | sheep.iter().filter(|&&x| x).count() as u8 8 | } 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Counting sheep/(8 kyu) Counting sheep.ts: -------------------------------------------------------------------------------- 1 | export function countSheeps(arrayOfSheep: boolean[]): number { 2 | return arrayOfSheep.filter((x) => x === true).length; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // #1 5 | // std::string DNAtoRNA(std::string dna) 6 | // { 7 | // std::regex e("T"); 8 | // std::string result; 9 | // std::regex_replace(std::back_inserter(result), 10 | // dna.begin(), dna.end(), e, "U"); 11 | // return result; 12 | // } 13 | 14 | // #2 15 | std::string DNAtoRNA(std::string dna) 16 | { 17 | std::replace(dna.begin(), dna.end(), 'T', 'U'); 18 | return dna; 19 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.cs: -------------------------------------------------------------------------------- 1 | namespace Converter { 2 | public class Converter 3 | { 4 | public string dnaToRna(string dna) 5 | { 6 | return dna.Replace("T", "U"); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func DNAtoRNA(dna string) string { 6 | return strings.Replace(dna, "T", "U", -1) 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function DNAtoRNA(dna) { 3 | // return dna.replace(/T/g, 'U') 4 | // } 5 | // #2 6 | const DNAtoRNA = (dna) => dna.replace(/T/g, 'U'); 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def DNAtoRNA(dna): 3 | # return dna.replace("T", "U") 4 | #2 5 | DNAtoRNA = lambda d: d.replace("T", "U") 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.rs: -------------------------------------------------------------------------------- 1 | fn dna_to_rna(dna: &str) -> String { 2 | // #1 3 | // dna.chars() 4 | // .map(|x| match x { 5 | // 'T' => 'U', 6 | // _ => x, 7 | // }) 8 | // .collect() 9 | // #2 10 | str::replace(dna, "T", "U") 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) DNA to RNA Conversion/(8 kyu) DNA to RNA Conversion.ts: -------------------------------------------------------------------------------- 1 | export function DNAtoRNA(dna: string): string { 2 | return dna.replace(/T/g, 'U'); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::string even_or_odd(int number) 4 | { 5 | return (number % 2) 6 | ? "Odd" 7 | : "Even"; 8 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Solution 4 | { 5 | public class SolutionClass 6 | { 7 | public static string EvenOrOdd(int number) 8 | { 9 | return number % 2 == 0 ? "Even":"Odd"; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func EvenOrOdd(number int) string { 4 | if number % 2 == 0 { 5 | return "Even" 6 | } else { 7 | return "Odd" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.java: -------------------------------------------------------------------------------- 1 | // #1 2 | public class EvenOrOdd { 3 | public static String even_or_odd(int number) { 4 | if (number % 2 == 0) { 5 | return "Even"; 6 | } else { 7 | return "Odd"; 8 | } 9 | } 10 | } 11 | 12 | // #2 13 | public class EvenOrOdd { 14 | public static String even_or_odd(int number) { 15 | return number % 2 == 0 ? "Even" : "Odd"; 16 | } 17 | } 18 | 19 | // #3 20 | public class EvenOrOdd { 21 | public static String even_or_odd(int number) { 22 | return (number & 1) == 0 ? "Even" : "Odd"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // const even_or_odd = (number) => (number % 2 ? 'Odd' : 'Even'); 3 | // #2 4 | const even_or_odd = (n) => ['Even', 'Odd'][n & 1]; 5 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.md: -------------------------------------------------------------------------------- 1 | # Even or Odd (8 kyu) 2 | 3 | https://www.codewars.com/kata/even-or-odd 4 | 5 | Create a function that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.py: -------------------------------------------------------------------------------- 1 | def even_or_odd(number): 2 | # #1 3 | # if number % 2 == 0: 4 | # return "Even" 5 | # else: 6 | # return "Odd" 7 | # #2 8 | # return "Odd" if number % 2 else "Even" 9 | # #3 10 | return ("Odd", "Even")[number % 2] 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.rs: -------------------------------------------------------------------------------- 1 | fn even_or_odd(i: i32) -> &'static str { 2 | // #1 3 | // if i % 2 == 0 { 4 | // return "Even"; 5 | // } else { 6 | // return "Odd"; 7 | // } 8 | // #2 9 | // return if i % 2 == 0 { "Even" } else { "Odd" }; 10 | // #3 11 | // if i % 2 == 0 { "Even" } else { "Odd" } 12 | // #4 13 | if i & 1 == 0 { 14 | "Even" 15 | } else { 16 | "Odd" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Even or Odd/(8 kyu) Even or Odd.ts: -------------------------------------------------------------------------------- 1 | export function even_or_odd(n: number): String { 2 | return n % 2 ? 'Odd' : 'Even'; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Fake Binary/(8 kyu) Fake Binary.md: -------------------------------------------------------------------------------- 1 | # Fake Binary (8 kyu) 2 | 3 | Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string. 4 | 5 | **Note: input will never be an empty string** 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // #1 6 | // int findSmallest(vector list) 7 | // { 8 | // sort(list.begin(), list.end()); 9 | // return list[0]; 10 | // } 11 | 12 | // #2 13 | int findSmallest(vector list) 14 | { 15 | return *std::min_element(list.begin(), list.end()); 16 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | public class Kata 5 | { 6 | public static int FindSmallestInt(int[] args) 7 | { 8 | Array.Sort(args); 9 | 10 | return args[0]; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "sort" 4 | 5 | func SmallestIntegerFinder(numbers []int) int { 6 | sort.Ints(numbers) 7 | return numbers[0] 8 | } 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.js: -------------------------------------------------------------------------------- 1 | class SmallestIntegerFinder { 2 | // #1 3 | // findSmallestInt(args) { 4 | // return args.sort((a, b) => a - b)[0]; 5 | // } 6 | // #2 7 | findSmallestInt(args) { 8 | return Math.min(...args); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.md: -------------------------------------------------------------------------------- 1 | # (8 kyu) Find the smallest integer in the array 2 | 3 | https://www.codewars.com/kata/find-the-smallest-integer-in-the-array 4 | 5 | Given an array of integers your solution should find the smallest integer. 6 | 7 | For example: 8 | 9 | ``` 10 | Given [34, 15, 88, 2] your solution will return 2 11 | Given [34, -345, -1, 100] your solution will return -345 12 | ``` 13 | 14 | You can assume, for the purpose of this kata, that the supplied array will not be empty. 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def find_smallest_int(arr): 3 | # arr.sort() 4 | # return arr[0] 5 | # #2 6 | # def find_smallest_int(arr): 7 | # return min(arr) 8 | # #3 9 | findSmallestInt=min 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.rs: -------------------------------------------------------------------------------- 1 | fn find_smallest_int(arr: &[i32]) -> i32 { 2 | *arr.iter().min().unwrap() 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Find the smallest integer in the array/(8 kyu) Find the smallest integer in the array.ts: -------------------------------------------------------------------------------- 1 | export function findSmallestInt(args: number[]): number { 2 | return Math.min(...args); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.cpp: -------------------------------------------------------------------------------- 1 | int multiply(int x, int y) { 2 | return x * y; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Multiply(x int, y int) int { 4 | return x * y 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.java: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | public static int multiply(int x, int y) { 3 | return x * y; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function multiply(x, y) { 3 | return x * y; 4 | } 5 | 6 | // 2 Optimized solution 7 | const multiply = (x, y) => x * y; 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.md: -------------------------------------------------------------------------------- 1 | # Function 3 - multiplying two numbers (8 kyu) 2 | 3 | https://www.codewars.com/kata/523b66342d0c301ae400003b 4 | 5 | Implement a function which multiplies two numbers. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Function 3 - multiplying two numbers/(8 kyu) Function 3 - multiplying two numbers.ts: -------------------------------------------------------------------------------- 1 | export function multiply(x: number, y: number) { 2 | return x * y; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) How good are you really/(8 kyu) How good are you really.ts: -------------------------------------------------------------------------------- 1 | export function betterThanAverage(classPoints: number[], yourPoints: number): boolean { 2 | return yourPoints > classPoints.reduce((a, c) => a + c, 0) / classPoints.length; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | string countSheep(int number) 5 | { 6 | string ret = ""; 7 | for (int i = 1; i <= number; i++) 8 | { 9 | ret += (to_string(i) + " sheep..."); 10 | } 11 | return ret; 12 | }; -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static string CountSheep(int n) 6 | { 7 | string res = ""; 8 | 9 | for (int i = 1; i <= n; i++) 10 | { 11 | res += $"{i} sheep..."; 12 | } 13 | 14 | return res; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.go: -------------------------------------------------------------------------------- 1 | package kata 2 | import "fmt" 3 | 4 | func countSheep(num int) string { 5 | res := "" 6 | 7 | for i := 1; i <= num; i++ { 8 | res += fmt.Sprintf("%d sheep...", i) 9 | } 10 | 11 | return res 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.js: -------------------------------------------------------------------------------- 1 | /* #1 2 | var countsheep = function (num){ 3 | //your code here 4 | } 5 | */ 6 | /* #2 7 | var countsheep = function (num){ 8 | let result = ''; 9 | 10 | for (let i = 1; i <= num; i++) { 11 | result += i + ' sheep...' 12 | } 13 | 14 | return result 15 | } 16 | */ 17 | /* #3 18 | const countsheep = num => 19 | Array(num) 20 | .fill() 21 | .map((x, i) => `${i + 1} sheep...`) 22 | .join('') 23 | */ 24 | /* #4 */ 25 | const countsheep = (num) => 26 | [...Array(num)].map((x, i) => `${i + 1} sheep...`).join(''); 27 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.md: -------------------------------------------------------------------------------- 1 | # If you can't sleep, just count sheep (8 kyu) 2 | 3 | https://www.codewars.com/kata/if-you-cant-sleep-just-count-sheep 4 | 5 | Given a number, 3 for example, return a string with a murmur: 6 | 7 | ``` 8 | "1 sheep...2 sheep...3 sheep..." 9 | ``` 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.py: -------------------------------------------------------------------------------- 1 | def count_sheep(n): 2 | return "".join("{} sheep...".format(i) for i in range(1, n+1)) -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.rs: -------------------------------------------------------------------------------- 1 | fn countSheep(n: u32) -> String { 2 | // #1 3 | // let mut result = String::new(); 4 | // for i in 0..n { 5 | // let x = format!("{} sheep...", i + 1); 6 | // result.push_str(&x); 7 | // } 8 | // return result; 9 | // #2 10 | let mut result = String::new(); 11 | for i in 0..n { 12 | result.push_str(&format!("{} sheep...", i + 1)); 13 | } 14 | result 15 | } 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) If you can't sleep, just count sheep/(8 kyu) If you can't sleep, just count sheep.ts: -------------------------------------------------------------------------------- 1 | export function countSheep(num: number): string { 2 | let result = ''; 3 | 4 | for (let i = 1; i <= num; i++) { 5 | result += i + ' sheep...'; 6 | } 7 | 8 | return result; 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is n divisible by x and y/(8 kyu) Is n divisible by x and y.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func IsDivisible(n, x, y int) bool { 4 | return n % x == 0 && n % y == 0 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is n divisible by x and y/(8 kyu) Is n divisible by x and y.java: -------------------------------------------------------------------------------- 1 | public class DivisibleNb { 2 | public static boolean isDivisible(long n, long x, long y) { 3 | if (n % x == 0 && n % y == 0) { 4 | return true; 5 | } else { 6 | return false; 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is n divisible by x and y/(8 kyu) Is n divisible by x and y.md: -------------------------------------------------------------------------------- 1 | # Is n divisible by x and y? 2 | 3 | https://www.codewars.com/kata/5545f109004975ea66000086 4 | 5 | Create a function that checks if a number n is divisible by two numbers x AND y. All inputs are positive, non-zero digits. 6 | 7 | ``` 8 | Examples: 9 | 1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 10 | 2) n = 12, x = 2, y = 6 => true because 12 is divisible by 2 and 6 11 | 3) n = 100, x = 5, y = 3 => false because 100 is not divisible by 3 12 | 4) n = 12, x = 7, y = 5 => false because 12 is neither divisible by 7 nor 5 13 | ``` -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is n divisible by x and y/(8 kyu) Is n divisible by x and y.rs: -------------------------------------------------------------------------------- 1 | fn is_divisible(n: i32, x: i32, y: i32) -> bool { 2 | n % x == 0 && n % y == 0 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is n divisible by x and y/(8 kyu) Is n divisible by x and y.ts: -------------------------------------------------------------------------------- 1 | export function isDivisible(n: number, x: number, y: number): boolean { 2 | return (n % x === 0 && n % y === 0) ? true : false; 3 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Is the string uppercase/(8 kyu) Is the string uppercase.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | String.prototype.isUpperCase = function () { 3 | for (let i = 0; i < this.length; i++) { 4 | if (this[i].toUpperCase() !== this[i]) { 5 | return false; 6 | } 7 | } 8 | 9 | return true; 10 | }; 11 | 12 | // 2 Clever solution 13 | String.prototype.isUpperCase = function () { 14 | return this == this.toUpperCase(); 15 | }; 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // #1 4 | // std::string greet(std::string name) 5 | // { 6 | // return (name == "Johnny") 7 | // ? "Hello, my love!" 8 | // : "Hello, " + name + "!"; 9 | // } 10 | // #2 11 | std::string greet(std::string name) 12 | { 13 | return "Hello, " + (name == "Johnny" ? "my love" : name) + "!"; 14 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static string greet(string name) 6 | { 7 | if(name == "Johnny") 8 | return "Hello, my love!"; 9 | return "Hello, " + name + "!"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "fmt" 4 | 5 | func Greet(name string) string { 6 | if name == "Johnny" { 7 | return fmt.Sprint("Hello, my love!") 8 | } else { 9 | return fmt.Sprintf("Hello, %v!", name) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function greet(name) { 3 | // if (name === 'Johnny') return 'Hello, my love!'; 4 | // return 'Hello, ' + name + '!'; 5 | // } 6 | // #2 7 | // function greet(name) { 8 | // return name === 'Johnny' ? 'Hello, my love!' : 'Hello, ' + name + '!'; 9 | // } 10 | // #3 11 | const greet = (name) => `Hello, ${name === 'Johnny' ? 'my love' : name}!`; 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.md: -------------------------------------------------------------------------------- 1 | # Jenny's secret message (8 kyu) 2 | 3 | https://www.codewars.com/kata/jennys-secret-message 4 | 5 | Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake. 6 | 7 | Can you help her? 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def greet(name): 3 | # if name == "Johnny": 4 | # return "Hello, my love!" 5 | # return "Hello, {name}!".format(name=name) 6 | # #2 7 | # def greet(name): 8 | # return "Hello, {name}!".format(name="my love" if name == "Johnny" else name) 9 | # #3 10 | 11 | 12 | def greet(n): return "Hello, {}!".format(n.replace("Johnny", "my love")) 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Jenny's secret message/(8 kyu) Jenny's secret message.ts: -------------------------------------------------------------------------------- 1 | export function greet(name: string): string { 2 | if (name === 'Johnny') { 3 | return 'Hello, my love!'; 4 | } 5 | return 'Hello, ' + name + '!'; 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) MakeUpperCase/(8 kyu) MakeUpperCase.md: -------------------------------------------------------------------------------- 1 | # MakeUpperCase (8 kyu) 2 | 3 | https://www.codewars.com/kata/57a0556c7cb1f31ab3000ad7 4 | 5 | Write a function which converts the input string to uppercase. -------------------------------------------------------------------------------- /8kyu/(8 kyu) MakeUpperCase/(8 kyu) MakeUpperCase.ts: -------------------------------------------------------------------------------- 1 | export function makeUpperCase(str: string): string { 2 | return str.toUpperCase(); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.cpp: -------------------------------------------------------------------------------- 1 | int multiply(int a, int b) 2 | { 3 | return a * b; 4 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.cs: -------------------------------------------------------------------------------- 1 | public class CustomMath { 2 | public static int multiply(int a, int b) { 3 | return a * b; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.dart: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | int multiply(int a, int b) { 3 | return a * b; 4 | } 5 | 6 | // 2 Optimized solution 7 | int multiply(a, b) => a * b; 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.go: -------------------------------------------------------------------------------- 1 | package multiply 2 | 3 | func Multiply(a, b int) int { 4 | r := a * b 5 | return r 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.java: -------------------------------------------------------------------------------- 1 | public class Multiply { 2 | public static Double multiply(Double a, Double b) { 3 | return a * b; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.js: -------------------------------------------------------------------------------- 1 | function multiply(a, b) { 2 | return a * b; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.md: -------------------------------------------------------------------------------- 1 | # Multiply (8 kyu) 2 | 3 | https://www.codewars.com/kata/multiply/train/javascript 4 | 5 | The code does not execute properly. Try to figure out why. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.py: -------------------------------------------------------------------------------- 1 | def multiply(a, b): 2 | return a * b 3 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.rs: -------------------------------------------------------------------------------- 1 | fn multiply(a: i32, b: i32) -> i32 { 2 | a * b 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Multiply/(8 kyu) Multiply.ts: -------------------------------------------------------------------------------- 1 | export function multiply(a: number, b: number): number { 2 | return a * b; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Name Shuffler/(8 kyu) Name Shuffler.md: -------------------------------------------------------------------------------- 1 | # Name Shuffler (8 kyu) 2 | 3 | https://www.codewars.com/kata/559ac78160f0be07c200005a 4 | 5 | Write a function that returns a string in which firstname is swapped with last name. 6 | 7 | ``` 8 | nameShuffler('john McClane'); => "McClane john" 9 | ``` 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.cpp: -------------------------------------------------------------------------------- 1 | int opposite(int number) 2 | { 3 | return -number; 4 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Kata 4 | { 5 | public static int Opposite(int number) 6 | { 7 | return -number; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Opposite(value int) int { 4 | return -value 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.java: -------------------------------------------------------------------------------- 1 | // #1 2 | // public class Kata { 3 | // public static int opposite(int number) { 4 | // return number * -1; 5 | // } 6 | // } 7 | 8 | // #2 9 | public class Kata { 10 | public static int opposite(int number) { 11 | return -number; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.js: -------------------------------------------------------------------------------- 1 | // // #1 2 | // function opposite(number) { 3 | // return number *= -1 4 | // } 5 | // // #2 6 | // function opposite(number) { 7 | // return -number 8 | // } 9 | // #3 10 | const opposite = (number) => -number; 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.md: -------------------------------------------------------------------------------- 1 | # Opposite number (8 kyu) 2 | 3 | https://www.codewars.com/kata/opposite-number 4 | 5 | Very simple, given a number, find its opposite. But can you do it in 1 line of code and without any conditionals? 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def opposite(number): 3 | # return -number 4 | # #2 5 | opposite = lambda n: -n 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.rs: -------------------------------------------------------------------------------- 1 | fn opposite(number: i32) -> i32 { 2 | // #1 3 | // let result: i32 = number * -1; 4 | // return result; 5 | // #2 6 | -number 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposite number/(8 kyu) Opposite number.ts: -------------------------------------------------------------------------------- 1 | export class Kata { 2 | static opposite(n: number) { 3 | return -n; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposites Attract/(8 kyu) Opposites Attract.md: -------------------------------------------------------------------------------- 1 | # Opposites Attract (8 kyu) 2 | 3 | https://www.codewars.com/kata/555086d53eac039a2a000083 4 | 5 | Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love. 6 | 7 | Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't. 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Opposites Attract/(8 kyu) Opposites Attract.ts: -------------------------------------------------------------------------------- 1 | export function lovefunc(flower1: number, flower2: number): boolean { 2 | return flower1 % 2 !== flower2 % 2 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Parse nice int from char problem/(8 kyu) Parse nice int from char problem.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function getAge(inputString) { 3 | const years = inputString[0]; 4 | const number = Number(years); 5 | 6 | return number; 7 | } 8 | 9 | // 2 Optimized solution 10 | function getAge(inputString) { 11 | const years = inputString[0]; 12 | 13 | return +years; 14 | } 15 | 16 | // 3 Clever solution 17 | function getAge(inputString) { 18 | return parseInt(inputString) 19 | } 20 | 21 | // 4 Coding golf 22 | getAge = parseInt 23 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Parse nice int from char problem/(8 kyu) Parse nice int from char problem.md: -------------------------------------------------------------------------------- 1 | # Parse nice int from char problem (8 kyu) 2 | 3 | https://www.codewars.com/kata/557cd6882bfa3c8a9f0000c1 4 | 5 | You ask a small girl, "How old are you?" She always says, "x years old", where x is a random number between 0 and 9. 6 | 7 | Write a program that returns the girl's age (0-9) as an integer. 8 | 9 | Assume the test input string is always a valid string. For example, the test input may be "1 year old" or "5 years old". The first character in the string is always a number. 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Plural/(8 kyu) Plural.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function plural(n) { 3 | if (n === 1 || n === -1) { 4 | return false; 5 | } else { 6 | return true; 7 | } 8 | } 9 | 10 | // 2 Optimized solution 11 | plural = n => (n !== 1 && n !== -1) 12 | 13 | // 3 Clever solution 14 | const plural = n => n !== 1; 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Plural/(8 kyu) Plural.md: -------------------------------------------------------------------------------- 1 | # Plural (8 kyu) 2 | 3 | https://www.codewars.com/kata/52ceafd1f235ce81aa00073a 4 | 5 | We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as 5 minutes, 14 apples, or 1 sun. 6 | 7 | > You only need to worry about english grammar rules for this kata, where anything that isn't singular (one of something), it is plural (not one of something). 8 | 9 | All values will be positive integers or floats, or zero. 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Powers of 2/(8 kyu) Powers of 2.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function powersOfTwo(n) { 3 | const res = []; 4 | 5 | for (let i = 0; i <= n; i++) { 6 | res.push(Math.pow(2, i)); 7 | } 8 | 9 | return res; 10 | } 11 | 12 | // 2 Optimized solution 13 | function powersOfTwo(n) { 14 | return Array(n + 1) 15 | .fill(0) 16 | .map((_, i) => 2 ** i); 17 | } 18 | 19 | // 3 Clever solution 20 | const powersOfTwo = (n) => [...Array(++n)].map((_, i) => 2 ** i); 21 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Powers of 2/(8 kyu) Powers of 2.md: -------------------------------------------------------------------------------- 1 | # Powers of 2 (8 kyu) 2 | 3 | https://www.codewars.com/kata/57a083a57cb1f31db7000028 4 | 5 | Complete the function that takes a non-negative integer `n` as input, and returns a list of all the powers of `2` with the exponent ranging from 0 to `n` ( inclusive ). 6 | 7 | Examples 8 | 9 | ``` 10 | n = 0 ==> [1] # [2^0] 11 | n = 1 ==> [1, 2] # [2^0, 2^1] 12 | n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2] 13 | ``` 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove First and Last Character/(8 kyu) Remove First and Last Character.md: -------------------------------------------------------------------------------- 1 | # Remove First and Last Character (8 kyu) 2 | 3 | https://www.codewars.com/kata/56bc28ad5bdaeb48760009b0 4 | 5 | It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // #1 4 | // #include 5 | // std::string no_space(std::string x) 6 | // { 7 | // x.erase(std::remove(x.begin(), x.end(), ' '), x.end()); 8 | // return x; 9 | // } 10 | 11 | // #2 12 | #include 13 | std::string no_space(std::string s) 14 | { 15 | return std::regex_replace(s, std::regex(" "), ""); 16 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | public static class SpacesRemover 4 | { 5 | public static string NoSpace(string input) 6 | { 7 | string res = ""; 8 | for (int i = 0; i < input.Length; i++) 9 | { 10 | if (input[i] != ' ') 11 | { 12 | res += input[i]; 13 | } 14 | } 15 | return res; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func NoSpace(word string) string { 6 | return strings.ReplaceAll(word, " ", "") 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function noSpace(x) { 3 | // return x.replace(/\s+/g, ''); 4 | // } 5 | // #2 6 | const noSpace = (x) => x.replace(/\s+/g, ''); 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.md: -------------------------------------------------------------------------------- 1 | # Remove String Spaces (8 kyu) 2 | 3 | https://www.codewars.com/kata/remove-string-spaces 4 | 5 | Simple, remove the spaces from the string, then return the resultant string. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def no_space(x): 3 | # return x.replace(' ' ,'') 4 | # #2 5 | import re 6 | 7 | def no_space(x): 8 | return re.sub(r"\s+", "", x) -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn no_space(x: String) -> String { 3 | // str::replace(&x, " ", "") 4 | // } 5 | // #2 6 | fn no_space(x: String) -> String { 7 | x.replace(" ", "") 8 | } 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Remove String Spaces/(8 kyu) Remove String Spaces.ts: -------------------------------------------------------------------------------- 1 | export function noSpace(x: string): string { 2 | return x.replace(/\s+/g, ''); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int makeNegative(int num) 4 | { 5 | return -std::abs(num); 6 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static int MakeNegative(int number) 6 | { 7 | return number < 0 ? number : -number; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "math" 4 | 5 | func MakeNegative(x int) int { 6 | var i float64 = float64(x) 7 | var res int = int(math.Abs(i)) 8 | return -res 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.java: -------------------------------------------------------------------------------- 1 | // #1 2 | public class Kata { 3 | public static int makeNegative(final int x) { 4 | return -Math.abs(x); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function makeNegative(num) { 3 | // if (num < 0) { 4 | // return num; 5 | // } else { 6 | // return (num = num * -1); 7 | // } 8 | // } 9 | // #2 10 | // function makeNegative(num) { 11 | // if (num < 0) { 12 | // return num; 13 | // } else { 14 | // return -num; 15 | // } 16 | // } 17 | // #3 18 | // function makeNegative(num) { 19 | // return num < 0 ? num : -num; 20 | // } 21 | // #4 22 | // const makeNegative = (num) => (num < 0 ? num : -num); 23 | // #5 24 | const makeNegative = (num) => -Math.abs(num); 25 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def make_negative( number ): 3 | # return number if number < 0 else - number 4 | # #2 5 | def make_negative( number ): 6 | return -abs(number) -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.rs: -------------------------------------------------------------------------------- 1 | fn make_negative(number: i32) -> i32 { 2 | number.abs() * -1 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Return Negative/(8 kyu) Return Negative.ts: -------------------------------------------------------------------------------- 1 | export const makeNegative = (num: number): number => { 2 | return -Math.abs(num); 3 | }; 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Returning Strings/(8 kyu) Returning Strings.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function greet(name) { 3 | const str1 = "Hello, "; 4 | const str2 = " how are you doing today?"; 5 | 6 | return str1 + name + str2; 7 | } 8 | 9 | // 2 Optimized solution 10 | function greet(name) { 11 | return "Hello, " + name + " how are you doing today?"; 12 | } 13 | 14 | // 3 Clever solution 15 | function greet(name) { 16 | return `Hello, ${name} how are you doing today?`; 17 | } 18 | 19 | // 4 Coding golf 20 | greet=_=>`Hello, ${_} how are you doing today?` 21 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Returning Strings/(8 kyu) Returning Strings.md: -------------------------------------------------------------------------------- 1 | # Returning Strings ( 8 kyu) 2 | 3 | Make a function that will return a greeting statement that uses an input; your program should return, `"Hello, how are you doing today?"`. 4 | 5 | _[Make sure you type the exact thing I wrote or the program may not execute properly]_ 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string reverseString(string str) 6 | { 7 | reverse(str.begin(), str.end()); 8 | return str; 9 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static string Solution(string str) 6 | { 7 | char[] array = str.ToCharArray(); 8 | Array.Reverse(array); 9 | return new string(array); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Solution(word string) (result string) { 4 | for _, c := range word { 5 | result = string(c) + result 6 | } 7 | return 8 | } 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function solution(str){ 3 | // return str.split("").reverse().join(""); 4 | // } 5 | // #2 6 | // const solution = (s) => s.split``.reverse().join`` 7 | // #3 8 | const solution = (s) => [...s].reverse().join``; 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.md: -------------------------------------------------------------------------------- 1 | # Reversed Strings (8 kyu) 2 | 3 | https://www.codewars.com/kata/reversed-strings 4 | 5 | Complete the solution so that it reverses the string value passed into it. 6 | 7 | ``` 8 | solution('world'); // returns 'dlrow' 9 | ``` 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.py: -------------------------------------------------------------------------------- 1 | def solution(string): 2 | return string[::-1] 3 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.rs: -------------------------------------------------------------------------------- 1 | fn solution(phrase: &str) -> String { 2 | // #1 3 | // phrase.chars().rev().collect::() 4 | // #2 5 | phrase.chars().rev().collect() 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Strings/(8 kyu) Reversed Strings.ts: -------------------------------------------------------------------------------- 1 | export function solution(str: string): string { 2 | return str 3 | .split('') 4 | .reverse() 5 | .join(''); 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | string reverse_words(const string& str) { 6 | string res = ""; 7 | string word = ""; 8 | for (auto w: str) 9 | { 10 | if (w == ' ') 11 | { 12 | res = word + " " + res; 13 | word = ""; 14 | } 15 | else { 16 | word = word + w; 17 | } 18 | } 19 | if (!word.empty()) res = word + " " + res; 20 | if (!res.empty()) res.pop_back(); 21 | 22 | return res; 23 | } 24 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | public class Kata 6 | { 7 | public static string ReverseWords(string str) 8 | { 9 | string[] res = str.Split(' '); 10 | Array.Reverse(res); 11 | return string.Join(' ', res); ; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func ReverseWords(str string) string { 6 | words := strings.Split(str, " ") 7 | res := "" 8 | 9 | for _, w := range words { 10 | res = w + " " + res 11 | } 12 | 13 | return res[:len(res)-1] 14 | } 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.js: -------------------------------------------------------------------------------- 1 | // #1 2 | // function reverseWords(str) { 3 | // return str.split` `.reverse().join` `; 4 | // } 5 | // #2 6 | // const reverseWords = (str) => str.split` `.reverse().join` `; 7 | // #3 8 | const reverseWords = (s) => s.match(/\S+/g).reverse().join` `; 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.md: -------------------------------------------------------------------------------- 1 | # Reversed Words (8 kyu) 2 | 3 | https://www.codewars.com/kata/reversed-words 4 | 5 | Complete the solution so that it reverses all of the words within the string passed in. 6 | 7 | Example: 8 | 9 | ``` 10 | reverseWords("The greatest victory is that which requires no battle") 11 | // should return "battle no requires which that is victory greatest The" 12 | ``` 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.py: -------------------------------------------------------------------------------- 1 | # #1 2 | # def reverseWords(str): 3 | # arr = str.split() 4 | # rev = arr[::-1] 5 | # return " ".join(rev) 6 | # #2 7 | # def reverseWords(str): 8 | # return " ".join(str.split()[::-1]) 9 | # #3 10 | 11 | 12 | def reverseWords(s): return " ".join(s.split(" ")[::-1]) 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.rs: -------------------------------------------------------------------------------- 1 | // #1 2 | // fn reverse_words(str: &str) -> String { 3 | // let s = str.split_whitespace().rev(); 4 | // let res: Vec<&str> = s.collect(); 5 | // res.join(" ") 6 | // } 7 | // #2 8 | fn reverse_words(s: &str) -> String { 9 | s.split_whitespace().rev().collect::>().join(" ") 10 | } 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed Words/(8 kyu) Reversed Words.ts: -------------------------------------------------------------------------------- 1 | export function reverseWords(str: string): string { 2 | return str.split(" ").reverse().join(" "); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::vector reverseSeq(int n) 4 | { 5 | std::vector res; 6 | for (int32_t i = n; i > 0; --i) 7 | { 8 | res.push_back(i); 9 | } 10 | return res; 11 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.cs: -------------------------------------------------------------------------------- 1 | public static class Kata 2 | { 3 | public static int[] ReverseSeq(int n) 4 | { 5 | int[] res = new int[n]; 6 | 7 | for (int i = 0; i < n; i++) 8 | { 9 | res[i] = res.Length - i; 10 | } 11 | 12 | return res; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func ReverseSeq(n int) []int { 4 | var res = make([]int, n) 5 | for i := 0; i < len(res); i++ { 6 | res[i] = len(res) - i 7 | } 8 | return res 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | const reverseSeq = n => { 3 | let res = []; 4 | 5 | for (let i = n; i > 0; i--) { 6 | res.push(i); 7 | } 8 | 9 | return res; 10 | }; 11 | 12 | // 2 Clever solution 13 | const reverseSeq = (n) => 14 | Array(n) 15 | .fill() 16 | .map((x, i) => n - i); 17 | 18 | // 3 Coding golf 19 | const reverseSeq = length => 20 | Array.from( 21 | {length}, 22 | () => length-- 23 | ) 24 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.md: -------------------------------------------------------------------------------- 1 | # Reversed sequence (8 kyu) 2 | 3 | https://www.codewars.com/kata/reversed-sequence 4 | 5 | Get the number n (n>0) to return the reversed sequence from n to 1. 6 | 7 | Example: 8 | 9 | ``` 10 | n=5 >> [5,4,3,2,1] 11 | ``` 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.py: -------------------------------------------------------------------------------- 1 | # 1 Plain solution 2 | def reverse_seq(n): 3 | arr = [] 4 | for i in range(n): 5 | arr.append(n - i) 6 | return arr 7 | 8 | # 2 Optimized solution 9 | def reverse_seq(n): 10 | return [x for x in range(n, 0, -1)] 11 | 12 | # 3 Clever solution 13 | def reverse_seq(n): 14 | return list(range(n, 0, -1)) 15 | 16 | # 4 Coding golf 17 | reverse_seq = lambda n: list(range(n, 0, -1)) 18 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Reversed sequence/(8 kyu) Reversed sequence.ts: -------------------------------------------------------------------------------- 1 | export const reverseSeq = (n: number): number[] => { 2 | return [...Array(n)].map((x, i) => n - i); 3 | }; 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Rock Paper Scissors/(8 kyu) Rock Paper Scissors.md: -------------------------------------------------------------------------------- 1 | # Rock Paper Scissors (8 kyu) 2 | 3 | Let's play! You have to return which player won! In case of a draw return `Draw!`. 4 | 5 | Examples: 6 | 7 | ``` 8 | rps('scissors','paper') // Player 1 won! 9 | rps('scissors','rock') // Player 2 won! 10 | rps('paper','paper') // Draw! 11 | ``` 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | std::string twoSort(std::vector s) 6 | { 7 | std::sort(s.begin(), s.end()); 8 | std::string ret; 9 | std::string word = s[0]; 10 | for (int32_t i = 0; i < word.length() - 1; ++i) 11 | { 12 | ret = ret + word[i] + "***"; 13 | } 14 | return ret + word.back(); 15 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | public class Kata 5 | { 6 | public static string TwoSort(string[] s) 7 | { 8 | Array.Sort(s, StringComparer.Ordinal); 9 | char[] str = s[0].ToCharArray(); 10 | return String.Join("***", str); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import ( 4 | "strings" 5 | "sort" 6 | ) 7 | 8 | func TwoSort(arr []string) string { 9 | sort.Strings(arr) 10 | a := strings.Split(arr[0], "") 11 | return strings.Join(a, "***") 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.md: -------------------------------------------------------------------------------- 1 | # Sort and Star (8 kyu) 2 | 3 | https://www.codewars.com/kata/sort-and-star 4 | 5 | You will be given an vector of string(s). You must sort it alphabetically (case-sensitive!!) and then return the first value. The returned value must be a string, and have "\*\*\*" between each of its letters. 6 | 7 | You should not remove or add elements from/to the array. 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.rs: -------------------------------------------------------------------------------- 1 | fn two_sort(arr: &[&str]) -> String { 2 | let mut a = vec![""; arr.len()]; 3 | a[..arr.len()].clone_from_slice(&arr); 4 | a.sort(); 5 | 6 | let mut res = String::new(); 7 | for (i, c) in a[0].chars().enumerate() { 8 | if i == a[0].len() - 1 { 9 | res.push(c); 10 | } else { 11 | res.push_str(&String::from(format!("{}***", c))); 12 | } 13 | } 14 | 15 | res 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sort and Star/(8 kyu) Sort and Star.ts: -------------------------------------------------------------------------------- 1 | export function twoSort(s: string[]): string { 2 | return s 3 | .sort()[0] 4 | .split('') 5 | .join('***'); 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int square_sum(const std::vector &numbers) 4 | { 5 | int res = 0; 6 | for (auto &i : numbers) 7 | { 8 | res += i * i; 9 | } 10 | return res; 11 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.cs: -------------------------------------------------------------------------------- 1 | public static class Kata 2 | { 3 | public static int SquareSum(int[] n) 4 | { 5 | int res = 0; 6 | 7 | for (int i = 0; i < n.Length; i++) 8 | { 9 | res += n[i] * n[i]; 10 | } 11 | 12 | return res; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | // #1 4 | // func SquareSum(numbers []int) int { 5 | // res := 0 6 | // for i := 0; i < len(numbers); i++ { 7 | // res += numbers[i] * numbers[i] 8 | // } 9 | // return res 10 | // } 11 | // #2 12 | // func SquareSum(numbers []int) (res int) { 13 | // for _, n := range numbers { 14 | // res = res + n*n 15 | // } 16 | // return 17 | // } 18 | // #3 19 | func SquareSum(numbers []int) (res int) { 20 | for _, n := range numbers { res += n*n } 21 | return 22 | } 23 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.java: -------------------------------------------------------------------------------- 1 | // #1 2 | // public class Kata { 3 | // public static int squareSum(int[] n) { 4 | // int sum = 0; 5 | // for (int num: n) { 6 | // sum += num * num; 7 | // } 8 | // return sum; 9 | // } 10 | // } 11 | 12 | // #2 13 | import java.util.Arrays; 14 | 15 | public class Kata { 16 | public static int squareSum(int[] n) { 17 | return Arrays.stream(n).map(num -> num * num).sum(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.md: -------------------------------------------------------------------------------- 1 | # Square(n) Sum (8 kyu) 2 | 3 | https://www.codewars.com/kata/square-n-sum 4 | 5 | Complete the squareSum/square_sum/SquareSum method so that it squares each number passed into it and then sums the results together. 6 | 7 | For example: 8 | 9 | ``` 10 | square_sum([1, 2, 2]) // should return 9 11 | ``` 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.py: -------------------------------------------------------------------------------- 1 | # 1 Plain solution 2 | def square_sum(numbers): 3 | sum = 0 4 | 5 | for x in numbers: 6 | sum += x * x 7 | 8 | return sum 9 | 10 | # 2 Optimized solution 11 | def square_sum(numbers): 12 | res = [] 13 | for x in numbers: 14 | res.append(x**2) 15 | return(sum(res)) 16 | 17 | # 3 Clever solution 18 | def square_sum(numbers): 19 | return sum(x ** 2 for x in numbers) 20 | 21 | # 4 Coding golf 22 | square_sum = lambda n: sum(x**2 for x in n) 23 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.rs: -------------------------------------------------------------------------------- 1 | fn square_sum(vec: Vec) -> i32 { 2 | // #1 3 | // let mut res = 0; 4 | // for i in 0..vec.len() { 5 | // res += vec[i] * vec[i] 6 | // } 7 | // res 8 | // #2 9 | // vec.iter().fold(0, |sum, x| sum + (x * x)) 10 | // #3 11 | vec.iter().map(|x| x * x).sum() 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Square(n) Sum/(8 kyu) Square(n) Sum.ts: -------------------------------------------------------------------------------- 1 | export function squareSum(numbers: number[]): number { 2 | return numbers.reduce((a, x) => a + x * x, 0); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::string repeat_str(int32_t n, std::string s) 4 | { 5 | std::stringstream ss; 6 | for (int32_t i = 0; i < n; ++i) 7 | { 8 | ss << s; 9 | } 10 | return ss.str(); 11 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | public static class Program 4 | { 5 | public static string RepeatStr(int n, string s) 6 | { 7 | string res = ""; 8 | for (int i = 0; i < n; i++) 9 | { 10 | res += s; 11 | } 12 | return res; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.dart: -------------------------------------------------------------------------------- 1 | String repeatString(int n, String s) { 2 | return s * n; 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "strings" 4 | 5 | func RepeatStr(repetitions int, value string) string { 6 | return strings.Repeat(value, repetitions) 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.java: -------------------------------------------------------------------------------- 1 | // #1 2 | // public class Solution { 3 | // public static String repeatStr(final int repeat, final String string) { 4 | // String result = ""; 5 | // for (int i = 0; i < repeat; i++) { 6 | // result += string; 7 | // } 8 | // return result; 9 | // } 10 | // } 11 | // #2 12 | public class Solution { 13 | public static String repeatStr(final int repeat, final String string) { 14 | return string.repeat(repeat); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.js: -------------------------------------------------------------------------------- 1 | // 1 Plain Solution 2 | function repeatStr (n, s) { 3 | let str = ''; 4 | 5 | for (let i = 0; i < n; i++) { 6 | str = str + s; 7 | } 8 | 9 | return str; 10 | } 11 | 12 | // 2 Optimized solution 13 | function repeatStr (n, s) { 14 | return ( 15 | new Array(n).fill(s) 16 | ).join(''); 17 | } 18 | 19 | // 3 Clever solution 20 | function repeatStr (n, s) { 21 | return s.repeat(n) 22 | } 23 | 24 | // 4 Coding golf 25 | repeatStr = (n, s) => s.repeat(n); 26 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.md: -------------------------------------------------------------------------------- 1 | # String repeat (8 kyu) 2 | 3 | https://www.codewars.com/kata/string-repeat 4 | 5 | Write a function called repeatStr which repeats the given string string exactly n times. 6 | 7 | ``` 8 | repeatStr(6, "I") // "IIIIII" 9 | repeatStr(5, "Hello") // "HelloHelloHelloHelloHello" 10 | ``` 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.py: -------------------------------------------------------------------------------- 1 | # 1 Plain Solution 2 | def repeat_str(repeat, string): 3 | str = "" 4 | 5 | for i in range(repeat): 6 | str = str + string 7 | 8 | return str 9 | 10 | # 2 Optimized solution 11 | def repeat_str(repeat, string): 12 | return "{}".format(string) * int(repeat) 13 | 14 | # 3 Clever solution 15 | def repeat_str(repeat, string): 16 | return repeat * string 17 | 18 | # 4 Coding golf 19 | repeat_str = lambda n, str: str * n 20 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.rs: -------------------------------------------------------------------------------- 1 | fn repeat_str(src: &str, count: usize) -> String { 2 | // #1 3 | // let mut str = String::new(); 4 | // for _ in 0..count { 5 | // str.push_str(src); 6 | // } 7 | // return str; 8 | // #2 9 | // let mut str = String::new(); 10 | // str = src.repeat(count); 11 | // return str; 12 | // #3 13 | // (0..count).map(|_| src).collect() 14 | // #4 15 | src.repeat(count) 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) String repeat/(8 kyu) String repeat.ts: -------------------------------------------------------------------------------- 1 | export function repeatStr(n: number, s: string): string { 2 | return s.repeat(n); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int positive_sum(std::vector arr) { 4 | int res = 0; 5 | for (int x : arr) { 6 | res += x > 0 ? x : 0; 7 | } 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | 4 | public class Kata 5 | { 6 | public static int PositiveSum(int[] arr) 7 | { 8 | int res = 0; 9 | foreach (int x in arr) 10 | { 11 | if (x > 0) res += x; 12 | } 13 | return res; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.dart: -------------------------------------------------------------------------------- 1 | int positiveSum(List arr) => arr.fold(0, (a, c) => c > 0 ? a + c : a); 2 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func PositiveSum(numbers []int) int { 4 | res := 0 5 | 6 | for _, n := range numbers { 7 | if (n > 0) { 8 | res += n 9 | } 10 | } 11 | 12 | return res 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.java: -------------------------------------------------------------------------------- 1 | public class Positive{ 2 | public static int sum(int[] arr){ 3 | int res = 0; 4 | 5 | for (int i = 0; i < arr.length; i++) { 6 | if (arr[i] > 0) { 7 | res += arr[i]; 8 | } 9 | } 10 | 11 | return res; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.md: -------------------------------------------------------------------------------- 1 | # Sum of positive (8 kyu) 2 | 3 | You get an array of numbers, return the sum of all of the positives ones. 4 | 5 | Example `[1,-4,7,12]` => `1 + 7 + 12 = 20` 6 | 7 | Note: if there is nothing to sum, the sum is default to `0`. 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.py: -------------------------------------------------------------------------------- 1 | def positive_sum(arr): 2 | res = 0 3 | 4 | for i in range(len(arr)): 5 | if arr[i] > 0: 6 | res += arr[i] 7 | 8 | return res 9 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.rs: -------------------------------------------------------------------------------- 1 | fn positive_sum(slice: &[i32]) -> i32 { 2 | let mut res = 0; 3 | 4 | for i in 0..slice.len() { 5 | if slice[i] > 0 { 6 | res += slice[i]; 7 | } 8 | } 9 | 10 | res 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Sum of positive/(8 kyu) Sum of positive.ts: -------------------------------------------------------------------------------- 1 | export function positiveSum(arr: number[]): number { 2 | let res = 0; 3 | arr.forEach((x) => (res += x > 0 ? x : 0)); 4 | return res; 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | bool feast(std::string beast, std::string dish) 4 | { 5 | return beast.front() == dish.front() && beast.back() == dish.back(); 6 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.cs: -------------------------------------------------------------------------------- 1 | public class Kata 2 | { 3 | public static bool Feast(string beast, string dish) 4 | { 5 | return beast[0] == dish[0] && beast[beast.Length - 1] == dish[dish.Length - 1]; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Feast(beast string, dish string) bool { 4 | return beast[:1] == dish[:1] && beast[len(beast)-1:] == dish[len(dish)-1:] 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.py: -------------------------------------------------------------------------------- 1 | # 1 Plain Solution 2 | def feast(beast, dish): 3 | start = beast.startswith(dish[:1]) 4 | end = beast.endswith(dish[-1:]) 5 | 6 | return start and end 7 | 8 | # 2 Optimized solution 9 | def feast(beast, dish): 10 | return beast.startswith(dish[:1]) and beast.endswith(dish[-1:]) 11 | 12 | # 3 Clever solution 13 | def feast(beast, dish): 14 | return beast[0] == dish[0] and beast[-1] == dish[-1] 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.rs: -------------------------------------------------------------------------------- 1 | fn feast(beast: &str, dish: &str) -> bool { 2 | // // #1 3 | // let start = beast.starts_with(dish.chars().next().unwrap()); 4 | // let end = beast.ends_with(dish.chars().last().unwrap()); 5 | // return start && end; 6 | // // #2 7 | // let start = beast.starts_with(&dish[0..1]); 8 | // let end = beast.ends_with(&dish[dish.len()-1..]); 9 | // start && end 10 | // #3 11 | &beast[..1] == &dish[..1] && &beast[beast.len() - 1..] == &dish[dish.len() - 1..] 12 | } 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) The Feast of Many Beasts/(8 kyu) The Feast of Many Beasts.ts: -------------------------------------------------------------------------------- 1 | export function feast(beast: string, dish: string): boolean { 2 | return beast[0] === dish[0] && beast.slice(-1) === dish.slice(-1); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "math" 4 | 5 | func SquareOrSquareRoot(arr []int) []int{ 6 | var res []int 7 | 8 | for _, x := range arr { 9 | squaredNumber := math.Pow(float64(x), .5) 10 | 11 | if squaredNumber == math.Trunc(squaredNumber) { 12 | res = append(res, int(squaredNumber)) 13 | } else { 14 | res = append(res, int(math.Pow(float64(x), 2))) 15 | } 16 | } 17 | 18 | return res 19 | } 20 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.java: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | public static int[] squareOrSquareRoot(int[] array) { 3 | int[] res = new int[array.length]; 4 | 5 | for (var i = 0; i < array.length; i++) { 6 | var squaredNumber = Math.sqrt(array[i]); 7 | if (squaredNumber == (int) squaredNumber) { 8 | res[i] = (int) squaredNumber; 9 | } else { 10 | res[i] = (int) Math.pow(array[i], 2); 11 | } 12 | } 13 | 14 | return res; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.md: -------------------------------------------------------------------------------- 1 | # To square(root) or not to square(root) (8 kyu) 2 | 3 | Write a method, that will get an integer array as parameter and will process every number from this array. 4 | 5 | Return a new array with processing every number of the input-array like this: 6 | 7 | If the number has an integer square root, take this, otherwise square the number. 8 | 9 | **Example** 10 | 11 | ``` 12 | [4,3,9,7,2,1] -> [2,9,3,49,4,1] 13 | ``` 14 | 15 | **Notes** 16 | 17 | The input array will always contain only positive numbers, and will never be empty or null. 18 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def square_or_square_root(arr): 4 | res = [] 5 | 6 | for x in arr: 7 | squared_number = math.sqrt(x) 8 | if squared_number == math.trunc(squared_number): 9 | res.append(squared_number) 10 | else: 11 | res.append(math.pow(x, 2)) 12 | 13 | return res 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.rs: -------------------------------------------------------------------------------- 1 | fn square_or_square_root(arr: &[u32]) -> Vec { 2 | let mut res: Vec = vec![]; 3 | 4 | for x in arr.into_iter() { 5 | let squared_number = f64::sqrt(*x as f64); 6 | if squared_number.fract() == 0.0 { 7 | res.push(squared_number as u32); 8 | } else { 9 | res.push(x * x); 10 | } 11 | } 12 | 13 | res.to_vec() 14 | } 15 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) To square or not/(8 kyu) To square or not.ts: -------------------------------------------------------------------------------- 1 | export function squareOrSquareRoot(array: number[]): number[] { 2 | return array.map((n) => 3 | Number.isInteger(Math.sqrt(n)) ? Math.sqrt(n) : Math.pow(n, 2) 4 | ); 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.cpp: -------------------------------------------------------------------------------- 1 | int points(const std::array& games) { 2 | int res = 0; 3 | for (auto game: games) { 4 | int x = game[0]; 5 | int y = game[2]; 6 | if (x > y) { 7 | res += 3; 8 | } else if (x == y) { 9 | res += 1; 10 | } 11 | } 12 | return res; 13 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | 3 | public static class Kata 4 | { 5 | public static int TotalPoints(string[] games) 6 | { 7 | int res = 0; 8 | 9 | foreach (string game in games) 10 | { 11 | int x = game[0]; 12 | int y = game[2]; 13 | 14 | if (x > y) 15 | { 16 | res += 3; 17 | } 18 | else if (x == y) 19 | { 20 | res += 1; 21 | } 22 | } 23 | 24 | return res; 25 | } 26 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Points(games []string) int { 4 | res := 0 5 | 6 | for _, game := range games { 7 | x := game[0] 8 | y := game[2] 9 | 10 | if x > y { 11 | res += 3 12 | } else if x == y { 13 | res += 1 14 | } 15 | } 16 | 17 | return res 18 | } 19 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.java: -------------------------------------------------------------------------------- 1 | public class TotalPoints { 2 | 3 | public static int points(String[] games) { 4 | int res = 0; 5 | 6 | for (var game : games) { 7 | var x = game.charAt(0); 8 | var y = game.charAt(2); 9 | 10 | if (x > y) { 11 | res += 3; 12 | } else if (x == y) { 13 | res += 1; 14 | } 15 | } 16 | 17 | return res; 18 | } 19 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.md: -------------------------------------------------------------------------------- 1 | # Total amount of points (8 kyu) 2 | 3 | Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection. 4 | 5 | For example: `["3:1", "2:2", "0:1", ...]` 6 | 7 | Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match: 8 | 9 | * if x>y - 3 points 10 | * if x y: 9 | res += 3 10 | elif x == y: 11 | res += 1 12 | 13 | return res; -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.rs: -------------------------------------------------------------------------------- 1 | fn points(games: &[String]) -> u32 { 2 | let mut res = 0; 3 | 4 | for game in games.iter() { 5 | let score = game.split(":").collect::>(); 6 | 7 | if score[0] > score[1] { 8 | res += 3; 9 | } else if score[0] == score[1] { 10 | res += 1; 11 | } 12 | } 13 | 14 | return res; 15 | } 16 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Total amount of points/(8 kyu) Total amount of points.ts: -------------------------------------------------------------------------------- 1 | export function points(games: string[]): number { 2 | return games.reduce((res, game) => { 3 | const [x, y] = game.split(":"); 4 | 5 | if (+x > +y) { 6 | return (res += 3); 7 | } else if (x === y) { 8 | return (res += 1); 9 | } 10 | 11 | return res; 12 | }, 0); 13 | } 14 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.cpp: -------------------------------------------------------------------------------- 1 | int twice_as_old(int dad, int son) { 2 | int twiceOld = son * 2; 3 | int res = dad - twiceOld; 4 | 5 | if (res > 0) { 6 | return res; 7 | } 8 | 9 | return -res; 10 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.cs: -------------------------------------------------------------------------------- 1 | namespace Solution 2 | { 3 | public class TwiceAsOldSolution 4 | { 5 | public static int TwiceAsOld(int dadYears, int sonYears) 6 | { 7 | int twiceOld = sonYears * 2; 8 | int res = dadYears - twiceOld; 9 | if (res > 0) 10 | { 11 | return res; 12 | } 13 | return -res; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | import "math" 4 | 5 | func TwiceAsOld(dadYearsOld, sonYearsOld int) int { 6 | return int(math.Abs(float64(dadYearsOld) - float64(sonYearsOld) * 2)); 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.java: -------------------------------------------------------------------------------- 1 | public class TwiceAsOld { 2 | 3 | public static int TwiceAsOld(int dadYears, int sonYears) { 4 | return Math.abs(dadYears - sonYears * 2); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function twiceAsOld(dadYearsOld, sonYearsOld) { 3 | const twiceOld = sonYearsOld * 2; 4 | const res = dadYearsOld - twiceOld; 5 | if (res > 0) { 6 | return res; 7 | } else { 8 | return -res; 9 | } 10 | } 11 | 12 | // 2 Optimized solution 13 | function twiceAsOld(dadYearsOld, sonYearsOld) { 14 | return Math.abs(dadYearsOld - sonYearsOld * 2); 15 | } 16 | 17 | // 3 Coding golf 18 | const twiceAsOld = (d, s) => Math.abs(d - s * 2); 19 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.md: -------------------------------------------------------------------------------- 1 | # Twice as old (8 kyu) 2 | 3 | https://www.codewars.com/kata/5b853229cfde412a470000d0 4 | 5 | Your function takes two arguments: 6 | 7 | 1. current father's age (years) 8 | 1. current age of his son (years) 9 | 10 | Сalculate how many years ago the father was twice as old as his son (or in how many years he will be twice as old). 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.py: -------------------------------------------------------------------------------- 1 | def twice_as_old(dad_years_old, son_years_old): 2 | twice_old = son_years_old * 2 3 | res = dad_years_old - twice_old 4 | if res > 0: 5 | return res 6 | else: 7 | return -res 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Twice as old/(8 kyu) Twice as old.ts: -------------------------------------------------------------------------------- 1 | export function twiceAsOld(dadYearsOld: number, sonYearsOld: number): number { 2 | return Math.abs(dadYearsOld - sonYearsOld * 2); 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.cpp: -------------------------------------------------------------------------------- 1 | double getVolumeOfCubiod(double length, double width, double height) { 2 | return length * width * height; 3 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.cs: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | public static double GetVolumeOfCuboid(double length, double width, double height) { 3 | return length * width * height; 4 | } 5 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.dart: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | double getVolumeOfCuboid(final double length, final double width, final double height) { 3 | return length * width * height; 4 | } 5 | 6 | // 2 Optimized solution 7 | double getVolumeOfCuboid(final double l, final double w, final double h) { 8 | return l * w * h; 9 | } 10 | 11 | // 3 Clever solution 12 | double getVolumeOfCuboid(final l, final w, final h) => l * w * h; 13 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func GetVolumeOfCuboid(length, width, height float64) float64 { 4 | return length * width * height 5 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.java: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | 3 | public static double getVolumeOfCuboid(final double length, final double width, final double height) { 4 | return length * width * height; 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.js: -------------------------------------------------------------------------------- 1 | class Kata { 2 | static getVolumeOfCuboid(length, width, height) { 3 | return length * width * height; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.md: -------------------------------------------------------------------------------- 1 | # Volume of a Cuboid (8 kyu) 2 | 3 | https://www.codewars.com/kata/58261acb22be6e2ed800003a/ 4 | 5 | Bob needs a fast way to calculate the volume of a cuboid with three values: `length`, `width` and the `height` of the cuboid. Write a function to help Bob with this calculation. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.py: -------------------------------------------------------------------------------- 1 | # 1 Plain solution 2 | def getVolumeOfCubiod(length, width, height): 3 | return length * width * height 4 | 5 | # 2 Optimized solution 6 | def getVolumeOfCubiod(l, w, h): return l * w * h 7 | 8 | # 3 Clever solution 9 | getVolumeOfCubiod = lambda l, w, h: l * w * h 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.rs: -------------------------------------------------------------------------------- 1 | fn get_volume_of_cuboid(length: f32, width: f32, height: f32) -> f32 { 2 | length * width * height 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Volume of a Cuboid/(8 kyu) Volume of a Cuboid.ts: -------------------------------------------------------------------------------- 1 | export function getVolumeOfCuboid( 2 | length: number, 3 | width: number, 4 | height: number 5 | ): number { 6 | return length * width * height; 7 | } 8 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Well of Ideas - Easy Version/(8 kyu) Well of Ideas - Easy Version.cs: -------------------------------------------------------------------------------- 1 | public class Kata 2 | { 3 | public static string Well(string[] x) 4 | { 5 | int goodIdeas = 0; 6 | 7 | foreach (var idea in x) 8 | { 9 | if (idea == "good") { 10 | goodIdeas++; 11 | } 12 | if (goodIdeas > 2) 13 | { 14 | return "I smell a series!"; 15 | } 16 | } 17 | 18 | if (goodIdeas == 0) 19 | { 20 | return "Fail!"; 21 | } 22 | 23 | return "Publish!"; 24 | } 25 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) Well of Ideas - Easy Version/(8 kyu) Well of Ideas - Easy Version.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func Well(x []string) string { 4 | goodIdeas := 0 5 | 6 | for _, w := range x { 7 | if w == "good" { 8 | goodIdeas += 1 9 | } 10 | } 11 | 12 | if goodIdeas == 0 { 13 | return "Fail!" 14 | } else if goodIdeas > 0 && goodIdeas < 3 { 15 | return "Publish!" 16 | } else { 17 | return "I smell a series!" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Well of Ideas - Easy Version/(8 kyu) Well of Ideas - Easy Version.md: -------------------------------------------------------------------------------- 1 | # Well of Ideas - Easy Version (8 kyu) 2 | 3 | For every good kata idea there seem to be quite a few bad ones! 4 | 5 | In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'. 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) Well of Ideas - Easy Version/(8 kyu) Well of Ideas - Easy Version.ts: -------------------------------------------------------------------------------- 1 | export function well(x: string[]): string { 2 | const goodIdeas = x.filter(y => y === 'good').length; 3 | return (goodIdeas <= 2) ? 4 | ['Fail!', 'Publish!', 'Publish!'][goodIdeas] 5 | : 'I smell a series!'; 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::vector between(int start, int end) { 4 | std::vector res; 5 | 6 | for (int i = start; i <= end; i++) { 7 | res.push_back(i); 8 | } 9 | 10 | return res; 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | public static class Kata 4 | { 5 | public static int[] Between(int a, int b) 6 | { 7 | var result = new List(); 8 | 9 | for (var i = a; i <= b; i++) 10 | { 11 | result.Add(i); 12 | } 13 | 14 | return result.ToArray(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.dart: -------------------------------------------------------------------------------- 1 | List between(int a, int b){ 2 | var res = []; 3 | 4 | for (int i = a; i <= b; i++) { 5 | res.add(i); 6 | } 7 | 8 | return res; 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.java: -------------------------------------------------------------------------------- 1 | public class Kata { 2 | public static int[] between(int a, int b) { 3 | int[] result = new int[b - a + 1]; 4 | 5 | for (int i = a; i <= b; i++) { 6 | result[i - a] = i; 7 | } 8 | 9 | return result; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function between(a, b) { 3 | const res = []; 4 | 5 | for (let i = a; i <= b; i++) { 6 | res.push(i); 7 | } 8 | 9 | return res; 10 | } 11 | 12 | // 2 Optimized solution 13 | function between(a, b) { 14 | const res = Array(b - a + 1).fill(0); 15 | return res.map((_, i) => a + i); 16 | } 17 | 18 | // 3 Clever solution 19 | const between = (a, b) => 20 | Array.from( 21 | new Array(b - a + 1), 22 | (_, i) => a + i 23 | ); 24 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.md: -------------------------------------------------------------------------------- 1 | # What is between (8 kyu) 2 | 3 | Complete the function that takes two integers (a, b, where a < b) and return an array of all integers between the input parameters, including them. 4 | 5 | For example: 6 | 7 | ``` 8 | a = 1 9 | b = 4 10 | --> [1, 2, 3, 4] 11 | ``` 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.py: -------------------------------------------------------------------------------- 1 | def between(a,b): 2 | res = []; 3 | for i in range (a, b + 1): 4 | res.append(i) 5 | return res; 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.rs: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | fn between(a: i16, b: i16) -> Vec { 3 | let mut result = Vec::new(); 4 | for i in a..=b { 5 | result.push(i); 6 | } 7 | result 8 | } 9 | 10 | // 2 Optimized solution 11 | fn between(a: i16, b: i16) -> Vec { 12 | (a..=b).map(|x| x).collect() 13 | } 14 | 15 | // 3 Clever solution 16 | fn between(a: i16, b: i16) -> Vec { 17 | (a..=b).collect() 18 | } 19 | 20 | // 4 Coding golf 21 | fn between(a: i16, b: i16) -> Vec { 22 | Vec::from_iter(a..=b) 23 | } 24 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) What is between/(8 kyu) What is between.ts: -------------------------------------------------------------------------------- 1 | export function between(a: number, b: number): number[] { 2 | const res = Array(b - a + 1).fill(0); 3 | return res.map((_, i) => a + i); 4 | } 5 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int32_t double_integer(int32_t n) 4 | { 5 | return n << 1; 6 | } 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public static class Kata 4 | { 5 | public static int DoubleInteger(int n) 6 | { 7 | return n << 1; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.dart: -------------------------------------------------------------------------------- 1 | int doubleInteger(int i) => i << 1; 2 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func DoubleInteger(i int) int { 4 | return i << 1 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.java: -------------------------------------------------------------------------------- 1 | class Java { 2 | public static int doubleInteger(int i) { 3 | return 2 * i; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.js: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | function doubleInteger(i) { 3 | // i will be an integer. Double it and return it. 4 | return 2 * i; 5 | } 6 | 7 | // 2 Optimized solution 8 | const doubleInteger = i => 2 * i; 9 | 10 | // 3 Clever solution 11 | const doubleInteger = i => i << 1; 12 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.md: -------------------------------------------------------------------------------- 1 | # You Can't Code Under Pressure #1 (8 kyu) 2 | 3 | https://www.codewars.com/kata/53ee5429ba190077850011d4 4 | 5 | Code as fast as you can! You need to double the integer and return it. 6 | 7 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.py: -------------------------------------------------------------------------------- 1 | def double_integer(i): 2 | return 2 * i 3 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.rs: -------------------------------------------------------------------------------- 1 | fn double_integer(n: i32) -> i32 { 2 | 2 * n 3 | } 4 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) You Cant Code Under Pressure 1/(8 kyu) You Cant Code Under Pressure 1.ts: -------------------------------------------------------------------------------- 1 | // 1 Plain solution 2 | export function doubleInteger(i: number): number { 3 | return 2 * i; 4 | } 5 | 6 | // 2 Optimized solution 7 | export const doubleInteger = (i: number): number => 2 * i; 8 | 9 | // 3 Coding golf 10 | export const doubleInteger = (i: any) => i << 1; 11 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | std::string to_alternating_case(const std::string &str) 5 | { 6 | std::string ret = str; 7 | for (char &c : ret) 8 | { 9 | c = isupper(c) ? tolower(c) : toupper(c); 10 | } 11 | return ret; 12 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.dart: -------------------------------------------------------------------------------- 1 | String toAlternatingCase(final String str) { 2 | return String.fromCharCodes( 3 | str.runes.map( 4 | (int rune) { 5 | if (rune >= 'a'.codeUnitAt(0) && rune <= 'z'.codeUnitAt(0)) { 6 | return rune - 'a'.codeUnitAt(0) + 'A'.codeUnitAt(0); 7 | } else if (rune >= 'A'.codeUnitAt(0) && rune <= 'Z'.codeUnitAt(0)) { 8 | return rune - 'A'.codeUnitAt(0) + 'a'.codeUnitAt(0); 9 | } else { 10 | return rune; 11 | } 12 | }, 13 | ), 14 | ); 15 | } -------------------------------------------------------------------------------- /8kyu/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.go: -------------------------------------------------------------------------------- 1 | package kata 2 | 3 | func ToAlternatingCase(str string) string { 4 | rs := make([]rune, len(str)) 5 | for i, c := range str { 6 | r := c 7 | if c >= 'a' && c <= 'z' { 8 | r = c + 'A' - 'a' 9 | } 10 | if c >= 'A' && c <= 'Z' { 11 | r = c + 'a' - 'A' 12 | } 13 | rs[i] = r 14 | } 15 | return string(rs[:]) 16 | } 17 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.md: -------------------------------------------------------------------------------- 1 | # (8 kyu) altERnaTIng cAsE <=> ALTerNAtiNG CaSe 2 | 3 | http://www.codewars.com/kata/alternating-case-%3C-equals-%3E-alternating-case 4 | 5 | Define `String.prototype.toAlternatingCase` (or a similar function/method *such as* `to_alternating_case`/`toAlternatingCase`/`ToAlternatingCase` in your selected language; **see the initial solution for details**) such that each lowercase letter becomes uppercase and each uppercase letter becomes lowercase. 6 | 7 | For example: 8 | 9 | `"hello world".toAlternatingCase() === "HELLO WORLD"` 10 | -------------------------------------------------------------------------------- /8kyu/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe/(8 kyu) altERnaTIng cAsE = ALTerNAtiNG CaSe.ts: -------------------------------------------------------------------------------- 1 | export function toAlternatingCase(s: string): string { 2 | return s 3 | .split('') 4 | .map((c) => (c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase())) 5 | .join(''); 6 | } 7 | --------------------------------------------------------------------------------