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
;; compiled from Rust function: | |
;; fn defrag_disk(sectors: &mut [Option<u32>]) -> Option<()> { | |
;; let mut sectors = sectors; | |
;; loop { | |
;; // Find the first Empty sector | |
;; let left_idx = sectors.iter().position(|s| s.is_none())?; | |
;; let left_bound = left_idx + 1; | |
;; // Find the last Full sector after the left_idx | |
;; let right_idx = sectors[left_bound..].iter().rposition(|s| s.is_some())? + left_bound; |
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
fn defrag_disk(sectors: &mut [Option<u32>]) -> Option<()> { | |
let mut sectors = sectors; | |
loop { | |
// Find the first Empty sector | |
let left_idx = sectors.iter().position(|s| s.is_none())?; | |
// Find the last Full sector after the left_idx | |
let right_idx = sectors[left_idx + 1..].iter().rposition(|s| s.is_some())? + left_idx + 1; | |
// Swap the Empty and Full sectors |
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
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br" } | |
import pf.Stdout | |
import pf.Stderr | |
appendN = \list, a, num -> | |
if num == 0 then | |
list | |
else | |
appendN (List.append list a) a (num - 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
Expr : [ | |
Func Str Expr, | |
Call Expr Expr, | |
Symbol Str, | |
Add Expr Expr, | |
Const I32, | |
] | |
eval: Expr, Dict Str Expr -> Result Expr [ExpectedFunction, SymbolNotFound Str, ExpectedI32] | |
eval = \ast, scope -> |
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
digitToInt = | |
\char -> Num.intCast (char - '0') | |
appendNTimes = | |
\list, v, n -> | |
if n == 0 then | |
list | |
else | |
appendNTimes (List.append list v) v (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
module Advent2024.Problem7 | |
let file = """ | |
190: 10 19 | |
3267: 81 40 27 | |
83: 17 5 | |
156: 15 6 | |
7290: 6 8 6 15 | |
161011: 16 10 13 | |
192: 17 8 14 |
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
/* | |
Bar Problem | |
N friends are playing a game. Each of them has a list of numbers in front of himself. | |
Each of N friends chooses a number from his list and reports it to the game administrator. Then the game administrator sorts the reported numbers and shouts the K-th largest number. | |
You want to know the count all possible numbers that the game administrator can shout. |
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
https://github.com/Netflix/falcor-path-utils/blob/master/lib/toTree.js | |
[ | |
["list",{from:0,to:9],["name","rating"]], | |
["list", "length"] | |
] | |
-> | |
{ |
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
module Main where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Data.Foldable (fold) | |
import TryPureScript (DOM, h1, h2, p, text, list, indent, link, render, code) | |
type Video = { name:: String } |
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 cyclops.control.Unrestricted; | |
import io.reactivex.Observable; | |
public class ObservableInterpreter { | |
public static <R> Observable<R> interpret(Unrestricted<R> program){ | |
//walk the Free data structure and handle each command, |
NewerOlder