├── .gitignore
├── .idea
├── .gitignore
├── codeStyles
│ └── codeStyleConfig.xml
├── misc.xml
├── modules.xml
├── uiDesigner.xml
└── vcs.xml
├── LICENSE
├── OneLinersRuby.md
├── README.md
├── community
├── adjacent-clone-letters
│ └── README.md
├── anadrome
│ ├── Anadrome.java
│ ├── AnadromeTest.java
│ └── README.md
├── array-partitioning
│ ├── ArrayPartitioning.java
│ └── README.md
├── base-converter
│ ├── BaseConverter.java
│ └── README.md
├── collatz-conjecture
│ ├── CollatzConjecture.java
│ └── README.md
├── consonant-value
│ ├── ConsonantValue.java
│ └── README.md
├── cube-root
│ └── README.md
├── deficient-numbers
│ └── README.md
├── disarium-numbers
│ ├── DisariumNumbers.java
│ └── README.md
├── draw-graph
│ ├── Graph.java
│ └── README.md
├── food-party
│ ├── README.md
│ └── Solution.java
├── gapful-numbers
│ ├── GapfulNumbers.java
│ ├── README.md
│ └── gapful_numbers.c
├── goldbachs-conjecture
│ └── README.md
├── guitar-subset
│ └── README.md
├── lab-numbers
│ └── README.md
├── magic-square
│ └── README.md
├── minimum-time-to-meet
│ ├── Main.java
│ └── README.md
├── power-calculator
│ ├── ExpressionEvaluation.java
│ └── README.md
├── prime-strings
│ ├── PrimeStrings.java
│ └── README.md
├── scrabble
│ ├── README.md
│ └── Scrabble.java
├── sort-a-string
│ ├── README.md
│ └── SortString.java
├── spy-number
│ ├── README.md
│ ├── SpyNumber.rb
│ └── SpyNumberBonus.rb
├── strange-root
│ ├── README.md
│ └── StrangeRoot.java
├── string-rotations
│ ├── README.md
│ └── StringRotations.java
├── sudoku-validator
│ └── README.md
├── summations-calculator
│ ├── README.md
│ └── SummationsCalculator.java
├── totatives
│ └── README.md
├── triangle
│ ├── README.md
│ └── Triangle.java
├── ugly-numbers
│ └── README.md
├── variable-name-validation
│ └── README.md
└── visitor-pattern
│ ├── README.md
│ ├── Solution.java
│ └── java-vistor-pattern-English.pdf
├── easy
├── argentina
│ ├── Argentina.c
│ ├── Argentina.java
│ ├── Argentina.py
│ ├── Argentina.rb
│ ├── README.md
│ └── argentina.cpp
├── cheer-creator
│ ├── CheerCreator.c
│ ├── CheerCreator.java
│ ├── CheerCreator.py
│ ├── CheerCreator.rb
│ ├── README.md
│ └── cheer_creator.cpp
├── easy.iml
├── extra-terristrials
│ ├── ExtraTerrestrials.c
│ ├── ExtraTerrestrials.java
│ ├── ExtraTerrestrials.py
│ ├── ExtraTerrestrials.rb
│ └── README.md
├── fruit-bowl
│ ├── FruitBowl.c
│ ├── FruitBowl.java
│ ├── FruitBowl.py
│ ├── FruitBowl.rb
│ └── README.md
├── gotham-city
│ ├── GothamCity.c
│ ├── GothamCity.java
│ ├── GothamCity.py
│ ├── GothamCity.rb
│ └── README.md
├── guard-flamingos
│ ├── GuardFlamingos.java
│ ├── GuardFlamingos.py
│ ├── GuardFlamingos.rb
│ ├── README.md
│ └── flamingos.c
├── halloween-candy
│ ├── HalloweenCandy.c
│ ├── HalloweenCandy.java
│ ├── HalloweenCandy.py
│ ├── HalloweenCandy.rb
│ └── README.md
├── hovercraft
│ ├── Hovercraft.c
│ ├── Hovercraft.java
│ ├── Hovercraft.py
│ ├── Hovercraft.rb
│ └── README.md
├── jungle-camping
│ ├── JungleCamping.c
│ ├── JungleCamping.java
│ ├── JungleCamping.py
│ ├── JungleCamping.rb
│ ├── JungleCamping_old.java
│ └── README.md
├── paint-costs
│ ├── PaintCosts.c
│ ├── PaintCosts.java
│ ├── PaintCosts.py
│ ├── PaintCosts.rb
│ ├── README.md
│ └── paint_cost.cpp
├── popsicles
│ ├── Popsicles.c
│ ├── Popsicles.cpp
│ ├── Popsicles.cs
│ ├── Popsicles.java
│ ├── Popsicles.py
│ ├── Popsicles.rb
│ └── README.md
├── pro-balconies
│ ├── Balconies.c
│ ├── Balconies.java
│ ├── Balconies.py
│ ├── Balconies.rb
│ └── README.md
├── pro-ballpark-orders
│ ├── BallparkOrders.java
│ ├── BallparkOrders.py
│ ├── BallparkOrders.rb
│ ├── README.md
│ └── ballpark_orders.c
├── pro-candles
│ ├── Candles.c
│ ├── Candles.java
│ ├── Candles.py
│ ├── Candles.rb
│ └── README.md
├── pro-duct-tape
│ ├── DuctTape.c
│ ├── DuctTape.java
│ ├── DuctTape.py
│ ├── DuctType.rb
│ └── README.md
├── pro-easter-eggs
│ ├── EasterEggs.java
│ ├── EasterEggs.py
│ ├── EasterEggs.rb
│ ├── README.md
│ └── easter-eggs.c
├── pro-isogram-detector
│ ├── IsogramDetector.java
│ ├── IsogramDetector.py
│ ├── IsogramDetector.rb
│ └── README.md
├── pro-izzy-the-iguana
│ ├── IzzyIguana.java
│ ├── IzzyIguana.py
│ ├── IzzyIguana.rb
│ └── README.md
├── pro-kaleidoscopes
│ ├── Kaleidoscopes.java
│ ├── Kaleidoscopes.py
│ ├── Kaleidoscopes.rb
│ ├── KaleidoscopesDifference.java
│ ├── KaleidoscopesDifference.txt
│ ├── Kaleidoscopes_Fails.java
│ ├── Kaleidoscopes_WTF.java
│ ├── README.md
│ └── kaleidoscopes.c
├── pro-land-ho
│ ├── LandHo.java
│ ├── LandHo.py
│ ├── LandHo.rb
│ ├── README.md
│ └── land_ho.c
├── pro-multiples
│ ├── Multiples.java
│ ├── Multiples.py
│ ├── Multiples.rb
│ ├── README.md
│ └── multiples.c
├── pro-neverland
│ ├── Neverland.java
│ ├── Neverland.py
│ ├── Neverland.rb
│ ├── README.md
│ └── neverland.c
├── pro-number-of-ones
│ ├── NumberOfOnes.java
│ ├── NumberOfOnes.py
│ ├── NumberOfOnes.rb
│ └── README.md
├── pro-vowel-counter
│ ├── README.md
│ ├── VowelCounter.java
│ ├── VowelCounter.py
│ ├── VowelCounter.rb
│ ├── VowelCounterRE.java
│ └── vowel_counter.c
├── pro-zip-code-validator
│ ├── README.md
│ ├── ZipCodeValidator.java
│ ├── ZipCodeValidator.py
│ └── ZipCodeValidator.rb
└── skee-ball
│ ├── README.md
│ ├── Skee-Ball.c
│ ├── SkeeBall.java
│ ├── SkeeBall.py
│ ├── SkeeBall.rb
│ └── skee_ball.cpp
├── hard
├── hard.iml
├── new-drivers-license
│ ├── NewDriversLicense.c
│ ├── NewDriversLicense.java
│ ├── NewDriversLicense.py
│ ├── NewDriversLicense.rb
│ ├── NewDriversLicense_2.py
│ ├── NewDriversLicense_old.java
│ └── README.md
├── password-validation
│ ├── PasswordValidation.c
│ ├── PasswordValidation.java
│ ├── PasswordValidation.py
│ ├── PasswordValidation.rb
│ ├── PasswordValidation_2.py
│ └── README.md
├── pro-2d-map
│ ├── Map2D.java
│ ├── Map2D.py
│ ├── Map2D.rb
│ ├── README.md
│ └── map.c
├── pro-digits-of-pi
│ ├── DigitsOfPi.java
│ ├── DigitsOfPi.rb
│ ├── DigitsPi.py
│ ├── PiCalculation.java
│ └── README.md
├── pro-hofstadter-q-sequence
│ ├── HofstadtersQSequence.java
│ ├── HofstadtersQSequence.py
│ ├── HofstadtersQSequence.rb
│ ├── HofstadtersQSequence_(bad).java
│ ├── README.md
│ └── hofstadter_q_sequence.c
├── pro-its-a-sign
│ ├── ItsSign.java
│ ├── ItsSign.rb
│ ├── README.md
│ ├── Sign.py
│ └── its_a_sign.c
├── pro-mathematics
│ ├── Mathematics.java
│ ├── Mathematics.py
│ └── README.md
├── pro-poker-hand
│ ├── PokerHand.c
│ ├── PokerHand.java
│ ├── PokerHand.py
│ └── README.md
├── pro-word-rank
│ ├── README.md
│ ├── WordRank.py
│ └── WordRank_2.py
└── security
│ ├── README.md
│ ├── Security.c
│ ├── Security.java
│ ├── Security.rb
│ ├── Security2.java
│ ├── Security_Regex.c
│ └── security.py
├── medium
├── average-word-length
│ ├── AverageWordLength.c
│ ├── AverageWordLength.java
│ ├── AverageWordLength.rb
│ ├── AverageWordLengthStream.java
│ ├── AverageWordLength_1.py
│ ├── AverageWordLength_2.py
│ ├── README.md
│ └── essay.txt
├── convert-date
│ ├── ConvertDate.c
│ ├── ConvertDate.java
│ ├── ConvertDate.py
│ ├── ConvertDate_RE.java
│ └── README.md
├── deja-vu
│ ├── DejaVu.c
│ ├── DejaVu.java
│ ├── DejaVu.py
│ ├── DejaVu.rb
│ ├── DejaVu_re.py
│ └── README.md
├── medium.iml
├── military-time
│ ├── MilitaryTime.c
│ ├── MilitaryTime.java
│ ├── MilitaryTime.py
│ ├── MilitaryTimeClassic.java
│ ├── MilitaryTimeRE.java
│ └── README.md
├── no-numerals
│ ├── NoNumerals.c
│ ├── NoNumerals.java
│ ├── NoNumerals.py
│ ├── NoNumerals.rb
│ ├── NoNumerals_old.java
│ └── README.md
├── pig-latin
│ ├── PigLatin.c
│ ├── PigLatin.py
│ ├── PigLatin.rb
│ ├── PigLatinClassic.java
│ ├── PigLatinRE.java
│ ├── PigLatinStream.java
│ └── README.md
├── pro-CMYK-to-RGB
│ ├── CMYK2RGB.rb
│ ├── CMYKtoRGB.py
│ ├── CmykToRgb.java
│ └── README.md
├── pro-building-blocks
│ ├── BuildingBlocks.java
│ ├── BuildingBlocks.py
│ ├── BuildingBlocks.rb
│ ├── README.md
│ └── building_blocks.c
├── pro-camel-to-snake
│ ├── Camel2Snake.rb
│ ├── CamelToSnake.java
│ ├── CamelToSnakeClassic.java
│ └── README.md
├── pro-carrot-cake
│ ├── CarrotCake.java
│ ├── CarrotCake.py
│ ├── CarrotCake.rb
│ ├── README.md
│ └── carrot_cake.c
├── pro-credit-card-validator
│ ├── CreditCardValidator.java
│ ├── CreditCardValidator.py
│ ├── CreditCardValidator.rb
│ └── README.md
├── pro-day-of-the-week
│ ├── DayOfWeek.java
│ └── README.md
├── pro-days-between-dates
│ ├── DaysBetweenDates.java
│ └── README.md
├── pro-divisible
│ ├── Divisible.java
│ ├── Divisible.py
│ ├── Divisible.rb
│ ├── README.md
│ └── divisible.c
├── pro-duty-free
│ ├── DutyFree.java
│ ├── DutyFree.py
│ ├── DutyFree.rb
│ ├── README.md
│ └── duty_free.c
├── pro-even-numbers
│ ├── EvenNumbers.java
│ ├── EvenNumbers.py
│ ├── EvenNumbers.rb
│ ├── README.md
│ └── even_numbers.c
├── pro-flowing-words
│ ├── FlowingWords.java
│ ├── FlowingWords.py
│ ├── FlowingWords.rb
│ └── README.md
├── pro-hex-color-code-generator
│ ├── HexCode.py
│ ├── HexColorCodeGenerator.java
│ ├── HexColorCodeGenerator.rb
│ ├── README.md
│ └── hex_color_code_generator.c
├── pro-how-far
│ ├── HowFar.java
│ ├── HowFar.py
│ ├── HowFar.rb
│ ├── README.md
│ └── how_far.c
├── pro-initials
│ ├── Initials.java
│ ├── Initials.py
│ ├── Initials.rb
│ └── README.md
├── pro-longest-common-substring
│ ├── LongestCommonSubstring.py
│ └── README.md
├── pro-missing-numbers
│ ├── MissingNumbers.java
│ ├── MissingNumbers.py
│ ├── MissingNumbers.rb
│ └── README.md
├── pro-name-buddy
│ ├── NameBuddy.java
│ ├── NameBuddy.py
│ ├── NameBuddy.rb
│ ├── NameBuddyRegEx.java
│ ├── NameBuddy_re.py
│ └── README.md
├── pro-roadrunner
│ ├── README.md
│ ├── Roadrunner.java
│ ├── Roadrunner.py
│ ├── Roadrunner.rb
│ └── roadrunner.c
├── pro-safety-deposit-boxes
│ ├── README.md
│ ├── SafetyDepositBoxes.java
│ ├── SafetyDepositBoxes.py
│ ├── SafetyDepositBoxes.rb
│ ├── SafetyDepositBoxesArrays.java
│ └── safety_deposit_boxes.c
├── pro-snap-crackle-and-pop
│ ├── README.md
│ ├── SnapCrackle.py
│ ├── SnapCrackleAndPop.java
│ ├── SnapCracklePop.rb
│ ├── snap_crackle_pop.c
│ └── snap_crackle_pop.cpp
├── pro-snowballing-numbers
│ ├── README.md
│ ├── SnowballingNumbers.java
│ ├── SnowballingNumbers.py
│ ├── SnowballingNumbers.rb
│ └── snowballing.c
├── pro-splitting-strings
│ ├── README.md
│ ├── SplittingStrings.java
│ ├── SplittingStrings.py
│ ├── SplittingStrings.rb
│ ├── SplittingStringsStream.java
│ └── splitting_strings.c
├── pro-super-sale
│ ├── README.md
│ ├── SuperSale.java
│ ├── SuperSale.py
│ ├── SuperSale.rb
│ └── super_sale.c
├── pro-tax-free
│ ├── README.md
│ ├── TaxFree.java
│ ├── TaxFree.py
│ └── TaxFree.rb
├── pro-text-decompressor
│ ├── README.md
│ ├── TextDecompressor.c
│ ├── TextDecompressor.java
│ ├── TextDecompressor.py
│ ├── TextDecompressor.rb
│ └── TextDecompressor2.java
├── secret-message
│ ├── README.md
│ ├── SecretMessage.c
│ ├── SecretMessage.java
│ ├── SecretMessage.py
│ └── SecretMessage.rb
├── symbols
│ ├── README.md
│ ├── Symbols.c
│ ├── Symbols.java
│ ├── Symbols.py
│ └── Symbols.rb
├── thats-odd
│ ├── README.md
│ ├── ThatsOdd.c
│ ├── ThatsOdd.java
│ ├── ThatsOdd.py
│ ├── ThatsOdd.rb
│ ├── ThatsOdd_2.py
│ └── ThatsOdd_old.java
├── the-spy-life
│ ├── README.md
│ ├── TheSpyLife.c
│ ├── TheSpyLife.java
│ ├── TheSpyLife.py
│ └── TheSpyLife.rb
└── youtube-link-finder
│ ├── README.md
│ ├── YouTubeLinkFinder.c
│ ├── YouTubeLinkFinder.java
│ ├── YouTubeLinkFinder.py
│ └── YouTubeLinkFinder.rb
├── one-statement
├── Argentina.java
├── AverageWordLength.java
├── CamelToSnake.java
├── Candles.java
├── DejaVu.java
├── Divisible.java
├── DuctTape.java
├── DutyFree.java
├── EasterEggs.java
├── EvenNumbers.java
├── FlowingWords.java
├── FlowingWordsRE.java
├── FlowingWordsRE2.java
├── FruitBowl.java
├── GothamCity.java
├── GuardFlamingos.java
├── HalloweenCandy.java
├── HexColorCodeGenerator.java
├── HowFar.java
├── Initials.java
├── IsogramDetector.java
├── ItsSign.java
├── IzzyIguana.java
├── JungleCamping.java
├── LandHo.java
├── MilitaryTime.java
├── Multiples.java
├── NameBuddy.java
├── NoNumerals.java
├── NumberOfOnes.java
├── PaintCosts.java
├── PigLatin.java
├── Popsicles.java
├── README.md
├── SecretMessage.java
├── Security.java
├── SnapCrackleAndPop.java
├── SnowballingNumbers.java
├── SuperSale.java
├── Symbols.java
├── TaxFree.java
├── TextDecompressor.java
├── TheSpyLife.java
├── VowelCounter.java
├── YouTubeLinkFinder.java
└── ZipCodeValidator.java
└── sololearn-challenges.iml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 | *.class
39 |
40 | #BlueJ files
41 | *.ctxt
42 | *.bluej
43 |
44 | # Debug files
45 | *.dSYM/
46 | *.su
47 | *.idb
48 | *.pdb
49 |
50 | # Kernel Module Compile Results
51 | *.mod*
52 | *.cmd
53 | .tmp_versions/
54 | modules.order
55 | Module.symvers
56 | Mkfile.old
57 | dkms.conf
58 | /out/
59 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /workspace.xml
3 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/community/adjacent-clone-letters/README.md:
--------------------------------------------------------------------------------
1 | # Adjacent Clone Letters
2 |
3 | Suppose you have a 2D array of letters. A letter is adjacent to another if it is positioned either at the top, bottom, left, right, upper left, upper right, lower left or lower right of the other.
4 |
5 | Create a program that accepts the dimensions of a 2D array and fills that array with random letters.
6 | Then search through the array for adjacent similar letters.
7 | Indicate which letters have adjacent clones and enumerate them.
8 |
9 | For example:
10 | ```
11 | Input: 5x4
12 | Output:
13 | Array:
14 | A C T T S
15 | R T N G T
16 | E E G G A
17 | U W P F A
18 | Results:
19 | T = 4 adjacent clones
20 | G = 3 adjacent clones
21 | E = 2 adjacent clones
22 | A = 2 adjacent clones
23 | ```
24 |
25 | > Bonus: Replace clone letters to get the array without adjacent clone letters.
26 |
--------------------------------------------------------------------------------
/community/anadrome/Anadrome.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.function.Function;
3 | import java.util.stream.Collectors;
4 |
5 | public class Anadrome {
6 | public static void main(final String[] args) {
7 | final var input = new Scanner(System.in);
8 | final var word = input.nextLine();
9 | input.close();
10 |
11 | final var isAnadrome = word.chars()
12 | .mapToObj(Integer::new)
13 | .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
14 | .entrySet()
15 | .stream()
16 | .filter(i -> i.getValue() % 2 != 0)
17 | .count() < 2;
18 |
19 | System.out.print(isAnadrome ? "yes" : "no");
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/community/anadrome/README.md:
--------------------------------------------------------------------------------
1 | # Anadrome
2 |
3 | An anagram is a word or phrase formed by rearranging the letters of a different word or phrase. For example, "Sool" is an anagram for "Solo".
4 |
5 | A palindrome is a word or phrase which reads the same backward as forward, such as "madam".
6 |
7 | An anadrome is a word or phrase if any of its anagrams form a palindrome.
8 |
9 | For example:
10 | ```
11 | Input: "SoloSolo"
12 | Output: yes ("SoollooS" is an anagram of "SoloSolo" which also is a palindrome).
13 |
14 | Input: "3haha"
15 | Output: yes ("ha3ah" is an anagram of "3haha" which also is a palindrome).
16 |
17 | Input: "Solo"
18 | Output: no
19 | ```
20 | Write a program to check if the user input is an anadrome or not.
21 |
--------------------------------------------------------------------------------
/community/array-partitioning/README.md:
--------------------------------------------------------------------------------
1 | # Array Partitioning
2 |
3 | Divide a given array of numbers into two subarrays such that the absolute difference between their sums is the smallest possible. For example, the array [2, 5, 4, 7, 15, 20] can be divided into subarrays [15, 7, 4] and [20, 5, 2]. The difference between the sums of those arrays is 1, and it is the smallest.
4 |
5 | > The first line of the input contains the size of the array. The next line contains the array elements.
6 | > Print the subarrays and the difference of their sums.
7 |
8 | **For example:**
9 |
10 | ```
11 | Input:
12 | 6
13 | 4, 15, 20, 2, 7, 5
14 |
15 | Output:
16 | [15, 7, 4]
17 | [20, 5, 2]
18 | 1
19 | ```
20 | (The sum of the first subarray is 26, the sum of the second subarray is 27, the difference is 1.)
21 |
22 | > Share your creations in the comments section below.
23 |
--------------------------------------------------------------------------------
/community/base-converter/README.md:
--------------------------------------------------------------------------------
1 | # Base Converter
2 |
3 | In mathematics, a base is the number of different digits or combination of digits and letters that a system of counting uses to represent numbers.
4 | For example, the most common base used today is the decimal system. Because "dec" means 10, it uses the 10 digits from 0 to 9.
5 | A decimal number has base 10, a binary has base 2, an octal has base 8, etc.
6 |
7 | Given a non-negative integer & a base as input, create a program to convert the given decimal into the corresponding base.
8 |
9 | Some Examples:
10 | ```
11 | Input: 25 7
12 | Output: 34
13 |
14 | Input: 368 4
15 | Output: 11300
16 |
17 | Input: 78 3
18 | Output: 2220
19 | ```
20 |
21 | > Bonus: Try not to use any library functions.
22 |
--------------------------------------------------------------------------------
/community/consonant-value/ConsonantValue.java:
--------------------------------------------------------------------------------
1 | public class ConsonantValue {
2 |
3 | public static void main(String[] args) {
4 | final var word = new java.util.Scanner(System.in).next();
5 | System.out.print(solve(word));
6 | }
7 |
8 | public static int solve(final String s) {
9 | return java.util.Arrays
10 | .stream(s.split("[aeiou]+"))
11 | .mapToInt(str -> str.chars().map(c -> 1 + c - 'a').sum())
12 | .max().orElse(0);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/community/consonant-value/README.md:
--------------------------------------------------------------------------------
1 | # Consonant value
2 |
3 | Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings. Consonants are any letters of the alphabet except "aeiou".
4 |
5 | We shall assign the following values: a = 1, b = 2, c = 3, .... z = 26.
6 |
7 | For example, for the word "zodiacs", let's cross out the vowels. We get: "z o d ia cs"
8 |
9 | -- The consonant substrings are: "z", "d" and "cs" and the values are z = 26, d = 4 and cs = 3 + 19 = 22. The highest is 26.
10 | solve("zodiacs") = 26
11 |
12 | For the word "strength", solve("strength") = 57
13 | -- The consonant substrings are: "str" and "ngth" w
14 |
--------------------------------------------------------------------------------
/community/cube-root/README.md:
--------------------------------------------------------------------------------
1 | # Cube Root
2 |
3 | A cube root of a number x is a number y such that y*y*y = x.
4 | Example: 2 × 2 × 2 = 8, so the cube root of 8 is 2.
5 |
6 | Write a code to find the cube root of a number N to a precision of 0.0001 without using any standard functions.
7 |
8 | For example:
9 | ```
10 | Input: 729
11 | Output: 9
12 |
13 | Input: 41
14 | Output: 3.4482
15 |
16 | Input: 2
17 | Output: 1.2599
18 | ```
19 | > Share your creations in the comments section below!
20 |
--------------------------------------------------------------------------------
/community/deficient-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Deficient Numbers
2 |
3 | A number is considered deficient if the sum of its factors is less than twice that number.
4 |
5 | For Example:
6 | ```
7 | 10 is a deficient number.
8 | Factors of 10 are 1, 2, 5, 10
9 | Sum is 1 + 2 + 5 + 10 = 18 < 2 * 10
10 | ```
11 | ## Tasks:
12 |
13 | (Easy) Write a program to verify whether a given number is deficient or not.
14 | (Medium) Write a program to find all the deficient numbers in a range.
15 | (Hard) Given a number, write a program to display its factors, their sum and then verify whether it's deficient or not.
16 |
--------------------------------------------------------------------------------
/community/disarium-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Disarium Numbers
2 |
3 | A number is called a Disarium number if the sum of the powers of its digits equals the number itself. The digits are powered to their positions in the number.
4 |
5 | For example:
6 | ```
7 | Input: 135
8 | Output: true
9 | ```
10 | 135 is a Disarium number because it equals to 1^1 + 3^2 + 5^3 (each digit powered to the position in the number).
11 |
12 | Write a program to check if the user input is a Disarium number or not.
13 |
14 | > Bonus: Print all the Disarium numbers in a given range.
15 |
--------------------------------------------------------------------------------
/community/draw-graph/README.md:
--------------------------------------------------------------------------------
1 | Draw like a graph without using any library
2 |
3 | Input : 47325
4 |
5 | Odd will be in up and even will be in down
6 |
7 | Output looks like this
8 |
9 | ```
10 | / \
11 | 4 / \
12 | / \7
13 | / \
14 | \ /
15 | \ /3. Like this
16 | \/
17 | ```
18 |
--------------------------------------------------------------------------------
/community/gapful-numbers/GapfulNumbers.java:
--------------------------------------------------------------------------------
1 | // Gapful numbers
2 | // https://www.sololearn.com/learn/14303/?ref=app
3 |
4 | import java.util.Scanner;
5 | import java.util.stream.IntStream;
6 |
7 | public class GapfulNumbers {
8 |
9 | public static boolean isGapful(final int number) {
10 | return number > 99
11 | && number <= 999
12 | && 0 == number % (number / 100 + number % 10);
13 | }
14 |
15 | public static void main(final String[] args) {
16 |
17 | final var in = new Scanner(System.in);
18 | final var start = in.nextInt();
19 | final var end = in.nextInt();
20 | in.close();
21 |
22 | IntStream.rangeClosed(start, end)
23 | .filter(GapfulNumbers::isGapful)
24 | .forEach(System.out::println);
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/community/gapful-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Gapful Numbers
2 |
3 | A gapful number is a number of at least 3 digits that is divisible by the number formed by the first and last digit of the original number.
4 |
5 | For Example:
6 | ```
7 | Input: 192
8 | Output: true (192 is gapful because it is divisible 12)
9 |
10 | Input: 583
11 | Output: true (583 is gapful because it is divisible by 53)
12 |
13 | Input: 210
14 | Output: false (210 is not gapful because it is not divisible by 20)
15 | ```
16 | Write a program to check if the user input is a gapful number or not.
17 |
18 | > Bonus: Print all the gapful numbers in a given range.
19 |
--------------------------------------------------------------------------------
/community/gapful-numbers/gapful_numbers.c:
--------------------------------------------------------------------------------
1 | // Gapful numbers
2 | // https://www.sololearn.com/learn/14303/?ref=app
3 |
4 | #include
5 |
6 | int main() {
7 | int number;
8 | scanf("%d", &number);
9 | int rest = number % (number / 100 + number % 10);
10 | printf("Number %d %d", number, rest);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/community/goldbachs-conjecture/README.md:
--------------------------------------------------------------------------------
1 | # Goldbach's Conjecture
2 |
3 | Goldbach's conjecture is a rule in math that states the following: every even number greater than 2 can be expressed as the sum of two prime numbers.
4 |
5 | Write a program that finds every possible pair of prime numbers, whose sum equals the given number or a set of numbers within a range.
6 |
7 | For example:
8 | ```
9 | Input: 16
10 | Output:
11 | 3 + 13
12 | 5 + 11
13 |
14 | Input: 32
15 | Output:
16 | 3 + 29
17 | 13 + 19
18 |
19 | Input: 4, 8
20 | Output:
21 | 4: 2 + 2
22 | 6: 3 + 3
23 | 8: 3 + 5
24 | ```
25 |
--------------------------------------------------------------------------------
/community/guitar-subset/README.md:
--------------------------------------------------------------------------------
1 | # Guitar Subset
2 |
3 | For a list of integers S and a target number G, a subset of S that adds up to G is called a guitar subset.
4 |
5 | **For example:**
6 | ```
7 | Input:
8 | 24
9 | [12, 1, 61, 5, 9, 2]
10 | Output:
11 | [12, 9, 2, 1]
12 | ```
13 | (G=24, S=[12, 1, 61, 5, 9, 2], there is a guitar subset [12, 9, 2, 1] that adds up to 24).
14 |
15 | Integers can appear more than once in the list. You may assume all numbers in the list are positive.
16 |
17 | Write a program to check if the user input has a guitar subset for the specified number G or not (both the list of integers and the number G are input parameters).
18 |
--------------------------------------------------------------------------------
/community/lab-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Lab Numbers
2 |
3 | A lab number is a number such that the square of any of its prime divisors is still one of its divisors.
4 |
5 | **For example:**
6 |
7 | ```
8 | Input: 8
9 | Output: true (2 is a prime divisor of 8, and 2x2=4 is also a divisor of 8)
10 |
11 | Input: 50
12 | Output: true (5 is a prime divisor of 50, and 5x5=25 is also a divisor of 50)
13 | ```
14 |
15 | Write a program to check if the user input is a Lab number or not.
16 |
17 | > Bonus: Print all the Lab numbers in a given range.
18 |
--------------------------------------------------------------------------------
/community/magic-square/README.md:
--------------------------------------------------------------------------------
1 | # Magic Square
2 |
3 | A magic square is a matrix of numbers in which the sums of elements in each row/column/diagonal are the same. That sum is called the magic sum.
4 |
5 | For example:
6 | ```
7 | Input:
8 | 4 3 8
9 | 9 5 1
10 | 2 7 6
11 |
12 | Output:
13 | It is a magic square with the magic sum 15.
14 | 4 + 3 + 8 = 9 + 5 + 1 = 2 + 7 + 6 = 15 (Rows)
15 | 4 + 9 + 2 = 3 + 5 + 7 = 8 + 1 + 6 = 15 (Columns)
16 | 4 + 5 + 6 = 8 + 5 + 2 = 15 (Diagonals)
17 | ```
18 | Write a program to check if the input matrix is a magic square or not. If it is a magic square, display the magic sum.
19 |
20 | > Bonus: take the square side length as input and generate a magic square.
21 |
--------------------------------------------------------------------------------
/community/prime-strings/PrimeStrings.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.regex.Pattern;
3 |
4 | public class PrimeStrings {
5 |
6 | public static void main(final String[] args) {
7 | final var input = new Scanner(System.in);
8 | final var string = input.nextLine();
9 | input.close();
10 |
11 | final var isPrime = !Pattern.matches("^(.+)\\1+$", string);
12 |
13 | System.out.println(isPrime ? "prime" : "not prime");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/community/prime-strings/README.md:
--------------------------------------------------------------------------------
1 | # Prime Strings
2 |
3 | A String is called prime if it can't be constructed by concatenating multiple (more than one) equal strings.
4 |
5 | For example:
6 | ```
7 | "abac" is prime, but "xyxy" is not ("xyxy" = "xy" + "xy").
8 | ```
9 |
10 | Implement a program which outputs whether a given string is prime.
11 |
12 | Examples
13 | ```
14 | Input: "xyxy"
15 | Output: "not prime"
16 |
17 | Input: "aaaa"
18 | Output: "not prime"
19 |
20 | Input: "hello"
21 | Output: "prime"
22 | ```
23 |
--------------------------------------------------------------------------------
/community/scrabble/README.md:
--------------------------------------------------------------------------------
1 | # Scrabble
2 |
3 | Give a variable number of words, create a program to output the word with the maximum score, based on the following scoring system:
4 | The score of a word is calculated based on its character values, according to this table:
5 | ```
6 | e, a, i, o, n, r, t, l, s, u are equal 1 point
7 | d, g 2 points
8 | b, c, m, p 3 points
9 | f, h, v, w, y 4 points
10 | k 5 points
11 | j, x 8 points
12 | q, z 10 points
13 | ```
14 | The max length of a word is 10 letters.
15 |
16 | For example:
17 | ```
18 | input { "This", "is", "a", "cool" , "Challenge" }
19 | output : Challenge
20 | ```
21 |
--------------------------------------------------------------------------------
/community/sort-a-string/README.md:
--------------------------------------------------------------------------------
1 | # Sort a String
2 |
3 | Given a string as input, output its characters alphabetically sorted from A to Z.
4 | For Example:
5 | ```
6 | Input: challenge
7 | Output: aceeghlln
8 |
9 | Number should go first:
10 | Input: happy42
11 | Output: 24ahppy
12 |
13 | Special characters, such as symbols, go before numbers and letters:
14 | Input: $tar3
15 | Output: $3art
16 | ```
17 | Whitespaces should be ignored.
18 |
--------------------------------------------------------------------------------
/community/sort-a-string/SortString.java:
--------------------------------------------------------------------------------
1 | /*
2 | Given a string as input, output its characters alphabetically sorted from A to Z.
3 | Whitespaces should be ignored.
4 | */
5 |
6 | import java.util.Arrays;
7 | import java.util.Scanner;
8 |
9 | public class SortString {
10 | public static void main(String[] args) {
11 | final var in = new Scanner(System.in);
12 | final var string = in.nextLine();
13 |
14 | final var temp = string.replaceAll("\\s", "").toCharArray();
15 | Arrays.sort(temp);
16 |
17 | final var sortedString = new String(temp);
18 | System.out.println(sortedString);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/community/spy-number/README.md:
--------------------------------------------------------------------------------
1 | # Spy Number
2 |
3 | A number is called a Spy number, if the sum and product of its digits are equal.
4 | For example, 123 is a Spy number, as the sum of its digits is 6 (1+2+3) which is equal to the product of its digits: 6 (1x2x3).
5 |
6 | Write a program to check if the user input is a Spy number or not.
7 |
8 | For example:
9 | ```
10 | Input: 1412
11 | Output: true
12 |
13 | Input: 247
14 | Output: false
15 | ```
16 | **Bonus:** Print all the Spy numbers in a given range.
17 |
--------------------------------------------------------------------------------
/community/spy-number/SpyNumber.rb:
--------------------------------------------------------------------------------
1 | n = gets.chars.map(&:to_i)
2 | puts n.inject(:+) == n.inject(:*)
3 |
--------------------------------------------------------------------------------
/community/spy-number/SpyNumberBonus.rb:
--------------------------------------------------------------------------------
1 | min = gets.to_i
2 | max = gets.to_i
3 |
4 | for n in min..max do
5 | puts n if n.digits.inject(:+) == n.digits.inject(:*)
6 | end
7 |
--------------------------------------------------------------------------------
/community/strange-root/README.md:
--------------------------------------------------------------------------------
1 | # Strange Root
2 |
3 | A number has a strange root if its square and square root share any digit. For example, 2 has a strange root because the square root of 2 equals 1.414 (consider the first three digits after the dot) and it contains 4 (which is the square of 2).
4 |
5 | Examples:
6 | ```
7 | Input: 11
8 | Output: true
9 | (the square root of 11 is 3.317, the square of 11 is 121. They share the same digit, 1.)
10 |
11 | Input: 24
12 | Output: false (the square root of 24 (4.899) and square (576) do not share any digits)
13 | ```
14 |
15 | Write a program to check if the user input has a strange root or not.
16 |
--------------------------------------------------------------------------------
/community/string-rotations/README.md:
--------------------------------------------------------------------------------
1 | # String Rotations
2 |
3 | Create a function that accepts a string argument and returns an array of strings, which are shifted versions of the argument string.
4 | ```
5 | Sample Input
6 | "Hello"
7 |
8 | Sample Output
9 | ["elloH", "lloHe", "loHel", "oHell", "Hello"]
10 | ```
11 | As you can see from the example above, each element shifts the first character of the previous version to the end.
12 | The original string should be included in the output array. The order matters; each element of the output array should be the shifted version of the previous element.
13 | The output array should have the same length as the input string.
14 | The function should return an empty array when a zero-length String is provided as the argument.
15 |
16 | > Share your creations in the comments section below!
17 |
--------------------------------------------------------------------------------
/community/string-rotations/StringRotations.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | import java.util.Scanner;
3 |
4 | public class StringRotations {
5 |
6 | public static String shiftWord(String word) {
7 | return word.substring(1) + word.charAt(0);
8 | }
9 |
10 | public static void main(final String[] args) {
11 |
12 | final var in = new Scanner(System.in);
13 | final var word = in.next();
14 | in.close();
15 |
16 | final String[] rotations = new String[word.length()];
17 |
18 | String next = word;
19 | for (int i = 0; i < word.length(); ++i) {
20 | next = shiftWord(next);
21 | rotations[i] = next;
22 | }
23 |
24 | System.out.print(Arrays.toString(rotations));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/community/summations-calculator/README.md:
--------------------------------------------------------------------------------
1 | # Summations Calculator
2 |
3 | Create a program that takes 3 inputs, a lower bound, an upper bound and the expression. Calculate the sum of that range based on the given expression and output the result.
4 |
5 | For Example:
6 | ```
7 | Input: 2 4 *2
8 | Output: 18 (2*2 + 3*2 + 4*2)
9 |
10 | Input: 1 5 %2
11 | Output: 3 (1%2 + 2%2 + 3%2 + 4%2 + 5%2)
12 | ```
13 | Share your creations in the comments section below!
14 |
--------------------------------------------------------------------------------
/community/totatives/README.md:
--------------------------------------------------------------------------------
1 | # Totatives
2 |
3 | In number theory, Euler's totient function (phi function) counts the positive integers up to a given integer n that are relatively prime to n. Two integers are said to be relatively prime if the only positive integer (factor) that divides both of them is 1.
4 |
5 | The numbers less than or equal to and relatively prime to a given number n are called totatives.
6 |
7 | For example:
8 | ```
9 | Input: 9
10 | Output: 6
11 | ```
12 | (The totatives of n = 9 are six numbers 1, 2, 4, 5, 7 and 8, so phi(9) = 6 because 3, 6 and 9 are not relatively prime with 9)
13 |
14 | Note that, phi(1)=1 because 1 is considered to be relatively prime to every positive number.
15 |
16 | Write a program to take positive integer n as an input and print the number of totatives in the numbers less than or equal to n.
17 |
--------------------------------------------------------------------------------
/community/triangle/README.md:
--------------------------------------------------------------------------------
1 | # Triangle
2 |
3 | Write a program that takes three integer values from the user input and outputs true if a triangle can be constructed with the sides of given length.
4 |
5 | For example:
6 | ```
7 | Input: 3, 4, 5
8 | Output: True
9 |
10 | Input: 10, 2, 9
11 | Output: True
12 |
13 | Input: 7, 9, 1
14 | Output: False
15 | ```
16 | Bonus: Visualize the triangles (web or terminal).
17 |
--------------------------------------------------------------------------------
/community/triangle/Triangle.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Triangle {
4 | public static void main(String[] args) {
5 |
6 | final var input = new Scanner(System.in);
7 | final var a = input.nextInt();
8 | final var b = input.nextInt();
9 | final var c = input.nextInt();
10 | input.close();
11 |
12 | final var isValidTriangle = a + b > c && a + c > b && b + c > a;
13 |
14 | System.out.print(isValidTriangle);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/community/ugly-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Ugly Numbers
2 |
3 | A number is considered to be ugly if its only prime factors are 2, 3 or 5.
4 |
5 | [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, …] is the sequence of ugly numbers.
6 |
7 | > By convention, 1 is also included.
8 |
9 | ## Task:
10 |
11 | Create a program which takes a number n as input and checks if it's an ugly number.
12 |
13 | ## Hint:
14 |
15 | An ugly number U can be expressed as: U = 2^a * 3^b * 5^c, where a, b and c are non-negative integers.
16 |
--------------------------------------------------------------------------------
/community/variable-name-validation/README.md:
--------------------------------------------------------------------------------
1 | # Variable Name Validation
2 |
3 | In all programming languages, there are some naming conventions for variables.
4 |
5 | Some conventions are the following:
6 | 1. A valid variable name can contain only alphabetic characters (a-z, A-Z), digits (0-9) and underscores(_).
7 | 2. It can't contain any special character (@, #, %, &, *, etc...) or any white space.
8 | 3. A valid variable name never starts with any digit.
9 | 4. A variable name can't be a keyword(depends on the language you are using).
10 |
11 | Create a program that takes a variable name as input and outputs whether it is valid or not.
12 |
13 | For example:
14 | ```
15 | Input: num1
16 | Output: Valid
17 |
18 | Input: num_1
19 | Output: Valid
20 |
21 | Input: 1num
22 | Output: Invalid
23 |
24 | Input: if
25 | Output: Invalid
26 | ```
27 |
--------------------------------------------------------------------------------
/community/visitor-pattern/README.md:
--------------------------------------------------------------------------------
1 | # Java Visitor Pattern
2 |
3 | Full problem description: (https://www.hackerrank.com/challenges/java-vistor-pattern/)
4 |
5 | Note: In this problem you must NOT generate any output on your own. Any such solution will be considered as being against the rules and its author will be disqualified. The output of your solution must be generated by the uneditable code provided for you in the solution template.
6 |
--------------------------------------------------------------------------------
/community/visitor-pattern/java-vistor-pattern-English.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabestro/sololearn-challenges/c88041a7b96296317c71ddbf5398f3559b81a71b/community/visitor-pattern/java-vistor-pattern-English.pdf
--------------------------------------------------------------------------------
/easy/argentina/Argentina.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int pesos, dollars;
5 | scanf("%d\n%d", &pesos, &dollars);
6 |
7 | if (dollars * 50l > pesos) puts("Pesos");
8 | else puts("Dollars");
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/easy/argentina/Argentina.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class Argentina {
4 | public static void main(final String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var pesos = scanner.nextInt();
7 | final var dollars = scanner.nextInt();
8 |
9 | System.out.println(
10 | dollars * 50l > pesos ? "Pesos" : "Dollars"
11 | );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/easy/argentina/Argentina.py:
--------------------------------------------------------------------------------
1 | pesos = int(input())
2 | dollars = int(input())
3 | if dollars * 50 > pesos:
4 | print("Pesos")
5 | else:
6 | print("Dollars")
--------------------------------------------------------------------------------
/easy/argentina/Argentina.rb:
--------------------------------------------------------------------------------
1 | pesos = gets.chomp.to_i
2 | dollars = gets.chomp.to_i
3 |
4 | if dollars * 50 > pesos
5 | puts "Pesos"
6 | else
7 | puts "Dollars"
8 | end
9 |
--------------------------------------------------------------------------------
/easy/argentina/README.md:
--------------------------------------------------------------------------------
1 | # Argentina
2 |
3 | You are in a hat store in Argentina! The prices are listed in US Dollars and Argentinian Pesos. You have both, but you want to make sure you pay the lower price! Do you pay in Dollars or Pesos? The exchange rate is 2 cents for every Peso.
4 |
5 | ## Task
6 | Create a program that takes two prices and tells you which one is lower after conversion.
7 |
8 | ## Input Format
9 | Two integer values, the first one is the price in Pesos and the second one is the price in Dollars.
10 |
11 | ## Output Format
12 | A string that says which currency you should make the purchase in ('Dollars' or 'Pesos').
13 |
14 | ## Sample Input
15 | 4000
16 | 100
17 |
18 | ## Sample Output
19 | Pesos
20 |
21 | ## Explanation
22 | You should use Pesos to buy the hat since 4000 pesos is equal to $80.
23 |
--------------------------------------------------------------------------------
/easy/argentina/argentina.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | long pesos, dollars;
6 | cin >> pesos >> dollars;
7 |
8 | cout << (dollars * 50 > pesos ? "Pesos" : "Dollars");
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/easy/cheer-creator/CheerCreator.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int yards;
5 | scanf("%d", &yards);
6 |
7 | if (yards > 10) puts("High Five");
8 | else if (yards < 1) puts("shh");
9 | else while (yards--) printf("Ra!");
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/cheer-creator/CheerCreator.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class CheerCreator {
4 | public static void main(final String[] args) {
5 | final var yards = new Scanner(System.in).nextInt();
6 |
7 | if (yards > 10) {
8 | System.out.print("High Five");
9 | } else if (yards < 1) {
10 | System.out.print("shh");
11 | } else {
12 | System.out.print("Ra!".repeat(yards));
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/easy/cheer-creator/CheerCreator.py:
--------------------------------------------------------------------------------
1 | yards = int(input())
2 |
3 | if yards > 10:
4 | print("High Five")
5 | elif yards < 1:
6 | print("shh")
7 | else:
8 | print("Ra!" * yards)
--------------------------------------------------------------------------------
/easy/cheer-creator/CheerCreator.rb:
--------------------------------------------------------------------------------
1 | yards = gets.chomp.to_i
2 |
3 | if yards > 10
4 | puts "High Five"
5 | elsif yards < 1
6 | puts "shh"
7 | else
8 | puts "Ra!" * yards
9 | end
10 |
--------------------------------------------------------------------------------
/easy/cheer-creator/README.md:
--------------------------------------------------------------------------------
1 | # Cheer Creator
2 |
3 | You are cheering on your favorite team. After each play, if your team got over 10 yards further down the field, you stand up and give your friend a high five. If they don't move forward by at least a yard you stay quiet and say 'shh', and if they move forward 10 yards or less, you say 'Ra!' for every yard that they moved forward in that play.
4 |
5 | ## Task
6 | Given the number of yards that your team moved forward, output either 'High Five' (for over 10), 'shh' (for <1), or a string that has a 'Ra!' for every yard that they gained.
7 |
8 | ## Input Format
9 | An integer value that represents the number of yards gained or lost by your team.
10 |
11 | ## Output Format
12 | A string of the appropriate cheer.
13 |
14 | ## Sample Input
15 | 3
16 |
17 | ## Sample Output
18 | Ra!Ra!Ra!
19 |
20 | ## Explanation
21 | If your team gains 3 yards you would cheer 'Ra!' three times for that play.
22 |
--------------------------------------------------------------------------------
/easy/cheer-creator/cheer_creator.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | int yards;
6 | cin >> yards;
7 |
8 | if (yards > 10) cout << "High Five";
9 | else if (yards < 1) cout << "shh";
10 | else while (yards--) cout << "Ra!";
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/easy/extra-terristrials/ExtraTerrestrials.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 80
4 |
5 | int main() {
6 | char word[MAX];
7 | int i = strlen(fgets(word, MAX, stdin));
8 |
9 | while (i--) putchar(word[i]);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/extra-terristrials/ExtraTerrestrials.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class ExtraTerrestrials {
4 | public static void main(final String[] args) {
5 | System.out.print(
6 | new StringBuilder(
7 | new Scanner(System.in).nextLine()
8 | ).reverse()
9 | );
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/easy/extra-terristrials/ExtraTerrestrials.py:
--------------------------------------------------------------------------------
1 | print(input()[::-1])
2 |
--------------------------------------------------------------------------------
/easy/extra-terristrials/ExtraTerrestrials.rb:
--------------------------------------------------------------------------------
1 | puts gets.reverse
2 |
--------------------------------------------------------------------------------
/easy/extra-terristrials/README.md:
--------------------------------------------------------------------------------
1 | # Extra-Terrestrials
2 |
3 | You meet a group of aliens, and their language is just like English except that they say every word backwards.
4 | How will you learn to communicate with them?
5 |
6 | ## Task:
7 | Take a word in English that you would like to say, and turn it into language that these aliens will understand.
8 |
9 | ## Input Format:
10 | A string of a word in English.
11 |
12 | ## Output Format:
13 | A string of the reversed word that represents the original word translated into alien language.
14 |
15 | ## Sample Input:
16 | howdy
17 |
18 | ## Sample Output:
19 | ydwoh
20 |
21 | ## Explanation:
22 | If you flip howdy backwards you get ydwoh.
23 |
--------------------------------------------------------------------------------
/easy/fruit-bowl/FruitBowl.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int fruit;
5 | scanf("%d", &fruit);
6 |
7 | //your code goes here
8 |
9 | int const apples = fruit / 2;
10 | int const pies = apples / 3;
11 |
12 | printf("%d", pies);
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/easy/fruit-bowl/FruitBowl.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class FruitBowl {
4 | public static void main(final String[] args) {
5 | final int fruit = new Scanner(System.in).nextInt();
6 |
7 | final int apples = fruit / 2;
8 | final int pies = apples / 3;
9 |
10 | System.out.print(pies);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/easy/fruit-bowl/FruitBowl.py:
--------------------------------------------------------------------------------
1 | fruit = int(input())
2 |
3 | # your code goes here
4 |
5 | apples = fruit // 2
6 | pies = apples // 3
7 | print(pies)
8 |
--------------------------------------------------------------------------------
/easy/fruit-bowl/FruitBowl.rb:
--------------------------------------------------------------------------------
1 | fruit = gets.chomp.to_i
2 |
3 | apples = fruit / 2
4 | pies = apples / 3
5 | puts pies
6 |
--------------------------------------------------------------------------------
/easy/fruit-bowl/README.md:
--------------------------------------------------------------------------------
1 | # Fruit Bowl
2 |
3 | You have a bowl on your counter with an even number of pieces of fruit in it. Half of them are bananas, and the other half are apples. You need 3 apples to make a pie.
4 |
5 | ## Task
6 | Your task is to evaluate the total number of pies that you can make with the apples that are in your bowl given to total amount of fruit in the bowl.
7 |
8 | ## Input Format
9 | An integer that represents the total amount of fruit in the bowl.
10 |
11 | ## Output Format
12 | An integer representing the total number of whole apple pies that you can make.
13 |
14 | ## Sample Input
15 | 26
16 |
17 | ## Sample Output
18 | 4
19 |
20 | ## Explanation
21 | If you have 26 pieces of fruit, you have 13 apples, which makes 4 pies, and leaves one apple left over.
22 |
--------------------------------------------------------------------------------
/easy/gotham-city/GothamCity.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int criminals;
5 | scanf("%d", &criminals);
6 |
7 | if (criminals < 5) puts("I got this!");
8 | else if (criminals < 11) puts("Help me Batman");
9 | else puts("Good Luck out there!");
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/gotham-city/GothamCity.java:
--------------------------------------------------------------------------------
1 | public class GothamCity {
2 | public static void main(String[] args) {
3 | System.out.print(java.text.MessageFormat.format(
4 | "{0,choice,0
2 |
3 | int main() {
4 | int length, width;
5 | scanf("%d\n%d", &length, &width);
6 | int flamingos = length + width;
7 | printf("%d", flamingos);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/easy/halloween-candy/HalloweenCandy.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main() {
5 | int houses;
6 | scanf("%d", &houses);
7 |
8 | int const percentage = (int)ceil(100 * 2.0 / houses);
9 | printf("%d", percentage);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/halloween-candy/HalloweenCandy.java:
--------------------------------------------------------------------------------
1 | public final class HalloweenCandy {
2 | public static void main(final String[] args) {
3 | final var houses = new java.util.Scanner(System.in).nextInt();
4 |
5 | final var percentage = (int) Math.ceil(200. / houses);
6 |
7 | System.out.print(percentage);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/easy/halloween-candy/HalloweenCandy.py:
--------------------------------------------------------------------------------
1 | from math import ceil
2 |
3 | houses = int(input())
4 | percentage = int(ceil(100 * 2 / houses))
5 |
6 | print(percentage)
--------------------------------------------------------------------------------
/easy/halloween-candy/HalloweenCandy.rb:
--------------------------------------------------------------------------------
1 | houses = gets.chomp.to_i
2 |
3 | #your code goes here
4 |
5 | percentage = (100 * 2.0 / houses).ceil
6 | puts percentage
7 |
--------------------------------------------------------------------------------
/easy/halloween-candy/README.md:
--------------------------------------------------------------------------------
1 | # Halloween Candy
2 |
3 | You go trick or treating with a friend and all but three of the houses that you visit are giving out candy. One house that you visit is giving out toothbrushes and two houses are giving out dollar bills.
4 |
5 | ## Task
6 | Given the input of the total number of houses that you visited, what is the percentage chance that one random item pulled from your bag is a dollar bill?
7 |
8 | ## Input Format
9 | An integer (>=3) representing the total number of houses that you visited.
10 |
11 | ## Output Format
12 | A percentage value rounded up to the nearest whole number.
13 |
14 | ## Sample Input
15 | 4
16 |
17 | ## Sample Output
18 | 50
19 |
20 | ## Explanation
21 | If you visited four houses, one would be candy, two would be dollars, and one would be a toothbrush. A 2 in 4 chance is 50%.
22 |
--------------------------------------------------------------------------------
/easy/hovercraft/Hovercraft.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int sales;
5 | scanf("%d", &sales);
6 |
7 | int const income = sales * 3;
8 | if (income > 21) puts("Profit");
9 | else if (income < 21) puts("Loss");
10 | else puts("Broke Even");
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/easy/hovercraft/Hovercraft.py:
--------------------------------------------------------------------------------
1 | sales = int(input())
2 |
3 | income = sales * 3
4 |
5 | if income > 21:
6 | print("Profit")
7 | elif income < 21:
8 | print("Loss")
9 | else:
10 | print("Broke Even")
11 |
--------------------------------------------------------------------------------
/easy/hovercraft/Hovercraft.rb:
--------------------------------------------------------------------------------
1 | sales = gets.chomp.to_i
2 |
3 | income = sales * 3;
4 |
5 | if income > 21
6 | print("Profit")
7 | elsif income < 21
8 | print("Loss")
9 | else
10 | print("Broke Even")
11 | end
12 |
--------------------------------------------------------------------------------
/easy/hovercraft/README.md:
--------------------------------------------------------------------------------
1 | # Hovercraft
2 |
3 | You run a hovercraft factory. Your factory makes ten hovercrafts in a month. Given the number of customers you got that month, did you make a profit? It costs you 2,000,000 to build a hovercraft, and you are selling them for 3,000,000. You also pay 1,000,000 each month for insurance.
4 |
5 | ## Task:
6 | Determine whether or not you made a profit based on how many of the ten hovercrafts you were able to sell that month.
7 |
8 | ## Input Format:
9 | An integer that represents the sales that you made that month.
10 |
11 | ## Output Format:
12 | A string that says 'Profit', 'Loss', or 'Broke Even'.
13 |
14 | ## Sample Input:
15 | 5
16 |
17 | ## Sample Output:
18 | Loss
19 |
20 | ## Explanation:
21 | If you only sold 5 hovercrafts, you spent 21,000,000 to operate but only made 15,000,000.
22 |
--------------------------------------------------------------------------------
/easy/jungle-camping/JungleCamping.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 500
4 |
5 | int main() {
6 | char *animals[] = {"Lion", "Tiger", "Snake", "Bird"};
7 | char *sounds[] = {"Grr", "Rawr", "Ssss", "Chirp"};
8 |
9 | char noise[MAX];
10 | fgets(noise, MAX, stdin);
11 |
12 | for (char *sound = strtok(noise, " "); sound; sound = strtok(NULL, " "))
13 | for (int i = 0; i < 4; ++i)
14 | if (strcmp(sound, sounds[i]) == 0)
15 | printf("%s ", animals[i]);
16 |
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/easy/jungle-camping/JungleCamping.java:
--------------------------------------------------------------------------------
1 | import java.util.Map;
2 | import java.util.Scanner;
3 |
4 | public class JungleCamping {
5 | public static void main(String[] args) {
6 | final var animals = Map.of(
7 | "Grr", "Lion ", "Rawr", "Tiger ", "Ssss", "Snake ", "Chirp", "Bird ");
8 |
9 | new Scanner(System.in).tokens().map(animals::get).forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/easy/jungle-camping/JungleCamping.py:
--------------------------------------------------------------------------------
1 | animals = {"Grr": "Lion", "Rawr": "Tiger", "Ssss": "Snake", "Chirp": "Bird"}
2 |
3 | noise = input().split()
4 | print(' '.join(map(animals.get, noise)))
5 |
--------------------------------------------------------------------------------
/easy/jungle-camping/JungleCamping.rb:
--------------------------------------------------------------------------------
1 | animals = {Grr: "Lion", Rawr: "Tiger", Ssss: "Snake", Chirp: "Bird"}
2 |
3 | gets.split.each {|sound| print animals[sound.to_sym], ' '}
4 |
--------------------------------------------------------------------------------
/easy/jungle-camping/JungleCamping_old.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.Map;
3 |
4 | public class JungleCamping_old
5 | {
6 | public static void main(final String[] args) {
7 | final Map animals = Map.of("Grr", "Lion", "Rawr", "Tiger", "Ssss", "Snake", "Chirp", "Bird");
8 |
9 | final var in = new Scanner(System.in);
10 | final var noise = in.nextLine().split(" ");
11 | in.close();
12 |
13 | for (final var sound : noise) {
14 | System.out.printf("%s ", animals.get(sound));
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/easy/jungle-camping/README.md:
--------------------------------------------------------------------------------
1 | # Jungle Camping
2 |
3 | You are camping alone out in the jungle and you hear some animals in the dark nearby. Based on the noise they make, determine which animals they are.
4 |
5 | ## Task:
6 | You are given the noises made by different animals that you can hear in the dark, evaluate each noise to determine which animal it belongs to. Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp'.
7 |
8 | ## Input Format:
9 | A string that represent the noises that you hear with a space between them.
10 |
11 | ## Output Format:
12 | A string that includes each animal that you hear with a space after each one. (animals can repeat)
13 |
14 | ## Sample Input:
15 | Rawr Chirp Ssss
16 |
17 | ## Sample Output:
18 | Tiger Bird Snake
19 |
20 | ## Explanation:
21 | You heard the noise made by a tiger, then a bird, and then a snake.
22 |
--------------------------------------------------------------------------------
/easy/paint-costs/PaintCosts.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main() {
5 | int colors;
6 | scanf("%d", &colors);
7 | printf("%d", (int)round(1.1 * (5 * colors + 40)));
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/easy/paint-costs/PaintCosts.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.math.BigDecimal;
3 | import java.math.RoundingMode;
4 |
5 | public final class PaintCosts {
6 | public static void main(String[] args) {
7 | final var scanner = new Scanner(System.in);
8 | final var numberOfColors = scanner.nextInt();
9 |
10 | final var brushesCost = new BigDecimal(40);
11 | final var colorsCost = new BigDecimal(5 * numberOfColors);
12 | final var price = brushesCost.add(colorsCost);
13 |
14 | final var tax = new BigDecimal("1.01");
15 | final var totalCost = tax.multiply(price);
16 |
17 | System.out.print(totalCost.setScale(0, RoundingMode.HALF_EVEN));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/easy/paint-costs/PaintCosts.py:
--------------------------------------------------------------------------------
1 | colors = int(input())
2 | cost = int(round(1.1 * (5 * colors + 40)))
3 | print(cost)
4 |
--------------------------------------------------------------------------------
/easy/paint-costs/PaintCosts.rb:
--------------------------------------------------------------------------------
1 | colors = gets.chomp.to_i
2 |
3 | cost = (1.1 * (5 * colors + 40)).round
4 |
5 | puts cost
6 |
--------------------------------------------------------------------------------
/easy/paint-costs/README.md:
--------------------------------------------------------------------------------
1 | # Paint costs
2 |
3 | You are getting ready to paint a piece of art. The canvas and brushes that you want to use will cost 40.00. Each color of paint that you buy is an additional 5.00. Determine how much money you will need based on the number of colors that you want to buy if tax at this store is 10%.
4 |
5 | ## Task
6 | Given the total number of colors of paint that you need, calculate and output the total cost of your project rounded up to the nearest whole number.
7 |
8 | ## Input Format
9 | An integer that represents the number of colors that you want to purchase for your project.
10 |
11 | ## Output Format
12 | A number that represents the cost of your purchase rounded up to the nearest whole number.
13 |
14 | ## Sample Input
15 | 10
16 |
17 | ## Sample Output
18 | 99
19 |
20 | ## Explanation
21 | You need 50.00 to buy 10 colors of paint + 40.00 for the canvas and brushes + 9.00 for the tax.
22 |
--------------------------------------------------------------------------------
/easy/paint-costs/paint_cost.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | using namespace std;
5 |
6 | int main()
7 | {
8 | int colors;
9 | cin>>colors;
10 | cout<<(int)round(1.1 * (5 * colors + 40));
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int siblings;
5 | int popsicles;
6 | scanf("%d", &siblings);
7 | scanf("%d", &popsicles);
8 |
9 | printf("%s", popsicles % siblings ? "eat them yourself" : "give away");
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | int siblings, popsicles;
6 | //take input
7 | cin>>siblings>>popsicles;
8 |
9 | //your code goes here
10 |
11 | cout << (popsicles % siblings ? "eat them yourself" : "give away");
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace SoloLearn
8 | {
9 | class Program
10 | {
11 | static void Main(string[] args)
12 | {
13 | int siblings, popsicles;
14 | siblings = Convert.ToInt32(Console.ReadLine());
15 | popsicles = Convert.ToInt32(Console.ReadLine());
16 |
17 | //your code goes here
18 |
19 | bool isEven = popsicles % siblings == 0;
20 |
21 | if (isEven) {
22 | Console.WriteLine("give away");
23 | }
24 | else {
25 | Console.WriteLine("eat them yourself");
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Popsicles {
4 | public static void main(String[] args) {
5 | var scanner = new Scanner(System.in);
6 | var siblings = scanner.nextInt();
7 | var popsicles = scanner.nextInt();
8 |
9 | var isEvenAmount = popsicles % siblings == 0;
10 |
11 | System.out.println(
12 | isEvenAmount ? "give away" : "eat them yourself"
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.py:
--------------------------------------------------------------------------------
1 | siblings = int(input())
2 | popsicles = int(input())
3 |
4 | if popsicles % siblings == 0:
5 | print("give away")
6 | else:
7 | print("eat them yourself")
8 |
--------------------------------------------------------------------------------
/easy/popsicles/Popsicles.rb:
--------------------------------------------------------------------------------
1 | siblings = gets.chomp.to_i
2 | popsicles = gets.chomp.to_i
3 |
4 | #your code goes here
5 |
6 | if popsicles % siblings == 0 then
7 | print "give away"
8 | else
9 | print "eat them yourself"
10 | end
11 |
--------------------------------------------------------------------------------
/easy/pro-balconies/Balconies.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int aw, al, bw, bl;
5 | scanf("%d,%d", &aw, &al);
6 | scanf("%d,%d", &bw, &bl);
7 |
8 | char ap = 'A' + (aw * al < bw * bl);
9 | printf("Apartment %c", ap);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/pro-balconies/Balconies.py:
--------------------------------------------------------------------------------
1 | aWidth, aLength = [int(i) for i in input().split(',')]
2 | bWidth, bLength = [int(i) for i in input().split(',')]
3 | if (aWidth * aLength) > (bWidth * bLength):
4 | print("Apartment A")
5 | else:
6 | print("Apartment B")
7 |
--------------------------------------------------------------------------------
/easy/pro-balconies/Balconies.rb:
--------------------------------------------------------------------------------
1 | aWidth, aLength = gets.chomp.split(",")
2 | bWidth, bLength = gets.chomp.split(",")
3 |
4 | isBiggerA = aWidth.to_i * aLength.to_i > bWidth.to_i * bLength.to_i
5 |
6 | puts "Apartment " + (isBiggerA ? "A": "B")
7 |
--------------------------------------------------------------------------------
/easy/pro-balconies/README.md:
--------------------------------------------------------------------------------
1 | # Balconies
2 |
3 | You are trying to determine which of two apartments has a larger balcony. Both balconies are rectangles, and you have the length and width, but you need the area.
4 |
5 | ## Task
6 | Evaluate the area of two different balconies and determine which one is bigger.
7 |
8 | ## Input Format
9 | Your inputs are two strings where the measurements for height and width are separated by a comma. The first one represents apartment A, the second represents apartment B.
10 |
11 | ## Output Format:
12 | A string that says whether apartment A or apartment B has a larger balcony.
13 |
14 | ## Sample Input
15 | ```
16 | 5,5
17 | 2,10
18 | ```
19 | ## Sample Output
20 | ```
21 | Apartment A
22 | ```
23 |
--------------------------------------------------------------------------------
/easy/pro-ballpark-orders/BallparkOrders.java:
--------------------------------------------------------------------------------
1 | import java.util.Map;
2 | import java.util.Scanner;
3 | import java.math.BigDecimal;
4 |
5 | public final class BallparkOrders {
6 | public static void main(String[] args) {
7 | final var menu = Map.of(
8 | "Nachos", 6, "Pizza", 6, "Cheeseburger", 10, "Water", 4, "Coke", 5);
9 |
10 | final var tax = new BigDecimal("1.07");
11 |
12 | final var sum = new Scanner(System.in)
13 | .tokens()
14 | .mapToInt(item -> menu.getOrDefault(item, menu.get("Coke")))
15 | .sum();
16 |
17 | final var totalCost = new BigDecimal(sum).multiply(tax);
18 |
19 | System.out.print(totalCost.setScale(2));
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/easy/pro-ballpark-orders/BallparkOrders.py:
--------------------------------------------------------------------------------
1 | menu = {'Nachos': 6, 'Pizza': 6, 'Cheeseburger': 10, 'Water': 4, 'Coke': 5}
2 | tax = 1.07
3 |
4 | items = input().split()
5 | total_cost = 0
6 |
7 | for item in items:
8 | if item not in menu:
9 | total_cost += menu['Coke']
10 | else:
11 | total_cost += menu[item]
12 |
13 | total_cost *= tax
14 |
15 | print('%.2f' % total_cost)
16 |
--------------------------------------------------------------------------------
/easy/pro-ballpark-orders/BallparkOrders.rb:
--------------------------------------------------------------------------------
1 | tax = 1.07
2 | menu = {Nachos: 6, Pizza: 6, Cheeseburger: 10, Water: 4, Coke: 5}
3 | menu.default = menu[:Coke]
4 |
5 | total_cost = gets.split.map {|i| menu[i.to_sym]}.inject(:+)
6 |
7 | puts '%.2f' % [total_cost * tax]
8 |
--------------------------------------------------------------------------------
/easy/pro-ballpark-orders/README.md:
--------------------------------------------------------------------------------
1 | # Ballpark Orders
2 |
3 | You and three friends go to a baseball game and you offer to go to the concession stand for everyone. They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. Water is $4.00 and Coke is $5.00. Tax is 7%.
4 |
5 | ## Task
6 | Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders something that isn't on the menu, you will order a Coke for them instead.
7 |
8 | ## Input Format
9 | You are given a string of the four items that you've been asked to order that are separated by spaces.
10 |
11 | ## Output Format
12 | You will output a number of the total cost of the food and drinks.
13 |
14 | ## Sample Input
15 | 'Pizza Cheeseburger Water Popcorn'
16 |
17 | ## Sample Output
18 | 26.75
19 |
20 | ## Explanation
21 | Because Popcorn is not on the menu, this friend gets a coke which brings the subtotal to $25.00 and $26.75 with tax.
22 |
--------------------------------------------------------------------------------
/easy/pro-ballpark-orders/ballpark_orders.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 300
4 |
5 | int main() {
6 | char order[MAX];
7 | fgets(order, MAX, stdin);
8 |
9 | double totalCost = 0;
10 | char menu[5][14] = {"Nachos", "Pizza", "Cheeseburger", "Water", "Coke"};
11 | int price[5] = {6, 6, 10, 4, 5};
12 |
13 | for (char *item = strtok(order, " "); item; item = strtok(NULL, " ")) {
14 | int itemCost = 5;
15 | for (int i = 0; i < 5; ++i) {
16 | if (strcmp(item, menu[i]) == 0) {
17 | itemCost = price[i];
18 | break;
19 | }
20 | }
21 | totalCost += itemCost;
22 | }
23 |
24 | totalCost *= 1.07;
25 | printf("%.2f", totalCost);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/easy/pro-candles/Candles.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int friends;
5 | scanf("%d", &friends);
6 | int const candles = 9 * (friends + 1);
7 | printf("%d", candles);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/easy/pro-candles/Candles.java:
--------------------------------------------------------------------------------
1 | public final class Candles {
2 | public static void main(String[] args) {
3 | final int friends = new java.util.Scanner(System.in).nextInt();
4 | final int candles = 9 * (1 + friends);
5 |
6 | System.out.print(candles);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/easy/pro-candles/Candles.py:
--------------------------------------------------------------------------------
1 | friends = int(input())
2 | candles = 9 * (friends + 1)
3 | print(candles)
4 |
--------------------------------------------------------------------------------
/easy/pro-candles/Candles.rb:
--------------------------------------------------------------------------------
1 | friends = gets.chomp.to_i
2 | candles = 9 * (friends + 1)
3 | puts candles
4 |
--------------------------------------------------------------------------------
/easy/pro-candles/README.md:
--------------------------------------------------------------------------------
1 | # Candles
2 |
3 | It is almost Hanukkah and the store in your town is completely out of candles! You decide to place an order online, and you talk to your friends to see who else needs candles. How many candles should you order in total for the holiday?
4 |
5 | ## Task
6 | Determine how many candles you need to order based on how many friends ask to join your order (each friend will need 9 candles).
7 |
8 | ## Input Format
9 | An integer that represents the number of friends that ask to order candles with you.
10 |
11 | ## Output Format
12 | An integer that represents the total number of candles that you need to order.
13 |
14 | ## Sample Input
15 | 4
16 |
17 | ## Sample Output
18 | 45
19 |
20 | ## Explanation
21 | If four of your friends ask you to order their candles for them, you will need 9 for each of them, and 9 for yourself. That's 45.
22 |
--------------------------------------------------------------------------------
/easy/pro-duct-tape/DuctTape.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main() {
5 | int h, w;
6 | scanf("%d\n%d", &h, &w);
7 | printf("%d", (int)ceil(h * w / 5.));
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/easy/pro-duct-tape/DuctTape.java:
--------------------------------------------------------------------------------
1 | public final class DuctTape {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var doorHeight = scanner.nextInt();
5 | final var doorWidth = scanner.nextInt();
6 |
7 | final var rollSquare = 10; // 60ft long * 2" / 12" width
8 | final var doorSquare = 2 * doorHeight * doorWidth; // Both sides of the door!
9 | final var rollsRequired = (int) Math.ceil((double) doorSquare / rollSquare);
10 |
11 | System.out.print(rollsRequired);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/easy/pro-duct-tape/DuctTape.py:
--------------------------------------------------------------------------------
1 | import math
2 |
3 | height = int(input())
4 | width = int(input())
5 | rollSquare = 10 # 60ft long * 2" / 12" width
6 | doorSquare = 2 * height * width # Both sides of the door!
7 |
8 | rollsRequired = math.ceil(doorSquare / rollSquare)
9 | print(rollsRequired)
10 |
--------------------------------------------------------------------------------
/easy/pro-duct-tape/DuctType.rb:
--------------------------------------------------------------------------------
1 | height = gets.chomp.to_i
2 | width = gets.chomp.to_i
3 |
4 | rollSquare = 10 # 60ft long * 2" / 12" width
5 | doorSquare = 2.0 * height * width # Both sides of the door!
6 |
7 | rollsRequired = (doorSquare / rollSquare).ceil
8 | puts rollsRequired
9 |
--------------------------------------------------------------------------------
/easy/pro-duct-tape/README.md:
--------------------------------------------------------------------------------
1 | # Duct Tape
2 |
3 | You want to completely cover a flat door on both sides with duct tape. You need to know how many rolls of duct tape to buy when you go to the store.
4 |
5 | ## Task:
6 | Given the height and width of the door, determine how many rolls of duct tape you will need (a roll of duct tape is 60 feet long and 2 inches wide and there are 12 inches in each foot). Don't forget both sides of the door!
7 |
8 | ## Input Format:
9 | Two integers that represent the height and width of the door.
10 |
11 | ## Output Format:
12 | An integer that represents the total rolls of duct tape that you need to buy.
13 |
14 | ## Sample Input:
15 | ```
16 | 7
17 | 4
18 | ```
19 | ## Sample Output:
20 | ```
21 | 6
22 | ```
23 | ## Explanation
24 | You will need 6 rolls of duct tape to cover both sides of a 7ft x 4ft door.
25 |
--------------------------------------------------------------------------------
/easy/pro-easter-eggs/EasterEggs.java:
--------------------------------------------------------------------------------
1 | public final class EasterEggs {
2 | public static void main(final String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 |
5 | final var totalNumberEggs = scanner.nextInt();
6 | final var yourAmount = scanner.nextInt();
7 | final var friendsAmount = scanner.nextInt();
8 |
9 | final var isStillEggs = totalNumberEggs > yourAmount + friendsAmount;
10 |
11 | System.out.println(
12 | isStillEggs ? "Keep Hunting" : "Candy Time"
13 | );
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/easy/pro-easter-eggs/EasterEggs.py:
--------------------------------------------------------------------------------
1 | eggs = int(input())
2 | you = int(input())
3 | friend = int(input())
4 |
5 | if you + friend < eggs:
6 | print('Keep Hunting')
7 | else:
8 | print('Candy Time')
9 |
--------------------------------------------------------------------------------
/easy/pro-easter-eggs/EasterEggs.rb:
--------------------------------------------------------------------------------
1 | eggs = gets.chomp.to_i
2 | you = gets.chomp.to_i
3 | friend = gets.chomp.to_i
4 |
5 | if you + friend < eggs
6 | print('Keep Hunting')
7 | else
8 | print('Candy Time')
9 | end
10 |
--------------------------------------------------------------------------------
/easy/pro-easter-eggs/README.md:
--------------------------------------------------------------------------------
1 | # Easter Eggs
2 |
3 | You go hunting for Easter eggs with a friend. You think that you have found all of the eggs, but you want to make sure that you don't leave any behind! Compare Easter baskets with your friend to decide if you should keep hunting.
4 |
5 | ## Task:
6 | If you know the total number of eggs that were hidden and the amount in both of your baskets. Evaluate whether it is time to eat candy or keep hunting for more eggs.
7 |
8 | ## Input Format:
9 | Three integer values. The first represents the total number of eggs, the second, the amount in your basket, and lastly the amount that your friend has found.
10 |
11 | ## Output Format:
12 | A string that says 'Keep Hunting' if there are still eggs out there or 'Candy Time' if you found all the eggs.
13 |
14 | ## Sample Input:
15 | ```
16 | 100
17 | 40
18 | 60
19 | ```
20 | ## Sample Output:
21 | ```
22 | Candy Time
23 | ```
24 |
--------------------------------------------------------------------------------
/easy/pro-easter-eggs/easter-eggs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int totalNumberEggs, yourAmount, friendsAmount;
5 | scanf("%d\n%d\n%d", &totalNumberEggs, &yourAmount, &friendsAmount);
6 |
7 | puts(yourAmount + friendsAmount < totalNumberEggs ? "Keep Hunting" : "Candy Time");
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/easy/pro-isogram-detector/IsogramDetector.java:
--------------------------------------------------------------------------------
1 | public final class IsogramDetector {
2 | public static void main(String[] args) {
3 | final var word = new java.util.Scanner(System.in).next();
4 | final var isIsogram = !word.matches(".*(.).*\\1.*");
5 | System.out.println(isIsogram);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/easy/pro-isogram-detector/IsogramDetector.py:
--------------------------------------------------------------------------------
1 | import re
2 | word = input()
3 |
4 | isogram = re.search(r'(.).*\1', word) is None
5 |
6 | print('true' if isogram else 'false')
7 |
--------------------------------------------------------------------------------
/easy/pro-isogram-detector/IsogramDetector.rb:
--------------------------------------------------------------------------------
1 | puts gets.match(/(.).*\1/) == nil
2 |
--------------------------------------------------------------------------------
/easy/pro-isogram-detector/README.md:
--------------------------------------------------------------------------------
1 | # Isogram Detector
2 |
3 | An isogram is a word that has no repeating letters, whether they are consecutive or non-consecutive.
4 | Your job is to find a way to detect if a word is an isogram.
5 |
6 | ## Task:
7 | Write a program that takes in a string as input, detects if the string is an isogram and outputs true or false based on the result.
8 |
9 | ## Input Format:
10 | A string containing one word.
11 |
12 | ## Output Format:
13 | A string: true or false.
14 |
15 | ## Sample Input:
16 | turbulence
17 |
18 | ## Sample Output:
19 | false
20 |
21 | ## Explanation:
22 | The word turbulence has multiple "u" and "e" in it, which would mean it is not an isogram.
23 |
--------------------------------------------------------------------------------
/easy/pro-izzy-the-iguana/IzzyIguana.java:
--------------------------------------------------------------------------------
1 | import java.util.Map;
2 | import java.util.Scanner;
3 |
4 | public class IzzyIguana {
5 | public static void main(String[] args) {
6 | final var snackPoints = Map.of("Lettuce", 5, "Carrot", 4, "Mango", 9, "Cheeseburger", 0);
7 | final var sum = new Scanner(System.in).tokens().mapToInt(snackPoints::get).sum();
8 |
9 | System.out.println(sum >= 10 ? "Come on Down!" : "Time to wait");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/easy/pro-izzy-the-iguana/IzzyIguana.py:
--------------------------------------------------------------------------------
1 | snack_points = {'Lettuce': 5, 'Carrot': 4, 'Mango': 9, 'Cheeseburger': 0}
2 |
3 | isCome = sum([snack_points[i] for i in input().split()]) >= 10
4 |
5 | if isCome:
6 | print('Come on Down!')
7 | else:
8 | print('Time to wait')
9 |
--------------------------------------------------------------------------------
/easy/pro-izzy-the-iguana/IzzyIguana.rb:
--------------------------------------------------------------------------------
1 | snack_points = {Lettuce: 5, Carrot: 4, Mango: 9, Cheeseburger: 0}
2 |
3 | totalSum = gets.split.map {|item| snack_points[item.to_sym]}.inject(:+)
4 |
5 | print totalSum >= 10 ? 'Come on Down!' : 'Time to wait'
6 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/Kaleidoscopes.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.math.BigDecimal;
3 | import java.math.RoundingMode;
4 |
5 | public class Kaleidoscopes {
6 | public static void main(final String[] args) {
7 | final var scanner = new Scanner(System.in);
8 | final var kaleidoscopes = scanner.nextInt();
9 |
10 | final var discount = 0.9;
11 | final var tax = 1.07;
12 |
13 | var price = kaleidoscopes * 5.0;
14 |
15 | if (kaleidoscopes > 1) {
16 | price *= discount;
17 | }
18 | price *= tax;
19 |
20 | System.out.printf("%.2f",
21 | new BigDecimal(price).setScale(2, RoundingMode.HALF_EVEN));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/Kaleidoscopes.py:
--------------------------------------------------------------------------------
1 | number = int(input())
2 | price = 5 * number
3 | if number > 1:
4 | price *= 0.9 # 10% discount
5 | price *= 1.07 # Tax
6 | print("%.2f" % price)
7 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/Kaleidoscopes.rb:
--------------------------------------------------------------------------------
1 | kaleidoscopes = gets.to_i
2 |
3 | price = 5 * kaleidoscopes;
4 | price *= 0.9 if kaleidoscopes > 1
5 | price *= 1.07
6 | price += 0.005 if kaleidoscopes == 3 # this added to pass test
7 |
8 | puts "%0.2f" % price
9 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/Kaleidoscopes_Fails.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.math.BigDecimal;
3 | import java.math.RoundingMode;
4 |
5 | public class Kaleidoscopes_Fails {
6 | public static void main(final String[] args) {
7 |
8 | final var input = new Scanner(System.in);
9 | final var kaleidoscopes = input.nextInt();
10 | input.close();
11 |
12 | final var discount = 0.9;
13 | final var tax = 1.07;
14 |
15 | double price = kaleidoscopes * 5;
16 |
17 | if (kaleidoscopes > 1) {
18 | price *= discount;
19 | }
20 |
21 | price *= tax;
22 |
23 | System.out.printf("%.2f", price); // One test fails
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/README.md:
--------------------------------------------------------------------------------
1 | # Kaleidoscopes
2 |
3 | You sell souvenir kaleidoscopes at a gift shop, and if a customer buys more than one, they get a 10% discount on all of them!
4 | Given the total number of kaleidoscopes that a customer buys, let them know what their total will be. Tax is 7%. All of your kaleidoscopes cost the same amount, 5.00.
5 |
6 | ## Task:
7 | Take the number of kaleidoscopes that a customer buys and output their total cost including tax and any discounts.
8 |
9 | ## Input Format:
10 | An integer value that represents the number of kaleidoscopes that a customer orders.
11 |
12 | ## Output Format:
13 | A number that represents the total purchase price to two decimal places.
14 |
15 | ## Sample Input:
16 | 4
17 |
18 | ## Sample Output:
19 | 19.26
20 |
21 | ## Explanation:
22 | A purchase of 4 kaleidoscopes would give the customer a 10% discount, then with tax the total is 19.26.
23 |
--------------------------------------------------------------------------------
/easy/pro-kaleidoscopes/kaleidoscopes.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int kaleidoscopes;
5 | scanf("%d", &kaleidoscopes);
6 |
7 | double price = 5 * kaleidoscopes;
8 | if (kaleidoscopes > 1) price *= 0.9;
9 | price *= 1.07;
10 | printf("%.2f", price);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/easy/pro-land-ho/LandHo.java:
--------------------------------------------------------------------------------
1 | public class LandHo {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(10 + new java.util.Scanner(System.in).nextInt() / 20 * 20);
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/easy/pro-land-ho/LandHo.py:
--------------------------------------------------------------------------------
1 | ahead = int(input())
2 | time = 10 + ahead // 20 * 20
3 | print(time)
4 |
--------------------------------------------------------------------------------
/easy/pro-land-ho/LandHo.rb:
--------------------------------------------------------------------------------
1 | puts gets.to_i / 20 * 20 + 10
2 |
--------------------------------------------------------------------------------
/easy/pro-land-ho/README.md:
--------------------------------------------------------------------------------
1 | # Land Ho!
2 |
3 | You are on a large ship and you put down anchor near a beautiful beach. There is a small boat ferrying passengers back and forth, and you get in line for it. How long will you have to wait to get to the beach? You know that 20 people can fit on the boat and each trip to shore takes 10 minutes each way.
4 |
5 | ## Task:
6 | Determine your wait time if you know the total number of people ahead of you in line.
7 |
8 | ## Input Format:
9 | An integer that represents the total number of people ahead of you in line.
10 |
11 | ## Output Format:
12 | An integer that represents the number of minutes that you will have to wait until you are standing on the beach.
13 |
14 | ## Sample Input:
15 | 15
16 |
17 | ## Sample Output:
18 | 10
19 |
20 | ## Explanation:
21 | You can get on the boat right away if you are the 16th person in line, it takes 10 minutes on the boat to get to the beach.
22 |
--------------------------------------------------------------------------------
/easy/pro-land-ho/land_ho.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int ahead;
5 | scanf("%d", &ahead);
6 | printf("%d", 10 + ahead / 20 * 20);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/easy/pro-multiples/Multiples.java:
--------------------------------------------------------------------------------
1 | public final class Multiples {
2 | public static void main(String[] args) {
3 | System.out.print(java.util.stream.IntStream
4 | .range(3, new java.util.Scanner(System.in).nextInt())
5 | .filter(i -> i % 3 == 0 || i % 5 == 0)
6 | .sum()
7 | );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/easy/pro-multiples/Multiples.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 | result = sum(range(0,n,3)) + sum(range(0,n,5)) - sum(range(0,n,15))
3 | print(result)
4 |
--------------------------------------------------------------------------------
/easy/pro-multiples/Multiples.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 |
3 | result = (0...n).filter {|i| i % 3 == 0 || i % 5 == 0}.reduce(0) { |sum, i| sum += i}
4 |
5 | print(result)
6 |
--------------------------------------------------------------------------------
/easy/pro-multiples/README.md:
--------------------------------------------------------------------------------
1 | # Multiples
2 |
3 | You need to calculate the sum of all the multiples of 3 or 5 below a given number.
4 |
5 | ## Task:
6 | Given an integer number, output the sum of all the multiples of 3 and 5 below that number.
7 | If a number is a multiple of both, 3 and 5, it should appear in the sum only once.
8 |
9 | ## Input Format:
10 | An integer.
11 |
12 | ## Output Format:
13 | An integer, representing the sum of all the multiples of 3 and 5 below the given input.
14 |
15 | ## Sample Input:
16 | 10
17 |
18 | ## Sample Output:
19 | 23
20 |
21 | ## Explanation:
22 | The numbers below 10 that are multiples of 3 or 5 are 3, 5, 6 and 9.
23 | The sum of these numbers is 3+5+6+9=23
24 |
--------------------------------------------------------------------------------
/easy/pro-multiples/multiples.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int Sn(int d, int N) {int n = N/d; return d * n * ++n / 2;}
4 |
5 | int main() {
6 | int N; scanf("%d", &N); --N;
7 |
8 | int const result = Sn(3,N) + Sn(5,N) - Sn(15,N);
9 |
10 | printf("%d", result);
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/pro-neverland/Neverland.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class Neverland {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var yourAge = scanner.nextInt();
7 | final var years = scanner.nextInt();
8 |
9 | System.out.printf(
10 | "My twin is %d years old and they are %d years older than me",
11 | yourAge + years, years);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/easy/pro-neverland/Neverland.py:
--------------------------------------------------------------------------------
1 | age = int(input())
2 | years = int(input())
3 | print(f'My twin is {age + years} years old and they are {years} years older than me')
4 |
--------------------------------------------------------------------------------
/easy/pro-neverland/Neverland.rb:
--------------------------------------------------------------------------------
1 | age = gets.to_i
2 | years = gets.to_i
3 | puts 'My twin is %d years old and they are %d years older than me' % [age + years, years]
4 |
--------------------------------------------------------------------------------
/easy/pro-neverland/neverland.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int yourAge, years;
5 | scanf("%d\n%d", &yourAge, &years);
6 | printf("My twin is %d years old and they are %d years older than me", yourAge + years, years);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/easy/pro-number-of-ones/NumberOfOnes.java:
--------------------------------------------------------------------------------
1 | public final class NumberOfOnes {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var number = scanner.nextInt();
5 | final var ones = Integer.bitCount(number);
6 | System.out.println(ones);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/easy/pro-number-of-ones/NumberOfOnes.py:
--------------------------------------------------------------------------------
1 | print(str(bin(int(input()))).count('1')) #One-Liner
2 |
3 | """
4 | num=bin(int(input()))
5 | to_str=str(num)
6 | print(to_str.count('1'))
7 | """
8 |
--------------------------------------------------------------------------------
/easy/pro-number-of-ones/NumberOfOnes.rb:
--------------------------------------------------------------------------------
1 | puts gets.to_i.to_s(2).gsub(/0/,'').size
2 |
--------------------------------------------------------------------------------
/easy/pro-number-of-ones/README.md:
--------------------------------------------------------------------------------
1 | # Number of Ones
2 |
3 | ## Task:
4 | Count the number of ones in the binary representation of a given integer.
5 |
6 | ## Input Format:
7 | An integer.
8 |
9 | ## Output Format:
10 | An integer representing the count of ones in the binary representation of the input.
11 |
12 | ## Sample Input:
13 | 9
14 |
15 | ## Sample Output:
16 | 2
17 |
18 | ## Explanation:
19 | The binary representation of 9 is 1001, which includes 2 ones.
20 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/README.md:
--------------------------------------------------------------------------------
1 | # Vowel Counter
2 |
3 | You are in an English class, your teacher tells the class that vowels are the glue that hold words and sentences together.
4 | They want to make sure you understand the importance of vowels in a sentence.
5 | You are given example sentences and are to give a total amount of vowels that are in each sentence.
6 |
7 | ## Task:
8 | Write a program that takes in a string as input, counts and outputs the number of vowels (A, E, I, O, U).
9 |
10 | ## Input Format:
11 | A string (letters can be both uppercase or lower case).
12 |
13 | ## Output Format:
14 | A number which represents the total number of vowels in the string.
15 |
16 | ## Sample Input:
17 | this is a sentence
18 |
19 | ## Sample Output:
20 | 6
21 |
22 | ## Explanation:
23 | There are 6 vowels in the sentence: this is a sentence.
24 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/VowelCounter.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class VowelCounter {
4 | public static void main(String[] args) {
5 |
6 | long vowels = new Scanner(System.in)
7 | .nextLine()
8 | .chars()
9 | .filter(c -> "AEIOUaeiou".indexOf(c) != -1)
10 | .count();
11 |
12 | System.out.println(vowels);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/VowelCounter.py:
--------------------------------------------------------------------------------
1 | import re
2 | vowels = len(re.sub('[^AEIOUaeiou]', '', input())
3 | print(vowels)
4 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/VowelCounter.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/[^AEIOUaeiou]/, '').size
2 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/VowelCounterRE.java:
--------------------------------------------------------------------------------
1 | public final class VowelCounterRE {
2 | public static void main(String[] args) {
3 | final var vowels = new java.util.Scanner(System.in)
4 | .nextLine()
5 | .replaceAll("[^AEIOUaeiou]", "")
6 | .length();
7 | System.out.println(vowels);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/easy/pro-vowel-counter/vowel_counter.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int vowels = 0;
5 |
6 | for (char c; scanf("%c", &c) == 1;)
7 | for (int i = 0; i < 10; ++i)
8 | if ("AEIOUaeiou"[i] == c) {++vowels; break;}
9 |
10 | printf("%d", vowels);
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/easy/pro-zip-code-validator/README.md:
--------------------------------------------------------------------------------
1 | # Zip Code Validator
2 |
3 | As headmaster of the post office, sometimes people write zip codes that don't exist or zip codes that are not valid.
4 | You are tasked with making a system to check if the inputted zip code is a valid zip code.
5 |
6 | ## Task:
7 | Write a program that takes in a string representing a zip code. Output true or false if it is a valid zip code or not.
8 | A valid zip code is only numbers, must be 5 characters in length, and contain no spaces.
9 |
10 | ## Input Format:
11 | A string containing a zip code.
12 |
13 | ## Output Format:
14 | A string: true is the input is a valid zip code, or false, if it is not.
15 |
16 | ## Sample Input:
17 | 752f78
18 |
19 | ## Sample Output:
20 | false
21 |
22 | ## Explanation:
23 | A valid zip code contains 5 digits, and no letters or spaces. The input is 6 characters long and contains letters, making it an invalid zip code.
24 |
--------------------------------------------------------------------------------
/easy/pro-zip-code-validator/ZipCodeValidator.java:
--------------------------------------------------------------------------------
1 | public class ZipCodeValidator {
2 | public static void main(String[] args) {
3 | var scanner = new java.util.Scanner(System.in);
4 | var zipCode = scanner.nextLine();
5 | var isValid = zipCode.matches("\\d{5}");
6 | System.out.println(isValid);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/easy/pro-zip-code-validator/ZipCodeValidator.py:
--------------------------------------------------------------------------------
1 | import re
2 | zip_code = input()
3 |
4 | is_valid = re.search(r'^\d{5}$', zip_code) is not None
5 |
6 | if is_valid:
7 | print('true')
8 | else:
9 | print('false')
10 |
--------------------------------------------------------------------------------
/easy/pro-zip-code-validator/ZipCodeValidator.rb:
--------------------------------------------------------------------------------
1 | puts gets.match(/^\d{5}$/) != nil
2 |
--------------------------------------------------------------------------------
/easy/skee-ball/Skee-Ball.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int points;
5 | scanf("%d", &points);
6 | int price;
7 | scanf("%d", &price);
8 |
9 | if (points / 12 >= price) puts("Buy it!");
10 | else puts("Try again");
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/easy/skee-ball/SkeeBall.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class SkeeBall {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var points = scanner.nextInt();
7 | final var price = scanner.nextInt();
8 |
9 | System.out.println(
10 | points / 12 >= price ? "Buy it!" : "Try again"
11 | );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/easy/skee-ball/SkeeBall.py:
--------------------------------------------------------------------------------
1 | points = int(input())
2 | price = int(input())
3 |
4 | if points // 12 >= price:
5 | print("Buy it!")
6 | else:
7 | print("Try again")
8 |
--------------------------------------------------------------------------------
/easy/skee-ball/SkeeBall.rb:
--------------------------------------------------------------------------------
1 | points = gets.chomp.to_i
2 | price = gets.chomp.to_i
3 |
4 | if points / 12 >= price
5 | puts "Buy it!"
6 | else
7 | print "Try again"
8 | end
9 |
--------------------------------------------------------------------------------
/easy/skee-ball/skee_ball.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | int points;
6 | int price;
7 |
8 | cin >> points >> price;
9 |
10 | cout << (points / 12 >= price ? "Buy it!" : "Try again");
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char name[MAX];
7 | int agents;
8 | char persons[4][MAX];
9 | scanf("%s", name);
10 | scanf("%d", &agents);
11 | scanf("%s %s %s %s", persons[0], persons[1], persons[2], persons[3]);
12 |
13 | int position = 0;
14 | for (int i = 4; i--; )
15 | if (strcmp(name, persons[i]) > 0)
16 | ++position;
17 |
18 | printf("%d", 20 + 20 * (int)(position / agents));
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense.java:
--------------------------------------------------------------------------------
1 | public final class NewDriversLicense {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var hero = scanner.next();
5 | final var agents = scanner.nextInt();
6 | final var position = scanner
7 | .tokens()
8 | .filter(person -> person.compareTo(hero) < 0)
9 | .count();
10 |
11 | final var time = 20 * (1 + position / agents);
12 |
13 | System.out.print(time);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense.py:
--------------------------------------------------------------------------------
1 | name = input()
2 | agents = int(input())
3 | persons = input().split()
4 |
5 | position = 0
6 |
7 | for person in persons:
8 | if person < name:
9 | position += 1
10 |
11 | time = 20 * (1 + position // agents)
12 | print(time)
13 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense.rb:
--------------------------------------------------------------------------------
1 | hero = gets.chomp
2 | agents = gets.chomp.to_i
3 | persons = gets.chomp.split
4 |
5 | position = persons.select{|name| name < hero}.size
6 |
7 | time = 20 * (1 + position / agents)
8 | puts time
9 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense_2.py:
--------------------------------------------------------------------------------
1 | hero = input()
2 | agents = int(input())
3 | persons = input().split()
4 |
5 | position = len(list(filter(lambda n: n < hero, persons)))
6 | time = 20 * (1 + position // agents)
7 |
8 | print(time)
9 |
--------------------------------------------------------------------------------
/hard/new-drivers-license/NewDriversLicense_old.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class NewDriversLicense
4 | {
5 | public static void main(final String[] args) {
6 | final var input = new Scanner(System.in);
7 | final var hero = input.next();
8 | final var agents = input.nextInt();
9 |
10 | int position = 0;
11 |
12 | while (input.hasNext()) {
13 | final var person = input.next();
14 | if (hero.compareTo(person) > 0) {
15 | ++position;
16 | }
17 | }
18 | input.close();
19 |
20 | final var time = 20 * (1 + position / agents);
21 |
22 | System.out.print(time);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/hard/password-validation/PasswordValidation.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main() {
5 | char password[80];
6 | fgets(password, 80, stdin);
7 |
8 | int numbers = 0;
9 | int symbols = 0;
10 | int length = 0;
11 |
12 | for (char *p = password; *p; ++length, ++p)
13 | if (isdigit(*p)) ++numbers;
14 | else if (strchr("!@#$%&*", *p) != NULL) ++symbols;
15 |
16 | if (length > 6 && numbers > 1 && symbols > 1) puts("Strong");
17 | else puts("Weak");
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/hard/password-validation/PasswordValidation.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class PasswordValidation {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var password = scanner.nextLine();
7 |
8 | final var isStrong = password.length() > 6
9 | && password.matches(".*\\d.*\\d.*")
10 | && password.matches("(.*[!@#$%&*].*){2,}");
11 |
12 | System.out.println(isStrong ? "Strong" : "Weak");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/hard/password-validation/PasswordValidation.py:
--------------------------------------------------------------------------------
1 | """
2 | # ===None Regex Solution===
3 | password = input()
4 |
5 | length = len(password)
6 | symbols = 0
7 | numbers = 0
8 |
9 | if length > 6:
10 | i = length
11 | while i > 0:
12 | i -= 1
13 | if password[i].isdigit():
14 | numbers += 1
15 | elif password[i] in "!@#$%&*":
16 | symbols += 1
17 |
18 | if length > 6 and numbers > 1 and symbols > 1:
19 | print("Strong")
20 | else:
21 | print("Weak")
22 | """
23 |
24 | import re
25 |
26 | if re.fullmatch(r'^(?=.*[A-Za-z])(?=.*\d){2,}(?=.*[@$!%*#?&]){2,}[A-Za-z\d@$!%*#?&]{7,}$', input()):
27 | print('Strong')
28 | else:
29 | print("Weak")
30 |
--------------------------------------------------------------------------------
/hard/password-validation/PasswordValidation.rb:
--------------------------------------------------------------------------------
1 | password = gets
2 |
3 | isStrong = password.length > 6 && password.match(/\d.*\d/) && password.match(/([!@#$%&*].*){2,}/)
4 |
5 | puts isStrong ? "Strong": "Weak"
6 |
--------------------------------------------------------------------------------
/hard/password-validation/PasswordValidation_2.py:
--------------------------------------------------------------------------------
1 | import re
2 | password = input()
3 | isStrong = len(password) > 6 \
4 | and re.search(r'\d.*\d', password) \
5 | and re.search(r'([!@#$%&*].*){2,}', password)
6 |
7 | if isStrong:
8 | print("Strong")
9 | else:
10 | print("Weak")
11 |
--------------------------------------------------------------------------------
/hard/pro-2d-map/Map2D.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Map2D {
4 | public final static int SIZE = 5 + 1; // Size of square + comma
5 |
6 | public static void main(String[] args) {
7 | var map = new Scanner(System.in).nextLine();
8 |
9 | int indexA = map.indexOf('P');
10 | int indexB = map.indexOf('P', indexA + 1);
11 |
12 | int path = indexB / SIZE - indexA / SIZE + Math.abs(indexA % SIZE - indexB % SIZE);
13 |
14 | System.out.print(path);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/hard/pro-2d-map/Map2D.py:
--------------------------------------------------------------------------------
1 | SIZE = 5 + 1 # Size of square + comma
2 |
3 | map = input()
4 | indexA = map.index('P')
5 | indexB = map.index('P', indexA + 1)
6 |
7 | path = indexB // SIZE - indexA // SIZE + abs(indexA % SIZE - indexB % SIZE)
8 |
9 | print(path)
10 |
--------------------------------------------------------------------------------
/hard/pro-2d-map/Map2D.rb:
--------------------------------------------------------------------------------
1 | SIZE = 5 + 1 # Size of square + comma
2 |
3 | map = gets
4 | indexA = map.index('P')
5 | indexB = map.index('P', indexA + 1)
6 |
7 | path = indexB / SIZE - indexA / SIZE + (indexA % SIZE - indexB % SIZE).abs
8 | puts path
9 |
--------------------------------------------------------------------------------
/hard/pro-2d-map/README.md:
--------------------------------------------------------------------------------
1 | # 2D Map
2 |
3 | You're given a representation of a 5x5 2D map, and if you can only move left, right, up, or down, determine how many moves you would have to make to get between two points on the map.
4 |
5 | ## Task:
6 | Determine the total number of moves that are needed between two points on a map. The points that you move between are marked with a P and the spaces in between are marked with X.
7 |
8 | ## Input Format:
9 | A string that represents the 2D space starting at the top left. Each level from top to bottom is separated by a comma.
10 |
11 | ## Output Format:
12 | An integer that represents the total number of moves that you had to make.
13 |
14 | ## Sample Input:
15 | ```
16 | XPXXX,XXXXX,XXXXX,XXXPX,XXXXX
17 | ```
18 | ## Sample Output:
19 | ```
20 | 5
21 | ```
22 | ## Explanation:
23 | The map looks as:
24 | ```
25 | XPXXX
26 | XXXXX
27 | XXXXX
28 | XXXPX
29 | XXXXX
30 | ```
31 | You had to move right 2 spaces, then down 3 spaces for a total of 5 moves.
32 |
--------------------------------------------------------------------------------
/hard/pro-2d-map/map.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 32
4 |
5 | int main() {
6 | char map[MAX];
7 | char *c = fgets(map, MAX, stdin);
8 | int p[2], i = 0;
9 |
10 | while (i < 2) if (*c++ == 'P') p[i++] = c - map;
11 | int path = p[1] / 6 - *p / 6 + abs(*p % 6 - p[1] % 6);
12 |
13 | printf("%d", path);
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/hard/pro-digits-of-pi/README.md:
--------------------------------------------------------------------------------
1 | # Digits of Pi
2 |
3 | The constant Pi is defined as the ratio of a circle's circumference to its diameter.
4 | Pi is an irrational number, meaning that it's digits never end or repeat in any known way.
5 |
6 | ## Task:
7 | Given an integer N as input, find and output the Nth decimal digit of Pi.
8 |
9 | ## Input Format:
10 | An integer: 0 2 ? Q(n - Q(n - 1)) + Q(n - Q(n - 2)) : 1;
7 | }
8 |
9 | public static void main(String[] args) {
10 | var input = new java.util.Scanner(System.in);
11 | int n = input.nextInt();
12 |
13 | System.out.print(Q(n));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/hard/pro-hofstadter-q-sequence/hofstadter_q_sequence.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int i = 1, n;
5 | scanf("%d", &n);
6 |
7 | int q[n];
8 | *q = q[1] = 1;
9 | while (++i < n) q[i] = q[i - q[i - 1]] + q[i - q[i - 2]];
10 |
11 | return printf("%d", q[--n]);
12 | }
13 |
--------------------------------------------------------------------------------
/hard/pro-its-a-sign/ItsSign.java:
--------------------------------------------------------------------------------
1 | public class ItsSign {
2 | public static void main(String[] args) {
3 | System.out.println(
4 | new java.util.Scanner(System.in)
5 | .tokens()
6 | .limit(4)
7 | .map(StringBuilder::new)
8 | .anyMatch(w -> w.toString().equals(w.reverse().toString()))
9 | ? "Open"
10 | : "Trash"
11 | );
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/hard/pro-its-a-sign/ItsSign.rb:
--------------------------------------------------------------------------------
1 | signs = Array.new(4) { gets.chomp }
2 |
3 | puts signs.any? {|s| s == s.reverse} ? 'Open' : 'Trash'
4 |
--------------------------------------------------------------------------------
/hard/pro-its-a-sign/Sign.py:
--------------------------------------------------------------------------------
1 | signs = [input() for i in range(4)]
2 | hasPalindrome = any(map(lambda w: w == w[::-1], signs))
3 | print(('Trash', 'Open')[hasPalindrome])
4 |
--------------------------------------------------------------------------------
/hard/pro-its-a-sign/its_a_sign.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main() {
5 | char s[99];
6 |
7 | for (int i = 4; i--;) {
8 | char *b = fgets(s, 99, stdin);
9 | char *e = s + strlen(s);
10 | if (*--e == '\n') --e;
11 | while (b < e && *b == *e--) ++b;
12 | if (b >= e) return puts("Open");
13 | }
14 | return puts("Trash");
15 | }
16 |
--------------------------------------------------------------------------------
/hard/pro-mathematics/README.md:
--------------------------------------------------------------------------------
1 | # Mathematics
2 |
3 | Find which math expression matches the answer that you are given, if you have an integer answer, and a list of math expressions.
4 |
5 | ## Task:
6 | Test each math expression to find the first one that matches the answer that you are given.
7 |
8 | ## Input Format:
9 | Two inputs: an integer and a space separated string of math expressions. The following operations need to be supported: addition +, subtraction -, multiplication *, division /.
10 | An expression can include multiple operations.
11 |
12 | ## Output Format:
13 | A string that tells the index of the first math expression that matches. If there are no matches, output 'none'.
14 |
15 | ## Sample Input:
16 | ```
17 | 15
18 | (2+100) (5*3) (14+1)
19 | ```
20 | ## Sample Output:
21 | ```
22 | index 1
23 | ```
24 |
--------------------------------------------------------------------------------
/hard/pro-word-rank/WordRank.py:
--------------------------------------------------------------------------------
1 | def word_rank(word, rank, prefix = ''):
2 | if len(word) < 2:
3 | return prefix + word
4 | s = set(word)
5 |
6 | for c in sorted(list(s)):
7 | l = list(word)
8 | l.remove(c)
9 | output = word_rank(''.join(l), rank, prefix + str(c))
10 | if output is None: continue
11 | rank[0] += 1
12 | # print(f'{rank[0]:3} {output}')
13 | if output == rank[1]:
14 | print(rank[0])
15 | exit
16 |
17 |
18 | string = input()
19 | word = sorted(string)
20 | length = len(word)
21 | rank = [0, string]
22 | word_rank(string, rank)
23 |
--------------------------------------------------------------------------------
/hard/pro-word-rank/WordRank_2.py:
--------------------------------------------------------------------------------
1 | from math import factorial
2 |
3 | w = word = input()
4 | s = sorted(w)
5 | rank = 1
6 | if s == w:
7 | pass
8 | else:
9 | while len(w) > 1:
10 | m = list(filter(lambda x: x > 1, map(s.count, set(w)))) # the list of repetitions of letters
11 | t = factorial(len(w) - 1) * s.index(w[0])
12 | for i in m:
13 | t /= factorial(i)
14 | rank += t
15 | w = w[1:]
16 | s = sorted(w)
17 |
18 | print(int(rank))
19 |
--------------------------------------------------------------------------------
/hard/security/Security.c:
--------------------------------------------------------------------------------
1 | #include
2 | #define MAX 200
3 |
4 | int main() {
5 | char floor[MAX];
6 | char *message;
7 | int alarm = 0;
8 | fgets(floor, MAX, stdin);
9 |
10 | for (char *c = floor; *c && !message; ++c)
11 | if (*c == 'G' && alarm) message = "quiet";
12 | else if ((*c == '$' || *c == 'T') && alarm++) message = "ALARM";
13 |
14 | puts(message);
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/hard/security/Security.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Security {
4 | public static void main(final String[] args) {
5 | var floor = new Scanner(System.in).nextLine();
6 | var isSafe = floor.matches(".*[$T].*G.*[$T].*");
7 |
8 | System.out.println(isSafe ? "quiet" : "ALARM");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/hard/security/Security.rb:
--------------------------------------------------------------------------------
1 | puts gets =~ /[$T].*G.*[$T]/ ? 'quiet': 'ALARM'
2 |
--------------------------------------------------------------------------------
/hard/security/Security2.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Security {
4 | public static void main(String[] args) {
5 | final var input = new Scanner(System.in);
6 | final var floor = input.nextLine();
7 | input.close();
8 |
9 | System.out.println(isSafe(floor) ? "quiet" : "ALARM");
10 | }
11 |
12 | static boolean isSafe(String floor) {
13 | int alarm = 0;
14 | for (char c : floor.toCharArray()) {
15 | if (c == 'G') {
16 | alarm = 0;
17 | } else if (c == '$' || c == 'T') {
18 | alarm++;
19 | if (alarm == 2)
20 | return false;
21 | }
22 | }
23 | return true;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/hard/security/Security_Regex.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char floor[MAX];
7 | fgets(floor,MAX,stdin);
8 |
9 | regex_t safeRegex;
10 | regcomp(&safeRegex, "[$T].*G.*[$T]", 0);
11 |
12 | int isSafe = regexec(&safeRegex, floor, 0, NULL, 0) == 0;
13 |
14 | puts(isSafe ? "quiet" : "ALARM");
15 | regfree(®ex);
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/hard/security/security.py:
--------------------------------------------------------------------------------
1 | import re
2 | floor = "".join(re.findall(r'[G$T]', 'xxxxxGxTx$xGxxT'))
3 | if re.search(r'(\$T)|(T\$)', floor):
4 | print('ALARM')
5 | else:
6 | print('quiet')
7 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLength.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 5000
4 |
5 | int main() {
6 | char essay[MAX];
7 |
8 | int words = 0;
9 | int characters = 0;
10 | char previous = 0;
11 |
12 | for (char *word = fgets(essay, MAX, stdin); *word; previous = *(word++))
13 | if (isalpha(*word)) ++characters;
14 | else if (isalpha(previous)) ++words;
15 |
16 | if (isalpha(previous)) ++words;
17 | printf("%d", (int)ceil(characters / (double)words));
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLength.java:
--------------------------------------------------------------------------------
1 | public final class AverageWordLength {
2 | public static void main(String[] args) {
3 | final var essay = new java.util.Scanner(System.in).nextLine();
4 | final var wordsCount = essay.split("\\W").length;
5 | final var charsCount = essay.replaceAll("\\W", "").length();
6 | final var average = (int) Math.ceil((double) charsCount / wordsCount);
7 | System.out.print(average);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLength.rb:
--------------------------------------------------------------------------------
1 | puts ((essay=gets).gsub(/[^a-zA-Z]+/,'').size.to_f / essay.split.size).ceil
2 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLengthStream.java:
--------------------------------------------------------------------------------
1 | import static java.util.stream.Collectors.averagingInt;
2 |
3 | public final class AverageWordLengthStream {
4 | public static void main(String[] args) {
5 | System.out.print((int) Math.ceil(
6 | new java.util.Scanner(System.in)
7 | .useDelimiter("\\W+")
8 | .tokens()
9 | .collect(averagingInt(String::length)))
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLength_1.py:
--------------------------------------------------------------------------------
1 | from math import ceil
2 | essay = input().split()
3 | characters = 0
4 | for word in essay:
5 | for symbol in word:
6 | if symbol.isalpha():
7 | characters += 1
8 |
9 | average = int(ceil(characters / len(essay)))
10 | print(average)
11 |
--------------------------------------------------------------------------------
/medium/average-word-length/AverageWordLength_2.py:
--------------------------------------------------------------------------------
1 | import re
2 | from math import ceil
3 |
4 | essay = input()
5 | words = len(essay.split())
6 | chars = len(re.sub(r'\W+', '', essay))
7 |
8 | average = int(ceil(chars / words))
9 | print(average)
10 |
--------------------------------------------------------------------------------
/medium/convert-date/ConvertDate.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 40
4 |
5 | int main() {
6 | char usDate[MAX];
7 | fgets(usDate, MAX, stdin);
8 |
9 | int month = 0, day, year;
10 |
11 | if (strlen(usDate) > 10) {
12 | char monthName[12];
13 | sscanf(usDate, "%s %d, %d", monthName, &day, &year);
14 | char *months[] = {"January", "February", "March", "April", "May", "June",
15 | "July", "August", "September", "October", "November", "December"};
16 | while (strcmp(monthName, months[month++]) && month < 12);
17 | }
18 | else sscanf(usDate, "%d/%d/%d", &month, &day, &year);
19 |
20 | printf("%d/%d/%d", day, month, year);
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/medium/convert-date/ConvertDate.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.Locale;
3 | import java.time.LocalDate;
4 | import java.time.format.DateTimeFormatter;
5 | import java.time.format.FormatStyle;
6 |
7 | public final class ConvertDate {
8 | public static void main(String[] args) {
9 | final var usDate = new Scanner(System.in).nextLine();
10 | final var usShort = DateTimeFormatter.ofPattern("M/d/yyyy");
11 | final var usLong = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(Locale.US);
12 | final var isFirstSymbolDigit = Character.isDigit(usDate.charAt(0));
13 |
14 | final var usFormat = isFirstSymbolDigit ? usShort : usLong;
15 | final var euFormat = DateTimeFormatter.ofPattern("d/M/yyyy");
16 | final var euDate = euFormat.format(LocalDate.parse(usDate, usFormat));
17 | System.out.println(euDate);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/medium/convert-date/ConvertDate.py:
--------------------------------------------------------------------------------
1 | import re
2 | months = {'January': 1, 'February': 2, 'March': 3, 'April': 4, 'May': 5, 'June': 6,
3 | 'July': 7, 'August': 8, 'September': 9, 'October': 10, 'November': 11, 'December': 12}
4 |
5 | usDate = re.search(r'(.*)[ /](\d{1,2})[,/] ?(\d{4})', input())
6 |
7 | month = usDate.group(1)
8 | day = usDate.group(2)
9 | year = usDate.group(3)
10 |
11 | if len(month) > 2:
12 | month = months.get(month)
13 |
14 | print('{}/{}/{}'.format(day, month, year))
15 |
--------------------------------------------------------------------------------
/medium/convert-date/README.md:
--------------------------------------------------------------------------------
1 | # Convert US date to EU date
2 |
3 | You and your friends are going to Europe! You have made plans to travel around Europe with your friends, but one thing you need to take into account so that everything goes according to play, is that the format of their date is different than from what is used in the United States. Your job is to convert all your dates from MM/DD/YYYY to DD/MM/YYYY.
4 |
5 | ## Task:
6 | Create a function that takes in a string containing a date that is in US format, and return a string of the same date converted to EU.
7 |
8 | ## Input Format:
9 | A string that contains a date formatting 11/19/2019 or November 19, 2019.
10 |
11 | ## Output Format:
12 | A string of the same date but in a different format: 19/11/2019.
13 |
14 | ## Sample Input:
15 | 7/26/2019
16 |
17 | ## Sample Output:
18 | 26/7/2019
19 |
20 | *Note, that the input can be in two different formats, 11/19/2019 or November 19, 2019.*
21 |
--------------------------------------------------------------------------------
/medium/deja-vu/DejaVu.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char string[MAX];
7 | char *c = fgets(string, MAX, stdin);
8 |
9 | for (; *c; ++c) if (strchr(c + 1, *c)) break;
10 |
11 | puts(*c ? "Deja Vu" : "Unique");
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/medium/deja-vu/DejaVu.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class DejaVu {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var text = scanner.nextLine();
7 | final var isDejaVu = text.matches(".*(.).*\\1.*");
8 |
9 | System.out.println(isDejaVu ? "Deja Vu" : "Unique");
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/medium/deja-vu/DejaVu.py:
--------------------------------------------------------------------------------
1 | def dejaVu(string):
2 | for i in range(len(string) - 1):
3 | if string[i] in string[i + 1::]:
4 | return 'Deja Vu'
5 | return 'Unique'
6 |
7 |
8 | print(dejaVu(input()))
9 |
--------------------------------------------------------------------------------
/medium/deja-vu/DejaVu.rb:
--------------------------------------------------------------------------------
1 | puts gets.match(/(.).*\1/) ? 'Deja Vu' : 'Unique'
2 |
--------------------------------------------------------------------------------
/medium/deja-vu/DejaVu_re.py:
--------------------------------------------------------------------------------
1 | import re
2 | string = input()
3 | isDejaVu = re.search(r"(.).*\1", string)
4 |
5 | if isDejaVu:
6 | print('Deja Vu')
7 | else:
8 | print('Unique')
9 |
--------------------------------------------------------------------------------
/medium/deja-vu/README.md:
--------------------------------------------------------------------------------
1 | # Deja Vu
2 |
3 | You aren't paying attention and you accidentally type a bunch of random letters on your keyboard. You want to know if you ever typed the same letter twice, or if they are all unique letters.
4 |
5 | ## Task:
6 | If you are given a string of random letters, your task is to evaluate whether any letter is repeated in the string or if you only hit unique keys while you typing.
7 |
8 | ## Input Format:
9 | A string of random letter characters (no numbers or other buttons were pressed).
10 |
11 | ## Output Format:
12 | A string that says 'Deja Vu' if any letter is repeated in the input string, or a string that says 'Unique' if there are no repeats.
13 |
14 | ## Sample Input:
15 | aaaaaaaghhhhjkll
16 |
17 | ## Sample Output:
18 | Deja Vu
19 |
20 | ## Explanation:
21 | Your program should output 'Deja Vu' because there are many repetitions in 'aaaaaaaghhhhjkll'.
22 |
--------------------------------------------------------------------------------
/medium/military-time/MilitaryTime.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int hours;
5 | int minutes;
6 | char indicator;
7 | scanf("%d:%d %cM", &hours, &minutes, &indicator);
8 |
9 | if (indicator == 'P') hours += 12;
10 | else if (hours == 12) hours = 0;
11 | printf("%02d:%02d", hours, minutes);
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/medium/military-time/MilitaryTime.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalTime;
2 | import java.time.format.DateTimeFormatter;
3 | import java.time.format.FormatStyle;
4 | import java.util.Locale;
5 | import java.util.Scanner;
6 |
7 | public final class MilitaryTime {
8 | public static void main(String[] args) {
9 | final var scanner = new Scanner(System.in);
10 | final var usTime = scanner.nextLine();
11 |
12 | final var formatter = DateTimeFormatter
13 | .ofLocalizedTime(FormatStyle.SHORT)
14 | .withLocale(Locale.US);
15 |
16 | final var euTime = LocalTime.parse(usTime, formatter);
17 | System.out.println(euTime);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/medium/military-time/MilitaryTime.py:
--------------------------------------------------------------------------------
1 | import re
2 | usTime = re.search(r'(\d?\d):(\d\d) (A|P)M', input())
3 |
4 | hours = int(usTime.group(1))
5 | minutes = usTime.group(2)
6 | indicator = usTime.group(3)
7 |
8 | if indicator == 'P':
9 | hours += 12
10 | elif hours == 12:
11 | hours = 0
12 |
13 | print('%02d:%s' % (hours, minutes))
14 |
--------------------------------------------------------------------------------
/medium/military-time/MilitaryTimeClassic.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class MilitaryTimeClassic {
4 | public static void main(String[] args) {
5 | final var input = new Scanner(System.in);
6 | var hours = Integer.parseInt(input.findInLine("\\d?\\d"));
7 | final var minutes = input.findInLine("\\d\\d");
8 | final var indicator = input.findInLine("(A|P)M").charAt(0);
9 |
10 | if (indicator == 'P') {
11 | hours += 12;
12 | } else if (hours == 12) {
13 | hours = 0;
14 | }
15 |
16 | System.out.printf("%02d:%s", hours, minutes);
17 | }
18 | }
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/medium/military-time/MilitaryTimeRE.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class MilitaryTimeRE {
4 | public static void main(String[] args) {
5 | final var input = new Scanner(System.in);
6 |
7 | input.findInLine("(\\d?\\d):(\\d\\d) (A|P)M");
8 | final var usTime = input.match();
9 |
10 | var hours = Integer.valueOf(usTime.group(1));
11 | final var minutes = usTime.group(2);
12 | final var indicator = usTime.group(3).charAt(0);
13 |
14 | if (indicator == 'P') {
15 | hours += 12;
16 | } else if (hours == 12) {
17 | hours = 0;
18 | }
19 | System.out.printf("%02d:%s", hours, minutes);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/medium/military-time/README.md:
--------------------------------------------------------------------------------
1 | # Military Time
2 |
3 | You want to convert the time from a 12 hour clock to a 24 hour clock. If you are given the time on a 12 hour clock, you should output the time as it would appear on a 24 hour clock.
4 |
5 | ## Task:
6 | Determine if the time you are given is AM or PM, then convert that value to the way that it would appear on a 24 hour clock.
7 |
8 | ## Input Format:
9 | A string that includes the time, then a space and the indicator for AM or PM.
10 |
11 | ## Output Format:
12 | A string that includes the time in a 24 hour format (XX:XX)
13 |
14 | ## Sample Input:
15 | 1:15 PM
16 |
17 | ## Sample Output:
18 | 13:15
19 |
20 | ## Explanation:
21 | 1:00 PM on a 12 hour clock is equivalent to 13:00 on a 24 hour clock.
22 |
--------------------------------------------------------------------------------
/medium/no-numerals/NoNumerals.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | char *numberToWord(char *word) {
6 | char const *numbers[] = {"10", "9", "8", "7", "6", "5", "4", "3", "2", "1", "0"};
7 | char const *words[] = {"ten", "nine", "eight", "seven", "six", "five", "four", "three", "two", "one", "zero"};
8 |
9 | for (int i = 0; i < 11; ++i)
10 | if (strcmp(word, numbers[i]) == 0)
11 | return words[i];
12 |
13 | return word;
14 | }
15 |
16 | int main() {
17 | char phrase[MAX];
18 | fgets(phrase, MAX, stdin);
19 |
20 | for (char *word = strtok(phrase, " "); word; word = strtok(NULL, " "))
21 | printf("%s ", numberToWord(word));
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/medium/no-numerals/NoNumerals.java:
--------------------------------------------------------------------------------
1 | import java.util.Map;
2 | import java.util.Scanner;
3 |
4 | public final class NoNumerals {
5 | public static void main(String[] args) {
6 | final var numbers = Map.of(
7 | "10", "ten", "1", "one", "2", "two", "3", "three", "4", "four",
8 | "5", "five", "6", "six", "7", "seven", "8", "eight", "9", "nine");
9 |
10 | new Scanner(System.in)
11 | .tokens()
12 | .map(word -> (numbers.containsKey(word) ? numbers.get(word) : word) + " ")
13 | .forEach(System.out::print);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/medium/no-numerals/NoNumerals.py:
--------------------------------------------------------------------------------
1 | phrase = input().split()
2 | output = ''
3 | numbers = 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'
4 |
5 | for word in phrase:
6 | if word.isdigit() and int(word) in range(11):
7 | output += numbers[int(word)] + ' '
8 | else:
9 | output += word + ' '
10 |
11 | print(output)
12 |
--------------------------------------------------------------------------------
/medium/no-numerals/NoNumerals.rb:
--------------------------------------------------------------------------------
1 | phrase = gets.split
2 | numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
3 | puts phrase.map{|w| w=~/1?\d/ ? numbers[w.to_i]: w}.join(' ')
4 |
--------------------------------------------------------------------------------
/medium/no-numerals/README.md:
--------------------------------------------------------------------------------
1 | # No Numerals
2 |
3 | You write a phrase and include a lot of number characters (0-9), but you decide that for numbers 10 and under you would rather write the word out instead. Can you go in and edit your phrase to write out the name of each number instead of using the numeral?
4 |
5 | ## Task:
6 | Take a phrase and replace any instances of an integer from 0-10 and replace it with the English word that corresponds to that integer.
7 |
8 | ## Input Format:
9 | A string of the phrase in its original form (lowercase).
10 |
11 | ## Output Format:
12 | A string of the updated phrase that has changed the numerals to words.
13 |
14 | ## Sample Input:
15 | i need 2 pumpkins and 3 apples
16 |
17 | ## Sample Output:
18 | i need two pumpkins and three apples
19 |
20 | ## Explanation:
21 | You would update the phrase to change '2' to 'two' and '3' to 'three'.
22 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatin.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char sentence[MAX];
7 | fgets(sentence, MAX, stdin);
8 |
9 | for (char *word = strtok(sentence, " "); word; word = strtok(NULL, " "))
10 | printf("%s%cay ", word + 1, *word);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatin.py:
--------------------------------------------------------------------------------
1 | sentence = input().split()
2 | pig_latin = ""
3 |
4 | for word in sentence:
5 | pig_latin += word[1:] + word[0] + "ay "
6 |
7 | print(pig_latin)
8 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatin.rb:
--------------------------------------------------------------------------------
1 | puts gets.split.map {|w| w[1,w.size] + w[0] + 'ay'}.join(' ')
2 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatinClassic.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class PigLatinClassic {
4 | public static void main(final String[] args) {
5 | final var input = new Scanner(System.in);
6 | final var sentence = input.nextLine().split(" ");
7 |
8 | for (final var word : sentence) {
9 | System.out.printf("%s%cay ", word.substring(1), word.charAt(0));
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatinRE.java:
--------------------------------------------------------------------------------
1 | public final class PigLatinRE {
2 | public static void main(String[] args) {
3 | System.out.println(
4 | new java.util.Scanner(System.in)
5 | .nextLine()
6 | .replaceAll("(\\S)(\\S*)", "$2$1ay")
7 | );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/pig-latin/PigLatinStream.java:
--------------------------------------------------------------------------------
1 | public final class PigLatinStream {
2 | public static void main(String[] args) {
3 | new java.util.Scanner(System.in)
4 | .tokens()
5 | .map(word -> word.substring(1) + word.charAt(0) + "ay ")
6 | .forEach(System.out::print);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/medium/pig-latin/README.md:
--------------------------------------------------------------------------------
1 | # Pig Latin
2 |
3 | You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put it on the end, then you add 'ay' to the end of that. ("road" = "oadray")
4 |
5 | ## Task
6 | Your task is to take a sentence in English and turn it into the same sentence in Pig Latin!
7 |
8 | ## Input Format
9 | A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization)
10 |
11 | ## Output Format
12 | A string of the same sentence in Pig Latin.
13 |
14 | ## Sample Input
15 | "nevermind youve got them"
16 |
17 | ## Sample Output
18 | "evermindnay ouveyay otgay hemtay"
19 |
20 | ## Explanation
21 | The output should be the original sentence with each word changed so that they first letter is at the end and then -ay is added after that.
22 |
--------------------------------------------------------------------------------
/medium/pro-CMYK-to-RGB/CMYK2RGB.rb:
--------------------------------------------------------------------------------
1 | C, M, Y, K = Array.new(4){gets.to_f}
2 |
3 | R = (255 * (1-C) * (1-K)).round
4 | G = (255 * (1-M) * (1-K)).round
5 | B = (255 * (1-Y) * (1-K)).round
6 |
7 | puts '%d,%d,%d' % [R, G, B]
8 |
--------------------------------------------------------------------------------
/medium/pro-CMYK-to-RGB/CMYKtoRGB.py:
--------------------------------------------------------------------------------
1 | C, M, Y, K = [float(input()) for i in range(4)]
2 |
3 | R = round(255 * (1-C) * (1-K))
4 | G = round(255 * (1-M) * (1-K))
5 | B = round(255 * (1-Y) * (1-K))
6 |
7 | print(f'{R},{G},{B}')
8 |
--------------------------------------------------------------------------------
/medium/pro-building-blocks/BuildingBlocks.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.stream.IntStream;
3 |
4 | public final class BuildingBlocks {
5 | private static final int COLORS = 4;
6 | private static final int STUDENTS = 15;
7 |
8 | public static void main(String[] args) {
9 | final var scanner = new Scanner(System.in);
10 |
11 | final var sum = IntStream
12 | .generate(scanner::nextInt)
13 | .limit(COLORS)
14 | .map(i -> i % STUDENTS)
15 | .sum();
16 |
17 | System.out.print(sum);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/medium/pro-building-blocks/BuildingBlocks.py:
--------------------------------------------------------------------------------
1 | STUDENTS = 15
2 | COLORS = 4
3 |
4 | blocks = [int(input()) for i in range(COLORS)]
5 |
6 | left_over = sum(map(lambda x: x % STUDENTS, blocks))
7 |
8 | print(left_over)
9 |
--------------------------------------------------------------------------------
/medium/pro-building-blocks/BuildingBlocks.rb:
--------------------------------------------------------------------------------
1 | puts Array.new(4){gets.to_i % 15}.inject(:+)
2 |
--------------------------------------------------------------------------------
/medium/pro-building-blocks/building_blocks.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int const students = 15;
5 | int blocks[4];
6 | scanf("%d\n%d\n%d\n%d", blocks, blocks + 1, blocks + 2, blocks + 3);
7 |
8 | int remainingBlocks = 0, i = 4;
9 | while (i--) remainingBlocks += blocks[i] % students;
10 |
11 | printf("%d", remainingBlocks);
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-camel-to-snake/Camel2Snake.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/(?<=[^\/b])([A-Z])/, '_\1').downcase
2 |
--------------------------------------------------------------------------------
/medium/pro-camel-to-snake/CamelToSnake.java:
--------------------------------------------------------------------------------
1 | public final class CamelToSnake {
2 | public static void main(String[] args) {
3 | System.out.println(
4 | new java.util.Scanner(System.in)
5 | .nextLine()
6 | .replaceAll("(?<=[^//b^])([A-Z])", "_$1")
7 | .toLowerCase()
8 | );
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-camel-to-snake/CamelToSnakeClassic.java:
--------------------------------------------------------------------------------
1 | public class CamelToSnakeClassic {
2 | public static void main(final String[] args) {
3 | final var input = new java.util.Scanner(System.in);
4 | final var codebase = input.nextLine();
5 | input.close();
6 |
7 | final var output = new StringBuilder();
8 | boolean isFirst = true;
9 |
10 | for (final char c : codebase.toCharArray()) {
11 | if (Character.isUpperCase(c) && !isFirst) {
12 | output.append('_');
13 | }
14 | output.append(Character.toLowerCase(c));
15 | isFirst = Character.isWhitespace(c);
16 | }
17 |
18 | System.out.println(output);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/medium/pro-camel-to-snake/README.md:
--------------------------------------------------------------------------------
1 | # Camel to Snake
2 |
3 | The company you are working for is refactoring its entire codebase. It's changing all naming conventions from camel to snake case (camelCasing to snake_casing).
4 | Every capital letter is replaced with its lowercase prefixed by an underscore _, except for the first letter, which is lowercased without the underscore, so that SomeName becomes some_name.
5 |
6 | ## Task:
7 | Write a program that takes in a string that has camel casing, and outputs the same string but with snake casing.
8 |
9 | ## Input Format:
10 | A string with camelCasing.
11 |
12 | ## Output Format:
13 | The same string but with snake_casing.
14 |
15 | ## Sample Input:
16 | camelCasing
17 |
18 | ## Sample Output:
19 | camel_casing
20 |
21 | ## Explanation:
22 | The capital C was lowercased and prefixed by an underscore.
23 |
--------------------------------------------------------------------------------
/medium/pro-carrot-cake/CarrotCake.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class CarrotCake {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var carrotsForCake = 7;
7 | final var carrots = scanner.nextInt();
8 | final var boxes = scanner.nextInt();
9 |
10 | final var leftOverCarrots = carrots % boxes;
11 | final var isEnoughForCake = leftOverCarrots >= carrotsForCake;
12 |
13 | if (isEnoughForCake) {
14 | System.out.print("Cake Time");
15 | } else {
16 | final var needMoreCarrots = carrotsForCake - leftOverCarrots;
17 | System.out.printf("I need to buy %d more", needMoreCarrots);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/medium/pro-carrot-cake/CarrotCake.py:
--------------------------------------------------------------------------------
1 | CAKE = 7
2 |
3 | carrots = int(input())
4 | boxes = int(input())
5 |
6 | left_over = carrots % boxes
7 |
8 | if left_over < CAKE:
9 | need_more = CAKE - left_over
10 | print(f'I need to buy {need_more} more')
11 | else:
12 | print('Cake Time')
13 |
--------------------------------------------------------------------------------
/medium/pro-carrot-cake/CarrotCake.rb:
--------------------------------------------------------------------------------
1 | CAKE = 7
2 | carrots = gets.chomp.to_i
3 | boxes = gets.chomp.to_i
4 |
5 | left_over = carrots % boxes
6 |
7 | if left_over < CAKE
8 | need_more = CAKE - left_over
9 | puts 'I need to buy %d more' % need_more
10 | else
11 | puts 'Cake Time'
12 | end
13 |
--------------------------------------------------------------------------------
/medium/pro-carrot-cake/carrot_cake.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int const carrotsForCake = 7;
5 | int carrots, boxes;
6 | scanf("%d\n%d", &carrots, &boxes);
7 |
8 | int const leftOverCarrots = carrots % boxes;
9 | int const isEnoughForCake = leftOverCarrots >= carrotsForCake;
10 |
11 | if (isEnoughForCake) {
12 | printf("Cake Time");
13 | } else {
14 | int const needMoreCarrots = carrotsForCake - leftOverCarrots;
15 | printf("I need to buy %d more", needMoreCarrots);
16 | }
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/medium/pro-credit-card-validator/CreditCardValidator.py:
--------------------------------------------------------------------------------
1 | def isValid(n):
2 | if len(n) != 16:
3 | return False
4 | r = [int(ch) for ch in n][::-1]
5 | return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0
6 |
7 | number = input()
8 |
9 | if isValid(number):
10 | print('valid')
11 | else:
12 | print('not valid')
13 |
--------------------------------------------------------------------------------
/medium/pro-credit-card-validator/CreditCardValidator.rb:
--------------------------------------------------------------------------------
1 | puts (n=gets).size == 16 && n.reverse.chars.map(&:to_i).map.with_index{|x,i| i.odd?? x>4 ? x*2-9: x*2: x}.sum%10==0 ? 'valid': 'not valid'
2 |
--------------------------------------------------------------------------------
/medium/pro-day-of-the-week/DayOfWeek.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalDate;
2 | import java.time.format.DateTimeFormatter;
3 | import java.time.format.FormatStyle;
4 | import java.time.format.TextStyle;
5 | import java.util.Locale;
6 | import java.util.Scanner;
7 |
8 | public final class DayOfWeek {
9 | public static void main(String[] args) {
10 | final var usDate = new Scanner(System.in).nextLine();
11 | final var dayOfWeek = LocalDate.parse(usDate,
12 | Character.isDigit(usDate.charAt(0))
13 | ? DateTimeFormatter.ofPattern("M/d/yyyy")
14 | : DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(Locale.US))
15 | .getDayOfWeek()
16 | .getDisplayName(TextStyle.FULL, Locale.US);
17 |
18 | System.out.println(dayOfWeek);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/medium/pro-day-of-the-week/README.md:
--------------------------------------------------------------------------------
1 | # Day of the Week
2 |
3 | You receive a date and need to know what day of the week it is.
4 |
5 | ## Task:
6 | Create a program that takes in a string containing a date, and outputs the day of the week.
7 |
8 | ## Input Format:
9 | A string containing a date in either "MM/DD/YYYY" format or "Month Day, Year" format.
10 |
11 | ## Output Format:
12 | A string containing the day of the week from the provided date.
13 |
14 | ## Sample Input:
15 | 11/19/2019
16 |
17 | ## Sample Output:
18 | Tuesday
19 |
20 | ## Explanation:
21 | 19 November 2019 is a Tuesday.
22 |
--------------------------------------------------------------------------------
/medium/pro-days-between-dates/DaysBetweenDates.java:
--------------------------------------------------------------------------------
1 | import java.time.LocalDate;
2 | import java.time.format.DateTimeFormatter;
3 | import java.time.format.FormatStyle;
4 | import java.util.Locale;
5 | import java.util.Scanner;
6 |
7 | import static java.time.temporal.ChronoUnit.DAYS;
8 |
9 | public class DaysBetweenDates {
10 | public static void main(final String[] args) {
11 | final var formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(Locale.US);
12 | final var scanner = new Scanner(System.in);
13 | final var firstDate = LocalDate.parse(scanner.nextLine(), formatter);
14 | final var secondDate = LocalDate.parse(scanner.nextLine(), formatter);
15 |
16 | final long days = firstDate.until(secondDate, DAYS);
17 | System.out.println(days);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/medium/pro-days-between-dates/README.md:
--------------------------------------------------------------------------------
1 | # Days between dates
2 |
3 | You need to calculate exactly how many days have passed between two dates.
4 |
5 | ## Task:
6 | Calculate how many days have passed between two input dates, and output the result.
7 |
8 | ## Input Format:
9 | Two strings that represent the dates, first date should be the older date.
10 | Date format: Month DD, YYYY
11 |
12 | ## Output Format:
13 | A number representing the number of days between the two dates.
14 |
15 | ## Sample Input:
16 | ```
17 | August 15, 1979
18 | June 15, 2018
19 | ```
20 | ## Sample Output:
21 | ```
22 | 14184
23 | ```
24 | ## Explanation:
25 | 14184 days have passed between the two input days.
26 |
--------------------------------------------------------------------------------
/medium/pro-divisible/Divisible.java:
--------------------------------------------------------------------------------
1 | public final class Divisible {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var number = scanner.nextInt();
5 | final var isDivisible = scanner.tokens().mapToInt(Integer::parseInt).allMatch(i -> number % i == 0);
6 |
7 | System.out.println(isDivisible ? "divisible by all" : "not divisible by all");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/pro-divisible/Divisible.py:
--------------------------------------------------------------------------------
1 | number = int(input())
2 |
3 | if any(number % int(i) for i in input().split()):
4 | print('not divisible by all')
5 | else:
6 | print('divisible by all')
7 |
--------------------------------------------------------------------------------
/medium/pro-divisible/Divisible.rb:
--------------------------------------------------------------------------------
1 | number = gets.to_i
2 | puts gets.split(' ').map(&:to_i).any?{|x| number % x > 0} ? 'not divisible by all' : 'divisible by all'
3 |
--------------------------------------------------------------------------------
/medium/pro-divisible/README.md:
--------------------------------------------------------------------------------
1 | # Divisible
2 |
3 | You need to know if a number is divisible by each of a group of other numbers. If you are given the number and the group of other numbers, you will test to make sure that it is divisible by all of them.
4 |
5 | ## Task:
6 | Test your number against all of the other numbers that you are given to make sure that it is divisible by them.
7 |
8 | ## Input Format:
9 | Two inputs: an integer value (the number you are testing) and a string of variable length of the integers that you should test against separated by spaces.
10 |
11 | ## Output Format:
12 | A string that says 'divisible by all' or 'not divisible by all'.
13 |
14 | ## Sample Input:
15 | ```
16 | 100
17 | 2 5 10
18 | ```
19 | ## Sample Output:
20 | ```
21 | divisible by all
22 | ```
23 | ## Explanation:
24 | 100 is divisible by 2, 5, and 10.
25 |
--------------------------------------------------------------------------------
/medium/pro-divisible/divisible.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int n, i;
5 | scanf("%d\n", &n);
6 |
7 | while (scanf("%d", &i) == 1)
8 | if (n % i) {
9 | puts("not divisible by all");
10 | return 0;
11 | }
12 |
13 | puts("divisible by all");
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/medium/pro-duty-free/DutyFree.java:
--------------------------------------------------------------------------------
1 | public final class DutyFree {
2 | public static void main(String[] args) {
3 | System.out.print(
4 | new java.util.Scanner(System.in)
5 | .useDelimiter(" ")
6 | .tokens()
7 | .mapToDouble(Double::parseDouble)
8 | .map(x -> 1.1 * x)
9 | .anyMatch(x -> x > 20)
10 | ? "Back to the store"
11 | : "On to the terminal"
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-duty-free/DutyFree.py:
--------------------------------------------------------------------------------
1 | rate = 1.1
2 | limit_usd = 20
3 | items = [float(i) for i in input().split()]
4 |
5 | if any(item * rate > limit_usd for item in items):
6 | print('Back to the store')
7 | else:
8 | print('On to the terminal')
9 |
--------------------------------------------------------------------------------
/medium/pro-duty-free/DutyFree.rb:
--------------------------------------------------------------------------------
1 | puts gets.split(' ').map(&:to_f).any?{|x| 20 < 1.1 * x} ? 'Back to the store' : 'On to the terminal'
2 |
--------------------------------------------------------------------------------
/medium/pro-duty-free/duty_free.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | float item;
5 | while (1 == scanf("%f", &item)) {
6 | if (item * 1.1 > 20) {
7 | puts("Back to the store");
8 | return 0;
9 | }
10 | }
11 | puts("On to the terminal");
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/medium/pro-even-numbers/EvenNumbers.java:
--------------------------------------------------------------------------------
1 | public final class EvenNumbers {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .tokens()
6 | .mapToInt(Integer::parseInt)
7 | .filter(i -> i % 2 == 0)
8 | .forEach(i -> System.out.printf("%d ", i));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-even-numbers/EvenNumbers.py:
--------------------------------------------------------------------------------
1 | numbers = [int(i) for i in input().split()]
2 | even = filter(lambda x: x % 2 == 0, numbers)
3 | result = ' '.join(map(str, even))
4 | print(result)
5 |
--------------------------------------------------------------------------------
/medium/pro-even-numbers/EvenNumbers.rb:
--------------------------------------------------------------------------------
1 | puts gets.split(' ').map(&:to_i).select(&:even?).join(' ')
2 |
--------------------------------------------------------------------------------
/medium/pro-even-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Even Numbers
2 |
3 | Given a list of numbers, you want to take out all of the odd ones and leave just the even ones.
4 |
5 | ## Task:
6 | Evaluate each number in your list to see if it is even or odd. Then, output a new list that only contains the even numbers from your original list.
7 |
8 | ## Input Format:
9 | A string that includes all of the integer values in your list separated by spaces.
10 |
11 | ## Output Format:
12 | A string that includes all of the even integer values from your first list separated by spaces.
13 |
14 | ## Sample Input:
15 | ```
16 | 8 10 19 25 5 16 12
17 | ```
18 | ## Sample Output:
19 | ```
20 | 8 10 16 12
21 | ```
22 | ## Explanation:
23 | Your new list would only contain the even numbers (8, 10, 16, and 12) and would not include the odd ones (19, 25, and 5). Note, that both, input and output, are strings.
24 |
--------------------------------------------------------------------------------
/medium/pro-even-numbers/even_numbers.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int n;
5 | while(scanf("%d", &n) == 1) if (n%2==0) printf("%d ", n);
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/medium/pro-flowing-words/FlowingWords.java:
--------------------------------------------------------------------------------
1 | public class FlowingWords {
2 | public static void main(String[] args) {
3 | System.out.println(!new java.util.Scanner(System.in).nextLine().matches(".*((\\w)\\s+)(?!\\2).*"));
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/medium/pro-flowing-words/FlowingWords.py:
--------------------------------------------------------------------------------
1 | import re
2 | isFlowing = ('false', 'true')[re.search(r'^(\S*(\S) \2\S*)*$', input()) is not None]
3 | print(isFlowing)
4 |
--------------------------------------------------------------------------------
/medium/pro-flowing-words/FlowingWords.rb:
--------------------------------------------------------------------------------
1 | puts gets.match(/^(\S*(\S) \2\S*)*$/) != nil
2 |
--------------------------------------------------------------------------------
/medium/pro-flowing-words/README.md:
--------------------------------------------------------------------------------
1 | # Flowing Words
2 |
3 | If a sentence flows, the first letter of each word will be the same to the last letter of the previous word.
4 |
5 | ## Task:
6 | Write a program that takes in a string that contains a sentence, checks if the first letter of each word is the same as the last letter of the previous word. If the condition is met, output true, if not, output false.
7 | Casing does not matter.
8 |
9 | ## Input Format:
10 | A string containing a sentence of words.
11 |
12 | ## Output Format:
13 | A string: true or false.
14 |
15 | ## Sample Input:
16 | this string gets stuck
17 |
18 | ## Sample Output:
19 | true
20 |
21 | ## Explanation:
22 | Each word begins with the letter that the previous word ends with, therefore the output is true.
23 |
--------------------------------------------------------------------------------
/medium/pro-hex-color-code-generator/HexCode.py:
--------------------------------------------------------------------------------
1 | red = int(input())
2 | green = int(input())
3 | blue = int(input())
4 | print(f'#{red:02x}{green:02x}{blue:02x}')
5 |
--------------------------------------------------------------------------------
/medium/pro-hex-color-code-generator/HexColorCodeGenerator.java:
--------------------------------------------------------------------------------
1 | public final class HexColorCodeGenerator {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var red = scanner.nextInt();
5 | final var green = scanner.nextInt();
6 | final var blue = scanner.nextInt();
7 |
8 | System.out.printf("#%02x%02x%02x", red, green, blue);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-hex-color-code-generator/HexColorCodeGenerator.rb:
--------------------------------------------------------------------------------
1 | printf("#%02x%02x%02x", gets.to_i, gets.to_i, gets.to_i)
2 |
--------------------------------------------------------------------------------
/medium/pro-hex-color-code-generator/hex_color_code_generator.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int r, g, b;
5 | scanf("%d\n%d\n%d", &r, &g, &b);
6 | printf("#%02x%02x%02x", r, g, b);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/medium/pro-how-far/HowFar.java:
--------------------------------------------------------------------------------
1 | public final class HowFar {
2 | public static void main(final String[] args) {
3 | final var street = new java.util.Scanner(System.in).nextLine();
4 | final var howFar = street.replaceAll("B*[PH](B*)[HP]B*", "$1").length();
5 |
6 | System.out.println(howFar);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/medium/pro-how-far/HowFar.py:
--------------------------------------------------------------------------------
1 | import re
2 | print(len(re.sub(r'^B*[HP](B*)[HP]B*$',r'\1', input())))
3 |
--------------------------------------------------------------------------------
/medium/pro-how-far/HowFar.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/^B*[HP](B*)[HP]B*$/,'\1').size
2 |
--------------------------------------------------------------------------------
/medium/pro-how-far/README.md:
--------------------------------------------------------------------------------
1 | # How Far?
2 |
3 | You are walking from your house to a pond that is down your street.
4 | How many blocks over will you have to walk until you get to the pond?
5 |
6 | ## Task:
7 | Evaluate how many blocks you will have to walk if you are given a representation of your street where H represents your house, P represents the pond, and every B represents a block in between the two.
8 |
9 | ## Input Format:
10 | A string of letters representing your house, the pond, and blocks on your street.
11 |
12 | ## Output Format:
13 | An integer value that represents the number of blocks between your house and the pond.
14 |
15 | ## Sample Input:
16 | BBHBBBBPBBB
17 |
18 | ## Sample Output:
19 | 4
20 |
21 | ## Explanation:
22 | There are 4 blocks between your house and the pond on your street.
23 |
--------------------------------------------------------------------------------
/medium/pro-how-far/how_far.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int n = 0;
5 | for (char c; scanf("%c", &c) == 1; )
6 | switch (c) {
7 | case 'B': if (n) ++n; break;
8 | case 'H':
9 | case 'P': if (n++) {printf("%d", n - 2); return 0;}
10 | }
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/medium/pro-initials/Initials.java:
--------------------------------------------------------------------------------
1 | public class Initials {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .useDelimiter("\\v+")
6 | .tokens()
7 | .skip(1)
8 | .map(name -> name.replaceAll("^(.).* (.).*$", "$1$2 "))
9 | .forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/medium/pro-initials/Initials.py:
--------------------------------------------------------------------------------
1 | print(' '.join(''.join(s[0:1] for s in input().split()) for i in range(int(input()))))
2 |
--------------------------------------------------------------------------------
/medium/pro-initials/Initials.rb:
--------------------------------------------------------------------------------
1 | puts Array.new(gets.to_i){gets.chomp.gsub(/(\w)\w* (\w)\w*/,'\1\2')}.join(' ')
2 |
--------------------------------------------------------------------------------
/medium/pro-initials/README.md:
--------------------------------------------------------------------------------
1 | # Initials
2 |
3 | You are given a list of names for a fundraiser, but you need to keep the names relatively anonymous. You are tasked with getting the **initials** for each name provided.
4 |
5 | ## Task:
6 | Given a list of first and last names, take the first letter from each name to create initials and output them as a space-separated string.
7 |
8 | ## Input Format:
9 | The first input denotes the number of names in the list (N). The next N lines contain the list elements as strings.
10 |
11 | ## Output Format:
12 | A string containing the initials of each name in the original list, separated by spaces.
13 |
14 | ## Sample Input:
15 | ```
16 | 3
17 | Nick Dunburry
18 | Tommy Newborne
19 | David James
20 | ```
21 | ## Sample Output:
22 | ```
23 | ND TN DJ
24 | ```
25 | ## Explanation:
26 | Taking the first letter from each name results in the output **ND TN DJ**.
27 |
--------------------------------------------------------------------------------
/medium/pro-longest-common-substring/LongestCommonSubstring.py:
--------------------------------------------------------------------------------
1 | import re
2 | words = sorted(input().split(), key=len)
3 | word = words[0]
4 | length = len(word)
5 |
6 | for i in range(length, 0, -1):
7 | substrings = set(word[j:j + i] for j in range(0, 1 + length - i))
8 | ok = sorted(list(filter(lambda ss: all(map(lambda w: ss in w, words[1:])), substrings)))
9 | if ok: break
10 |
11 | print(ok[0])
12 |
--------------------------------------------------------------------------------
/medium/pro-longest-common-substring/README.md:
--------------------------------------------------------------------------------
1 | # Longest Common Substring
2 |
3 | ## Task:
4 | Given multiple words, you need to find the longest string that is a substring of all words.
5 |
6 | ## Input Format:
7 | A string of words, separated by spaces. The string can also contain numbers.
8 |
9 | ## Output Format:
10 | A string, representing the longest common substring.
11 | If there are multiple longest common substrings, output the smallest one in alphabetical order.
12 |
13 | ## Sample Input:
14 | SoloLearn Learning LearningIsFun Learnable
15 |
16 | ## Sample Output:
17 | Learn
18 |
19 | ## Explanation:
20 | Learn is the longest common substring for the words SoloLearn Learning LearningIsFun Learnable.
21 |
--------------------------------------------------------------------------------
/medium/pro-missing-numbers/MissingNumbers.py:
--------------------------------------------------------------------------------
1 | numbers = [int(input()) for i in range(int(input()))]
2 | missing = list(set(range(numbers[0], numbers[-1])) - set(numbers))
3 | output = ' '.join(map(str, sorted(missing)))
4 | print(output)
5 |
--------------------------------------------------------------------------------
/medium/pro-missing-numbers/MissingNumbers.rb:
--------------------------------------------------------------------------------
1 | data = Array.new(gets.to_i){gets.to_i}
2 | print (data[0].upto(data[-1]).to_a - data).join(' ')
3 |
--------------------------------------------------------------------------------
/medium/pro-missing-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Missing Numbers
2 |
3 | You are given a list of whole numbers in ascending order. You need to find which numbers are missing in the sequence.
4 |
5 | ## Task:
6 | Create a program that takes in a list of numbers and outputs the missing numbers in the sequence separated by spaces.
7 |
8 | ## Input Format:
9 | The first input denotes the length of the list (N). The next N lines contain the list elements as integers.
10 |
11 | ## Output Format:
12 | A string containing a space-separated list of the missing numbers.
13 |
14 | ## Sample Input:
15 | ```
16 | 5
17 | 2
18 | 4
19 | 5
20 | 7
21 | 8
22 | ```
23 | ## Sample Output:
24 | ```
25 | 3 6
26 | ```
27 | ## Explanation:
28 | The input list is missing the numbers 3 and 6.
29 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/NameBuddy.java:
--------------------------------------------------------------------------------
1 | public final class NameBuddy {
2 | public static void main(String[] args) {
3 | System.out.print(
4 | new java.util.Scanner(System.in)
5 | .tokens()
6 | .map(name -> name.substring(0,1))
7 | .reduce(String::concat)
8 | .orElse("")
9 | .matches(".*(.).*\\1$")
10 | ? "Compare notes"
11 | : "No such luck"
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/NameBuddy.py:
--------------------------------------------------------------------------------
1 | group = input()
2 | hero = input()
3 | isSame = any(map(lambda x: x[0:1] == hero[0:1], group))
4 |
5 | if isSame:
6 | print('Compare notes')
7 | else:
8 | print('No such luck')
9 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/NameBuddy.rb:
--------------------------------------------------------------------------------
1 | puts gets.chomp + ' ' + gets =~ /\b(\w).*\b\1\w*$/ ? 'Compare notes' : 'No such luck'
2 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/NameBuddyRegEx.java:
--------------------------------------------------------------------------------
1 | public final class NameBuddyRegEx {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var members = scanner.nextLine();
5 | final var myName = scanner.nextLine();
6 | final var isCompare = members.matches(".*\\b" + myName.charAt(0) + ".*");
7 |
8 | System.out.print(isCompare ? "Compare notes" : "No such luck");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/NameBuddy_re.py:
--------------------------------------------------------------------------------
1 | import re
2 | group = input()
3 | hero = input()
4 | isSame = re.search(r'^(.).*\b.*\b\1', hero + ' ' + group)
5 |
6 | if isSame:
7 | print('Compare notes')
8 | else:
9 | print('No such luck')
10 |
--------------------------------------------------------------------------------
/medium/pro-name-buddy/README.md:
--------------------------------------------------------------------------------
1 | # Name Buddy
2 |
3 | You are grouped into groups for a project, and you are supposed to come up with as many famous scientists who have the same first letter of their name as you as possible.
4 | Will you have to come up with the answers on your own, or is there somebody in your group that you can work with?
5 |
6 | ## Task:
7 | Determine if anyone in your group has the same first letter of their name as you.
8 |
9 | ## Input Format:
10 | A string of your group members' names separated by spaces, and then a string of your name.
11 |
12 | ## Output Format:
13 | A string that says 'Compare notes' if you have a name buddy, or 'No such luck' if you have to work on this alone.
14 |
15 | ## Sample Input:
16 | ```
17 | Becky Joan Fred Trey
18 | Brad
19 | ```
20 | ## Sample Output:
21 | ```
22 | Compare notes
23 | ```
24 | ## Explanation:
25 | Congratulations! You have a name buddy since Brad and Becky both start with a 'B'. You can work together.
26 |
--------------------------------------------------------------------------------
/medium/pro-roadrunner/Roadrunner.java:
--------------------------------------------------------------------------------
1 | public final class Roadrunner {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var distanceApart = 50;
5 | final var distanceSafety = scanner.nextInt();
6 | final var speedRoadrunner = scanner.nextInt();
7 | final var speedCoyote = scanner.nextInt();
8 |
9 | final var timeToSafety = (double) distanceSafety / speedRoadrunner;
10 | final var isCoyoteCaughtRoadrunner = speedCoyote > (distanceApart + distanceSafety) / timeToSafety;
11 |
12 | System.out.print(isCoyoteCaughtRoadrunner ? "Yum" : "Meep Meep");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-roadrunner/Roadrunner.py:
--------------------------------------------------------------------------------
1 | apart = 50
2 | safety = int(input())
3 | roadrunners_speed = int(input())
4 | coyotes_speed = int(input())
5 |
6 | time = safety / roadrunners_speed
7 |
8 | if coyotes_speed > (apart + safety) / time:
9 | print ('Yum')
10 | else:
11 | print ('Meep Meep')
12 |
--------------------------------------------------------------------------------
/medium/pro-roadrunner/Roadrunner.rb:
--------------------------------------------------------------------------------
1 | distanceApart = 50
2 | distanceSafety = gets.chomp.to_i
3 | speedRoadrunner = gets.chomp.to_i
4 | speedCoyote = gets.chomp.to_i
5 |
6 | timeToSafety = distanceSafety.to_f / speedRoadrunner
7 |
8 | isCoyoteCaughtRoadrunner = speedCoyote > (distanceApart + distanceSafety) / timeToSafety
9 |
10 | puts isCoyoteCaughtRoadrunner ? "Yum": "Meep Meep"
11 |
--------------------------------------------------------------------------------
/medium/pro-roadrunner/roadrunner.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int const distanceApart = 50;
5 | int distanceSafety, speedRoadrunner, speedCoyote;
6 | scanf("%d\n%d\n%d", &distanceSafety, &speedRoadrunner, &speedCoyote);
7 |
8 | float timeToSafety = (float) distanceSafety / speedRoadrunner;
9 | int isCoyoteCaughtRoadrunner = speedCoyote > (distanceApart + distanceSafety) / timeToSafety;
10 | puts(isCoyoteCaughtRoadrunner ? "Yum" : "Meep Meep");
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/medium/pro-safety-deposit-boxes/SafetyDepositBoxes.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SafetyDepositBoxes {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var items = scanner.nextLine();
7 | final var lookingFor = scanner.nextLine();
8 |
9 | final int itemsBeforeDesired = items
10 | .substring(0, items.indexOf(lookingFor))
11 | .replaceAll("[^,]", "").length();
12 |
13 | final int time = 5 + 5 * itemsBeforeDesired;
14 |
15 | System.out.print(time);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/medium/pro-safety-deposit-boxes/SafetyDepositBoxes.py:
--------------------------------------------------------------------------------
1 | items = input().split(',')
2 | desired = input()
3 | time = 5 * (1 + items.index(desired))
4 | print (time)
5 |
--------------------------------------------------------------------------------
/medium/pro-safety-deposit-boxes/SafetyDepositBoxes.rb:
--------------------------------------------------------------------------------
1 | puts gets.chomp.split(',').index(gets) * 5 + 5
2 |
--------------------------------------------------------------------------------
/medium/pro-safety-deposit-boxes/SafetyDepositBoxesArrays.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import static java.util.Arrays.asList;
3 |
4 | public class SafetyDepositBoxesArrays {
5 | public static void main(String[] args) {
6 | final var input = new Scanner(System.in);
7 | final var items = input.nextLine();
8 | final var lookingFor = input.nextLine();
9 | input.close();
10 |
11 | final int time = 5 + 5 * asList(items.split(",")).indexOf(lookingFor);
12 |
13 | System.out.print(time);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/medium/pro-safety-deposit-boxes/safety_deposit_boxes.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 300
4 |
5 | int main() {
6 | char boxes[MAX], item[MAX];
7 | scanf("%s\n%s", boxes, item);
8 |
9 | int time = 5;
10 | for (char *box = strtok(boxes, ","); box; box = strtok(NULL, ","))
11 | if (strcmp(item, box)) time += 5;
12 | else break;
13 |
14 | printf("%d", time);
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/medium/pro-snap-crackle-and-pop/SnapCrackle.py:
--------------------------------------------------------------------------------
1 | def sound(n):
2 | if n % 3 == 0: return 'Pop'
3 | if n % 2 == 0: return 'Crackle'
4 | else: return 'Snap'
5 |
6 |
7 | sounds = ' '.join(map(sound, [int(input()) for i in range(6)]))
8 |
9 | print(sounds)
10 |
--------------------------------------------------------------------------------
/medium/pro-snap-crackle-and-pop/SnapCrackleAndPop.java:
--------------------------------------------------------------------------------
1 | public class SnapCrackleAndPop {
2 | public static void main(String[] args) {
3 | new java.util.Scanner(System.in)
4 | .tokens()
5 | .map(Integer::parseInt)
6 | .map(i -> i % 3 > 0 ? i % 2 > 0 ? "Snap " : "Crackle " : "Pop ")
7 | .forEach(System.out::print);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/pro-snap-crackle-and-pop/SnapCracklePop.rb:
--------------------------------------------------------------------------------
1 | puts Array.new(6){gets.to_i}.map{|i| i % 3 > 0 ? i % 2 > 0 ? "Snap" : "Crackle" : "Pop"}.join(' ')
2 |
--------------------------------------------------------------------------------
/medium/pro-snap-crackle-and-pop/snap_crackle_pop.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int i;
5 |
6 | while(scanf("%d\n", &i) == 1)
7 | printf(i % 3 ? i % 2 ? "Snap " : "Crackle " : "Pop ");
8 |
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-snap-crackle-and-pop/snap_crackle_pop.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | int main() {
5 | for (int i = 0; i < 6; ++i) {
6 | int n;
7 | cin >> n;
8 | cout << (n % 3 ? n % 2 ? "Snap " : "Crackle " : "Pop ");
9 | }
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/medium/pro-snowballing-numbers/README.md:
--------------------------------------------------------------------------------
1 | # Snowballing Numbers
2 |
3 | You are given a list of numbers in a particular order. You need to check to see if each number is greater than the sum of all the previous number of the list.
4 | If they are, you have created successful snowball numbers.
5 |
6 | ## Task:
7 | Create a program that takes in an array of numbers, check if each number is greater than the sum of all previous numbers, and output true if the condition is met, and false, if not.
8 |
9 | ## Input Format:
10 | The first input denotes the length of the list (N). The next N lines contain the list elements as integers.
11 |
12 | ## Output Format:
13 | A string, true or false.
14 |
15 | ## Sample Input:
16 | ```
17 | 4
18 | 1
19 | 3
20 | 7
21 | 58
22 | ```
23 | ## Sample Output:
24 | ```
25 | true
26 | ```
27 | ## Explanation:
28 | Each number in the input list is greater than the sum of the previous numbers: 3>1, 7>3+1, 58>7+3+1
29 |
--------------------------------------------------------------------------------
/medium/pro-snowballing-numbers/SnowballingNumbers.java:
--------------------------------------------------------------------------------
1 | public final class SnowballingNumbers {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .skip(1)
8 | .mapToInt(Integer::parseInt)
9 | .reduce((a, b) -> a = a > 0 && b > a ? a + b : 0)
10 | .orElse(0)
11 | > 0
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-snowballing-numbers/SnowballingNumbers.py:
--------------------------------------------------------------------------------
1 | numbers = [int(input()) for i in range(int(input()))]
2 |
3 | sum = 0
4 | for n in numbers:
5 | if n <= sum:
6 | print('false')
7 | break
8 | sum += n
9 | else:
10 | print('true')
11 |
--------------------------------------------------------------------------------
/medium/pro-snowballing-numbers/SnowballingNumbers.rb:
--------------------------------------------------------------------------------
1 | puts 0 < Array.new(gets.to_i){gets.to_i}.reduce{|a,b| a > 0 && b > a ? a + b : 0}
2 |
--------------------------------------------------------------------------------
/medium/pro-snowballing-numbers/snowballing.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int n;
5 | scanf("%d", &n);
6 |
7 | for (int i, sum = 0; n--; sum += i) {
8 | scanf("%d", &i);
9 | if (i <= sum) {
10 | puts("false");
11 | return 0;
12 | }
13 | }
14 | puts("true");
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/README.md:
--------------------------------------------------------------------------------
1 | # Splitting Strings
2 |
3 | You are given a word and want to split it into even parts based on a number that is provided, each half being the size of the number.
4 |
5 | ## Task:
6 | Write a program that takes in a string, and a number as input.
7 | Split the string into even parts sized by the number, and output the parts separated by hyphens.
8 | The last part of the output will be any leftover, as the input string might not split into the provided parts evenly.
9 |
10 | ## Input Format:
11 | Two inputs: a string and an integer.
12 |
13 | ## Output Format:
14 | A string, representing the hyphen-separated parts.
15 |
16 | ## Sample Input:
17 | ```
18 | hello
19 | 2
20 | ```
21 | ## Sample Output:
22 | ```
23 | he-ll-o
24 | ```
25 | ## Explanation:
26 | We split the word "hello" into 2-sized parts. The last letter **o** was leftover, resulting in the output **he-ll-o**.
27 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/SplittingStrings.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public final class SplittingStrings {
4 | public static void main(String[] args) {
5 | final var scanner = new Scanner(System.in);
6 | final var s = scanner.nextLine();
7 | final var n = scanner.nextInt();
8 |
9 | final var separated = String.join("-", s.split(String.format("(?<=\\G.{%d})", n)));
10 | System.out.print(separated);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/SplittingStrings.py:
--------------------------------------------------------------------------------
1 | word = input()
2 | n = int(input())
3 |
4 | print('-'.join(word[i:i+n] for i in range(0, len(word), n)))
5 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/SplittingStrings.rb:
--------------------------------------------------------------------------------
1 | s = gets.chomp
2 | n = gets.to_i
3 |
4 | puts s.split(Regexp.new '(?<=\G.{%d})' % n).join('-')
5 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/SplittingStringsStream.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.stream.IntStream;
3 | import java.util.stream.Collectors;
4 |
5 | public class SplittingStringsStream
6 | {
7 | public static void main(String[] args) {
8 | final var input = new Scanner(System.in);
9 | final var text = input.nextLine();
10 | final var n = input.nextInt();
11 | final var len = text.length();
12 |
13 | var separated = IntStream
14 | .range(0, (len % n > 0 ? 1 : 0) + len / n)
15 | .mapToObj(i -> text.substring(i * n, Math.min(n + i * n, len)))
16 | .collect(Collectors.joining("-"));
17 |
18 | System.out.print(separated);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/medium/pro-splitting-strings/splitting_strings.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | char s[99];
5 | char* c = fgets(s, 99, stdin);
6 | int n;
7 | scanf("%d", &n);
8 |
9 | for (int i = 0; *c; ++i, ++c) {
10 | if (*c == '\n') break;
11 | if (i && i % n == 0) putchar('-');
12 | putchar(*c);
13 | }
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/medium/pro-super-sale/SuperSale.java:
--------------------------------------------------------------------------------
1 | public class SuperSale {
2 | public static void main(String[] args) {
3 | System.out.print((int)(0.3 * 1.07
4 | * -new java.util.Scanner(System.in)
5 | .useDelimiter(",")
6 | .tokens()
7 | .mapToDouble(Double::parseDouble)
8 | .map(x -> -x)
9 | .sorted()
10 | .skip(1)
11 | .sum())
12 | );
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/medium/pro-super-sale/SuperSale.py:
--------------------------------------------------------------------------------
1 | from math import floor
2 |
3 | tax = 1 + 0.07
4 | discount = 1 - 0.3
5 |
6 | items = sorted([float(x) for x in input().split(',')])
7 |
8 | full_price = sum(items)
9 | sale_price = sum(items[-1:]) + discount * sum(items[:-1])
10 |
11 | savings = floor((full_price - sale_price) * tax)
12 |
13 | print(savings)
14 |
--------------------------------------------------------------------------------
/medium/pro-super-sale/SuperSale.rb:
--------------------------------------------------------------------------------
1 | items = gets.split(',').map(&:to_i).sort
2 | savings = 1.07 * 0.30 * (items.inject(:+) - items[-1])
3 | puts savings.to_i
4 |
--------------------------------------------------------------------------------
/medium/pro-super-sale/super_sale.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | float item, sum, max;
5 | for (max = sum = 0; 1 == scanf("%f,", &item); sum += item)
6 | if (item > max) max = item;
7 | int save = (sum - max) * 0.3 * 1.07;
8 |
9 | printf("%d", save);
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/medium/pro-tax-free/README.md:
--------------------------------------------------------------------------------
1 | # Tax Free
2 |
3 | You are shopping at a store that is having a special where you do not have to pay the tax on anything that costs 20 dollars or more!
4 | If you have a list of prices for all of your items, what is your total once the tax is added in? Tax is 7% on the items that you would still need to pay tax on.
5 |
6 | ## Task:
7 | Determine the total cost once you include tax of 7% on the items that are still taxed.
8 |
9 | ## Input Format:
10 | A string of numbers, separated by commas, that represent to price of each item that you are going to buy.
11 |
12 | ## Output Format:
13 | A number, rounded to two decimal places, of the total for your purchase once tax is included on items under 20 dollars.
14 |
15 | ## Sample Input:
16 | 5,18,25,34
17 |
18 | ## Sample Output:
19 | 83.61
20 |
21 | ## Explanation:
22 | You would only have to pay the tax on the 5 and 18 dollar items and that bring your total to $83.61.
23 |
--------------------------------------------------------------------------------
/medium/pro-tax-free/TaxFree.java:
--------------------------------------------------------------------------------
1 | public final class TaxFree {
2 | public static void main(String[] args) {
3 | final var sum = new java.util.Scanner(System.in)
4 | .useDelimiter(",")
5 | .tokens()
6 | .mapToInt(Integer::parseInt)
7 | .mapToDouble(i -> i < 20 ? i * 1.07 : i)
8 | .sum();
9 |
10 | System.out.printf("%.2f", sum);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/medium/pro-tax-free/TaxFree.py:
--------------------------------------------------------------------------------
1 | tax = 0.07
2 | items = [float(x) for x in input().split(',')]
3 | total = sum(items) + tax * sum(filter(lambda x: x < 20, items))
4 | print(f'{total:.2f}')
5 |
--------------------------------------------------------------------------------
/medium/pro-tax-free/TaxFree.rb:
--------------------------------------------------------------------------------
1 | puts gets.split(',').map(&:to_f).map{|x| x < 20 ? 1.07 * x : x}.inject(:+)
2 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/README.md:
--------------------------------------------------------------------------------
1 | # Text Decompressor
2 |
3 | You need to decompress text. The compressed version has a number next to each symbol/letter, representing the amount of time that symbol should appear.
4 | For example, a2b3 is the compressed version of aabbb
5 |
6 | ## Task:
7 | Write a program that takes the compressed text as input and outputs the decompressed version.
8 |
9 | ## Input Format:
10 | A single string with letters/symbols, each followed by a number.
11 |
12 | ## Output Format:
13 | A string, representing the decompressed text.
14 |
15 | ## Sample Input:
16 | k2&4b1
17 |
18 | ## Sample Output:
19 | kk&&&&b
20 |
21 | ## Explanation:
22 | The letter k appears 2 times, the symbol & - 4 times and the letter b - 1 time.
23 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/TextDecompressor.c:
--------------------------------------------------------------------------------
1 | #include
2 | #define MAX 200
3 |
4 | int main() {
5 | char text[MAX];
6 | char *p = fgets(text, MAX, stdin);
7 |
8 | for(char c; c = *p++; ++p) while ((*p)--> '0') putchar(c);
9 |
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/TextDecompressor.java:
--------------------------------------------------------------------------------
1 | public final class TextDecompressor {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .useDelimiter("(?<=\\d)")
6 | .tokens()
7 | .map(x -> x.substring(0, 1).repeat(Integer.parseInt(x.substring(1))))
8 | .forEach(System.out::print);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/TextDecompressor.py:
--------------------------------------------------------------------------------
1 | text = input()
2 | decompressed = ''.join(text[i]*int(text[i+1]) for i in range(0,len(text),2))
3 | print(decompressed)
4 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/TextDecompressor.rb:
--------------------------------------------------------------------------------
1 | puts gets.split(/(?<=\d)/).map{|x| x[0] * x[1].to_i}.join
2 |
--------------------------------------------------------------------------------
/medium/pro-text-decompressor/TextDecompressor2.java:
--------------------------------------------------------------------------------
1 | public class TextDecompressor2 {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .useDelimiter("(?<=\\d)")
6 | .tokens()
7 | .map(x -> x.substring(0, 1).repeat(x.charAt(1) - '0'))
8 | .forEach(System.out::print);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/medium/secret-message/README.md:
--------------------------------------------------------------------------------
1 | # Secret Message
2 |
3 | You are trying to send a secret message, and you've decided to encode it by replacing every letter in your message with its corresponding letter in a backwards version of the alphabet.
4 | What do your messages look like?
5 |
6 | ## Task:
7 | Create a program that replaces each letter in a message with its corresponding letter in a backwards version of the English alphabet.
8 |
9 | ## Input Format:
10 | A string of your message in its normal form.
11 |
12 | ## Output Format:
13 | A string of your message once you have encoded it (all lower case).
14 |
15 | ## Sample Input:
16 | Hello World
17 |
18 | ## Sample Output:
19 | svool dliow
20 |
21 | ## Explanation:
22 | If you replace each letter in 'Hello World' with the corresponding letter in a backwards version of the alphabet, you get 'svool dliow'.
23 |
--------------------------------------------------------------------------------
/medium/secret-message/SecretMessage.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char message[MAX];
7 |
8 | for (char *c = fgets(message, MAX, stdin); *c; ++c)
9 | if (isalpha(*c)) putchar('a' + 'z' - tolower(*c));
10 | else putchar(*c);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/medium/secret-message/SecretMessage.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SecretMessage {
4 | public static void main(String[] args) {
5 |
6 | new Scanner(System.in)
7 | .nextLine()
8 | .toLowerCase()
9 | .chars()
10 | .forEach(i -> {
11 | char encoded = (char) (i >= 'a' && i <= 'z' ? 'a' + 'z' - i : i);
12 | System.out.print(encoded);
13 | });
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/medium/secret-message/SecretMessage.py:
--------------------------------------------------------------------------------
1 | message = input()
2 |
3 | for c in message.lower():
4 | if c.isalpha():
5 | print(chr(ord('a') + ord('z') - ord(c)), end='')
6 | else:
7 | print(c, end='')
8 |
--------------------------------------------------------------------------------
/medium/secret-message/SecretMessage.rb:
--------------------------------------------------------------------------------
1 | puts gets.downcase.chars.map{|c| c=~/^[a-z]$/?('az'.sum-c.ord).chr: c}.join
2 |
--------------------------------------------------------------------------------
/medium/symbols/README.md:
--------------------------------------------------------------------------------
1 | # Symbols
2 |
3 | There is a problem with your keyboard: it randomly writes symbols when you are typing a text. You need to clean up the text by removing all symbols.
4 |
5 | ## Task:
6 | Take a text that includes some random symbols and translate it into a text that has none of them. The resulting text should only include letters and numbers.
7 |
8 | ## Input Format:
9 | A string with random symbols.
10 |
11 | ## Output Format:
12 | A string of the text with all the symbols removed.
13 |
14 | ## Sample Input:
15 | #l$e%ts go @an#d@@ g***et #l#unch$$$
16 |
17 | ## Sample Output:
18 | lets go and get lunch
19 |
20 | ## Explanation:
21 | If you take out every symbol and leave only the letters and numbers, your text says 'lets go and get lunch'.
22 |
--------------------------------------------------------------------------------
/medium/symbols/Symbols.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char text[MAX];
7 |
8 | for (char *c = fgets(text, MAX, stdin); *c; ++c)
9 | if (isalnum(*c) || isspace(*c)) putchar(*c);
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/medium/symbols/Symbols.java:
--------------------------------------------------------------------------------
1 | public final class Symbols {
2 | public static void main(String[] args) {
3 | System.out.print(
4 | new java.util.Scanner(System.in)
5 | .nextLine()
6 | .replaceAll("[^a-zA-Z0-9 ]", "")
7 | );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/symbols/Symbols.py:
--------------------------------------------------------------------------------
1 | text = input()
2 |
3 | for c in text:
4 | if c.isalnum() or c.isspace():
5 | print(c, end='')
6 |
--------------------------------------------------------------------------------
/medium/symbols/Symbols.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/[^A-Za-z 0-9]/, '')
2 |
--------------------------------------------------------------------------------
/medium/thats-odd/README.md:
--------------------------------------------------------------------------------
1 | # That's odd...
2 |
3 | You want to take a list of numbers and find the sum of all of the even numbers in the list. Ignore any odd numbers.
4 |
5 | ## Task:
6 | Find the sum of all even integers in a list of numbers.
7 |
8 | ## Input Format:
9 | The first input denotes the length of the list (N). The next N lines contain the list elements as integers.
10 |
11 | ## Output Format:
12 | An integer that represents the sum of only the even numbers in the list.
13 |
14 | ## Sample Input:
15 | ```
16 | 9
17 | 1
18 | 2
19 | 3
20 | 4
21 | 5
22 | 6
23 | 7
24 | 8
25 | 9
26 | ```
27 | ## Sample Output:
28 | ```
29 | 20
30 | ```
31 | ## Explanation:
32 | If you add together 2, 4, 6, and 8 from the list, you get a sum of 20.
33 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | int count;
5 | scanf("%d", &count);
6 |
7 | int summa = 0;
8 | while (count--) {
9 | int number;
10 | scanf("%d", &number);
11 | if (number % 2 == 0) summa += number;
12 | }
13 |
14 | printf("%d", summa);
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.stream.IntStream;
3 |
4 | public final class ThatsOdd {
5 | public static void main(String[] args) {
6 | final var scanner = new Scanner(System.in);
7 | final int count = scanner.nextInt();
8 | final int sum = IntStream
9 | .generate(scanner::nextInt)
10 | .limit(count)
11 | .filter(i -> i % 2 == 0)
12 | .sum();
13 |
14 | System.out.print(sum);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd.py:
--------------------------------------------------------------------------------
1 | count = int(input())
2 | summa = 0
3 | while count > 0:
4 | count -= 1
5 | number = int(input())
6 | if number % 2 == 0:
7 | summa += number
8 |
9 | print(summa)
10 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd.rb:
--------------------------------------------------------------------------------
1 | puts Array.new(gets.to_i){gets.to_i}.select(&:even?).push(0).inject(:+)
2 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd_2.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 | no = 'not ' if any(n % int(i) for i in input().split()) else ''
3 | print(no + 'divisible by all')
4 |
--------------------------------------------------------------------------------
/medium/thats-odd/ThatsOdd_old.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class ThatsOdd_old
4 | {
5 | public static void main(final String[] args) {
6 | final Scanner input = new Scanner(System.in);
7 | int count = input.nextInt();
8 | int summa = 0;
9 |
10 | while (count-- > 0) {
11 | final int number = input.nextInt();
12 | if (number % 2 == 0) {
13 | summa += number;
14 | }
15 | }
16 | System.out.print(summa);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/medium/the-spy-life/README.md:
--------------------------------------------------------------------------------
1 | # The Spy Life
2 |
3 | You are a secret agent, and you receive an encrypted message that needs to be decoded. The code that is being used flips the message backwards and inserts non-alphabetic characters in the message to make it hard to decipher.
4 |
5 | ## Task:
6 | Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message.
7 |
8 | ## Input Format:
9 | A string of characters that represent the encoded message.
10 |
11 | ## Output Format:
12 | A string of character that represent the intended secret message.
13 |
14 | ## Sample Input:
15 | d89%l++5r19o7W *o=l645le9H
16 |
17 | ## Sample Output:
18 | Hello World
19 |
20 | ## Explanation:
21 | If you remove everything that isn't a letter or space from the original message and flip it around, you get 'Hello World'.
22 |
--------------------------------------------------------------------------------
/medium/the-spy-life/TheSpyLife.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #define MAX 200
5 |
6 | int main() {
7 | char message[MAX];
8 | fgets(message, MAX, stdin);
9 |
10 | for (int i = strlen(message); i--; ) {
11 | char c = message[i];
12 | if (isalpha(c) || isspace(c)) putchar(c);
13 | }
14 |
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/medium/the-spy-life/TheSpyLife.java:
--------------------------------------------------------------------------------
1 | public final class TheSpyLife {
2 | public static void main(String[] args) {
3 | final var scanner = new java.util.Scanner(System.in);
4 | final var encoded = new StringBuilder(scanner.nextLine());
5 | final var message = encoded.reverse().toString().replaceAll("[^a-zA-Z ]", "");
6 |
7 | System.out.print(message);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/medium/the-spy-life/TheSpyLife.py:
--------------------------------------------------------------------------------
1 | message = input()
2 |
3 | for c in message[::-1]:
4 | if c.isalpha() or c.isspace():
5 | print(c, end='')
6 |
--------------------------------------------------------------------------------
/medium/the-spy-life/TheSpyLife.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/[^A-Za-z ]/, '').reverse
2 |
--------------------------------------------------------------------------------
/medium/youtube-link-finder/README.md:
--------------------------------------------------------------------------------
1 | # YouTube Link Finder
2 |
3 | You and your friends like to share YouTube links all throughout the day. You want to keep track of all the videos you watch in your own personal notepad, but you find that keeping the entire link is unnecessary.
4 | Keep the video ID (the combination of letters and numbers at the end of the link) in your notepad to slim down the URL.
5 |
6 | ## Task:
7 | Create a program that parses through a link, extracts and outputs the YouTube video ID.
8 |
9 | ## Input Format:
10 | A string containing the URL to a YouTube video. The format of the string can be in "https://www.youtube.com/watch?v=kbxkq_w51PM" or the shortened "https://youtu.be/KMBBjzp5hdc" format.
11 |
12 | ## Output Format:
13 | A string containing the extracted YouTube video id.
14 |
15 | ## Sample Input:
16 | https://www.youtube.com/watch?v=RRW2aUSw5vU
17 |
18 | ## Sample Output:
19 | RWW2aUSwvU
20 |
21 | *Note that the input can be in two different formats.*
22 |
--------------------------------------------------------------------------------
/medium/youtube-link-finder/YouTubeLinkFinder.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #define MAX 200
4 |
5 | int main() {
6 | char url[MAX];
7 | fgets(url, MAX, stdin);
8 |
9 | char *p = url + strlen(url);
10 | while (*--p != '=' && *p != '/' && p != url);
11 | puts(++p);
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/medium/youtube-link-finder/YouTubeLinkFinder.java:
--------------------------------------------------------------------------------
1 | public final class YouTubeLinkFinder {
2 | public static void main(String[] args) {
3 | final var url = new java.util.Scanner(System.in).nextLine();
4 | final var videoId = url.replaceAll(".*[=/](.*)$", "$1");
5 | System.out.print(videoId);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/medium/youtube-link-finder/YouTubeLinkFinder.py:
--------------------------------------------------------------------------------
1 | import re
2 | url = input()
3 | videoId = re.search(r'[^=/]*$', url).group()
4 | print(videoId)
5 |
--------------------------------------------------------------------------------
/medium/youtube-link-finder/YouTubeLinkFinder.rb:
--------------------------------------------------------------------------------
1 | puts gets.gsub(/.*[=\/](?=[^=\/]*$)/, '')
2 |
--------------------------------------------------------------------------------
/one-statement/Argentina.java:
--------------------------------------------------------------------------------
1 | public class Argentina {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .mapToInt(Integer::parseInt)
8 | .reduce((pesos, dollars) -> dollars * 50l > pesos ? 0: -1)
9 | .orElse(0) == 0 ? "Pesos" : "Dollars"
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/AverageWordLength.java:
--------------------------------------------------------------------------------
1 | import static java.util.stream.Collectors.averagingInt;
2 |
3 | public class AverageWordLength {
4 | public static void main(String[] args) {
5 | System.out.print((int)Math.ceil(
6 | new java.util.Scanner(System.in)
7 | .useDelimiter("\\W+")
8 | .tokens()
9 | .collect(averagingInt(String::length))));
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/CamelToSnake.java:
--------------------------------------------------------------------------------
1 | public class CamelToSnake {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(
5 | new java.util.Scanner(System.in)
6 | .nextLine()
7 | .replaceAll("(?<=[^//b^])([A-Z])", "_$1")
8 | .toLowerCase());
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/Candles.java:
--------------------------------------------------------------------------------
1 | public class Candles {
2 | public static void main(String[] args) {
3 | System.out.print(9 * (1 + new java.util.Scanner(System.in).nextInt()));
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/one-statement/DejaVu.java:
--------------------------------------------------------------------------------
1 | public class DejaVu {
2 | public static void main(String[] args) {
3 | System.out.println(
4 | new java.util.Scanner(System.in)
5 | .nextLine()
6 | .matches(".*(.).*\\1.*") ? "Deja Vu" : "Unique"
7 | );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/one-statement/Divisible.java:
--------------------------------------------------------------------------------
1 | public class Divisible {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new java.util.Scanner(System.in)
6 | .useDelimiter("\\s")
7 | .tokens()
8 | .mapToInt(Integer::parseInt)
9 | .reduce((a, b) -> a = a % b == 0 ? a : 0)
10 | .orElse(0) > 0
11 | ? "divisible by all" : "not divisible by all");
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/one-statement/DuctTape.java:
--------------------------------------------------------------------------------
1 | public class DuctTape {
2 | public static void main(String[] args) {
3 | System.out.print(
4 | new java.util.Scanner(System.in)
5 | .tokens()
6 | .mapToInt(Integer::parseInt)
7 | .reduce((doorHeight, doorWidth) -> (int) Math.ceil(doorHeight * doorWidth / 5.))
8 | .orElse(1)
9 | );
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/DutyFree.java:
--------------------------------------------------------------------------------
1 | public class DutyFree {
2 | public static void main(String[] args) {
3 | System.out.print(
4 | new java.util.Scanner(System.in)
5 | .useDelimiter(" ")
6 | .tokens()
7 | .mapToDouble(Double::parseDouble)
8 | .map(x -> 1.1 * x)
9 | .anyMatch(x -> x > 20) ? "Back to the store" : "On to the terminal"
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/EasterEggs.java:
--------------------------------------------------------------------------------
1 | public class EasterEggs {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .limit(3)
8 | .mapToInt(Integer::parseInt)
9 | .reduce((a,b) -> a = a - b)
10 | .getAsInt() > 0 ? "Keep Hunting" : "Candy Time");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/EvenNumbers.java:
--------------------------------------------------------------------------------
1 | public class EvenNumbers {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .tokens()
6 | .mapToInt(Integer::parseInt)
7 | .filter(i -> i % 2 == 0)
8 | .forEach(i -> System.out.printf("%d ", i));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/FlowingWords.java:
--------------------------------------------------------------------------------
1 | public class FlowingWords {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(!new java.util.Scanner(System.in)
5 | .tokens()
6 | .reduce((a, b) -> a = !a.isEmpty() && a.endsWith(b.substring(0,1)) ? b : "")
7 | .get()
8 | .isEmpty());
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/FlowingWordsRE.java:
--------------------------------------------------------------------------------
1 | public class FlowingWordsRE {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(java.util.regex.Pattern
5 | .matches("^(\\w*(\\w)\\s+\\2\\w*)+$",
6 | new java.util.Scanner(System.in).nextLine()));
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/one-statement/FlowingWordsRE2.java:
--------------------------------------------------------------------------------
1 | public class FlowingWordsRE2 {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.print(!java.util.regex.Pattern
6 | .matches(".*((\\w)\\s+)(?!\\2).*",
7 | new java.util.Scanner(System.in).nextLine()));
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/one-statement/FruitBowl.java:
--------------------------------------------------------------------------------
1 | public class FruitBowl {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(new java.util.Scanner(System.in).nextInt() / 6);
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/one-statement/GothamCity.java:
--------------------------------------------------------------------------------
1 | public class GothamCity {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new String[] {"I got this!", "Help me Batman", "Good Luck out there!"}
6 | [Math.min((1 + new java.util.Scanner(System.in).nextInt()) / 6, 2)]
7 | );
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/one-statement/GuardFlamingos.java:
--------------------------------------------------------------------------------
1 | public class GuardFlamingos {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .limit(2)
8 | .mapToInt(Integer::parseInt)
9 | .reduce(Integer::sum)
10 | .getAsInt());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/HalloweenCandy.java:
--------------------------------------------------------------------------------
1 | public class HalloweenCandy {
2 | public static void main(String[] args) {
3 |
4 | System.out.print((int)Math.ceil(200. / new java.util.Scanner(System.in).nextInt()));
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/one-statement/HexColorCodeGenerator.java:
--------------------------------------------------------------------------------
1 | public class HexColorCodeGenerator {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.printf("#%02x%02x%02x",
6 | new java.util.Scanner(System.in)
7 | .tokens()
8 | .limit(3)
9 | .mapToInt(Integer::parseInt)
10 | .boxed()
11 | .toArray());
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/one-statement/HowFar.java:
--------------------------------------------------------------------------------
1 | public class HowFar {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(
5 | new java.util.Scanner(System.in)
6 | .nextLine()
7 | .replaceAll("B*[PH](B*)[HP]B*", "$1")
8 | .length());
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/Initials.java:
--------------------------------------------------------------------------------
1 | public class Initials {
2 | public static void main(String[] args) {
3 |
4 | new java.util.Scanner(System.in)
5 | .useDelimiter("\\v+")
6 | .tokens()
7 | .skip(1)
8 | .map(name -> name.replaceAll("^(.).* (.).*$", "$1$2 "))
9 | .forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/IsogramDetector.java:
--------------------------------------------------------------------------------
1 | public class IsogramDetector {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(!java.util.regex.Pattern
6 | .matches(".*(.).*\\1.*", new java.util.Scanner(System.in).nextLine()));
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/one-statement/ItsSign.java:
--------------------------------------------------------------------------------
1 | public class ItsSign {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(new java.util.Scanner(System.in)
6 | .tokens()
7 | .limit(4)
8 | .map(StringBuilder::new)
9 | .anyMatch(w -> w.toString().equals(w.reverse().toString()))
10 | ? "Open" : "Trash");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/IzzyIguana.java:
--------------------------------------------------------------------------------
1 | public class IzzyIguana {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(new java.util.Scanner(System.in)
6 | .tokens()
7 | .mapToInt(java.util.Map.of("Lettuce", 5, "Carrot", 4, "Mango", 9, "Cheeseburger", 0)::get)
8 | .sum() >= 10 ? "Come on Down!" : "Time to wait");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/JungleCamping.java:
--------------------------------------------------------------------------------
1 | public class JungleCamping {
2 |
3 | public static void main(String[] args) {
4 |
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .map(java.util.Map
8 | .of("Grr", "Lion ", "Rawr", "Tiger ", "Ssss", "Snake ", "Chirp", "Bird ")::get)
9 | .forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/LandHo.java:
--------------------------------------------------------------------------------
1 | public class LandHo {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.print(10 + new java.util.Scanner(System.in).nextInt() / 20 * 20);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/one-statement/MilitaryTime.java:
--------------------------------------------------------------------------------
1 | public class MilitaryTime {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(java.time.LocalTime.parse(
5 | new java.util.Scanner(System.in).nextLine(),
6 | java.time.format.DateTimeFormatter
7 | .ofLocalizedTime(java.time.format.FormatStyle.SHORT)
8 | .withLocale(java.util.Locale.US)));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/Multiples.java:
--------------------------------------------------------------------------------
1 | public class Multiples {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.print(java.util.stream.IntStream
6 | .range(3, new java.util.Scanner(System.in).nextInt())
7 | .filter(i -> i % 3 == 0 || i % 5 == 0)
8 | .sum());
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/NameBuddy.java:
--------------------------------------------------------------------------------
1 | public class NameBuddy {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(java.util.regex.Pattern.matches(".*(.).*\\1$",
5 | new java.util.Scanner(System.in)
6 | .useDelimiter("\\s")
7 | .tokens()
8 | .map(name -> name.substring(0,1))
9 | .reduce(String::concat)
10 | .orElse("")) ? "Compare notes" : "No such luck");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/NoNumerals.java:
--------------------------------------------------------------------------------
1 | import java.util.Map;
2 |
3 | public class NoNumerals {
4 | static final Map numbers = Map.of(
5 | "10", "ten", "1", "one", "2", "two", "3", "three", "4", "four",
6 | "5", "five", "6", "six", "7", "seven", "8", "eight", "9", "nine");
7 |
8 | public static void main(String[] args) {
9 |
10 | new java.util.Scanner(System.in)
11 | .tokens()
12 | .map(word -> (numbers.containsKey(word) ? numbers.get(word) : word) + " ")
13 | .forEach(System.out::print);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/one-statement/NumberOfOnes.java:
--------------------------------------------------------------------------------
1 | public class NumberOfOnes {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(
6 | Integer.bitCount(
7 | new java.util.Scanner(System.in).nextInt()));
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/one-statement/PaintCosts.java:
--------------------------------------------------------------------------------
1 | public class PaintCosts {
2 | public static void main(String[] args) {
3 |
4 | System.out.print((int)Math.round(1.1 * (5 * new java.util.Scanner(System.in).nextInt() + 40)));
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/one-statement/PigLatin.java:
--------------------------------------------------------------------------------
1 | public class PigLatin {
2 |
3 | public static void main(String[] args) {
4 |
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .map(word -> word.substring(1) + word.charAt(0) + "ay ")
8 | .forEach(System.out::print);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/Popsicles.java:
--------------------------------------------------------------------------------
1 | public class Popsicles {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | 0 == new java.util.Scanner(System.in)
6 | .tokens()
7 | .mapToInt(Integer::parseInt)
8 | .reduce((siblings, popsicles) -> popsicles % siblings)
9 | .orElse(1) ? "give away" : "eat them yourself"
10 | );
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/README.md:
--------------------------------------------------------------------------------
1 | # Hacker code
2 |
3 | In this directory I had put hackers «one-statement» java solutions for some of sololearn chalenges. The main reason I started writing this code was the desire to explore the possibilities of the Java language. For some snippets the code is clean but usally it is tricky and dirty.
4 |
5 | **Don't copy&paste the code snippets into your production code!**
6 |
--------------------------------------------------------------------------------
/one-statement/SecretMessage.java:
--------------------------------------------------------------------------------
1 | public class SecretMessage {
2 |
3 | public static void main(String[] args) {
4 |
5 | new java.util.Scanner(System.in)
6 | .nextLine()
7 | .toLowerCase()
8 | .chars()
9 | .forEach(i -> {
10 | char encoded = (char)(i >= 'a' && i <= 'z' ? 'a' + 'z' - i : i);
11 | System.out.print(encoded);});
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/one-statement/Security.java:
--------------------------------------------------------------------------------
1 | public class Security {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(java.util.regex.Pattern
6 | .matches(".*[$T].*G.*[$T].*", new java.util.Scanner(System.in).nextLine()) ? "quiet" : "ALARM");
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/one-statement/SnapCrackleAndPop.java:
--------------------------------------------------------------------------------
1 | public class SnapCrackleAndPop {
2 |
3 | public static void main(String[] args) {
4 |
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .mapToInt(Integer::parseInt)
8 | .mapToObj(i -> i % 3 == 0 ? "Pop " : i % 2 == 0 ? "Crackle " : "Snap ")
9 | .forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/SnowballingNumbers.java:
--------------------------------------------------------------------------------
1 | public class SnowballingNumbers {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new java.util.Scanner(System.in)
6 | .tokens()
7 | .skip(1)
8 | .mapToInt(Integer::parseInt)
9 | .reduce((a,b) -> a = a > 0 && b > a ? a + b : 0)
10 | .orElse(0) > 0);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/SuperSale.java:
--------------------------------------------------------------------------------
1 | public class SuperSale {
2 | public static void main(String[] args) {
3 |
4 | System.out.printf("%d", (int) (0.3 * 1.07 *
5 | -new java.util.Scanner(System.in)
6 | .useDelimiter(",")
7 | .tokens()
8 | .mapToDouble(Double::parseDouble)
9 | .map(x -> -x)
10 | .sorted()
11 | .skip(1)
12 | .sum()));
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/one-statement/Symbols.java:
--------------------------------------------------------------------------------
1 | public class Symbols {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.print(
6 | new java.util.Scanner(System.in)
7 | .nextLine()
8 | .replaceAll("[^a-zA-Z0-9 ]", ""));
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/one-statement/TaxFree.java:
--------------------------------------------------------------------------------
1 | public class TaxFree {
2 | public static void main(String[] args) {
3 |
4 | System.out.printf("%.2f",
5 | new java.util.Scanner(System.in)
6 | .useDelimiter(",")
7 | .tokens()
8 | .mapToInt(Integer::parseInt)
9 | .mapToDouble(i -> i < 20 ? i * 1.07 : i)
10 | .sum());
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/one-statement/TextDecompressor.java:
--------------------------------------------------------------------------------
1 | public class TextDecompressor {
2 |
3 | public static void main(String[] args) {
4 |
5 | new java.util.Scanner(System.in)
6 | .useDelimiter("(?<=\\d)")
7 | .tokens()
8 | .map(x -> x.substring(0,1).repeat(x.charAt(1) - '0'))
9 | .forEach(System.out::print);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/TheSpyLife.java:
--------------------------------------------------------------------------------
1 | public class TheSpyLife {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.println(
6 | new StringBuilder(new java.util.Scanner(System.in).nextLine())
7 | .reverse()
8 | .toString()
9 | .replaceAll("[^a-zA-Z ]", ""));
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/VowelCounter.java:
--------------------------------------------------------------------------------
1 | public class VowelCounter {
2 |
3 | public static void main(String[] args) {
4 |
5 | System.out.print(
6 | new java.util.Scanner(System.in)
7 | .nextLine()
8 | .replaceAll("[^AEIOUaeiou]", "")
9 | .length());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/one-statement/YouTubeLinkFinder.java:
--------------------------------------------------------------------------------
1 | public class YouTubeLinkFinder {
2 | public static void main(String[] args) {
3 |
4 | System.out.print(
5 | new java.util.Scanner(System.in)
6 | .nextLine()
7 | .replaceAll(".*[=/](.*)$", "$1"));
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/one-statement/ZipCodeValidator.java:
--------------------------------------------------------------------------------
1 | public class ZipCodeValidator {
2 | public static void main(String[] args) {
3 |
4 | System.out.println(java.util.regex.Pattern
5 | .matches("\\d{5}", new java.util.Scanner(System.in).nextLine()));
6 | }
7 | }
8 |
--------------------------------------------------------------------------------