Skip to content

Instantly share code, notes, and snippets.

@programaths
programaths / array-rotate-rl.php
Created September 22, 2017 17:13
Rotate an array left and right
<?php
function matMul( $a, $b ) {
$countI = count( $a );
$countJ = count( $b[0] );
$countK = count( $b );
$c = [];
for ( $i = 0; $i < $countI; $i ++ ) {
for ( $j = 0; $j < $countJ; $j ++ ) {
$sum = 0;
for ( $k = 0; $k < $countK; $k ++ ) {
@programaths
programaths / rotateArrayLinearAlgebra.php
Created September 22, 2017 07:27
rotate Array Linear Algebra
<?php
function matMul($a,$b){
$countI = count($a);
$countJ = count($b[0]);
$countK = count($b);
$c=[];
for($i=0;$i<$countI;$i++){
for($j=0;$j<$countJ;$j++){
$sum = 0;
@programaths
programaths / Wims-Mat-Puzzle.kt
Created August 14, 2017 17:04
Solving the Wims Mat Puzzle
package com.wimpuzzle
import java.util.*
fun main(args: Array<String>) {
val solver = Solver()
solver.solve()
}
class Piece(val positions: Array<Array<Array<Int>>>,val id:Int,var orientation: Int=0){
@programaths
programaths / text-adventure.kt
Created May 31, 2017 19:39
An example of text adventure in Kotlin
/*
* This file implement a very simple text game engine and a DSL.
*/
fun main(args: Array<String>) {
val game=Branch("You awake in a dark forest. Where do you want to go ?"){
WalkNorth() leadsTo TerminalBranch("You went too far in the dark and have been killed by a somber creature")
WalkSouth() leadsTo TerminalBranch("You just fel from a cliff. Dumb move !")
WalkEast() leadsTo Branch("""In front of you is a yellowish box.
It really stand out from the night."""){
OpenAction() leadsTo TerminalBranch("A snake pop out of the box and bite you. You die of a painful poisoning!")
@programaths
programaths / deobfuscate.go
Created March 16, 2017 20:32
Generate deobfusacting golang
package main
import (
"fmt"
"math/rand"
)
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i
@programaths
programaths / KTGW_VTX.kt
Created March 2, 2017 21:03
This code show a complex stuff done in few lines and 60ms max out of which 20ms come from the origin having hard time serving an HTML file...
import io.netty.buffer.ByteBufInputStream
import io.vertx.core.Vertx
import io.vertx.ext.web.client.WebClient
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
fun main(args: Array<String>) {
val vertx = Vertx.vertx()
val server = vertx.createHttpServer()
val client = WebClient.create(vertx)
@programaths
programaths / LineCount.kt
Created September 15, 2016 19:21
A functional line count.
import java.io.File
fun main(args: Array<String>) {
args.map { name -> File(name) }
.filter { file -> file.isFile }
.map { file -> Pair(file.name, file.readLines().partition { line -> line.trim().isEmpty() }) }
.forEach {
val name = it.first
val (filledLines,emptyLines) = it.second
println("$name: ${filledLines.size+emptyLines.size} total, ${emptyLines.size} empty")
package main
import (
"fmt"
"math/rand"
"math"
"time"
)
-- V1
[ if x `mod` 3 == 0 then
"Fizz"
else
if x `mod` 5 == 0 then
"Buzz"
else
if x `mod` 15 == 0 then
"FizzBuzz"
else show x
@programaths
programaths / GameService.kt
Created April 15, 2016 12:02
Example of formatting
gameService.gamelistArray()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
gameList ->
adapter=GameListAdapter(gameList.toList().map { it.second },ctx)
}