Skip to content

Instantly share code, notes, and snippets.

View Veeyikpong's full-sized avatar
😎
Coding

Veeyik Pong Veeyikpong

😎
Coding
View GitHub Profile
@Veeyikpong
Veeyikpong / sudokusolver.kt
Created December 27, 2022 07:39
Sudoku solver using backtracking
solveSudoku(
arrayOf(
charArrayOf('8', '.', '.', '.', '.', '.', '.', '.', '.'),
charArrayOf('.', '.', '3', '6', '.', '.', '.', '.', '.'),
charArrayOf('.', '7', '.', '.', '9', '.', '2', '.', '.'),
charArrayOf('.', '5', '.', '.', '.', '7', '.', '.', '.'),
charArrayOf('.', '.', '.', '.', '4', '5', '7', '.', '.'),
charArrayOf('.', '.', '.', '1', '.', '.', '.', '3', '.'),
charArrayOf('.', '.', '1', '.', '.', '.', '.', '6', '8'),
charArrayOf('.', '.', '8', '5', '.', '.', '.', '1', '.'),
@Veeyikpong
Veeyikpong / countNumberOfIslands.kt
Created December 22, 2022 08:32
Count number of islands
numIslands(
grid = arrayOf(
charArrayOf('1', '1', '1', '1', '0'),
charArrayOf('1', '1', '0', '1', '0'),
charArrayOf('1', '1', '0', '0', '0'),
charArrayOf('0', '0', '0', '0', '0')
)
)
numIslands(
@Veeyikpong
Veeyikpong / mergesort.kt
Last active December 14, 2022 06:53
Merge sort in Kotlin
sortArray(intArrayOf(5, 2, 3, 1, 5, 6))
fun sortArray(nums: IntArray): IntArray {
mergeSort(nums, 0, nums.size - 1)
return nums
}
fun mergeSort(nums: IntArray, left: Int, right: Int) {
if (right <= left) return
val mid = (left + right) / 2
@Veeyikpong
Veeyikpong / NestedHorizontalRecyclerView.kt
Created July 31, 2019 10:02
A nested horizontal recyclerview to achieves smooth horizontal scrolling. Written in Kotlin.
package com.veeyikpong.utils
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.abs
class NestedHorizontalRecyclerView : RecyclerView {
private val Y_BUFFER = 10
@Veeyikpong
Veeyikpong / MiddleDividerItemDecoration.kt
Last active July 15, 2023 11:54
MiddleDividerItemDecoration, suitable for both LinearLayoutManager and GridLayoutManager.
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software