meeting’s cancelled (late) april fools. potw solution - stelia bufferedreader ff = new...

14
MEETING’S CANCELLED (Late) April Fools

Upload: alexander-cole

Post on 17-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

MEETING’S CANCELLED

(Late) April Fools

Page 2: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

PotW Solution - SteliaBufferedReader ff = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());int[][] points = new int[n][2];String[] l;for (int i = 0; i < n; i++) { l = ff.readLine().trim().split(" "); points[i][0] = Integer.parseInt(l[0]); points[i][1] = Integer.parseInt(l[1]);}int min = Integer.MAX_VALUE, low = 0, up = 0;for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { int x = points[i][0] - points[j][0], y = points[i][1] - points[j][1]; int sqrDist = x * x + y * y; if (sqrDist < min) { min = sqrDist; low = i; up = j; } }}System.out.println(points[low][0] + " " + points[low][1]);System.out.println(points[up][0] + " " + points[up][1]);

Page 3: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Stuff to pay attention to

• USACOo US Open is this coming weekend! (4/6 - 4/9)o 5 hours, 10 points PotW credit, mandatory for those hoping to get into

USACO camp

• ProCoo May 26o Registration link can be found at http://proco.stanford.edu, as well as

rules, directions, and practice problems

Page 4: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Esoteric Programming Languages

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

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

Page 5: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

What is an Esoteric Programming

Language?• Also known as esolangs• A programming language designed to experiment

with weird ideas, to be hard to program in, or as a joke, rather than for practical useo Usually no intention of the language being adopted for mainstream

programming; usability rarely a high priority

• First known deliberate esolang is INTERCAL, designed in 1972 to be as different as possible from existing programming languages

Page 6: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Turing Completeness• A term referring to the capabilities of a language• “Turing complete” means that the language can

be used to simulate a Turing machineo Can theoretically emulate any computer (the practicality of doing so

may vary)o Any Turing-complete system can model any other Turing-complete

system

• True Turing-completeness cannot be reached by physical computers since it requires infinite memory and infinite lifetime

• Esolangs may or may not be Turing-completeo “Turing tarpit” = language that aims for Turing-completeness with

minimal language elements; result is flexible but impractical language

Page 7: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

HQ9+• “Joke” language• Four instructions:

o H: Print “Hello, world!”o Q: Print the program’s source codeo 9: Print lyrics of “99 Bottles of Beer”o +: Increment the accumulator (an instruction as useless as it sounds)

• Example program: HQ+QH++o Output:

Hello, world!HQ+QH++HQ+QH++Hello, world!

Page 8: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Brain****• Minimalist, arguably the most famous esolang• Eight commands:

Command Description

> Move the pointer to the right

< Move the pointer to the left

+ Increment the memory cell under the pointer

- Decrement the memory cell under the pointer

. Output the character signified by the cell at the pointer

, Input a character and store it in the cell at the pointer

[ Jump past the matching ] if the cell under the pointer is 0

] Jump back to the matching [ if the cell under the pointer is nonzero

Page 9: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Brain**** (cont.)• Operates on array of memory cells each initially

set to zero, pointer initially pointing to first memory cell

• Hello world program:o >+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.++

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

• Print Fibonacci numbers (runs until terminated):o >++++++++++>+>+[ [+++++[>++++++++<-]>.<++++++

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

Page 10: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Stack-based Programming

• Equivalent to postfix, or Reverse Polish notationo E.g. "3 4 - print"o 3 is pushed onto stack firsto 4 is pushed nexto '-' is encountered, causing 3 and 4 to be popped, and 3 - 4 = -1 to be

pushedo 'print' is encountered, causing -1 to be popped and printed

• Examples: Whitespace, Forth, Factor, Befungeo Can be somewhat useful for its simplicity and concisiono Factor is one of the most well-developed

Page 11: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Befunge• Esoteric Language

o Stack-basedo 2-Dimensional code

• Flow controlled by arrows.

• Examples:o Print (n*n+n)/2

&::*+2/.@o Print first n natural numbers, in reverse order.

& v-1.:_@#:<

Operation Char Behavior

Push 0-9Push number from 0-9

Clone :Clone top value of stack

Arithmetic +-*/%Pop a,b.Push b-a.

Direction ><^vChange direction

If-Else _

Pop a.If a==0 go rightElse go left.

Jump # Skip next cell

Scan &Push next int from input

Print .Pop a, print to output

End @ Kill program

Page 12: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Java(jk)(actually not jk)(no really, jk)...Learn more about esoteric programming languages at http://esolangs.org!

Page 13: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

PotW - Inception• Write a Befunge program that prints out a Brain****

program that prints out a HQ9+ program that prints out “Hello, world”

• Worth 30 points. The shortest version will receive 5 bonus points.

• As an easier version, for 15 points, write a Brain**** program that prints out a HQ9+ program.

• For access to compilers, use http://codeforces.com/problemset/customtestWe will be using the same system, so if your code works on it, it should easily get the points.Note that all of these programming languages work with ASCII values for representing characters.

Page 14: MEETING’S CANCELLED (Late) April Fools. PotW Solution - Stelia BufferedReader ff = new BufferedReader( new InputStreamReader(System.in)); int n = Integer.parseInt(ff.readLine().trim());

Don’t Jack the sign-in sheets >:[

(Meeting adjourned)