Crunching Part 3 Flashcards
Crunching (20 cards)
Vowel Counter (2mins)
Count the number of vowels in a given string (case-insensitive).
Input:
Enter a string: Engineering Instructor
Output:
Vowels: 8
A
Odd/Even Splitter (2mins)
Separate and print odd and even numbers from a list.
Input:
Enter numbers: 3,8,5,12,7,6,9
Output:
Even: 8, 12, 6
Odd: 3, 5, 7, 9
A
Mode Counter (3mins)
Get the mode in a list of numbers.
Input:
Enter numbers: 1 4 2 4 3 2 4 5
Output:
Mode: 4
A
Caesar Cipher (Shift by 3) (3mins)
Encode a string using Caesar cipher with a shift of 3. Ignore spaces and punctuation.
Input:
Enter message: attack at dawn
Output:
Encoded: dwwdfn dwdgdzq
A
Power of 2 (2mins)
Check whether a binary number represents a power of 2.
Input:
Enter a binary number: 100000
Output:
Power of 2
A
Hamming Weight (3mins)
Count the number of 1s in the binary representation of a decimal number.
Input:
Enter a number: 29
Output:
Binary: 11101
Hamming weight: 4
A
Binary Addition (2mins)
Ask the user for two binary numbers and output their sum in binary.
Input:
Enter binary1: 1011
Enter binary2: 1010
Output:
10101
A
Binary Odd/Even (2mins)
Determine whether a binary number is even or odd.
Input:
1101
Output:
Odd
A
Binary Pattern Match (2mins)
Ask the user for a binary string and a pattern. Count how many times the pattern occurs.
Input:
Binary: 10111010101
Pattern: 101
Output:
Occurrences: 3
A
Binary AND, OR, XOR (3mins)
Given two binary strings, print their AND, OR, and XOR results.
Input:
First binary: 1101
Second binary: 1010
Output:
AND: 1000
OR: 1111
XOR: 0111
A
Leading Zeros (3mins)
Count the number of leading 0s in a fixed-length binary string.
Input:
Enter binary (8-bit): 00010110
Output:
Leading zeros: 3
A
Binary to Gray Code (3mins)
Convert a binary number to its Gray code equivalent.
Input:
Enter binary: 1011
Output:
Gray code: 1110
A
Gray Code to Binary (3mins)
Convert Gray code back to its original binary value.
Input:
Enter Gray code: 1110
Output:
Binary: 1011
A
Bit Parity Checker (2mins)
Count the number of 1s and determine if it’s even or odd parity.
Input:
Binary: 1101011
Output:
1s: 5
Parity: Odd
A
Reverse Binary (2mins)
Reverse the bits of a binary number and print its decimal equivalent.
Input:
Enter binary: 1101
Output:
Reversed: 1011
Decimal: 11
A
Binary Rotate and Mask (3mins)
Rotate a binary number left by 1 and mask it with 1111 (AND operation).
Input:
Binary: 1010
Output:
Rotated: 0101
Masked: 0101
A
Count Consecutive 1s (3mins)
Count the longest run of consecutive 1s in a binary string.
Input:
Binary: 11011101111
Output:
Max consecutive 1s: 4
A
Set Bit at Position (3mins)
Ask for a binary number and a bit position, then set that bit to 1.
Input:
Binary: 1000
Position to set (from right, 0-based): 1
Output:
Result: 1010
A
0 Set (3mins)
Ask the user to enter numbers and the indexes that he wants to set as 0. The index will determine the indexes that will be set to 0 on the left and right sides.
Input:
Enter numbers: 1,4,3,2,1,6
Enter index: 2
Output:
0,0,3,2,0,0
A
Binary Mirror (2mins)
Ask the user to enter a binary number and output the mirror of that number.
Input:
Enter Binary: 0101101
Output:
Mirror: 1101010
A