Skip to content

This repository is a dynamic collection that grows as I learn, test, and update my programming skills. It includes tasks from platforms like CodeWars, where developers enhance their coding abilities through gamified challenges, as well as various simple projects I’ve created.

Notifications You must be signed in to change notification settings

rokasauras/light_practice

Repository files navigation

Python Utility Functions

This repository contains multiple Python functions designed to solve distinct problems, listed below:


Converting a Binary Array to a Decimal Number - binary_array_decoder

Description

This function converts a binary array (series of 0s and 1s) to its corresponding decimal (base-10) value.

Features

  • Handles binary arrays of any length.
  • Efficiently calculates the decimal value using bitwise operations.

Finding the Complementary DNA Strand

Description

Automates finding the complementary DNA strand based on base pairing rules:

  • A pairs with T
  • C pairs with G

Features

  • Takes a DNA strand (string) as input.
  • Outputs the complementary DNA strand.
  • Handles both uppercase and lowercase letters.

Paino Tiles Game Bot

Description

Automates playing the Paino Tiles game by detecting black pixels at user-specified click locations.

Features

  • Allows the user to define click coordinates.
  • Analyses the screen for black pixels at those coordinates.

No Duplicates Script

Description

Ensures a sequence (list or array) contains no duplicate elements by comparing each element to the previous ones.

Features

  • Takes a sequence of elements as input.
  • Removes any duplicate elements from the sequence.
  • Maintains the order of unique elements.

Highest and Lowest Numbers

Description

The high_and_low function takes a string of numbers separated by spaces and returns the highest and lowest numbers in the sequence.

Features

  • Input: Accepts a string of numbers separated by spaces.
  • Output: Returns a string containing the highest and lowest numbers separated by a space.
  • Error Handling: Assumes valid input format (numbers separated by spaces).
  • Efficiency: Utilises Python's built-in min() and max() functions for optimal performance.
  • String Formatting: Uses Python's f-string for clear and concise output formatting.

Hashtag Generator

Description

Generates a hashtag from a given string.

Features

  • Removes spaces from the input string.
  • Capitalises the first letter of each word.
  • Ensures non-empty input for hashtag generation.

Index Position

Description

Converts each alphabetic letter in the input text to its corresponding position in the alphabet.

Features

  • Iterates over each character in the string.
  • Checks if the character is an alphabetic letter.
  • Converts each alphabetic letter to lowercase.
  • Computes the position using the ASCII value.
  • Returns the list of alphabetic positions.

Space Identifier

Description

The solution function in Python converts a camelCase formatted string into a spaced format where each uppercase letter (except the first) is preceded by a space.

Usage

Call solution(s) where s is the camelCase string you want to convert. It returns the converted string.

Example


  print(solution("camelCasing"))  # Output: "camel Casing"
  

This function is useful for formatting camelCase strings into a more readable format, often used in display or user interface contexts where separation between words is needed.


The perfect square

Description

The find_next_square function calculates and returns the next perfect square greater than a given number sq or returns -1 if sq is not a perfect square.

Features

  • Identifies the next perfect square greater than a given number.
  • Returns -1 if the input number is not a perfect square.

Example usage:


  print(find_next_square(1234))  # Output: 1296 (36^2)
  

This function is handy for scenarios where determining the next perfect square number is required, such as in mathematical computations or algorithms.


Tail Swap

Description

This is a Python function that swaps the parts of two input strings after the colon (:). The function takes a list of two strings as input and returns a list of two strings with the parts after the colon swapped.

Features

  • Efficiently swaps the parts after the colon in two strings.
  • Utilizes list comprehensions for concise and readable code.
  • Demonstrates the use of list indexing and string manipulation in Python.

Example

Given the input ["abc:123", "cde:456"], the function will return ["abc:456", "cde:123"].


RGB to HEX Color Converter

Description

This project provides a simple Python function to convert RGB color values to their hexadecimal (HEX) representation. The function ensures the RGB values are within the valid range (0-255) and accurately converts them to a two-digit hexadecimal format for each color component.

Features

  • Converts individual RGB values to a two-digit hexadecimal string.
  • Ensures RGB values are clamped within the 0-255 range.
  • Combines the hexadecimal values of Red, Green, and Blue components into a single HEX color code.
  • Easy to integrate and use in other Python projects.

Example Usage

<p>Below are examples demonstrating the usage of the RGB to HEX color converter function:</p>

<h3>Example 1: Convert RGB (255, 255, 255) to HEX</h3>
<pre><code>    

def rgb(r, g, b): def to_hex(value): # Ensure the value is within the range 0-255 value = max(0, min(value, 255)) # Convert the integer part to a hexadecimal string digit1 = value // 16 # Convert the remainder to a hexadecimal string digit2 = value % 16 # Convert both to hexadecimal characters and combine them return f'{digit1:X}{digit2:X}'

# Combine all three parts
return to_hex(r) + to_hex(g) + to_hex(b)

Example 1

hex_value = rgb(255, 255, 255) console.log(RGB (255, 255, 255) converts to HEX: ${hex_value}); // Output: FFFFFF

<h3>Example 2: Convert RGB (0, 128, 192) to HEX</h3>
<pre><code>    

// Example 2 hex_value = rgb(0, 128, 192) console.log(RGB (0, 128, 192) converts to HEX: ${hex_value}); // Output: 0080C0

About

This repository is a dynamic collection that grows as I learn, test, and update my programming skills. It includes tasks from platforms like CodeWars, where developers enhance their coding abilities through gamified challenges, as well as various simple projects I’ve created.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages