This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package forcomp | |
object Anagrams { | |
/** A word is simply a `String`. */ | |
type Word = String | |
/** A sentence is a `List` of words. */ | |
type Sentence = List[Word] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 // |