Skip to content

Instantly share code, notes, and snippets.

View go-cristian's full-sized avatar
💭
Never stop learning!

Cristian Gómez go-cristian

💭
Never stop learning!
View GitHub Profile
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class FisrtThenLastOrder {
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();
import android.app.Activity
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.Intent.EXTRA_SUBJECT
import android.content.Intent.EXTRA_TEXT
import android.net.Uri
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KClass
@go-cristian
go-cristian / game.kt
Last active August 7, 2017 12:31
Code based on Matthias Käppler's post about Monoids and Sum Types, check https://medium.com/@mttkay/refactoring-with-monoids-and-sum-types-part-1-bddc9ea61f5f for the complete explanation of this code. Thanks to @mttkay for the excellent blogpost!
import java.util.Arrays
val inventory = Array<Elem>(size = 3) { Empty }
fun main(args: Array<String>) {
val sword1 = Sword("Sword 1")
val sword2 = Sword("Sword 2")
val pickaxe = Pickaxe("Pickaxe 1")
val item1 = Item(sword1)
val item2 = Item(sword2)
@go-cristian
go-cristian / game.kt
Created August 7, 2017 12:29
Code based on Mathias's post about Monoids and Sum Types
import java.util.Arrays
val inventory = Array<Elem>(size = 3) { Empty }
fun main(args: Array<String>) {
val sword1 = Sword("Sword 1")
val sword2 = Sword("Sword 2")
val pickaxe = Pickaxe("Pickaxe 1")
val item1 = Item(sword1)
val item2 = Item(sword2)
ReactorApi{
@Get fun visits(): Chainable<VisitsResult>
}
BillingApi{
@Post fun billing(): Chainable<BillingResult>
}
/*
Tablero de control
Nivel 1
Profesor Sesion 1 Sesion 2 Sesion 3 Sesion 4
Pepito _ _ _ _ _ _ _ _ _ _ _
Menganita _ _ _ _ _ _ _ _ _ _ _
Sultaneira _ _ _ _ _ _ _ _ _ _ _
Nivel 2
func partition<T: Comparable>(inout array: [T], first: Int, last: Int) -> Int {
let pivot = first
let pivotVal = array[pivot]
(array[first], array[pivot]) = (array[pivot], array[first])
var i = first + 1
var j = first + 1
while j < last {
if array[j] < pivotVal {
(array[i], array[j]) = (array[j], array[i])
i += 1
import Foundation
/**
Counts the number of inversions on the given array.
- Returns: the number of the inversions.
*/
func countInversions(arr:[Int]) -> Int {
guard arr.count > 1 else {return 0}
let middle: Int = Int(ceil(Double(arr.count/2)))
let left: [Int] = Array(arr[0..<arr.count/2])
@go-cristian
go-cristian / MergeSort.swift
Last active August 18, 2016 11:48
Merge sort implementation on Swift
import Foundation
/**
Sorts an array using the merge arrangement, which relays in order the left & right half arrays in a major set of elements. giving a complexity of O(n log n).
- Returns: An ordered array.
*/
func mergeSort(arr:[Int]) -> [Int] {
guard arr.count > 1 else {return arr}
let middle: Int = Int(ceil(Double(arr.count/2)))
let left: [Int] = mergeSort(Array(arr[0..<arr.count/2]))