Skip to content

Instantly share code, notes, and snippets.

View ibarland's full-sized avatar

Ian Barland ibarland

  • Radford University
  • Blacksburg, VA, USA
View GitHub Profile
@ibarland
ibarland / AddNotAssoc.java
Created October 9, 2022 17:37
Q: What % of randomly-chosen doubles in [0,1) aren't associative (x+y+z != z+x+y e.g.). A: About 15%.
import java.util.*;
class AddNotAssoc {
public static void main( String... args ) {
int N = 1000;
int errs=0;
Random rng = new Random(0);
double x,y,z;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ibarland
ibarland / tm-dup.yaml
Last active November 4, 2020 12:08
A TM to duplicate a string
name: divisible by 3
source code: |-
# A TM to duplicate a string.
# (That is, compute f(w) = ww.)
#
# @author: ibarland@radford.edu
# run this at: https://turingmachine.io/?import-gist=7732e683354339c9993fb0fe5390af90
# assignment: https://www.radford.edu/itec420/2020fall-ibarland/Homeworks/hw06.html
#
input: 'abbab'
name: palindrome
source code: |
# https://turingmachine.io/ can run this TM format.
# Starting with a^m b^n where m>n, compute a^m b^m
# (that is: add b's at the end, to end up with equal a's,b's.)
# From Rich (Ch17a slides, slide 13)
#
input: '_aaaabb'
blank: '_' # or try: '␣' '❏'
start state: 1
@ibarland
ibarland / .emacs
Last active July 24, 2022 03:02
copy/paste for evil (emacs/vim) users
; Improve how OS's "copy" interacts with evil mode.
; We want yank'd/kill'd text to be added to the system clipboard, w/o explicit visual text-selection (via mouse-drag, say).
;
; The problem:
; While 'select-enable-clipboard' works find for non-evil emacs users,
; it interferes with evil/vim's `evil-change` and relatives:
; E.g. you want to replace a couple words with the clipboard,
; so you try typing "c2w cmd-V" -- BUT the c2w itself changes the clipboard
; (if `select-enable-clipboard` is set), so you end up pasting in exactly the two words
; you wanted to replace.
@ibarland
ibarland / chownR_if.py
Last active May 30, 2019 21:52
chownR_If: For every file+dir rooted at `root`, if the owner of that file/dir is `targetUid`, then change the owner to `replacementUid`.
#! /usr/bin/env python3
import os
def chownIf(path, targetUid, replacementUid ):
"""If the owner of `path` is `targetUid`, then change the owner to `replacementUid`.
(UID's are numeric, not string.)
BUG -- this doesn't work: Also, if a link is owned by root(0), change it to `replacementUid` as well.
"""
ownerUid = os.stat(path).st_uid
@ibarland
ibarland / languages-count-1-10.rkt
Last active August 14, 2018 18:10
The counting numbers 1-10, in various languages.
(define numbers-in-languages '#hash(
; (language . #[ 0 1 2 3 4 5 6 7 8 9 10 ])
(english . #[ zero one two three four five six seven eight nine ten ])
(spanish . #[ cero uno dos tres quatro cinqo seis siete ocho nueve dies ])
(italian . #[ zero uno due tre quattro cinque sei sette otto nove dieci ])
(german . #[ null eins zwei drei vier fuenf sechs sieben acht neun zehn ])
(dutch . #[ nul een twee drie vier vijf zes zeven acht negen tien ])
(croatian . #[ nula jedan dva tri cetiri pet sest sedam osam devet deset ])
(hungarian . #[ nulla egy ketto harom negy ot hat het nyolc kilenc tiz ])
(finnish . #[ nolla yksi kaksi kolme nelja viisi kuusi seitseman kahdeksan yhdeksan
@ibarland
ibarland / lists-algebraic.py
Last active April 1, 2018 19:56
Python implementation of lists, as approached by bootstrapworld.org / How to Design Programs -- that is as an "algebraic data type".
# Data definition: A list is either
# - [], OR
# put( {someItem}, {someList} ) (that is: one item "put" onto the front of some existing (slightly shorter) list)
#### helper functions for lists (which we represent internally as the python-builtin-list-type, unsurprisingly).
# put: T, list<T> → list<T> (constructor)
# Construct a new list, by adding one item to the front of an existing list
assert Arrays.deepEquals(
rotateMatrix( new String[][]{ {" ", "X", " "}
{" ", "X", "X"},
{" ", " ", " "} } ),
new String[][]{ {" ", " ", " "}
{" ", "X", "X"},
{" ", "X", " "} } )