Skip to content

Instantly share code, notes, and snippets.

View naughty-code's full-sized avatar

Javier Andres Mura Rios naughty-code

View GitHub Profile
@naughty-code
naughty-code / CRCDivision.js
Created March 8, 2017 10:31
CRC division algorithm
//variables
var Trama;//cadena con los datos a enciar que se quiere enviar//
var TramaCodificada;
var TramaCodificadaConRellenoDeBitConBanderas;
var TramaCodificadaConRellenoDeBit;
const generator = "10001000000100001"
//----main()------//
//trama de ejemplo //
@naughty-code
naughty-code / PrototypeExample.js
Created February 5, 2017 21:52
Ejemplo de patrones de diseño
/* funcion constructora */
function Weapon(range, damage) {
this.range = range;
this.damage = damage;
}
var sword = new Weapon(10, 16); //no solo crea un objeto y le agrega los atributos range y damage
//adicionalmente le agrega un atributo llamado Weapon.prototype
//que representa el prototipo de todos los objetos Weapon
/** Returns the list of all subsets of the occurrence list.
* This includes the occurrence itself, i.e. `List(('k', 1), ('o', 1))`
* is a subset of `List(('k', 1), ('o', 1))`.
* It also include the empty subset `List()`.
*
* Example: the subsets of the occurrence list `List(('a', 2), ('b', 2))` are:
*
* List(
* List(),
* List(('a', 1)),
/** Converts the word into its character occurrence list.
*
* Note: the uppercase and lowercase version of the character are treated as the
* same character, and are represented as a lowercase character in the occurrence list.
*
* Note: you must use `groupBy` to implement this method!
*/
def wordOccurrences(w: Word): Occurrences = w.toLowerCase.groupBy(char => char).map{
case (char, repetitions) => (char, repetitions.length)
}.toList.sortBy{ case (char, _) => char}
package forcomp
object Anagrams {
/** A word is simply a `String`. */
type Word = String
/** A sentence is a `List` of words. */
type Sentence = List[Word]
/** Converts the word into its character occurrence list.
*
* Note: the uppercase and lowercase version of the character are treated as the
* same character, and are represented as a lowercase character in the occurrence list.
*
* Note: you must use `groupBy` to implement this method!
*/
def wordOccurrences(w: Word): Occurrences = w.toLowerCase.groupBy(char => char).map{
case (char, repetitions) => (char, repetitions.length)
}.toList.sortBy{ case (char, _) => char}
abstract class CodeTree
case class Fork(left: CodeTree, right: CodeTree, chars: List[Char], weight: Int) extends CodeTree
case class Leaf(char: Char, weight: Int) extends CodeTree
// Part 1: Basics
def weight(tree: CodeTree): Int = tree match {
case Fork(left, right, _, weight) => weight
case Leaf(_, weight) => weight