Skip to content

Instantly share code, notes, and snippets.

View atonamy's full-sized avatar
🏠
Working from home

Atonamy atonamy

🏠
Working from home
  • Singapore
View GitHub Profile
@atonamy
atonamy / LCS.kt
Last active August 5, 2022 14:22
Find the the longest common substrings
/*
Solution to this problem https://www.geeksforgeeks.org/print-longest-common-substring/ extended version
time complexity O(m*n)
*/
data class Str(val string: StringBuilder,
var startPosition: Int,
var nextPosition: Int = startPosition+1,
val id: String = UUID.randomUUID().toString()
)
@atonamy
atonamy / Metaballs.gd
Created June 6, 2021 05:48
2D Metaballs implementation in Godot
#based on this article http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/
extends Node2D
class Blob:
var pos_x
var pos_y
var radius
var velocity
@atonamy
atonamy / CaesarCipher.kt
Created April 16, 2020 06:11
Technical test for Igloohome
fun CaesarCipher(str: String, num: Int): String {
val result = StringBuilder()
for(i in str.indices) {
if(str[i].toLowerCase() in 'a'..'z') {
val a = 'a'.toLong()
val A = 'A'.toLong()
val shift = (str[i] + num).toLong()
val letterLower = shift - a
val letterUpper = shift - A
val lower = ('z' + 1).toLong() - a
@atonamy
atonamy / Java REST GET Simple.java
Last active March 16, 2023 09:54
[Coderbyte] Technical test for NTUC Singapore (Android Engineer)
/*
Java REST GET Simple
In the Java file, write a program to perform a GET request on the route:
https://coderbyte.com/api/challenges/json/rest-get-simple
and then print to the console the hobbies property in the following format:
ITEM1, ITEM2, ...
@atonamy
atonamy / SeatingStudents.kt
Last active October 1, 2022 11:05
[Coderbyte] Technical test for NTUC Singapore (Android Engineer)
/*
Challenge
Have the function SeatingStudents(arr) read the array of integers stored in arr which will be in the
following format: [K, r1, r2, r3, ...] where K represents the number of desks in a classroom,
and the rest of the integers in the array will be in sorted order and will represent the desks
that are already occupied. All of the desks will be arranged in 2 columns,
where desk #1 is at the top left, desk #2 is at the top right, desk #3 is below #1, desk #4 is below #2, etc.
Your program should return the number of ways 2 students can be seated next to each other.
This means 1 student is on the left and 1 student on the right, or 1 student is directly above or below the other student.
For example: if arr is [12, 2, 6, 7, 11] then this classrooms looks like the following diagram:
@atonamy
atonamy / BitmapHoles.kt
Last active December 8, 2021 19:06
[Coderbyte] Technical test for NTUC Singapore (Android Engineer)
/*
Using the Kotlin language, have the function BitmapHoles(strArr: Array<String>): String
take the array of strings stored in strArr, which will be a 2D matrix
of 0 and 1's, and determine how many holes, or contiguous regions of 0's,
exist in the matrix. A contiguous region is one where there is a
connected group of 0's going in one or more of four directions: up,
down, left, or right. For example: if strArr is
["10111", "10101", "11101", "11111"], then this looks like the following matrix:
1 0 1 1 1
fun maxDifference(arr: Array<Int>): Int {
var min: Pair<Int, Int> = Pair(0, 0)
var max: Pair<Int, Int> = Pair(0, 0)
var result = -1
for(i in 0 until arr.size) {
when {
i == 0 -> {
min = Pair(i, arr[i])
@atonamy
atonamy / gist:e7fae0f7ad0e80490ebbe9f2cc16cccc
Created May 21, 2019 12:12 — forked from patrickhammond/gist:0b13ec35160af758d98c
Sample for how to use the Google Play Services dynamic security provider to keep the SSL library that the app will use to up date.
package com.mycompany.myapp.app;
import android.app.Application;
import android.content.Intent;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.security.ProviderInstaller;
import com.google.android.gms.security.ProviderInstaller.ProviderInstallListener;
public class MainApplication extends Application {
@atonamy
atonamy / GenomicRangeQuery.kt
Created May 18, 2019 08:12
100% perfomance/correctness solution for GenomicRangeQuery problem https://app.codility.com/programmers/lessons/5-prefix_sums/genomic_range_query
val String.prefixSumOfGenoms: Array<IntArray>
get() {
val genoms = Array(3) {
IntArray(length+1)
}
for(i in 0 until length) {
var (a, c, g) = arrayOf<Short>(0, 0, 0)
when(this[i]) {
'A' -> {a = 1}
import java.io.*
import java.math.*
import java.text.*
import java.util.*
import java.util.regex.*
val mod = 1000000007
fun maxbit(value: Int): Int = if(value <= 1) value else maxbit(value shr 1) shl 1