This file contains hidden or 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::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; |
This file contains hidden or 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 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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |