code-golf

python dict.add_by_value(dict_2)?

六眼飞鱼酱① 提交于 2019-12-17 09:56:22
问题 The problem: >>> a = dict(a=1,b=2 ) >>> b = dict( b=3,c=2) >>> c = ??? c = {'a': 1, 'b': 5, 'c': 2} So, the idea is two add to dictionaries by int/float values in the shortest form. Here's one solution that I've devised, but I don't like it, cause it's long: c = dict([(i,a.get(i,0) + b.get(i,0)) for i in set(a.keys()+b.keys())]) I think there must be a shorter/concise solution (maybe something to do with reduce and operator module? itertools?)... Any ideas? Update: I'm really hoping to find

Code Golf: Number to Words

早过忘川 提交于 2019-12-17 01:39:34
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. The code golf series seem to be fairly popular. I ran across some code that converts a number to its word representation. Some examples would be (powers of 2 for programming fun): 2 -> Two 1024 -> One Thousand Twenty Four 1048576 -> One Million Forty Eight Thousand Five Hundred Seventy Six The algorithm my co-worker

Codegolf: Convert csv to HTML table with smallest amount of code in C#

╄→гoц情女王★ 提交于 2019-12-10 00:25:17
问题 I'm adding a function to my own personal toolkit lib to do simple CSV to HTML table conversion. I would like the smallest possible piece of code to do this in C# , and it needs to be able to handle CSV files in excess of ~500mb. So far my two contenders are splitting csv into arrays by delimiters and building HTML output search-replace delimiters with table th tr td tags Assume that the file/read/disk operations are already handled... i.e., i'm passing a string containing the contents of said

Code Golf: Diamond Pattern

巧了我就是萌 提交于 2019-12-09 14:05:45
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. The challenge The shortest code by character count to output a a pattern of diamonds according to the input. The input is composed of 3 positive numbers representing the size of the diamond and the size of the grid. A diamond is made from the ASCII characters / and \ with spaces. A diamond of size 1 is: /\ \/ The size

Code golf: “Color highlighting” of repeated text

北战南征 提交于 2019-12-09 02:51:29
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. (Thanks to greg0ire below for helping with key concepts) The challenge: Build a program that finds all substrings and "tags" them with color attributes (effectively highlighting them in XML). The rules: This should only be done for substrings of length 2 or more. Substrings are just strings of consecutive characters,

How to Rewrite of One Line Code (or Less Line Code in command line) of this code in Perl?

走远了吗. 提交于 2019-12-08 08:26:28
I have a code like that: #!/usr/bin/perl use strict; use warnings; my %proteins = qw/ UUU F UUC F UUA L UUG L UCU S UCC S UCA S UCG S UAU Y UAC Y UGU C UGC C UGG W CUU L CUC L CUA L CUG L CCU P CCC P CCA P CCG P CAU H CAC H CAA Q CAG Q CGU R CGC R CGA R CGG R AUU I AUC I AUA I AUG M ACU T ACC T ACA T ACG T AAU N AAC N AAA K AAG K AGU S AGC S AGA R AGG R GUU V GUC V GUA V GUG V GCU A GCC A GCA A GCG A GAU D GAC D GAA E GAG E GGU G GGC G GGA G GGG G /; open(INPUT,"<dna.txt"); while (<INPUT>) { tr/[a,c,g,t]/[A,C,G,T]/; y/GCTA/CGAU/; foreach my $protein (/(...)/g) { if (defined $proteins{$protein}

How to Rewrite of One Line Code (or Less Line Code in command line) of this code in Perl?

孤人 提交于 2019-12-08 06:33:33
问题 I have a code like that: #!/usr/bin/perl use strict; use warnings; my %proteins = qw/ UUU F UUC F UUA L UUG L UCU S UCC S UCA S UCG S UAU Y UAC Y UGU C UGC C UGG W CUU L CUC L CUA L CUG L CCU P CCC P CCA P CCG P CAU H CAC H CAA Q CAG Q CGU R CGC R CGA R CGG R AUU I AUC I AUA I AUG M ACU T ACC T ACA T ACG T AAU N AAC N AAA K AAG K AGU S AGC S AGA R AGG R GUU V GUC V GUA V GUG V GCU A GCC A GCA A GCG A GAU D GAC D GAA E GAG E GGU G GGC G GGA G GGG G /; open(INPUT,"<dna.txt"); while (<INPUT>) {

Convert decimal number to excel-header-like number

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 19:58:32
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. 0 = A 1 = B ... 25 = Z 26 = AA 27 = AB ... 701 = ZZ 702 = AAA I cannot think of any solution that does not involve loop-bruteforce :-( I expect a function/program, that accepts a decimal number and returns a string as a result. 回答1: Haskell, 78 57 50 43 chars o=map(['A'..'Z']:)$[]:o e=(!!)$o>>=sequence Other entries

Convert decimal number to excel-header-like number

▼魔方 西西 提交于 2019-12-05 01:28:42
0 = A 1 = B ... 25 = Z 26 = AA 27 = AB ... 701 = ZZ 702 = AAA I cannot think of any solution that does not involve loop-bruteforce :-( I expect a function/program, that accepts a decimal number and returns a string as a result. stusmith Haskell, 78 57 50 43 chars o=map(['A'..'Z']:)$[]:o e=(!!)$o>>=sequence Other entries aren't counting the driver, which adds another 40 chars: main=interact$unlines.map(e.read).lines A new approach, using a lazy, infinite list, and the power of Monads! And besides, using sequence makes me :) , using infinite lists makes me :o If you look carefully the excel

Codegolf: Convert csv to HTML table with smallest amount of code in C#

为君一笑 提交于 2019-12-04 22:43:22
I'm adding a function to my own personal toolkit lib to do simple CSV to HTML table conversion. I would like the smallest possible piece of code to do this in C# , and it needs to be able to handle CSV files in excess of ~500mb. So far my two contenders are splitting csv into arrays by delimiters and building HTML output search-replace delimiters with table th tr td tags Assume that the file/read/disk operations are already handled... i.e., i'm passing a string containing the contents of said CSV into this function. The output will consist of straight up simple HTML style-free markup, and yes