RGB2Rv6/Codegolf: Difference between revisions

From NoName e.V.
Jump to navigation Jump to search
No edit summary
No edit summary
Line 44: Line 44:
== sECuRE (C) ==
== sECuRE (C) ==
  main(){char i[4096];read(0,i,4096);char*p="pcmajagagagagajamapakaiagaeaeaeaeagaiakafaeadacaeaeacadaeafakaiagaeaeaeaeagaiaka",*n=strchr(i+58,10),*c,*s=0;*n++=0;for(c=n;*c!=0;c++)s+=p[strchr(i,*c)-i]-97;printf("%d",s);}
  main(){char i[4096];read(0,i,4096);char*p="pcmajagagagagajamapakaiagaeaeaeaeagaiakafaeadacaeaeacadaeafakaiagaeaeaeaeagaiaka",*n=strchr(i+58,10),*c,*s=0;*n++=0;for(c=n;*c!=0;c++)s+=p[strchr(i,*c)-i]-97;printf("%d",s);}
== Zählscript (phil_fry) ==
require "open3"
include Open3
require 'optparse'
options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options]"
  opts.on("-f", "--file FILE", "file with test lines") do |v|
    $fn = v
  end
  opts.on("-s", "--solution PROGRAM", "the program") do |v|
    $exec = v
  end
end.parse!
module Golf
  def self.check(program, keymap, text)
    puts "testing with keymap"
    puts keymap
    puts "test text: >>#{text}<<"
    expected = get_val("./reference", keymap, text)
    puts "reference C: #{expected}"
    expected = get_val("../moredread/moredread2.py", keymap, text)
    puts "moredread: #{expected}"
    expected = get_val("../martl/run.sh", keymap, text)
    puts "martl: #{expected}"
    solution = get_val(program, keymap, text)
    if (solution.to_i == expected)
      puts 'success'
      true
    else
      "fail, got #{solution}"
      false
    end
  end
  def self.get_val(program, keymap, text)
    solution = nil
    puts "executing #{program}"
    `echo "#{keymap}\n#{text}" > /tmp/tmp.keys`
    solution = `cat /tmp/tmp.keys | #{program}`
    puts "gots #{solution}"
    return solution.to_i
  end
  class Keymap
    QWERTY = Keymap.new
    def initialize(keys = "1234567890qwertyuiopasdfghjklzxcvbnm")
      #@keys=((?a..?z).to_a + (?0..?9).to_a).map{|c| c.chr}
      @keys = []
      keys.each_char {|c| @keys << c}
    end
    def shuffle!
      @keys.shuffle!
      self
    end
    def to_s
      [@keys[0..9].join(' '), @keys[10..19].join(' '), @keys[20..28].join(' '), @keys[29..36].join(' ')].join("\n")
    end
  end
end
$success = true
lines = IO.readlines($fn).each do |line|
  next if line.chomp! == ""
  res = Golf.check($exec, Golf::Keymap.new, line)
  $success = $success && res
  puts '-' * 70
  3.times do
    res = Golf.check($exec, Golf::Keymap.new.shuffle!, line)
    $success = $success && res
    puts '-' * 70
  end
end
if $success
  puts "all tests succeeded"
else
  puts "some or all tests failed"
  exit 1
end

Revision as of 22:26, 31 October 2009

Codegolf auf der RGB2Rv6

Die Aufgabe findet sich unter https://www.noname-ev.de/w/File:Rgb2rv6-codegolf.pdf

Sieger

  • Platz 1: urs in Perl mit 146 Bytes
  • Platz 2: blubberdiblub in unerweitertem C64-BASIC mit 176 Glyphs (und 155 Bytes)
  • Platz 3: martl in Java mit 350 Bytes

Originellste Lösung: blubberdiblub in C64-BASIC

Leider nicht gewonnen

  • Moredread in Python (249 Zeichen)

nichtbestätigte Scores

  • (wird nicht bewertet da Jury) sECuRE in C mit 218 Glyphs (und 218 Bytes)

Lösungen

urs (Perl)

$c{" "}=2;$#[19]=$#[23]=1;map{map{$c{$_}=(abs($.-3)+1+$#[$.+$?*4])*(5,4,3,(2)x4,3,4,5)[$?++]}split" ",<>;`-`}1..4;$/=\1;map{$?+=$c{$_}}<>;print$?

blubberdiblub

Folgt (als Foto)

martl (Java)

import java.util.*;class M{public static void main(String[]z){String a="",t="";Scanner S=new Scanner(System.in);while(S.hasNext()){a+=t;t=S.nextLine();}int s=0;for(char c:t.toCharArray()){s+=2;s+=c==' '?0:new int[]{13,10,7,4,4,4,4,7,10,13,8,6,4,2,2,2,2,4,6,8,3,2,1,0,2,2,0,1,2,8,6,4,2,2,2,2}[a.replaceAll(" ","").indexOf(c)];}System.out.println(s);}}


Moredread (Python)

import sys
i,u,O,t,v,x=0,sys.stdin.read().split('\n'),lambda O:O[::-1]+O,[4,2,3,4,5],[4,4,6,8,10],[6,6,8,12,15]
p=O(x),O(v),O(t),O(v)
for c in u[4]:
 if c is " ":
  i+=2
  continue
 for g in 0,1,2,3:
  L=u[g].find(c)/2
  if L!=-1:i+=p[g][L]
print i

sECuRE (C)

main(){char i[4096];read(0,i,4096);char*p="pcmajagagagagajamapakaiagaeaeaeaeagaiakafaeadacaeaeacadaeafakaiagaeaeaeaeagaiaka",*n=strchr(i+58,10),*c,*s=0;*n++=0;for(c=n;*c!=0;c++)s+=p[strchr(i,*c)-i]-97;printf("%d",s);}

Zählscript (phil_fry)

require "open3"
include Open3
require 'optparse'

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options]"

  opts.on("-f", "--file FILE", "file with test lines") do |v|
    $fn = v
  end

  opts.on("-s", "--solution PROGRAM", "the program") do |v|
    $exec = v
  end
end.parse!

module Golf
  def self.check(program, keymap, text)
    puts "testing with keymap"
    puts keymap
    puts "test text: >>#{text}<<"
    expected = get_val("./reference", keymap, text)
    puts "reference C: #{expected}"
    expected = get_val("../moredread/moredread2.py", keymap, text)
    puts "moredread: #{expected}"

    expected = get_val("../martl/run.sh", keymap, text)
    puts "martl: #{expected}"


    solution = get_val(program, keymap, text)
    if (solution.to_i == expected)
      puts 'success'
      true
    else
      "fail, got #{solution}"
      false
    end
  end

  def self.get_val(program, keymap, text)
    solution = nil
    puts "executing #{program}"
    `echo "#{keymap}\n#{text}" > /tmp/tmp.keys`
    solution = `cat /tmp/tmp.keys | #{program}`
    puts "gots #{solution}"
    return solution.to_i
  end

  class Keymap
    QWERTY = Keymap.new

    def initialize(keys = "1234567890qwertyuiopasdfghjklzxcvbnm")
      #@keys=((?a..?z).to_a + (?0..?9).to_a).map{|c| c.chr}
      @keys = []
      keys.each_char {|c| @keys << c}
    end

    def shuffle!
      @keys.shuffle!
      self
    end

    def to_s
      [@keys[0..9].join(' '), @keys[10..19].join(' '), @keys[20..28].join(' '), @keys[29..36].join(' ')].join("\n")
    end
  end
end

$success = true
lines = IO.readlines($fn).each do |line|
  next if line.chomp! == ""
  res = Golf.check($exec, Golf::Keymap.new, line)
  $success = $success && res
  puts '-' * 70
  3.times do
    res = Golf.check($exec, Golf::Keymap.new.shuffle!, line)
    $success = $success && res
    puts '-' * 70
  end
end

if $success
  puts "all tests succeeded"
else
  puts "some or all tests failed"
  exit 1
end