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 / addition_loop.hs
Last active December 1, 2020 15:43
Inner loop for finding all the ways to add up to a number
loop counter runningTotal accumulator = do
current <- pool
case accumulator of
[] -> guard True
(previous:_) -> guard (current < previous)
guard (current + runningTotal <= target)
loop (counter-1) (runningTotal+current) (current:accumulator)

Toy Robot Simulator

Description:

The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units. There are no other obstructions on the table surface. The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed.

Create an application that can read in commands of the following form –

new Grid({rows: 3, columns: 3})
.selectAll()
.fill(cell => Grid.flatIndex(cell, 3) + 1)
.selectAll(cell => cell.col < 2)
.mutate(val => val -1)
.apply()
[[1,2,3],[4,5,6],[7,8,9]].map(row=> row.map((el, i) => i < 2 ? el - 1 : el))
@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():
@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 / 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 / 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 / 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 / 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];