Skip to content

Instantly share code, notes, and snippets.

View VizGhar's full-sized avatar

Ján Kandráč VizGhar

  • Bratislava, Slovakia
View GitHub Profile
package xyz.kandrac.u
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
@VizGhar
VizGhar / dijkstra.kt
Created October 10, 2022 10:08
Dijkstra implementation in Kotlin language
private const val startPoint = "A"
private const val finalPoint = "G"
data class Vertex(val id: String, val length: Int)
// adjacency list graph
val graph =
mapOf(
"A" to listOf(Vertex("B", 3), Vertex("C", 5)),
"B" to listOf(Vertex("A", 3), Vertex("D", 4), Vertex("E", 2)),
import kotlin.math.pow
import kotlin.random.Random
const val boardSize = 40
const val tries = 100
val random = Random(System.currentTimeMillis())
fun cost(solution: Array<Int>): Int {
var cost = 0
@VizGhar
VizGhar / nqueens_tabusearch.kt
Created June 20, 2022 14:56
N-queens problem solved using TabuSearch Algorithm
import kotlin.math.pow
const val boardSize = 10
fun cost(solution: Array<Int>): Int {
var cost = 0
for (i in 0 until boardSize) {
for (j in (i + 1) until boardSize) {
if (solution[i] == solution[j]) cost++
if (solution[i] == solution[j] + (j - i)) cost++
import java.awt.Color
import java.awt.Dimension
import java.awt.Graphics
import java.io.File
import javax.imageio.ImageIO
import javax.swing.BorderFactory
import javax.swing.JFrame
import javax.swing.JPanel
import kotlin.math.*
@VizGhar
VizGhar / Game.java
Created April 26, 2022 09:16
LibGDX + Box2D colissions + mapping sprite to game
package sk.ssnd;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
@VizGhar
VizGhar / Game.java
Created April 25, 2022 10:17
libGDX - falling square
package sk.ssnd.platformer;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.*;
public class Game extends ApplicationAdapter {
import java.awt.Color
import java.awt.Dimension
import java.awt.Graphics
import java.io.File
import javax.imageio.ImageIO
import javax.swing.BorderFactory
import javax.swing.JFrame
import javax.swing.JPanel
import kotlin.math.*
@VizGhar
VizGhar / ga-sin.kt
Last active March 25, 2022 20:45
Geneticky algoritmus pre vypocet sinusoidy v jazyku C++
import kotlin.math.absoluteValue
import kotlin.math.sin
import kotlin.random.Random
const val chromosomeSize = 100
const val mutationProbability = 0.05 // each block of chromosome mutates with this probability
const val populationSize = 1000 // this many individuals will be in each generation
const val keepNBest = 200 // this many best individuals will be taken without change to next gen
const val tournamentSize = 3 // this many individuals will fight in tournament
@VizGhar
VizGhar / n-queens-problem-genetic_algorithm.kt
Created March 20, 2022 13:31
Solution for 8 (or n) queen problem solved using genetic algorithm
import kotlin.math.absoluteValue
import kotlin.random.Random
const val chromosomeSize = 8
const val mutationProbability = 0.05 // each block of chromosome mutates with this probability
const val populationSize = 1000 // this many individuals will be in each generation
const val keepNBest = 200 // this many best individuals will be taken without change to next gen
const val tournamentSize = 3 // this many individuals will fight in tournament
val random = Random(System.currentTimeMillis())