Giter Club home page Giter Club logo

goal's Introduction

g()('al')

g()('al') is a challenge whereby you need to write in as many languages as possible code which enables the code g()('al') to return the string "goal", the code g()()('al') to return the string "gooal", the code g()()()('al') return the string "goooal", etc.

g()('al') is the creation of acruikshank who originally posed it as a functional programming challenge. Extensive stubbornness and misinterpretation led to its current form.

Rules

  1. You are encouraged to break the rules, cleverly.
  2. When executed, the solution must print "goal" with sufficient o's to demonstrate the program's functionality.
  3. The code g()('al') must appear in the source.
  4. g()('al') must not be a string literal.
  5. 'al' must be a string, or your language's equivalent thereof. You may use your language's standard method of creating a string (e.x. C should use ", ruby may use either " or ').
  6. g()('al') must be a valid rvalue if applicable in your language.
  7. g()('al') may not print the string. If returning a string cannot be done in your language, you should submit rationale as to why this is impossible for a solution which prints a string to be accepted.
  8. You must be able to insert an arbitrary number of () calls without modification to your solution. Therefore solutions like this are incorrect.
  9. g('al') must return "gal".

If you see a complete solution that breaks any of these rules, file a bug!

If you have a solution that is close, but does not meet these rules, submit it anyway. A close and interesting solution is better than no solution.

Previous Solutions

The more exciting solutions are original, not applying techniques that have already been discovered. The following broadly applicable techniques have already been discovered:

Languages

Solved Incomplete
ActionScript
Befunge
Bel
Brainfuck
C
C#
C++
Clojure
Coffeescript
Common Lisp
D
Dart
DYLD
Emacs Lisp
English
Finite State Transducer
Forth
GNU Octave
Go
Groovy
Haskell
Haxe
IO
Java
JavaScript
Julia
Kotlin
Lua
Mathematica
Nimrod
Nix
OCaml
Objective-J
PHP
PHP 7
Perl
Python
R
Raku
Regexp
Ruby
Rust
Scala
Scheme
Sed
Bourne Shell
TCL
XP
ZSH

Help out, add some more languages!

g()('lf')

Lets play golf! Submit a pull-request with a shorter solution for an already solved language and you can get the title of shortest, as shown in that language's README.

Note: I'm not done making READMEs for all the languages yet. Don't let that stop you!

Editor's Picks

These are some of the editor's favorite submissions:

goal's People

Contributors

andrioni avatar axldns avatar capicue avatar catwell avatar eamonnerbonne avatar eatnumber1 avatar gambogi avatar gryn010 avatar hoffman avatar jastanton avatar lcfvs avatar lopopolo avatar mastfissh avatar nenillo avatar nickdepinet avatar panzi avatar raleksandar avatar ramnathv avatar robert-nix avatar robertzk avatar robgssp avatar samadamday avatar scryptonite avatar seanmccully avatar seanmcgary avatar shaneqful avatar steveniemitz avatar thekid avatar tolmasky avatar worr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goal's Issues

Javascript Solution

var holdMyBeer = '';
var g = function() {
  if (arguments.length > 0) {
   var temp = holdMyBeer;
   holdMyBeer = '';
   return "g" + temp + arguments[0];
  }
  holdMyBeer += "o";
  return g;
};
// g('al') -> gal
// g()('al') -> goal
// g()()()()('al') -> gooooal

Coffeescript Solution

g = (str) ->
  _g = (str) ->
    return [ goal, str ].join("")  if str
    goal += "o"
    _g
  goal = "g"
  new _g(str)

Possible in Modelica?

@sjoelund I was thinking of how this could be solved in Modelica (or (undocumented) Mo script) but did not come to any result. Do you think it is possible at all by using operator overloading?

Impossible in erlang

g()().

This is not valid syntax and not even a parse_transform can save you :(

semantics around the rules

When you say g('al') must return "gal".

Do you mean that the actual return value of function g is "gal" or do you mean that the string "gal" must be printed by the specified invocation of function g?

Cause I have something that does this:
image

Python solution

def g(s=None,n=0): return 'G'+'o'*n+s if s else lambda s=None,n=n+1: g(s,n)

Call out: the Haskell one

The Haskell one is super clever for a number of reasons!

  1. Foremost, g() is not syntax for calling g with no arguments, it's syntax for calling g with a single argument: the empty tuple

  2. There is no such thing as a polyvariadic (i.e. a function with "splat" arguments) function in Haskell! The type must indicate the exact set of arguments

  3. Haskell is statically typed, so if you try to write a function which returns a function then the type would fix how many times you could apply an empty tuple. In other words, here's a simple function which returns g()()("al") --> "gooal"

    g :: () -> (() -> (String -> String))
    g = \() -> \() -> \string -> "goo" ++ string
    

    if it's not clear, there's no room for this function to suddenly accept a new tuple argument.

So, this seems pretty terrible. How does the solution work?

"Simple." We teach the compiler how to generate, on the fly, every possible function:

    g0(s) -- "g" ++ s
    g1()(s) -- "go" ++ s
    g2()()(s) -- "goo" ++ s
    g3()()()(s) -- "gooo" ++ s
    ...

then we name them all g. At compile time Haskell wanders around looking for (ambiguous) references to g, infers their type, and then uses that inferred type to determine which of the gN-series of functions is correct!

Then it inlines that gN function, typechecks it to prove that everything is sane, and goes on its merry way.


I said that Haskell demands we give exact types to all functions. So what's the type of g?

g :: (Goaly a, Stringy b) => b -> a

Here, Goaly and Stringy are defined in eatnumber1's solution. Roughly, they indicate polymorphism: b can be either () or a string indicating the two kinds of input types we're interested in and a is either a String (if we're demanding the result) or a "continuation" function of type (Goaly a, Stringy b) => b -> a again.

Together these cases ensure that we've got an inductive definition of the entire family of gN functions. We've actually defined something even larger, to be honest:

>>> g()"ooooo"()"al" :: String
"goooooooal"

We can even add more cases

instance Stringy Int where
  toString 0 = "o"
  toString n = show n
  (+++) x y = x ++ toString y

>>> default (Int)
>>> g()0()0()0()0()0()0"al" :: String
"gooooooooooooal"

Impossible in Rust

This is impossible in Rust because Rust cannot have functions that accept a variable number of arguments.

String/ pattern match between two data frame columns using R

i want to do a string match for 'product' column in data set A with 'Description' column in dataset B and get the corresponding cost. If no match found I want something like 'NA' or 'No match' using R

The two data set look like this:

data set A:
image

and the second data set is:

data set B:

image

i want the output to look like the one below:

image

I have tried the grep and agrep but was not able to arrive at the desired output.

Any help from your end is Appreciated.

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.