From 27C3 public wiki

Jump to: navigation, search

CodeGolfChallenge

Contents

Chaos Codegolf

What is golf?

You have to create a program that consists of as few characters as possible. Warning: it's addicting!

Squeeze your logic into the smallest pieces possible!

Challenges

Generate C

Example

input:

 3

output:

    ##  ##  ##
  #   #   #
 #   #   #
 #   #   #
 #   #   #
  #   #   #
    ##  ##  ##
Solution in brainfuck

The grader's brainfuck support is broken, so here goes my brainfuck solution for problem 1. There are many ways to golf it further down. Jchillerup 11:22, 30 December 2010 (CET)

>>>>>>>>>>+++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++>
++++++++++<<<<<<<<<<<<[-]>>,------------------------------------------------[<<+>+>-]
[-],----------[--------------------------------------<[<+++++++++>-]>[<<+>>-]-,-------
---><]<<>[-]>[-]<<[->+>+<<]>>[-<<+>>]<<>>>>>>>>>>>.<<<<<<<<<<[>>>>>>>>>>..<..<<<<<<<<
<-]>>>>>>>>>>>.<.<<<<<<<<<<>>++++[<<<>[-]>[-]<<[->+>+<<]>>[-<<+>>]<<>->>>>>>>>>.<<<<<<<<<
[>>>>>>>>>>...<.<<<<<<<<<-]>>>>>>>>>>>.<<<<<<<<<<<>>-]<<<>[-]>[-]<<
[->+>+<<]>>[-<<+>>]<<>->>>>>>>>>>.<.<<<<<<<<<[>>>>>>>>>>...<.<<<<<<<<<-]>>>>>>>>>>>.<<<<
<<<<<<<[-]>[-]<<[->+>+<<]>>[-<<+>>]<>>>>>>>>>>.<<<<<<<<<<[>>>>>>>>>>..<..<<<<<<<<<-]>>>>
>>>>>>>.<<<<<<<<<<<

Punycode encoder

Example

input:

 Chäos
 Cömpüter
 Clüb

output:

 Chos-moa
 Cmpter-wxa4c
 Clb-ioa

Please note: To win mate, you are not allowed to use existing punycode libraries ;)

Results

I hope you've learned something, had fun, and now rather play code golf than playing sudoku if you want to waste time :]

To get your club mate (because you've submitted a good solution), talk to me or ask at the c3d2 <<</>> desk for codegolf from time to time.

Some code golf examples

Perl

 s`(\w|
 )|([+-])|.`${$@[@@]=$1||join$&,map{((ord$&,$#-)[$0^=1]%3?!$2*/\W/:$$_)?"($_)":$_}splice@@,-2}=$2`gefor<>;print@@

(by ySas)

This perl program turns

 abc+-
 abc++
 ab+c*
 ab*c+

To

 a-(b+c)
 a+b+c
 (a+b)*c
 a*b+c

Link: http://golf.shinh.org/p.rb?postfix+to+infix

Ruby

 _,$_=*$<;$><<split.sort_by{|i|-i.hex}*' '

(by leonid)

A little program that sorts for you.

Input:

 25
 1 7 8 6 9 3 5 6 4 2 2 5 8 11 3 7 -8 6 9 0 5 4 12 3 8

Output:

 12 11 9 9 8 8 8 7 7 6 6 6 5 5 5 4 4 3 3 3 2 2 1 0 -8

Link: http://golf.shinh.org/p.rb?sort

Python

 while 1:a,b=map(int,raw_input().split());print a,"=><"[cmp(a,b)],b

(by recursive)

Compare two numbers:

 3 3
 4 2
 5 9

Output:

 3 = 3
 4 > 2
 5 < 9

Link: http://golf.shinh.org/p.rb?Comparing+two+numbers

Golfscript

 6666,-2%{2+.2/@*\/10.3??2*+}*

(by flagitious)

Calculates 1000 digits of PI.

Link: http://www.golfscript.com/golfscript/examples.html

Archived page - Impressum/Datenschutz