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 Rational(n: Int, d: Int) { | |
require(d != 0) | |
private val g = gcd(n.abs, d.abs) | |
val numer = n / g | |
val denom = d / g | |
def this(n: Int) = this(n, 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
def concat(heads: List[Char], tails: List[String]): List[String] = { | |
for { | |
h <- heads | |
t <- tails | |
} yield h.toString + t | |
} | |
def replace(str: String, replacement_rules: Map[Char, List[Char]], max_replacements: Int): List[String] = { | |
def replaceStep(str: String, replacements_count: Int): List[String] = { | |
if (replacements_count == 0) List(str) |
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 Nat { | |
def isZero: Boolean | |
def predecessor: Nat | |
def successor: Nat | |
def +(that: Nat): Nat | |
def -(that: Nat): Nat | |
} | |
object Zero extends Nat { | |
def isZero: Boolean = true |
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 funsets | |
/** | |
* 2. Purely Functional Sets. | |
*/ | |
object FunSets { | |
/** | |
* We represent a set by its characteristic function, i.e. | |
* its `contains` predicate. |
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
from typing import List | |
def count_change(money: int, coins: List[int]): | |
if money == 0: | |
return 1 | |
# Amount > 0 | |
if len(coins) == 0: | |
return 0 | |
# Amount > 0, 1+ coins | |
coin = coins[0] |
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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"s3:GetBucketLocation", | |
"s3:ListAllMyBuckets" | |
], | |
"Resource": "arn:aws:s3:::*" |
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
# Install Nextcloud stack | |
sudo snap install nextcloud | |
# Create administrator account | |
sudo nextcloud.manual-install <admin_username> <admin_password> | |
# Configure trusted domains (only localhost by default) | |
sudo nextcloud.occ config:system:get trusted_domains | |
sudo nextcloud.occ config:system:set trusted_domains 1 --value=<dns-domain> | |
# Set 512M as PHP memory limit | |
sudo snap get nextcloud php.memory-limit # Should be 512M | |
sudo snap set nextcloud php.memory-limit=512M |