Crunching Part 3 Flashcards

Crunching (20 cards)

1
Q

Vowel Counter (2mins)

Count the number of vowels in a given string (case-insensitive).

Input:
Enter a string: Engineering Instructor

Output:
Vowels: 8

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Binary Odd/Even (2mins)

Determine whether a binary number is even or odd.

Input:
1101

Output:
Odd

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Binary to Gray Code (3mins)

Convert a binary number to its Gray code equivalent.

Input:
Enter binary: 1011

Output:
Gray code: 1110

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Gray Code to Binary (3mins)

Convert Gray code back to its original binary value.

Input:
Enter Gray code: 1110

Output:
Binary: 1011

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

17
Q

Count Consecutive 1s (3mins)

Count the longest run of consecutive 1s in a binary string.

Input:
Binary: 11011101111

Output:
Max consecutive 1s: 4

18
Q

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

19
Q

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

20
Q

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