Skip to content

Instantly share code, notes, and snippets.

View coderodde's full-sized avatar

Rodion Efremov coderodde

View GitHub Profile
@coderodde
coderodde / main.c
Created October 2, 2017 05:51
Demo driver for linked list C code question
#include "singly_linked_list.h"
#include <stdio.h>
#include <string.h>
int main() {
int i;
singly_linked_list_t* list = singly_linked_list_alloc();
singly_linked_list_iterator_t* iterator;
for (i = 1; i < 6; ++i)
@coderodde
coderodde / Pathfinders.js
Last active September 13, 2017 20:15
Pathfinders.js
/////////////
// HashMap //
/////////////
function HashMapNode(key, value) {
this.key = key;
this.value = value;
this.prev = null;
this.next = null;
}
from time import time
def SieveofEratosthenes(primeseries):
i=1
primeserieslist = []
while(i<primeseries):
i=i+1
primeserieslist.append(i)
@coderodde
coderodde / InShuffleAlgorithm.java
Last active August 25, 2017 19:30
In-Shuffle algorithm in Java
package net.coderodde.util;
import java.util.Arrays;
import java.util.Objects;
/**
* This class implements a linear-time, in-place in-shuffle algorithm.
*
* @author Rodion "rodde" Efremov
* @version 1.6 (Aug 25, 2017).
package square;
import java.awt.*;
public class Paddle {
public static final int RECT_WIDTH = 200;
public static final int RECT_HEIGHT = 100;
private int x = (Shapes.WIN_WIDTH - RECT_WIDTH) / 2;
private int y = (Shapes.WIN_HEIGHT - RECT_HEIGHT) / 2;
@coderodde
coderodde / dt.bat
Last active August 19, 2017 15:17
Directory tagging tool for Windows
@echo off
del "C:\Users\Rodion Efremov\.dt\cd.bat"
if [%1] == [] (
dt_engine.exe > "C:\Users\Rodion Efremov\.dt\cd.bat"
) else (
dt_engine.exe %1 > "C:\Users\Rodion Efremov\.dt\cd.bat"
)
if %ERRORLEVEL% NEQ 0 (
G16 = {'a':[('b',3),('c',2)], 'b':[('c',-2)], 'c':[('d',1)], 'd':[]}
# the graph is a dictionary with they "key" as nodes and the "value" as a
# list of tuples
# each of those tuples represent an edge from the key vertex to the first
# element of the tuple
# the second element of the tuple is the weight of that edge.
# so, 'a':[('b',3),('c',2)] means an edge from a to b with weight 3
# and another edge from a to c with weight 2.
class minq: #min_queue implementation to pop the vertex with the minimum distance
@coderodde
coderodde / a_star.hpp
Last active July 30, 2017 14:36
Practicing modern C++
#ifndef NET_CODERODDE_PATHFINDING_A_STAR_HPP
#define NET_CODERODDE_PATHFINDING_A_STAR_HPP
#include "child_node_iterator.hpp"
#include "heuristic_function.hpp"
#include "path_not_found_exception.hpp"
#include "weighted_path.hpp"
#include "weight_function.hpp"
#include <iostream>
#include <queue>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
typedef std::vector<std::list<int>> AdjacencyList;
typedef std::unordered_map<int, std::unordered_map<int, size_t>> Weights;
std::pair<std::vector<int>, std::vector<size_t>> dijkstra(AdjacencyList &adj, Weights weights, int src) {
from random import randint
from time import time
def insertionSort(lst):
for i in range(1, len(lst)):
if lst[i] < lst[i-1]:
for j in range(i):
if lst[i] < lst[j]:
lst[i], lst[j] = lst[j], lst[i]