C代码- - - / normal-youth.c /

  • - main() {
  • - printf("hello world");
  • - }
  • - 复制代码C代码- - / literature-youth.c /
  • int main(int argc, char** argv) {
  • printf("Hello world!\n");
  • return 0;
  • }
  • 复制代码C代码- - / 2b-youth.c /
  • #define m main
  • #define p(x) printf(#x)
  • m(){p(hello world);}
  • - 复制代码Java代码- - // NormalYouth.java
  • public class NormalYouth {
  • public static void sayHello(String name) {
  • System.out.println("Hello, "+name);
  • }
  • }
  • 复制代码Java代码- - // LiteratureYouth.java
  • - /**
  • * Copyright 2011 Literature Youth
  • *
  • * Permission is granted to anyone who obtained a copy of this code.
  • * You may
  • * use,
  • * compile,
  • * modify
  • * and/or redistribute this code
  • * provided that you
  • * don't blame the Literature Youth for any consequences caused
  • * by using this code.
  • */
  • package com.example.youth.literature.hello;
  • - /**
  • * LiteratureYouth is a hello-saying object.
  • */
  • public class LiteratureYouth {
  • private String name;
  • - /**
  • * Get the name to say hello to.
  • * @return the name to say hello to.
  • */
  • public getName() { return name; }
  • - /**
  • * Set the name to say hello to.
  • * @param name the name to say hello to.
  • */
  • public setName(String name) { this.name = name; }
  • - /**
  • * Construct a LiteratureYouth object that says hello to name.
  • * @param name the name to say hello to.
  • */
  • public LiteratureYouth(String name) {
  • super();
  • this.name = name;
  • }
  • - /**
  • * Say hello to the code-defined name.
  • */
  • public void sayHello() {
  • System.out.println("Hello, "+name);
  • }
  • }
  • - 复制代码Java代码- - // TwoBiYouth.java
  • public class TwoBiYouth {
  • public static String name = "world";
  • private static TwoBiYouth instance = new TwoBiYouth();
  • public static TwoBiYouth getInstance() { return instance; }
  • - public interface SayHelloStrategy {
  • void sayHello();
  • }
  • - public class DefaultSayHelloStrategy implements SayHelloStrategy {
  • @Override public void sayHello() {
  • System.out.println("Hello, "+name);
  • }
  • }
  • - private SayHelloStrategy strategy = new DefaultSayHelloStrategy();
  • public SayHelloStrategy getStrategy() { return strategy; }
  • - public static class TwoBiYouthVisitor {
  • public void visit(TwoBiYouth tby) {
  • tby.getStrategy().sayHello();
  • }
  • }
  • - public static class Facade {
  • public void sayHello(String n) {
  • TwoBiYouth.name = n;
  • TwoBiYouth tby = TwoBiYouth.getInstance();
  • TwoBiYouthVisitor visitor = new TwoBiYouthVisitor();
  • visitor.visit(tby);
  • }
  • }
  • }
  • - 复制代码Sql代码- - # normal-youth.sql
  • SELECT 'Hello world';
  • 复制代码Sql代码- - # literature-youth.sql
  • SELECT 'Hello', name FROM hw WHERE p = 'Hello';
  • - 复制代码Java代码- - // 2bYouth.sql.java
  • conn.createStatement().execute(
  • "SELECT 'Hello', name FROM hw WHERE p = '"
  • + scanner.next() + "';");
  • - 复制代码Python代码- - """ normal-youth.py """
  • def hello(name):
  • print "Hello", name
  • - 复制代码Python代码- - """ literature-youth.py """
  • def hello(name):
  • assert(sys.version_info.major == 2 and
  • sys.version_info.minor >= 6 or
  • sys.version_info.major > 2)
  • print "Hello {}".format(name)
  • - 复制代码Python代码- - """ 2b-youth.py """
  • hello = lambda n : (lambda v: v + " " + n)("Hello")
  • - 复制代码Bash代码- - #!/bin/bash
  • # normal-youth.sh
  • - # calculate 1+2+...+100
  • SUM=0
  • for n in {1..100}; do
  • SUM=$((SUM + n))
  • done
  • echo $SUM
  • - - 复制代码Bash代码- - #!/bin/bash
  • # literature-youth.sh
  • - # calculate 1+2+...+100
  • for x in $(seq 100); do
  • for y in $(seq $x); do
  • echo $y
  • done
  • done | wc -l
  • - 复制代码Bash代码- - #!/bin/bash
  • # 2b-youth.sh
  • - # calculate 1+2+...+100
  • echo $((1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99+100))
  • - 复制代码Haskell代码- - -- NormalYouth.hs
  • factorial 0 = 1
  • factorial n = n * fac (n-1)
  • - 复制代码Haskell代码- - -- LiteratureYouth.hs
  • factorial n = foldr (*) 1 [1..n]
  • - 复制代码Haskell代码- - -- 2bYouth.hs
  • module Main where
  • - data Natural = Zero | Succ Natural deriving Show
  • - one = Succ Zero
  • two = Succ one
  • three = Succ two
  • four = Succ three
  • five = Succ four
  • six = Succ five
  • - a +++ Zero = a
  • a +++ Succ x = Succ a +++ x
  • - a *** Zero = Zero
  • a Succ x = a +++ (a x)
  • - factorial Zero = one
  • factorial n@(Succ x) = n *** factorial x
  • - toi Zero = 0
  • toi (Succ x) = 1 + toi x
  • - 复制代码COPY http://www.hexiela.com/?p=40

[ 本帖最后由 China 于 2011-10-27 23:36 编辑 ]