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
type result('a) = | |
| Success('a) | |
| Failure(string); | |
/* Encapsulate a parsing function in a type */ | |
type parser('a) = | |
| Parser(string => result(('a, string))); | |
let reduce = (fn, list) => | |
switch list { |
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
proc nbYear*(p0: int, percent: float64, aug: int, p: int): int = | |
var count = 0 | |
var pop = p0 | |
while pop != p: | |
count = count + 1 | |
pop = pop + p0 * (percent / 100.float).int + aug | |
return count | |
echo(nbYear(1000, 5, 50, 2000)) |
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
const | |
alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " | |
proc base62(input: int): string = | |
result = "" | |
var q = input | |
while q != 0: | |
var i = q mod 62 | |
q = q div 62 | |
result = result & alphabet[i] |
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
import base64, strutils | |
let | |
input = """49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d""" | |
expected = "SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t" | |
assert expected == encode(parseHexStr(strIn)) |
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
def rollDice(n: String): String = { | |
val input = n.split("d") | |
val numberOfRolls = input(0).toInt | |
val numberOfSides = input(1).toInt | |
var r = scala.util.Random | |
var rolls = scala.collection.mutable.ArrayBuffer[Int]() | |
var result = 0 | |
for (n <- (1 to numberOfRolls)) { | |
val currentRoll = r.nextInt(numberOfSides + 1) | |
rolls += currentRoll |
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
import strutils | |
import math | |
const | |
input = "95 17".split(" ") | |
n = input[0].parseInt | |
m = input[1].parseInt | |
proc mortalRabbits(n: int, m: int): uint64 = |
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
# taken from: https://github.com/pragmagic/godot-nim/issues/17#issuecomment-399192271 | |
import godot, node, input | |
gdobj MyNode of Node: | |
method init*() = | |
addUserSignal("my_signal") # Declare on init. If need to connect this signal to other nodes, should be done in code | |
method ready*() = | |
connect("my_signal", self, "_on_my_signal_emitted") |
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
class Director(val firstName: String, val lastName: String, val yearOfBirth: Int) { | |
def name(): String = firstName + " " + lastName | |
} | |
class Film(val name: String, val yearOfRelease: Int, val imdbRating: Double, val director: Director) { | |
def directorsAge(): Int = this.yearOfRelease - director.yearOfBirth | |
def isDirectedBy(d: Director) = if (d.name == this.director.name) true else false | |
def copy(name: String = this.name, yearOfRelease: Int = this.yearOfRelease, imdbRating: Double = this.imdbRating, director: Director = this.director): Film = { | |
new Film(name, yearOfRelease, imdbRating, director) | |
} |
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
object Translator { | |
def translate(rna: String) = { | |
val splittedRna = rna.grouped(3).toList | |
println(splittedRna) | |
for (codon <- splittedRna) { | |
codon match { | |
case "AUG" => print("M") | |
case "GCC" | "GCG" | "GCU" | "GCA" => print("A") |
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
object MotifFinder { | |
def find(text: String, motif: String) = { | |
var result = Seq[Int]() | |
for (i <- 0 until text.length - motif.length) { | |
var aheadSS = text.slice(i, i + motif.length) | |
if (aheadSS == motif) { | |
result = result :+ (i + 1) | |
} | |
} |
OlderNewer