Skip to content

Instantly share code, notes, and snippets.

@je6bmq
je6bmq / gcd_in_polynomial.rs
Created December 4, 2018 06:24
for TUT AdC 2018
use std::cmp::Ordering;
use std::fmt;
use std::ops::{Add, Div, Mul, Rem, Sub};
#[derive(Debug, Clone, PartialEq)]
struct Polynomial {
coefficients: Vec<f32>, // ascend order.
}
trait Zero {
fn get_zero() -> Self;
@je6bmq
je6bmq / toyogy_vol8_rust_example.rs
Created July 27, 2018 16:16
とよぎぃ通信 vol.8 に登場するRustコード例
fn main() {
// Variable binding
let a = 1; // immutable
let mut b = 1; //mutable
assert_eq!(b, 1);
// a = 2; // compile error
b = 2;
let c: i32 = 1; // i32 is 32 bit signed integer
assert_eq!(a, c); // a == c
assert_eq!(b, 2); // b == 2
@je6bmq
je6bmq / gumimaze_mission_3.exs
Last active June 16, 2018 10:00
Erlang & Elixir Fest 2018 gumi quiz mission 3
defmodule Gumimaze do
def read() do
lines = "maze.txt" |> File.read!() |> String.trim() |> String.split("\n")
for {line, y} <- Enum.with_index(lines), {c, x} <- Enum.with_index(String.to_charlist(line)), into: %{} do
{{x, y}, c}
end
end
def solve3(maze) do
{x, y} = elem(Enum.find(maze, fn {_, v} -> v == ?S end), 0)
@je6bmq
je6bmq / gumimaze_mission_2.exs
Created June 16, 2018 09:55
Erlang & Elixir Fest 2018 gumi quiz mission 2
defmodule Gumimaze do
def read() do
lines = "maze.txt" |> File.read!() |> String.trim() |> String.split("\n")
for {line, y} <- Enum.with_index(lines), {c, x} <- Enum.with_index(String.to_charlist(line)), into: %{} do
{{x, y}, c}
end
end
def solve2(maze) do
tailrec fun PPAP( pcount:Int=0, isA:Boolean=false)
{
val rnd=Random()
val c=if (rnd.nextBoolean()) "P" else "A"
print(c)
when(c)
{
"P" -> when{
isA && pcount>=2->println("")
else ->PPAP(pcount+1,false)