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
use std::collections::VecDeque; | |
use std::env; | |
use std::fmt::{Display, Formatter}; | |
use std::ops::{Index, IndexMut}; | |
use rand::RngCore; | |
use crate::Dir::*; | |
fn main() { | |
let args: Vec<_> = env::args().collect(); | |
let dimension = if args.len() < 2 { |
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
use std::env; | |
use std::fmt::{Display, Formatter}; | |
use std::ops::{Index, IndexMut}; | |
use rand::RngCore; // cargo add rand | |
use crate::Dir::*; | |
fn main() { | |
let args: Vec<_> = env::args().collect(); | |
let dimension = if args.len() < 2 { | |
println!("No dimension, defaulting to 20"); |
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
-- Summing the sequence 1..n in as many ways as I can think of! | |
-- With the closed form | |
function sum(n) | |
return ((n+1) * n) / 2 | |
end | |
print(sum(6)) -- Had better be 21 | |
-- With tail recursion |
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
function load_dictionary(filename) | |
local dictionary = {} | |
for line in io.lines(filename) do | |
if line:match("^%l%l+$") then | |
insert(dictionary, line .. "$") | |
end | |
end | |
-- We're cutting all single-letter words, but |
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
use std::arch::aarch64::float32x4x4_t; | |
use std::f32::consts::PI; | |
use std::thread::sleep; | |
use std::time::Duration; | |
use pixels::{Pixels, PixelsBuilder}; | |
use pixels::wgpu::TextureFormat; | |
use raqote::{DrawOptions, DrawTarget, Path, PathBuilder, SolidSource, Source}; | |
use winit::dpi::LogicalSize; | |
use winit::event::{Event, WindowEvent}; | |
use winit::event_loop::{ControlFlow, EventLoop}; |
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
use std::f32::consts::PI; | |
use pixels::{Pixels, PixelsBuilder}; | |
use pixels::wgpu::TextureFormat; | |
use raqote::{DrawOptions, DrawTarget, Path, PathBuilder, SolidSource, Source}; | |
use winit::dpi::LogicalSize; | |
use winit::event::{Event, WindowEvent}; | |
use winit::event_loop::{ControlFlow, EventLoop}; | |
use winit::window::WindowBuilder; | |
fn main() -> ! { |
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
#include <lua.h> | |
#include <lauxlib.h> | |
#include <lualib.h> | |
#include <stdlib.h> | |
int map_create(lua_State *lua); | |
int map_slice(lua_State *lua); | |
int main(int argc, char **argv){ | |
lua_State *lua = lua_open(); |
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
---------------------------------------------------------------------------------------------------- | |
--- Making Lua look like Prolog: | |
--- | |
--- Let's use metatables for something other than emulating prototype-based OO. By making the | |
--- __index metamethod create values for undefined things, we can make Lua look like Prolog! | |
--- We create empty tables for anything starting with a capital letter, functions that populate | |
--- those tables for lowercase things (to assign relationships) and if a name begins with "is_" | |
--- then it becomes a function that queries those tables. | |
---------------------------------------------------------------------------------------------------- |
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
-- Pack this into an object file with ld: ld -r -b binary -o hello.o hello.lua | |
print "Hello, World!" |
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
function string.ordinalize(str) | |
local num = tonumber(str) | |
local endings = {"st", "nd", "rd"} | |
if num >= 11 and num <= 13 then | |
return num .. "th" | |
elseif num % 10 > 0 and num % 10 <= #endings then | |
return num .. endings[num % 10] | |
else | |
return num .. "th" | |
end |
NewerOlder