Skip to content

Instantly share code, notes, and snippets.

View muromtsev's full-sized avatar
Hi

Ilya muromtsev

Hi
  • Russia Volgograd
View GitHub Profile
@muromtsev
muromtsev / TwoSum.java
Created September 23, 2024 21:36
Дан отсортированный массив, необходимо вернуть два индекса тех чисел из массива, которые в сумме будут давать target
public class TwoSum {
public static void main(String[] args) {
int[] array = { -9, -6, 0, 1, 2, 7, 11, 15, 20, 35, 47};
System.out.println(Arrays.toString(twoSum(array, 100)));
}
public static int[] twoSum(int[] arr, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
if (map.containsKey(target - arr[i])) {
@muromtsev
muromtsev / calculator.cpp
Created March 3, 2024 08:53
Calculator (Pointers to functions)
#include <iostream>
int add(int x, int y){ return x + y; }
int multiply(int x, int y){ return x * y; }
int subtract(int x, int y){ return x - y; }
int divide(int x, int y){ return x / y; }
typedef int (*arithmeticFcn)(int, int);
struct arithmeticStruct
@muromtsev
muromtsev / blackJack.cpp
Last active March 3, 2024 08:53
BlackJack
#include <iostream>
#include <array>
#include <cstring>
#include <cstdlib>
#include <ctime>
// перечисление для достоинств карт
enum CardRank
{
@muromtsev
muromtsev / sortingStudentsByGrades.cpp
Created March 1, 2024 17:13
Sorting students by grades
#include <iostream>
#include <string>
struct Students
{
std::string name;
int grade;
};
void sortNames(Students *students, int length)
1.
https://github.com/alexey-goloburdin/typed-python-book
@muromtsev
muromtsev / binary_search.py
Created October 12, 2023 17:52
binary_search
def binary_search(lst, item):
low = 0
high = len(lst) - 1
while low <= high:
mid = (low + high) // 2
guess = lst[mid]
if guess == item:
return mid
if guess > item:
@muromtsev
muromtsev / quick_sort.py
Last active October 12, 2023 17:52
Quick sort
def quicksort(arr):
if len(arr) < 2:
return arr
else:
pivot = arr[0]
less = [i for i in arr[1:] if i < pivot]
greater = [i for i in arr[1:] if i > pivot]
return quicksort(less) + [pivot] + quicksort(greater)
@muromtsev
muromtsev / selection_sort.py
Created October 11, 2023 18:33
Selection sort
def findSmallest(arr):
smallest = arr[0]
smallest_idx = 0
for i in range(1, len(arr)):
if arr[i] < smallest:
smallest = arr[i]
smallest_idx = i
return smallest_idx