I Exercise on Programming I http://bit.ly/oitprog1 1, 2 of 14 ( RD S ) I 1, 2 of 14 1 / 44
Ruby Ruby ( RD S ) I 1, 2 of 14 2 / 44
7 5 9 2 9 3 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 ( RD S ) I 1, 2 of 14 3 / 44
3 q q = 7 5 9 2 9 3 1, 2,, 9 3 2 6 5 1 3 2 5 6 4 7 8 4 5 2 7 9 6 4 7 1 3 1 q 2 q q 3 q 1 9 q 1, q 2,, q 9 q i ( RD S ) I 1, 2 of 14 4 / 44
solvesdk q = if chksdk q == False then [] else if zp == 81 then q (81) q else concat (map (\i -> let q' = (take zp q) ++ [i] ++ drop (zp + 1) q in solvesdk q') [1..9]) where zp = index q 0 q q ( RD S ) I 1, 2 of 14 5 / 44
( Haskell) q0 = [7, 0, 0, 0, 0, 5, 9, 0, 0, 0, 2, 0, 0, 9, 0, 0, 3, 0, 0, 0, 3, 2, 0, 6, 0, 0, 5, 1, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 7, 8, 4, 0, 0, 5, 0, 2, 7, 0, 0, 0, 9, 0, 0, 6, 0, 0, 4, 0, 0, 0, 7, 1, 0, 0, 0, 0, 3] main = mapm_ (\i -> print (take 9 (drop i ans))) [0,9..72] where ans = solvesdk q0 chkdup a = foldl (&&) True (map (\i -> length (filter (== i) a) <= 1) [1..9]) chksdk x = foldl (&&) True (map (\i -> chkdup (take 9 (drop i x))) [0,9..72]) && foldl (&&) True (map (\i -> chkdup (map (\j -> x!!(i + j)) [0,9..72])) [0..8]) && foldl (&&) True (map (\i -> chkdup (map (\j -> x!!(i + j)) box)) tl) where box = [0, 1, 2, 9, 10, 11, 18, 19, 20] tl = [0, 3, 6, 27, 30, 33, 54, 57, 60] index [] _ = 0 index (x:xs) tgt = if x == tgt then 0 else 1 + index xs tgt -- solvesdk q = if chksdk q == False then [] else if zp == 81 then q else concat (map (\i -> let q' = (take zp q) ++ [i] ++ drop (zp + 1) q in solvesdk q') [1..9]) where zp = index q 0 ( RD S ) I 1, 2 of 14 6 / 44
( Ruby) 14 q0 = [7, 0, 0, 0, 0, 5, 9, 0, 0, 0, 2, 0, 0, 9, 0, 0, 3, 0, 0, 0, 3, 2, 0, 6, 0, 0, 5, 1, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 0, 0, 4, 0, 0, 0, 0, 7, 8, 4, 0, 0, 5, 0, 2, 7, 0, 0, 0, 9, 0, 0, 6, 0, 0, 4, 0, 0, 0, 7, 1, 0, 0, 0, 0, 3, ] def chk9(ary) # dup test (1 line) (1..9).inject(true) { a, i ary.count(i) > 1? false : a } end def chk_all(ary) # dup test (all) 9.times { i return false unless chk9(ary[i*9,9]) return false unless chk9((0..8).map{ j ary[i + j * 9] }) } [0,3,6,27,30,33,54,57,60].each { i return false unless chk9( ary[i,3] + ary[i+9,3] + ary[i+18,3] ) } true end def solve_sdk(q) return nil unless chk_all(q) return q unless tgt = q.index(0) ans = nil (1..9).each { i q[tgt] = i return ans if ans = solve_sdk(q) } q[tgt] = 0 nil end ans = solve_sdk(q0) 9.times { i p ans[i * 9, 9] } ( RD S ) I 1, 2 of 14 7 / 44
=3 / ( =2, =0 ) =3 / ( 1 3 ) =16 :, ( ),,, ( ),, ( RD S ) I 1, 2 of 14 8 / 44
Wi-Fi ssh ( RD S ) I 1, 2 of 14 9 / 44
edu1 edu2 edu3 PC ( RD S ) I 1, 2 of 14 10 / 44
Wi-Fi Windows macos Wi-Fi OIT-AirLAN.1x ID e1 ( : e1x19123) OIT-AirLAN.1x OIT-AirLAN ( RD S ) I 1, 2 of 14 11 / 44
ssh Windows mac, Linux Windows https://gitforwindows.org [Download] ( RD S ) I 1, 2 of 14 12 / 44
( RD S ) I 1, 2 of 14 13 / 44
0 + 1 +... + 9 in C #include <stdio.h> int main() { int sum; int i; for (i = 0, sum = 0; i < 10; i++) { sum = sum + i; } printf("%d\n", sum); return 0; } ( RD S ) I 1, 2 of 14 14 / 44
0 + 1 +... + 9 in Java public class Sum { public static void main(string[] args) { int i; int sum; for (i = 0, sum = 0; i < 10; i++) { sum = sum + i; } System.out.println(sum); } } ( RD S ) I 1, 2 of 14 15 / 44
0 + 1 +... + 9 in JavaScript let sum = 0 for (let i = 0; i < 10; i++) { sum = sum + i } console.log(sum) ( RD S ) I 1, 2 of 14 16 / 44
0 + 1 +... + 9 in Python sum = 0 for i in range(10): sum = sum + i print(sum) ( RD S ) I 1, 2 of 14 17 / 44
0 + 1 +... + 9 in Ruby sum = 0 (0..9).each { i sum = sum + i } puts sum ( RD S ) I 1, 2 of 14 18 / 44
0 + 1 +... + 9 in Swift var sum = 0 (1...9).forEach{(i) in sum = sum + i } print(sum) ( RD S ) I 1, 2 of 14 19 / 44
0 + 1 +... + 9 in Haskell main = print $ mysum [0..9] mysum [a] = a mysum (car:cdr) = car + mysum cdr ( RD S ) I 1, 2 of 14 20 / 44
0 + 1 +... + 9 in (old) BASIC 10 S=0 20 FOR I=0 TO 9 30 S=S+I 40 NEXT I 50 PRINT S ( RD S ) I 1, 2 of 14 21 / 44
0 + 1 +... + 9 in Scratch ( RD S ) I 1, 2 of 14 22 / 44
classroom (1 of 2) 1 https://classroom.google.com 2 OIT Google OIT ( RD S ) I 1, 2 of 14 23 / 44
classroom (2 of 2) 3 ( 1nmp0c9) ( RD S ) I 1, 2 of 14 24 / 44
(Windows, ) 1 Git Git Bash 2 ( ) ($ ) $ ssh e1w19???@edu1.rd.oit.ac.jp $ ssh e1x19???@edu2.rd.oit.ac.jp $ ssh e1919???@edu3.rd.oit.ac.jp 3 (yes/no) yes 4 ( ) ( RD S ) I 1, 2 of 14 25 / 44
(macos, ) 1 Launcher 2 ( ) (mac $ ) mac: someone$ ssh e1w19???@edu1.rd.oit.ac.jp mac: someone$ ssh e1x19???@edu2.rd.oit.ac.jp mac: someone$ ssh e1919???@edu3.rd.oit.ac.jp 3 (yes/no) yes 4 ( ) ( RD S ) I 1, 2 of 14 26 / 44
(, ) Windows/macOS 1 URL https://edu2.rd.oit.ac.jp:3000 https://edu2.rd.oit.ac.jp:3001 https://edu2.rd.oit.ac.jp:3002 https://edu2.rd.oit.ac.jp:3003 https://edu3.rd.oit.ac.jp:3000 https://edu3.rd.oit.ac.jp:3001 https://edu3.rd.oit.ac.jp:3002 https://edu3.rd.oit.ac.jp:3003 2 (e1w1???? ) ( RD S ) I 1, 2 of 14 27 / 44
( ) logout logout ( exit ) ( RD S ) I 1, 2 of 14 28 / 44
1 Windows Git Bash 1 ( RD S ) I 1, 2 of 14 29 / 44
UNIX cal edu2: e1x19999$ cal 4 2019 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 cal 2020 cal 9 1752 cal edu2: e1x19999$ w date pi 1000 ( RD S ) I 1, 2 of 14 30 / 44
: program me 1. 2. 3. program(me) counter ( RD S ) I 1, 2 of 14 31 / 44
program (source code) editor 1 2 3 ( RD S ) I 1, 2 of 14 32 / 44
Ruby 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 6 end ( ) ( RD S ) I 1, 2 of 14 33 / 44
(editor) nano nano game.rb game.rb.rb ruby ˆX [Control] [X] ( RD S ) I 1, 2 of 14 34 / 44
1 1 buf = [] [] ()( ) {}( ) =( ) ( RD S ) I 1, 2 of 14 35 / 44
2 1 buf 2 while = [] true do while true do ( RD S ) I 1, 2 of 14 36 / 44
3 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 3 2 ( ( ) ) " " ([SHIFT] [2]) *( ) [SHIFT] [L] 2 ( RD S ) I 1, 2 of 14 37 / 44
4, 5 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 3 4 [0] 5 (0.03) ( RD S ) I 1, 2 of 14 38 / 44
6 ( ) 1 buf = [] 2 while true do 3 buf.unshift(" " * rand(40) + "#") 4 puts(buf[0]) 5 sleep(0.03) 6 end 0 ( )end ( RD S ) I 1, 2 of 14 39 / 44
1 ˆX ( [Control]+[X] ) 2 y 3 [Enter] ( [Return]) Y [Enter] ( RD S ) I 1, 2 of 14 40 / 44
ls e1w19999@edu1: $ ls game.rb e1w19999@edu1: $ ls ls list 2 2 ( RD S ) I 1, 2 of 14 41 / 44
Ruby ruby e1w19999@edu1: $ ruby game.rb (!?) ( RD S ) I 1, 2 of 14 42 / 44
Windows [Windows] [Print Screen (Prt Sc)] macos [Shift]+[command] [3] ( ) ( RD S ) I 1, 2 of 14 43 / 44
game.rb Google classroom (https://classroom.google.com) ( RD S ) I 1, 2 of 14 44 / 44