Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@heuristicfencepost
Created July 10, 2012 06:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heuristicfencepost/3081640 to your computer and use it in GitHub Desktop.
Save heuristicfencepost/3081640 to your computer and use it in GitHub Desktop.
GEB MIU system in various languages
# Simple implementation of the productions for the MIU system
open INFILE,"<",$ARGV[0];
while(<INFILE>) {
chomp;
next if $_ =~ /#.*/;
print "$1IU\n" if $_ =~ /^(.+?)I$/;
print "M$1$1\n" if $_ =~ /^M(.+)$/;
print "$1U$2\n" if $_ =~ /^(.*)III(.*)$/;
print "$1$2\n" if $_ =~ /^(.*)UU(.*)$/;
}
# Simple implementation of the productions for the MIU system
from sys import argv
import re
re_c = re.compile("#.*")
re1 = re.compile("^(.+?)I$")
re2 = re.compile("^M(.+)$")
re3 = re.compile("^(.*)III(.*)$")
re4 = re.compile("^(.*)UU(.*)$")
for line in [line.strip() for line in open(argv[1])]:
if re_c.match(line):
continue
m1 = re1.match(line)
if m1:
print m1.group(1) + "IU"
m2 = re2.match(line)
if m2:
print "M" + m2.group(1) + m2.group(1)
m3 = re3.match(line)
if m3:
print m3.group(1) + "U" + m3.group(2)
m4 = re4.match(line)
if m4:
print m4.group(1) + m4.group(2)
# Simple implementation of the productions for the MIU system
File.new(ARGV[0]).readlines.each do |line |
next if line =~ /#.*/
puts "#{$1}IU\n" if line =~ /^(.+)I$/
puts "M#{$1}#{$1}\n" if line =~ /^M(.+)$/
puts "#{$1}U#{$2}\n" if line =~ /^(.*)III(.*)$/
puts "#{$1}#{$2}\n" if line =~ /^(.*)UU(.*)$/
end
# Implementation of the productions for the MIU system with match objects
open INFILE,"<",$ARGV[0];
while(<INFILE>) {
chomp;
next if $_ =~ /#.*/;
print "$foo[0]IU\n" if (@foo = ($_ =~ /^(.+?)I$/));
print "M$foo[0]$foo[0]\n" if (@foo = ($_ =~ /^M(.+)$/));
print "$foo[0]U$foo[1]\n" if (@foo = ($_ =~ /^(.*)III(.*)$/));
print "$foo[0]$foo[1]\n" if (@foo = ($_ =~ /^(.*)UU(.*)$/));
}
# Implementation of the productions for the MIU system with match objects
File.new(ARGV[0]).readlines.each do |line |
next if line =~ /#.*/
foo = nil
puts "#{foo[1]}IU\n" if foo = /^(.+)I$/.match(line)
puts "M#{foo[1]}#{foo[1]}\n" if foo = /^M(.+)$/.match(line)
puts "#{foo[1]}U#{foo[2]}\n" if foo = /^(.*)III(.*)$/.match(line)
puts "#{foo[1]}#{foo[2]}\n" if foo = /^(.*)UU(.*)$/.match(line)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment