scripting challenge, easy mode |
scripting challenge, easy mode |
Aug 22 2009, 04:59 PM
Post
#1
|
|
![]() /人◕‿‿◕人\ ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Member Posts: 8,283 Joined: Dec 2007 Member No: 602,927 |
1. think up your own esoteric language.
2. write a hello world script with it. 3. explain the code. 4. show the output. 5. ??? 6. profit! Mine: a brainfuck-esque language that uses four commands and seven characters. Useful for learning binary in an extreme way. CODE .[->+>+>->+>->->->->+>+>->->+>->+>->+>+>->+>+>->->->+>+>->+>+>->->->+>+>->+>+>+>+>->->+>->->->->->->+>+>+>->+>+>->+>+>->+>+>+>+>->+>+>+>->->+>->->+>+>->+>+>->->->+>+>->->+>->->->->+>->->->->+]~[->+>+>+>+>+>+>->->->+>->+>+>+>+>->+>+>->+>->->->->+>+>->->+>->+>->+>+>->+>+>->->->+>+>->+>+>->->->+>+>->+>+>+>+>->+>+>+>->+>+>+>->+>+>->+>+>+>+>->+>+>+>->->+>->->+>+>->+>+>->->->+>+>->->+>->->->->+>->+>+>+>->->+>+>+>->+>->->->+>+>+>+>->->->->+>+>+>->+>->-] This code creates "~/helloworld.txt" and writes "hello world!" to it. .[(string)]~[(location)] = write (string) to (location) - = turn bit off + = turn bit on > = next bit You can make a compiler if you really want to. |
|
|
|
![]() |
Nov 8 2009, 01:50 AM
Post
#2
|
|
![]() Senior Member ![]() ![]() ![]() ![]() ![]() ![]() Group: Administrator Posts: 2,648 Joined: Apr 2008 Member No: 639,265 |
Wrote one for Ruby. Thought I'd have more fun with the Ruby version, so I used Treetop to generate a grammar.
Here's the grammar (buttf*ck.tt): CODE grammar Buttf*ck rule program '.[' string ']~[' location ']' end rule string bit+ end rule location bit+ end rule bit [+-] '>'? end end And here's the program that uses that grammar to parse a file (bf.rb): CODE #!/usr/bin/env ruby require 'rubygems' require 'treetop' require 'buttf*ck' class String def from_buttf*ck data = {:bitpos => 0, :masked => 0, :bitmask => 0} buf = '' each_char do |ch| case ch when '>' data[:bitpos] += 1 if data[:bitpos] > 7 buf << data[:masked] data[:bitpos] = 0 data[:masked] = 0 end data[:bitmask] = 2 ** (7 - data[:bitpos]) when '+' data[:masked] |= (0xffffffff & data[:bitmask]) when '-' data[:masked] |= (0x0 & data[:bitmask]) end end buf end def to_path File.expand_path self end end if $0 == __FILE__ if $*.length < 1 $stderr.puts 'Usage: ruby bf.rb file.bf' exit 1 end string = nil location = nil open($*[0], 'r') do |fh| nodes = Buttf*ckParser.new.parse fh.read.strip string = nodes.string.text_value.from_buttf*ck location = nodes.location.text_value.from_buttf*ck end open(location.to_path, 'w') { |fh| fh.print string } end Grammar: buttf*ck.tt Source: bf.rb |
|
|
|
Buttsex scripting challenge Aug 22 2009, 04:59 PM
mipadi So how does it work? At first I assumed that the b... Aug 24 2009, 01:05 PM
Buttsex The bit-flipping operations turn single bits on an... Aug 24 2009, 04:31 PM
mipadi Oh, I see. I was looking for an encoded "~... Aug 24 2009, 07:08 PM
jcp How do you run it? And where is the file created? Aug 24 2009, 07:28 PM
Buttsex QUOTE.[->+>+>->+>->->->-... Aug 24 2009, 07:29 PM
mipadi QUOTE(Buttsex @ Aug 24 2009, 08:29 PM) fy... Aug 24 2009, 07:33 PM
Buttsex Oh, alright. Makes sense. Aug 24 2009, 07:39 PM
mipadi I wrote an interpreter in C for this language. I... Aug 24 2009, 10:31 PM
jcp PHP:
CODE<?php
Print "Hello, World!... Aug 24 2009, 10:56 PM
Buttsex You're softcore, lose. Aug 25 2009, 04:10 PM
mipadi Boring day at work, wrote a Python version of the ... Oct 29 2009, 02:18 PM
Cristy QUOTE(mipadi @ Oct 29 2009, 03:18 PM) Sou... Oct 29 2009, 08:24 PM
mipadi QUOTE(Cristy @ Oct 29 2009, 09:24 PM) Use... Oct 29 2009, 10:36 PM
jcp QUOTE(mipadi @ Oct 29 2009, 10:36 PM) I t... Oct 29 2009, 10:39 PM
mipadi Ha!
Well, I used bit.ly to generate better UR... Oct 29 2009, 11:29 PM
superstitious I honestly don't know what any of this means, ... Nov 8 2009, 02:38 PM![]() ![]() |