Skip to content

Instantly share code, notes, and snippets.

View newton-migosi's full-sized avatar

Newton Migosi newton-migosi

View GitHub Profile
@newton-migosi
newton-migosi / scan2darray
Created March 8, 2018 11:49
My solution to the picobot problem at https://www.cs.hmc.edu/picobot/
# State zero, move north if nothing to north else move west
0 x*** -> N 0
0 N*** -> X 1
# Move west state
# If nothing to the west move West
# If end of row move south then east
# If at top left corner move East
# If at bottom left corner do nothing
1 **x* -> W 1
@newton-migosi
newton-migosi / caesar_cypher.rs
Created April 7, 2018 12:28
Learning rust using caesar cypher
fn encrypt_decrypt(plaintext: &str, key: usize) -> String{
let alphabet = "ABCDFGHIJKLMNOPQRSTUVWXYZ";
let plaintext = &plaintext.to_uppercase();
let mut ciphertext = String::from("");
//println!("{}", plaintext);
//MORINGA
for each_char in plaintext.chars(){
//println!("char {}", each_char);
@newton-migosi
newton-migosi / api_call.rs
Created April 8, 2018 09:17
Rust API call on Africa's Talking
extern crate reqwest;
#[macro_use]
extern crate hyper;
use hyper::header::{Accept, Headers};
header! {(Apikey, "apikey") => [String]}
fn send_request(url: &str, apikey: String) -> Result<reqwest::Response, reqwest::Error> {
let mut headers = Headers::new();
@newton-migosi
newton-migosi / red_image.rs
Created April 8, 2018 17:31
Generating a red image using Rust. Simple demo of Rust program flow.
extern crate image;
use std::fs::File;
use std::path::Path;
fn main(){
let image_size = 300;
let mut image_buf = image::ImageBuffer::new(image_size, image_size);
let red = [255, 0, 0];
@newton-migosi
newton-migosi / fibo.rs
Created April 10, 2018 10:13
Rust CLI app for getting nth fibonacci number.
use std::io;
fn main() {
//nth fibonacci number generator
loop{
println!("Enter position of fibonacci you want.");
let mut pos = String::from("");
io::stdin().read_line(&mut pos)
.expect("Could not read input.");
@newton-migosi
newton-migosi / degree_converter.rs
Created April 10, 2018 10:15
Converting between Fahrenheit and Celsius using Rust
use std::io;
fn main() {
println!("Hello there user,");
loop{
println!("Which units will you be converting from F or C? (type q to quit):");
let mut unit = String::new();
io::stdin().read_line(&mut unit)
.expect("Could not read input.");
@newton-migosi
newton-migosi / LSystems.py
Last active July 20, 2018 11:57
Python script for visualizing L Systems using turtle. Run it online: https://trinket.io/python/a050d41536
import turtle
def main(lString):
wn = turtle.Screen()
kurt = turtle.Turtle()
scheme = makeLSystem(lString)
drawLSystem(kurt, scheme)
def makeLSystem(lString, times=5):
@newton-migosi
newton-migosi / labdata.txt
Last active July 20, 2018 11:38
Plotting scatter plot and line of best fit using python (turtle and math modules). Run the code online: https://trinket.io/python/d43cc2dddf
44 71
79 37
78 24
41 76
19 12
19 32
28 36
22 58
89 92
91 6
@newton-migosi
newton-migosi / sudoku.py
Created May 18, 2018 22:29
trying out sudoku
import sys
import random
def main():
generate_sudoku()
initial_state = load_sudoku()
sudoku = Sudoku(initial_state)
print(sudoku)
def generate_sudoku():
[[1,2,3],[4,5,6],[7,8,9]].map(row=> row.map((el, i) => i < 2 ? el - 1 : el))