2014年7月30日より開催中のpaizaオンラインハッカソン(略してPOH![ポー!])Lite「天才火消しエンジニア霧島 もしPMおじさんが『丸投げ』を覚えたら」ですが、たくさんのご参加ありがとうございます。引き続き開催中ですので、まだチャレンジしていない方は是非チャレンジください。
今回の物語では、主人公霧島京子の発注元にあたる1次請けSIerのPM火村氏に、いかにアホなコードを書かせるかという事で色々悩んだのですが、ネタとしては面白いが可読性が悪すぎてヒントにならないという事でお蔵入りしたコードを紹介ます。
■しょうもなさ過ぎてお蔵入りに…
今回は、これまでのオンラインハッカソンVol.1、Vol.2よりも難易度を下げて、より参加しやすい形を目指して、タイトルもPOH Liteとしました。物語の中で提示される元受PMの火村氏が書いたコードを読めば「愚直な解き方はある程度分かる」というのを目指して火村氏のコードを作成しました。
ただ物語の流れ上、いかにしょうもない「こんなコード書くんだったらエンジニアやめたほうが良い」というようなコードを作るかが肝だったわけですが、それと同時にある程度何をやっているかがパッと見で分かって、自分で書くための参考になるものにもしなければなりません。
下記に紹介するコードは、しょうもなささに振りすぎて、可読性が悪くて本当に使えなかったのですが(ただし動作はします)、このブログを読んでいる方でこういったコードを日常書いているとしたらエンジニアをには向いていないかもしれません。『霧島、火消しやめるってよ』レベルのコードですw
■PHP
<?php fscanf(STDIN, '%d', $M); fscanf(STDIN, '%d', $N); $QR = array(); for($i = 0; $i < $N; $i++) { fscanf(STDIN, '%d %d', $QR[$i][0], $QR[$i][1]); } $use_list = array(); for($a = 0; $a < 2; $a++){ if($N == 1) { $use_list = array($a); } else { for($b = 0; $b < 2; $b++){ if($N == 2) { $use_list[] = array($a, $b); } else { for($c = 0; $c < 2; $c++) { if($N == 3) { $use_list[] = array($a, $b, $c); } else { for($d = 0; $d < 2; $d++) { if($N == 4) { $use_list[] = array($a, $b, $c, $d); } else { for($e = 0; $e < 2; $e++) { if($N == 5) { $use_list[] = array($a, $b, $c, $d, $e); } else { for($f = 0; $f < 2; $f++) { if($N == 6) { $use_list[] = array($a, $b, $c, $d, $e, $f); } else { for($g = 0; $g < 2; $g++) { if($N == 7) { $use_list[] = array($a, $b, $c, $d, $e, $f, $g); } else { for($h = 0; $h < 2; $h++) { if($N == 8) { $use_list[] = array($a, $b, $c, $d, $e, $f, $g, $h); } else { for($i = 0; $i < 2; $i++) { if($N == 9) { $use_list[] = array($a, $b, $c, $d, $e, $f, $g, $h, $i); } else { for($j = 0; $j < 2; $j++) { if($N == 10) { $use_list[] = array($a, $b, $c, $d, $e, $f, $g, $h, $i, $j); } } } } } } } } } } } } } } } } } } } } #使う使わないリストから、人月を満たせる組み合わせで最安を探す $ans = 0; foreach($QR as $v) { $ans += $v[1]; } foreach($use_list as $v) { $cost = 0; $ningetsu = 0; foreach($v as $key => $vv) { if($vv == 1) { $ningetsu += $QR[$key][0]; $cost += $QR[$key][1]; } } if($ningetsu >= $M && $ans > $cost) { $ans = $cost; } } print($ans."\n");
…この時点ですでにおなかいっぱいだと思いますが、それぞれの言語版もあるので掲載します。もはやアスキーアートのようですが、言語により美しさの質が異なりますので是非ご鑑賞ください。
■Perl
$M = <STDIN>; $N = <STDIN>; @Ql = (); @Rl = (); for($i = 0; $i < $N; $i++) { $tmp = <STDIN>; @tmp = split(/ /, $tmp); push(@Ql, @tmp[0]); push(@Rl, @tmp[1]); } @use_list = (); for($a = 0; $a < 2; $a++){ if($N == 1) { push(@use_list, ([$a])); } else { for($b = 0; $b < 2; $b++){ if($N == 2) { push(@use_list, ([$a, $b])); } else { for($c = 0; $c < 2; $c++) { if($N == 3) { push(@use_list, ([$a, $b, $c])); } else { for($d = 0; $d < 2; $d++) { if($N == 4) { push(@use_list, ([$a, $b, $c, $d])); } else { for($e = 0; $e < 2; $e++) { if($N == 5) { push(@use_list, ([$a, $b, $c, $d, $e])); } else { for($f = 0; $f < 2; $f++) { if($N == 6) { push(@use_list, ([$a, $b, $c, $d, $e, $f])); } else { for($g = 0; $g < 2; $g++) { if($N == 7) { push(@use_list, ([$a, $b, $c, $d, $e, $f, $g])); } else { for($h = 0; $h < 2; $h++) { if($N == 8) { push(@use_list, ([$a, $b, $c, $d, $e, $f, $g, $h])); } else { for($i = 0; $i < 2; $i++) { if($N == 9) { push(@use_list, ([$a, $b, $c, $d, $e, $f, $g, $h, $i])); } else { for($j = 0; $j < 2; $j++) { if($N == 10) { push(@use_list, ([$a, $b, $c, $d, $e, $f, $g, $h, $i, $j])); } } } } } } } } } } } } } } } } } } } } #使う使わないリストから、人月を満たせる組み合わせで最安を探す $ans = 0; for($i = 0; $i < $N; $i++){$ans += $Rl[i];} foreach $v (@use_list) { $cost = 0; $ningetsu = 0; for($i = 0; $i < $N; $i++) { if(@$v[$i] == 1) { $ningetsu += @Ql[$i]; $cost += @Rl[$i]; } } if($ningetsu >= $M && $ans > $cost) { $ans = $cost; } } print($ans);
■Ruby
Rubyは結構エレガントですね。。
# coding: utf-8 m = gets.to_i n = gets.to_i qr = [] n.times do tmp = gets.split(" ") qr.push([tmp[0].to_i, tmp[1].to_i]) end #m社のうちi番目の会社を使うか使わないかの表を作る #3社とかなら # A, B, C # 1, 1, 1 # 1, 1, 0 # 1, 0, 1 #.....続く... #みたいな1を使う0は使わないの表を作る use_list = [] 2.times do |a| if n == 1 use_list.push([a]) else 2.times do |b| if n == 2 use_list.push([a, b]) else 2.times do |c| if n == 3 use_list.push([a, b, c]) else 2.times do |d| if n == 4 use_list.push([a, b, c, d]) else 2.times do |e| if n == 5 use_list.push([a, b, c, d, e]) else 2.times do |f| if n == 6 use_list.push([a, b, c, d, e, f]) else 2.times do |g| if n == 7 use_list.push([a, b, c, d, e, f, g]) else 2.times do |h| if n == 8 use_list.push([a, b, c, d, e, f, g, h]) else 2.times do |i| if n == 9 use_list.push([a, b, c, d, e, f, g, h, i]) else 2.times do |j| if n == 10 use_list.push([a, b, c, d, e, f, g, h, i, j]) end end end end end end end end end end end end end end end end end end end end #使う使わないリストから、人月を満たせる組み合わせで最安を探す ans = qr.map { |i| i[1] }.inject(:+) use_list.each do |i| cost = 0; ningetsu = 0; i.each_with_index do |v, j| if v == 1 ningetsu += qr[j][0] cost += qr[j][1] end if ningetsu >= m and ans > cost ans = cost end end end print ans, "\n"
■JavaScript
var input = ''; process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', function(chunk) { input += chunk; }); process.stdin.on('end', function(){ input = input.split('\n'); main() }); function main() { M = Number(input[0]); N = Number(input[1]); QR = []; for(i = 0; i < N; i++) { tmp = input[2+i].split(' '); q = Number(tmp[0]); r = Number(tmp[1]); QR.push([q, r]); } //m社のうちi番目の会社を使うか使わないかの表を作る //3社とかなら // A, B, C // 1, 1, 1 // 1, 1, 0 // 1, 0, 1 //.....続く... //みたいな1を使う0は使わないの表を作る use_list = [] for(a = 0; a < 2; a++) { if(N == 1) { use_list.push([a]); } else { for(b = 0; b < 2; b++) { if(N == 2) { use_list.push([a, b]); } else { for(c = 0; c < 2; c++) { if(N == 3) { use_list.push([a, b, c]); } else { for(d = 0; d < 2; d++) { if(N == 4) { use_list.push([a, b, c, d]); } else { for(e = 0; e < 2; e++) { if(N == 5) { use_list.push([a, b, c, d, e]); } else { for(f = 0; f < 2; f++) { if(N == 6) { use_list.push([a, b, c, d, e, f]); } else { for(g = 0; g < 2; g++) { if(N == 7) { use_list.push([a, b, c, d, e, f, g]); } else { for(h = 0; h < 2; h++) { if(N == 8) { use_list.push([a, b, c, d, e, f, g, h]); } else { for(i = 0; i < 2; i++) { if(N == 9) { use_list.push([a, b, c, d, e, f, g, h, i]); } else { for(j = 0; j < 2; j++) { if(N == 10) { use_list.push([a, b, c, d, e, f, g, h, i, j]); } } } } } } } } } } } } } } } } } } } } //使う使わないリストから、人月を満たせる組み合わせで最安を探す ans = 0; len = use_list[0].length; for(i = 0; i < N; i++)ans += QR[i][1]; for(i = 0; i < use_list.length; i++) { cost = 0; ningetsu = 0; for(j = 0; j < len; j++) { if(use_list[i][j] == 1) { ningetsu += QR[j][0]; cost += QR[j][1]; } } if(ningetsu >= M && ans > cost) { ans = cost; } } console.log(ans + "\n"); }
■Java
import java.util.Scanner; import java.util.List; import java.util.ArrayList; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int m = scanner.nextInt(); int n = scanner.nextInt(); int[] q = new int[n]; int[] r = new int[n]; for (int i=0; i<n; i++) { q[i] = scanner.nextInt(); r[i] = scanner.nextInt(); } // m社のうちi番目の会社を使うか使わないかの表を作る // 3社とかなら // A, B, C // 1, 1, 1 // 1, 1, 0 // 1, 0, 1 // .....続く... // みたいな1を使う0は使わないの表を作る List<List<Integer>> use_list = new ArrayList<List<Integer>>(); for (int a=0; a<2; a++) { if (n == 1) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); use_list.add(tmp); } else { for (int b=0; b<2; b++) { if (n == 2) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); use_list.add(tmp); } else { for (int c=0; c<2; c++) { if (n == 3) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); use_list.add(tmp); } else { for (int d=0; d<2; d++) { if (n == 4) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); use_list.add(tmp); } else { for (int e=0; e<2; e++) { if (n == 5) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); use_list.add(tmp); } else { for (int f=0; f<2; f++) { if (n == 6) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); tmp.add(f); use_list.add(tmp); } else { for (int g=0; g<2; g++) { if (n == 7) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); tmp.add(f); tmp.add(g); use_list.add(tmp); } else { for (int h=0; h<2; h++) { if (n == 8) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); tmp.add(f); tmp.add(g); tmp.add(h); use_list.add(tmp); } else { for (int i=0; i<2; i++) { if (n == 9) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); tmp.add(f); tmp.add(g); tmp.add(h); tmp.add(i); use_list.add(tmp); } else { for (int j=0; j<2; j++) { if (n == 10) { List<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); tmp.add(d); tmp.add(e); tmp.add(f); tmp.add(g); tmp.add(h); tmp.add(i); tmp.add(j); use_list.add(tmp); } } } } } } } } } } } } } } } } } } } } // 使う使わないリストから、人月を満たせる組み合わせで最安を探す int ans = 0; for (int i=0; i<n; i++) { ans += r[i]; } for (int i=0; i<use_list.size(); i++) { int cost = 0; int ningetsu = 0; for (int j=0; j<use_list.get(i).size(); j++) { if (use_list.get(i).get(j) == 1) { ningetsu += q[j]; cost += r[j]; } } if (ningetsu >= m && ans > cost) { ans = cost; } } System.out.println(ans); } }
■C#
using System; using System.IO; using System.Text; using System.Linq; using System.Collections; using System.Diagnostics; using System.Collections.Generic; public class ClassName { public static void Main() { int m = int.Parse(Console.ReadLine()); int n = int.Parse(Console.ReadLine()); List<int[]> qr = new List<int[]>(); for (int i = 0; i < n; i++) { string line = Console.ReadLine(); string[] tmp = line.Split(' '); qr.Add(new int[] { int.Parse(tmp[0]), int.Parse(tmp[1]) }); } //m社のうちi番目の会社を使うか使わないかの表を作る //3社とかなら // A, B, C // 1, 1, 1 // 1, 1, 0 // 1, 0, 1 //.....続く... //みたいな1を使う0は使わないの表を作る List<int[]> use_list = new List<int[]>(); for (int a = 0; a < 2; a++) { if (n == 1) { use_list.Add(new int[] { a }); } else { for (int b = 0; b < 2; b++) { if (n == 2) { use_list.Add(new int[] { a, b }); } else { for (int c = 0; c < 2; c++) { if (n == 3) { use_list.Add(new int[] { a, b, c }); } else { for (int d = 0; d < 2; d++) { if (n == 4) { use_list.Add(new int[] { a, b, c, d }); } else { for (int e = 0; e < 2; e++) { if (n == 5) { use_list.Add(new int[] { a, b, c, d, e }); } else { for (int f = 0; f < 2; f++) { if (n == 6) { use_list.Add(new int[] { a, b, c, d, e, f }); } else { for (int g = 0; g < 2; g++) { if (n == 7) { use_list.Add(new int[] { a, b, c, d, e, f, g }); } else { for (int h = 0; h < 2; h++) { if (n == 8) { use_list.Add(new int[] { a, b, c, d, e, f, g, h }); } else { for (int i = 0; i < 2; i++) { if (n == 9) { use_list.Add(new int[] { a, b, c, d, e, f, g, h, i }); } else { for (int j = 0; j < 2; j++) { if (n == 10) { use_list.Add(new int[] { a, b, c, d, e, f, g, h, i, j }); } } } } } } } } } } } } } } } } } } } } //使う使わないリストから、人月を満たせる組み合わせで最安を探す int ans = 0; for (int i = 0; i < qr.Count; i++) { ans += qr[i][1]; } for (int i = 0; i < use_list.Count; i++) { int cost = 0; int ningetsu = 0; for (int j = 0; j < use_list[i].Length; j++) { if (use_list[i][j] == 1) { ningetsu += qr[j][0]; cost += qr[j][1]; } } if (ningetsu >= m && ans > cost) { ans = cost; } } Console.WriteLine(ans); } }
■C言語
視界に入りきりませんね(笑)
#include <stdio.h> int main(){ int m;int n; int cost;int ningetsu; int ans; int a,b,c,d,e,f,g,h,i,j; int cnt; char str[128]; int qr[10][2]; int use_list[1<<10][10]; scanf("%d%d",&m,&n); for (int i = 0; i < n; i++){ scanf("%d%d", &qr[i][0], &qr[i][1]); } //m社のうちi番目の会社を使うか使わないかの表を作る //3社とかなら // A, B, C // 1, 1, 1 // 1, 1, 0 // 1, 0, 1 //.....続く... //みたいな1を使う0は使わないの表を作る cnt = 0; for (a = 0; a < 2; a++){ if (n == 1){ use_list[cnt++][0] = a; }else{ for (b = 0; b < 2; b++){ if (n == 2){ use_list[cnt][0] = a; use_list[cnt++][1] = b; } else{ for (c = 0; c < 2; c++){ if (n == 3){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt++][2] = c; }else{ for (d = 0; d < 2; d++){ if (n == 4){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt++][3] = d; }else{ for (e = 0; e < 2; e++){ if (n == 5){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt++][4] = e; }else{ for (f = 0; f < 2; f++){ if (n == 6){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt++][5] = f; }else{ for (g = 0; g < 2; g++){ if (n == 7){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt++][6] = g; }else{ for (h = 0; h < 2; h++){ if (n == 8){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt++][7] = h; }else{ for (i = 0; i < 2; i++){ if (n == 9){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt][7] = h; use_list[cnt++][8] = i; }else{ for (j = 0; j < 2; j++){ if (n == 10){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt][7] = h; use_list[cnt][8] = i; use_list[cnt++][9] = j; } } } } } } } } } } } } } } } } } } } } //使う使わないリストから、人月を満たせる組み合わせで最安を探す ans = 0; for (int i = 0; i < n; i++){ ans += qr[i][1]; } for (int i = 0; i < cnt; i++){ cost = 0; ningetsu = 0; for (int j = 0; j < n; j++){ if (use_list[i][j] == 1){ ningetsu += qr[j][0]; cost += qr[j][1]; } } if (ningetsu >= m && ans > cost){ ans = cost; } } sprintf(str,"%d",ans); printf("%s\n",str); }
■C++
塊り感が凄い!
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int M, N; cin >> M >> N; vector<int> qs(N), rs(N); for(int i = 0; i < N; i++) { cin >> qs[i] >> rs[i]; } //m社のうちi番目の会社を使うか使わないかの表を作る //3社とかなら // A, B, C // 1, 1, 1 // 1, 1, 0 // 1, 0, 1 //.....続く... //みたいな1を使う0は使わないの表を作る vector< vector<int> > use_list (pow(2,N), vector<int>(N) ); int cnt = 0; for (int a = 0; a < 2; a++){ if (N == 1){ use_list[cnt++][0] = a; }else{ for (int b = 0; b < 2; b++){ if (N == 2){ use_list[cnt][0] = a; use_list[cnt++][1] = b; } else{ for (int c = 0; c < 2; c++){ if (N == 3){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt++][2] = c; }else{ for (int d = 0; d < 2; d++){ if (N == 4){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt++][3] = d; }else{ for (int e = 0; e < 2; e++){ if (N == 5){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt++][4] = e; }else{ for (int f = 0; f < 2; f++){ if (N == 6){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt++][5] = f; }else{ for (int g = 0; g < 2; g++){ if (N == 7){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt++][6] = g; }else{ for (int h = 0; h < 2; h++){ if (N == 8){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt++][7] = h; }else{ for (int i = 0; i < 2; i++){ if (N == 9){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt][7] = h; use_list[cnt++][8] = i; }else{ for (int j = 0; j < 2; j++){ if (N == 10){ use_list[cnt][0] = a; use_list[cnt][1] = b; use_list[cnt][2] = c; use_list[cnt][3] = d; use_list[cnt][4] = e; use_list[cnt][5] = f; use_list[cnt][6] = g; use_list[cnt][7] = h; use_list[cnt][8] = i; use_list[cnt++][9] = j; } } } } } } } } } } } } } } } } } } } } //使う使わないリストから、人月を満たせる組み合わせで最安を探す int ans = 0; for (int i = 0; i < N; i++){ ans += rs[i]; } int ningetsu = 0; int cost = 0; for (int i = 0; i < cnt; i++){ cost = 0; ningetsu = 0; for (int j = 0; j < N; j++){ if (use_list[i][j] == 1){ ningetsu += qs[j]; cost += rs[j]; } } if (ningetsu >= M && ans > cost){ ans = cost; } } cout << ans << endl; }
■Python
#coding:utf-8 if __name__ == "__main__": m = input() n = input() qr = [] for i in range(n): tmp = raw_input().split() qr.append([int(tmp[0]), int(tmp[1])]) #m社のうちi番目の会社を使うか使わないかの表を作る #3社とかなら # A, B, C # 1, 1, 1 # 1, 1, 0 # 1, 0, 1 #.....続く... #みたいな1を使う0は使わないの表を作る use_list = [] for a in range(2): if n == 1: use_list.append([a]) else: for b in range(2): if n == 2: use_list.append([a, b]) else: for c in range(2): if n == 3: use_list.append([a, b, c]) else: for d in range(2): if n == 4: use_list.append([a, b, c, d]) else: for e in range(2): if n == 5: use_list.append([a, b, c, d, e]) else: for f in range(2): if n == 6: use_list.append([a, b, c, d, e, f]) else: for g in range(2): if n == 7: use_list.append([a, b, c, d, e, f, g]) else: for h in range(2): if n == 8: use_list.append([a, b, c, d, e, f, g, h]) else: for i in range(2): if n == 9: use_list.append([a, b, c, d, e, f, g, h, i]) else: for j in range(2): if n == 10: use_list.append([a, b, c, d, e, f, g, h, i, j]) #使う使わないリストから、人月を満たせる組み合わせで最安を探す ans = sum([i[1] for i in qr]) for i in use_list: cost = 0 ningetsu = 0 for j, v in enumerate(i): if v == 1: ningetsu += qr[j][0] cost += qr[j][1] if ningetsu >= m and ans > cost: ans = cost print ans
■まとめ
いかがだったでしょうか。Rubyが一番美しいかったように思いますが、C、C++の塊り感も捨てがたくあります。一方でPythonはダメですね、直角三角形になっていて美しくない。。今回は10社の組み合せまでのコードでしたが、この書き方でPOH Liteの条件どおり50社まで対応するコードにするとしたら恐ろしいですね。。ただ、今回のオンラインハッカソンに対するコメント等を拝見していると、現実社会でも有りえるコードなのかもしれませんが。。。
皆さんはこういうコード書かないように気を付けましょう、という事で。
POH Lite 天才火消しエンジニア霧島 もしPMおじさんが『丸投げ』を覚えたら
paizaは、技術を追い続けることが仕事につながり、スキルのある人がきちんと評価される場を作ることで、日本のITエンジニアの地位向上を目指したいと考えています。
「paiza転職」は、自分のプログラミング力が他社で通用するか(こっそり)腕試しができる、IT/Webエンジニアのための転職サービスです。プログラミングスキルチェック(コーディングのテスト)を受けて、スコアが一定基準を超えれば、書類選考なしで複数の会社へ応募ができます。
まずはスキルチェックだけ、という使い方もできます。すぐには転職を考えていない方でも、自分のプログラミングスキルを客観的に知ることができますので、興味がある方はぜひ一度ご覧ください。
また、paiza転職をご利用いただいている企業の人事担当や、paiza転職を使って転職を成功した方々へのインタビューもございます。こちらもぜひチェックしてみてください。
詳しくはこちら