GithubHelp home page GithubHelp logo

tabadstyle's Introduction

Bad Style Contest

The 15-150 (Spring 2017) TAs have been making submission to a bad style contest. Below we have submissions from 6 TAs, all given the following problem:

Write the function is_rotation, which takes in two values of type ''a list, and determines if one of the lists is a rotation of the other. 

That is, if the lists have the same values in the same order, possibly with the indices of their elements shifted by some number. For example, 

is_rotation [1, 2, 3, 4, 5] [4, 5, 1, 2, 3] ==> true 

Recall that ''a denotes any type that can be compared using =.

A regular solution to this problem might look something like this:

fun is_rotation (A : ''a list) (B : ''a list) =
  let
      fun check_n [] [] 0 = true
        | check_n A (B as x::xs) i =
          i <> 0 andalso (A = B orelse (check_n A (xs @ [x]) (i - 1)))
  in
      length A = length B andalso check_n A B (length A)
  end

And so, we present to you, all of the worst ways that TAs have found to write this simple function.

1. Lizzi

This solution makes great use of all the features of SML that we don't talk about - including refs and while loops. It even uses some gasp C syntax for extra horrific style.

Lizzi's Solution

2. Vijay

This solution uses some very well named variables, including a function called ?, to spell out some interesting English sentences in code.

Vijay's Solution

3. Sushain

This solution makes great use of randomness - in fact, it uses randomness so well that even though the code should theoretically terminate, it timed out on Autolab before running even one test case. It also features some wonderful test-driven development.

Sushain's Solution

4. Richard

This solution is a work of art - quite literally. It spells out a lambda in code.

Richard's Solution

5. Jeanne

This solution makes good use of the exn type. In fact, it's so good at using the exn type that all helper functions have type exn ref -> exn ref.

Jeanne's Solution

6. Chris

This solution implements a two tape version of the esoteric language Brainfuck, and then solves the problem in the language. Not only does it use a different language, it also assumes that lists are less than 500 elements long and claims ''a = int.

Chris's Solution

tabadstyle's People

Contributors

jluningp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.