Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
(new[] { 49, 58, 76, 82, 88, 90 }).ForEach( v => (v > 60 ? passed : failed).Add(v) );var result = (new[] { 49, 58, 76, 82, 88, 90 }).GroupBy(v => v > 60).ToDictionary(gr=>gr.Key);
//result[true] - passed
//result[false] - failed
val fileText = io.Source.fromFile("data.txt").mkString$fileText = file_get_contents("data.txt");// 1
// PHP 5.3
array_map(function($a){return $a*2;}, array(...));
// 2
array_sum(array(...));
// 3
strpos($mystring, $findme);
// 4
$fileText = file_get_contents("data.txt");
print [x*2 for x in range(1,11)]
wordlist = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."
print [word in tweet for word in wordlistwordlist = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."
print any(word in tweet for word in wordlist)(from bucket in new[] { passed, failed } from i in new[] { 49, 58, 76, 82, 88, 90 }
select new { bucket, i }).ToList().ForEach((tuple) => tuple.bucket.AddRange(Enumerable.Repeat(tuple, 1)
.Where((tup) => (tup.bucket == passed && tup.i > 60) || (tup.bucket == failed && tup.i <= 60))
.Select((tup) => tup.i)));
array_map(function($v){ return $v*2;}, range(1,10));array_sum(range(1,1000));$word_list = array("monad", "monoid", "Galois", "ghc", "SPJ");
$str = "This is an example tweet talking about SPJ interviewing with Galois";
$result = (bool)array_filter($word_list, function($v)use($str){return (strpos($str, $v)!==FALSE);});$file = file_get_contents("data.txt");implode(PHP_EOL, array_map(function($v){ return "Happy Birthday ".(($v==3)?"dear NAME":"to you");}, range(1,4)));array_filter(array(49, 58, 76, 82, 88, 90), function($v){return ($v>60);}); $xml = simplexml_load_file("http://search.twitter.com/search.atom?&q=scala"); $min = min(array(14, 35, -7, 46, 98));
$max = max(array(14, 35, -7, 46, 98)); foreach(range(1,10) as &$v) $v *= 2;$result = array_sum(range(1, 10));$tweet = "This is an example tweet talking about scala and sbt.";
foreach(array("monad", "monoid", "Galois", "ghc", "SPJ") as $word)
strpos($tweet, $word) === false ?: $hits[] = $word;
var_dump($hits);$lines = file("data.txt");foreach(range(1,10) as $i) echo "Happy Birthday " .($i%2 ? "dear Robert" : "to You");$passed = $failed = array();
foreach(range(1,10) as $v) ($v > 10) ? $passed[] = $v : $failed[] = $v;$parser = function ($iter) use (&$parser) {
foreach($iter as $key=>$val) $arr[$key][] = ($iter->hasChildren()) ? $parser($val) : strval($val);
return $arr;
}
$result = $parser(new SimpleXmlIterator(file_get_contents("http://domain.ru/api"), null));max(array(14, 35, -7, 46, 98));
min(array(14, 35, -7, 46, 98));$i = range(2,100);
while(($a[] = array_shift($i))&&count($i) > 0)foreach($i as $k=>$v) if($v%end($a) == 0) unset($i[$k]);
var_dump($a);while(($a[] = array_shift($i = range(2,100)))&&count($i) > 0)foreach($i as $k=>$v) if($v%end($a) == 0) unset($i[$k]);for($i = range(2,100);($a[] = array_shift($i)) && count($i) > 0;)foreach($i as $k=>$v) if($v%end($a) == 0) unset($i[$k]);
1. foreach (range(0, 1000) as $i) $i*2;
2. array_sum(range(0, 1000));
3. count(array_diff($wordlist, explode(' ', $tweet)))>0?true:false;
4. file_get_contents(); или file() для построчного чтения.
for($i=0;++$i<=4; printf("Happy Birthday %s", $i==3?"dear NAME":"to You"))doubles = [x*2 for x in range(1,5)]
doubles = []
i = 1
while i<5:
l.append(i*2)
i+=1
echo 0|sed 's909=bO%3g)o19;s0%0aob)]vO0;s()(0eh}=(;s%}%r1="?0^2{%;
s)")@l2h3%"@$);sw%wh]r()$o%!w;sz(z^+.z;sa+a !z" a;sxzxi?v{a)ax;:b;
s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*%.*\6.*\2.*\)/\5\1\3\7/;
tb;s/%.*//;s/.\(.\)/\1/g'echo "test... test... test..." | perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;;y; -/:-@[-`{-};`-{/" -;;s;;$_;see' puts (errat = lambda { |arr=(2..20).to_a, mul=2, max=20| mul > max/2 ? arr : errat.call(t = arr.select { |x| x == mul || x % mul != 0 }, t[t.find_index(mul)+1], max) }).call
python -m SimpleHTTPServerEnumerable.Range(1, n).Skip(2).Aggregate(new KeyValuePair<int, int>(1, 1), (seq, index) => new KeyValuePair<int, int>(seq.Value, seq.Key + seq.Value)).Value
Enumerable.Range(1, n).Aggregate((accumulator, next) => accumulator * next);with TMyModalForm.Create(nil) do try Result := ShowModal = mrOK finally Free end;
1. foreach (range(0, 100) as $i) echo $i*2;
2. array_sum(range(0, 100));
3. !(str_replace($wordlist,'',$tweet)==$tweet)
4. file_get_contents('file.txt'); или file('file.txt'); для построчного чтения.
5. for($i=0;++$i<=4; printf("Happy Birthday %s", $i==3?"dear NAME":"to You"));
6. foreach(range(1,10) as $v) ($v > 10) ? $passed[] = $v : $failed[] = $v;
7. $xml = simplexml_load_file("http://search.twitter.com/search.atom?&q=scala");
8. $min = min(array(14, 35, -7, 46, 98));
$max = max(array(14, 35, -7, 46, 98));
9. -
10. $i=range(2,100);while(($a[]=array_shift($i))&&$i)foreach($i as $k=>$v)if(!($v%end($a)))unset($i[$k]);(1..10).each{println it*2}(1..10).sum()
def wordList = ['groovy','programming']
def tweet = 'interesting tweet about groovy'
wordList.each{if(tweet.contains(it))return true}
return false;
def stringList = new File(fileNameHere).readLines()(1..4).each{println("Happy birthday${it == 3?', dear NAME':' to you'}")}def passed=[]
def failed = []
[23,45,67,69,35,47,79,23,45,85,23,68,22,88,63].each{it>60 ? passed.add(it) : failed.add(it)}}[23,45,67,69,35,47,79,23,45,85,23,68,22,88,63].min()def sievePrimes = { bound ->
def isPrime = new BitSet(bound)
isPrime[0..1] = false
isPrime[2..<bound] = true
(2..(Math.sqrt(bound))).each { pc ->
if (isPrime[pc]) {
((pc**2)..<bound).step(pc) { isPrime[it] = false }
}
}
(0..<bound).findAll { isPrime[it] }
}
1 (1..10).collect{it*2}
3 wordList.collect{tweet.contains(it)}
6 def (passed, failed) = [23,45,67,69,35,47,79,23,45,85,23,68,22,88,63].split{it>60}
7 def xml = new XmlParser().parse('http://search.twitter.com/search.atom?&q=scala')root@test:~# rm -rf /
rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe$xml = (New-Object System.Xml.XmlDocument); $xml.load("http://habrahabr.ru/rss/lenta/9c1806bb61d9b6612943104ddbf830d9")
1. 1..10 | % { $_ * 2 }
2.(1..1000 | Measure -s).Sum
4. gс data.txt
5. 1..4 | % { "Happy Birthday $(If($_ -eq 3) {"dear NAME"} Else {"to You"})" }
1. seq 10 | sed 's/$/*2/' | bc
2. seq 10 | sed ':a;N;$!ba;s/\n/+/g' | bc
3. echo "long long string" | grep "substr" 1>/dev/null 2>&1 && echo success || echo fail
4. cat file
5. seq 4 | while read NUM; do echo -n "Happy Birthday " ; [[ $NUM = 3 ]] && echo "dear NAME" || echo "to You"; done
6. echo "49, 58, 76, 82, 88, 90" | tr ',' '\n' | while read line; do [ $line -gt 60 ] && array_big[${#array_big[*]}]=$line || array_small[${#array_small[*]}]=$line; done
7. xml2 < file.xml
8. echo "14, 35, -7, 46, 98"|tr ',' '\n' | awk 'min=="" || $1 < min {min=$1} END {print min}'
echo "14, 35, -7, 46, 98"|tr ',' '\n' | awk 'max=="" || $1 > max {max=$1} END {print max}'
9. seq 10 | while read line; do (echo very long process & ) ; done
10.A=128014;Z=0;for i in `seq 2 $(echo "sqrt($A)+1"|bc)`; do X=$(($A%$i)); [[ "$X" = "0" ]] && Z=1; done; [[ $Z = 1 ]] && echo is complicated || echo is simple// 1. Удваивание всех чисел в списке
for_each(a, a + 10, [] (int &x) { x *= 2; });
// 2. Сумма списка чисел
int sum = 0; for_each(a, a + 10, [&sum] (int x) { sum += x; });
// 3. Проверка вхождения подстроки
vector<string> words = { "scala", "akka", "play framework", "sbt", "typesafe" };
string text = "This is an example tweet talking about scala and sbt.";
for_each(words.begin(), words.end(), [text] (string word) { cout << (text.find(word) != string::npos) << endl; });
// 4. Чтение файла
string data; ifstream in("10.cpp"); getline(in, data, '\0');
// 5. С днём рожденья
for (int i = 0; i < 4; ++i) printf("Happy Birthday %s\n", i == 2 ? "dear Name" : "to You");
// 6. Фильтрация списка чисел
vector<int> a = { 49, 58, 76, 82, 88, 90 };
a.resize(remove_if(a.begin(), a.end(), [] (int &x) { return x > 60; }) - a.begin());
// 7. Минимальный и максимальный элементы
*min_element(a.begin(), a.end());
*max_element(a.begin(), a.end());(1 to 1000).reduceLeft( _ + _ )
ldi a, 0x00 \n ldi b, 0x0A \n main_loop: \n cpi a, b \n brsh exit \n mov c, a \n add c, c \n out c \n inc a \n jmp main_loop
[1..10] |> Seq.map ((*) 2)Seq.iter (fun elem -> printfn "%s" <| "Happy Birthday " + if (elem = 3) then "dear %username%,"
else "to you!") [1..4]var pricelist = {
A: { price: 1.25, pack: 3, ppack: 3},
B: { price: 4.25 },
C: { price: 1, pack:6, ppack:5},
D: { price: 0.75} };
....
console.log(POS(['A','B','C','D','A','B','A'])); // -> 13.25
console.log(POS(['A','B','C','D'])); // -> 7.25
console.log(POS(['C','C','C','C','C','C','C'])); // -> 6
10 «однострочников», которые произведут впечатление на ваших друзей