Mercurial > hgrepos > hgweb.cgi > skipweb
changeset 2289:a44da64f54e0
chusen.rb added
author | FUJIKAWA Kosuke <c111126@g.koeki-u.ac.jp> |
---|---|
date | Wed, 23 Jul 2014 15:23:35 +0900 |
parents | 8b9018495e6b |
children | bd675bc7adcf |
files | minato2014/chusen.rb |
diffstat | 1 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/minato2014/chusen.rb Wed Jul 23 15:23:35 2014 +0900 @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- + +require 'sqlite3' +require 'cgi' + +c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8") +db = SQLite3::Database.new("sql/stamp.sq3") + +begin + result = db.execute("select id,exp,rank from main;") +rescue + exit +end + +all = Array.new +for id,lv,rank in result + if id == "ID" || lv == 0 || rank.to_i != 0 + next + end + lv.to_i.times do + all << id + end +end + +tousen = Array.new(0) +atari1 = rand(all.length) +tousen << all[atari1] +all.delete_if {|x| x == tousen[0]} + +sql = "update main set rank = 1 where id = ?;" +db.execute(sql,tousen[0]) + +sql = "update main set rank = 2 where id = ?;" +while tousen.length < 4 + srand + atari2 = rand(all.length) + hoge = all[atari2] + tousen << all[atari2] + all.delete_if {|x| x == hoge} + db.execute(sql,hoge) +end + +i=0 +printf("Content-type: text/html; charset=UTF-8\n\n") + +printf("<p>1等はIDが%04dの方!おめでとー!</p>\n",tousen[i].to_i) +printf("<p>2等はIDが%04dと%04dと%04dの方!おめでとー!</p>\n",tousen[i+=1].to_i,tousen[i+=1].to_i,tousen[i+=1].to_i) +