├── .gitignore ├── C ├── Class examples │ ├── 2014-15 │ │ ├── 2015-03-16.c │ │ ├── 2015-03-17.c │ │ ├── 2015-03-23a.c │ │ ├── 2015-03-23b.c │ │ ├── 2015-03-23c.c │ │ ├── 2015-03-23d.c │ │ ├── 2015-03-23e.c │ │ ├── 2015-03-30.c │ │ ├── 2015-03-31a.c │ │ ├── 2015-03-31b.c │ │ ├── 2015-04-05.c │ │ ├── 2015-04-13a.c │ │ ├── 2015-04-13b.c │ │ ├── 2015-04-14.c │ │ ├── 2015-04-20.c │ │ ├── 2015-04-21.c │ │ ├── 2015-04-27a.c │ │ ├── 2015-04-27b.c │ │ ├── 2015-04-28a.c │ │ ├── 2015-04-28b.c │ │ ├── 2015-05-04a.c │ │ ├── 2015-05-04b.c │ │ ├── 2015-05-05.c │ │ ├── 2015-05-11.c │ │ ├── 2015-05-12.c │ │ ├── 2015-05-18a.c │ │ ├── 2015-05-18b.c │ │ ├── 2015-05-18c.c │ │ ├── 2015-05-19.c │ │ ├── 2015-05-25.c │ │ ├── 2015-05-26a.c │ │ ├── 2015-05-26b.c │ │ ├── 2015-05-28a.c │ │ ├── 2015-05-28b.c │ │ ├── 2015-05-28c.c │ │ ├── 2015-06-01.c │ │ ├── 2015-06-08a.c │ │ ├── 2015-06-08b.c │ │ └── 2015-06-08c.c │ ├── 2015-16 │ │ ├── FlowCharts │ │ │ ├── README.md │ │ │ ├── c-like loops.reg │ │ │ ├── equations.rap │ │ │ ├── fibonacci.rap │ │ │ ├── gcd.rap │ │ │ ├── gcd_euclid.rap │ │ │ ├── guess-a-number.rap │ │ │ ├── prime.rap │ │ │ ├── prime_v1.rap │ │ │ └── prime_v2.rap │ │ ├── w03-FirstProgram.c │ │ ├── w04-Bin2Dec.c │ │ ├── w04-Dec2Bin.c │ │ ├── w04-Overflow.c │ │ ├── w04-Sizeof.c │ │ ├── w05-bin2dec.c │ │ ├── w05-dec2bin.c │ │ ├── w05-floats.c │ │ ├── w05-overflow.c │ │ ├── w05-pow.c │ │ ├── w06-array.c │ │ ├── w06-array_for.c │ │ ├── w06-int2bin_array.c │ │ ├── w06-max.c │ │ ├── w06-spare_ops.c │ │ ├── w06-zero.c │ │ ├── w07_double_loop.c │ │ ├── w07_func+arrays.c │ │ ├── w07_func+vars.c │ │ ├── w07_loops.c │ │ ├── w07_my_first_function.c │ │ ├── w07_switch.c │ │ ├── w07_zero.c │ │ ├── w08_eq.c │ │ ├── w08_my-toupper.c │ │ ├── w08_strings1.c │ │ ├── w08_strings2.c │ │ ├── w09-file.c │ │ ├── w09-remove.c │ │ ├── w09-strcmp.c │ │ ├── w09-string-sort.c │ │ ├── w09-super-palindromes.c │ │ ├── w10-calc.c │ │ ├── w10-commandline1.c │ │ ├── w10-exam.c │ │ ├── w10-files.c │ │ ├── w10-help.c │ │ ├── w10-lab.c │ │ ├── w10-myecho.c │ │ ├── w11-struct.c │ │ ├── w11-swamp.c │ │ ├── w12-hiil_cliber.c │ │ ├── w13-filter.c │ │ ├── xxx-Find maximas.c │ │ └── xxx-FindSecondMax.c │ ├── 2016-17 │ │ ├── FlowCharts │ │ │ ├── README.md │ │ │ ├── c-like loops.reg │ │ │ ├── w01-Div7.rap │ │ │ ├── w01-Fibonacci.rap │ │ │ ├── w01-Prime.rap │ │ │ ├── w01_AbbaZabba.rap │ │ │ ├── w02-GCD.rap │ │ │ ├── w02-GCD_smart.rap │ │ │ ├── w02-multTable.rap │ │ │ ├── w02-triangle.rap │ │ │ └── w03-mountains.rap │ │ ├── w03-absolute_value.c │ │ ├── w03-hola_mundo.c │ │ ├── w03-mountains.c │ │ ├── w04-eq2.c │ │ ├── w04-max.c │ │ ├── w05-avg100.c │ │ ├── w05-do_while.c │ │ ├── w05-for.c │ │ ├── w05-if_elseif (dumb).c │ │ ├── w05-if_elseif (smart).c │ │ ├── w05-nested_loop.c │ │ ├── w05-single_loop.c │ │ ├── w05-sizeof.c │ │ ├── w05-switch.c │ │ ├── w05-switch2.c │ │ ├── w05-while.c │ │ ├── w06-array1.c │ │ ├── w06-d2b_1.c │ │ ├── w06-d2b_2.c │ │ ├── w06-hack.c │ │ ├── w06-ovrflow.c │ │ ├── w06_b2d_1.c │ │ ├── w06_b2d_2.c │ │ ├── w07-arrays_0.c │ │ ├── w07-arrays_1.c │ │ ├── w07-const.c │ │ ├── w07-flag_1.c │ │ ├── w07-flag_2.c │ │ ├── w07-input_1.c │ │ ├── w07-input_2.c │ │ ├── w08-arrays-func.c │ │ ├── w08-dups.c │ │ ├── w08-functions_1.c │ │ ├── w08-functions_2.c │ │ ├── w08-top_down.c │ │ ├── w08-utils.c │ │ ├── w09-chars.c │ │ ├── w09-chars_v2.c │ │ ├── w09-chars_v3.c │ │ ├── w09-coding.c │ │ ├── w09-months.c │ │ ├── w09-months_alt.c │ │ ├── w09-strcat.c │ │ ├── w09-strings_madness.c │ │ ├── w09-strings_v1.c │ │ ├── w09-strings_v2.c │ │ ├── w09-strings_v3.c │ │ ├── w10-2d_array.c │ │ ├── w10-Arrays_of_Strings-1.c │ │ ├── w10-Arrays_of_Strings-2.c │ │ ├── w10-calculator.c │ │ ├── w10-old_friends.c │ │ ├── w10-old_friends_alt.c │ │ ├── w11-struct.c │ │ ├── w11-struct_1.c │ │ ├── w11-struct_2.c │ │ ├── w11-struct_read.c │ │ ├── w11-struct_rite.c │ │ ├── w12-dopie.c │ │ ├── w13-difftime.c │ │ ├── w13-map.c │ │ ├── w14-exam_1.c │ │ ├── w14-exam_2.c │ │ ├── w14-exam_islands.c │ │ ├── w14-exam_numbers.c │ │ └── w14-exam_satellites.c │ ├── 2017-18 │ │ ├── 2017-10-10_my-first-program.c │ │ ├── 2017-10-16_42.c │ │ ├── 2017-10-17_while.c │ │ ├── 2017-10-23A_loops.c │ │ ├── 2017-10-23B_switch.c │ │ ├── 2017-10-23C_loops.c │ │ ├── 2017-10-23D_nested-loops.c │ │ ├── 2017-10-24A_do-while.c │ │ ├── 2017-10-24B_continue.c │ │ ├── 2017-10-24C_primes.c │ │ ├── 2017-10-24D_fibonacci.c │ │ ├── 2017-10-25A_equations.c │ │ ├── 2017-10-25B_equations2.c │ │ ├── 2017-10-25C_if-elseif.c │ │ ├── 2017-10-30A_printf.c │ │ ├── 2017-10-30B_pi.c │ │ ├── 2017-10-30C_loops.c │ │ ├── 2017-10-30D_loops.c │ │ ├── 2017-10-30_E_arrays.c │ │ ├── 2017-10-30_F_arrays.c │ │ ├── 2017-10-31A_arrays.c │ │ ├── 2017-10-31B_arrays.c │ │ ├── 2017-10-31C_primes+arrays.c │ │ ├── 2017-10-31D_slang.c │ │ ├── 2017-11-06_pre-post.c │ │ ├── 2017-11-06_random1.c │ │ ├── 2017-11-07_randint.c │ │ ├── 2017-11-07_random.c │ │ ├── 2017-11-07_subseq.c │ │ ├── 2017-11-13_bits.c │ │ ├── 2017-11-13_counting.c │ │ ├── 2017-11-13_duplicated.c │ │ ├── 2017-11-14_bin2smc │ │ ├── 2017-11-14_dec2bin.c │ │ ├── 2017-11-20_array-sum.c │ │ ├── 2017-11-20_arrayswap.c │ │ ├── 2017-11-20_functions.c │ │ ├── 2017-11-20_sort-bubble.c │ │ ├── 2017-11-20_sort-selection.c │ │ ├── 2017-11-20_toupper.c │ │ ├── 2017-11-21_functions+arrays_1.c │ │ ├── 2017-11-21_functions+arrays_2.c │ │ ├── 2017-11-21_functions.c │ │ ├── 2017-11-22_functions+arrays_1.c │ │ ├── 2017-11-22_functions+arrays_2.c │ │ ├── 2017-11-27_char-io.c │ │ ├── 2017-11-27_codepages.c │ │ ├── 2017-11-27_strings.c │ │ ├── 2017-11-27_strings_intro.c │ │ ├── 2017-11-27_word-count.c │ │ ├── 2017-11-28_palindromes.c │ │ ├── 2017-11-28_strings.c │ │ ├── 2017-12-04_argc.c │ │ ├── 2017-12-04_array1.c │ │ ├── 2017-12-04_convert.c │ │ ├── 2017-12-04_matrix2.c │ │ ├── 2017-12-04_trans.c │ │ ├── 2017-12-05_calc.c │ │ ├── 2017-12-05_friends.c │ │ ├── 2017-12-05_more-args.c │ │ ├── 2017-12-17_file1.c │ │ ├── 2017-12-17_file2.c │ │ ├── 2017-12-17_file_in.gx │ │ ├── 2017-12-17_myfile.gx │ │ ├── 2017-12-18_feof.c │ │ ├── 2017-12-18_files1.c │ │ ├── 2017-12-18_files2.c │ │ ├── 2017-12-18_myfile.gx │ │ ├── 2017-12-19_feof_problems.c │ │ ├── 2017-12-19_feof_problems.gx │ │ ├── 2017-12-19_file-feof.c │ │ ├── 2017-12-19_islands.c │ │ ├── 2017-12-19_map.c │ │ ├── 2017-12-19_map.dat │ │ ├── 2017-12-19_terribe_feof.gx │ │ ├── 2017-12-file_in.gx │ │ ├── 2017-12-file_out.gx │ │ ├── 2018-01-09_struct2.c │ │ ├── 2018-01-09_typedef.c │ │ ├── 2018-01-10_es_extras.c │ │ ├── 2018-01-10_es_struct.c │ │ ├── 2018-01-10_es_typedef.c │ │ ├── 2018-01-14_bus.dat │ │ ├── 2018-01-14_exam-buses.c │ │ ├── 2018-01-14_exam-matrix.c │ │ ├── 2018-01-14_map.dat │ │ └── 2018-01-14_mat1.dat │ ├── 2018-19 │ │ ├── w03_ex01.c │ │ ├── w03_ex02-loops.c │ │ ├── w03_ex03-primes1.c │ │ ├── w03_ex04-primes2.c │ │ ├── w03_ex05-eq.c │ │ ├── w03_ex06-eq2.c │ │ ├── w03_ex07-fibo.c │ │ ├── w03_ex08-data.c │ │ ├── w04-0_printf.c │ │ ├── w04-1_ascii.c │ │ ├── w04-2_switch.c │ │ ├── w04-3_c2f.c │ │ ├── w04-4_switch-and-if.c │ │ ├── w04-5_while.c │ │ ├── w04-6_print.c │ │ ├── w04-8_avg2.c │ │ ├── w04-8_for.c │ │ ├── w04_9-for2.c │ │ ├── w05_1-array-copy.c │ │ ├── w05_2-array-minmax.c │ │ ├── w06-1_array.c │ │ ├── w06-2_float-arrays.c │ │ ├── w06-3_bin2dec.c │ │ ├── w06-4_bin2dec2.c │ │ ├── w06-5_overflow.c │ │ ├── w06-6_pow.c │ │ ├── w07-7_overflow.c │ │ ├── w07-8_bitwise.c │ │ ├── w08-01_char.c │ │ ├── w08-02_function.c │ │ ├── w08-03_hex.c │ │ ├── w09-1_math.c │ │ ├── w09-2_chario.c │ │ ├── w09-3_eof.c │ │ ├── w09-4_strings.c │ │ ├── w09-5_arrayfunc.c │ │ ├── w09_4-chars.c │ │ ├── w10-01_str-functions.c │ │ ├── w10-02_conversion.c │ │ ├── w10-03_date.c │ │ ├── w10-04_strcpies.c │ │ ├── w10-05_pointers.c │ │ ├── w10-06_mdarrays.c │ │ ├── w10-07_table.c │ │ ├── w10-08_friends.c │ │ ├── w11-1_strstr.c │ │ ├── w11-2_133t.c │ │ ├── w11-3_sort.c │ │ ├── w11-4_anagram.c │ │ ├── w11-5_palindrome.c │ │ ├── w12-1-points.c │ │ ├── w12-2_file1.c │ │ ├── w13-1_strings.c │ │ ├── w13-2_strings2.c │ │ ├── w13-3_island.c │ │ ├── w13-4_calc.c │ │ ├── w13-5_copy.c │ │ ├── w14-1_size.c │ │ ├── w14-2_exam1.c │ │ ├── w14-3_histogram.c │ │ ├── w14-4_pickwick.c │ │ ├── w15-1_rtn.c │ │ ├── w15-2_ltp.c │ │ ├── w15-3_empl.c │ │ └── w15-4_museum.c │ └── 2019-20 │ │ ├── w03-00-Whoa.c │ │ ├── w03-01-printf.c │ │ ├── w03-02_numbers.c │ │ ├── w03-03_scanf.c │ │ ├── w03-04_f2c.c │ │ ├── w03-05_scanf-problems.c │ │ ├── w03-06_if.c │ │ ├── w03-07_f2c+c2f.c │ │ ├── w03-08_if.c │ │ ├── w03-09_equation.c │ │ ├── w03-10_loop.c │ │ ├── w04-01_basic-loop.c │ │ ├── w04-02_square.c │ │ ├── w04-03_inv-triangle.c │ │ ├── w04-03_triangle.c │ │ ├── w04-04_guess.c │ │ ├── w04-05_guess2.c │ │ ├── w04-06_ptable.c │ │ ├── w04-07_prime.c │ │ ├── w04-08_primes.c │ │ ├── w04-09_define.c │ │ ├── w04-10_printf.c │ │ ├── w04-11_zero.c │ │ ├── w05-01_pre-post.c │ │ ├── w05-02_arrays.c │ │ ├── w05-03_array.c │ │ ├── w05-04_flag.c │ │ ├── w05-05_array-eq.c │ │ ├── w06-01_arrays.c │ │ ├── w06-02_array-init.c │ │ ├── w06-03_delete-element.c │ │ ├── w06-04_delete-element_2.c │ │ ├── w06-05_dec2bin.c │ │ ├── w06-06_bin2dec.c │ │ ├── w06-07_bin2dec_2.c │ │ ├── w06-08_constants.c │ │ ├── w06-09_dec2gen.c │ │ ├── w08-01_overflow.c │ │ ├── w08-02_arrays+functions.c │ │ ├── w08-02_functions.c │ │ ├── w08-03_by-value.c │ │ ├── w08-04_multidim.c │ │ ├── w09-01_codepages.c │ │ ├── w09-02_strings+char.c │ │ ├── w09-03_functions.c │ │ ├── w09-04_arrays.c │ │ ├── w09-05_strings.c │ │ ├── w10-01_typedef.c │ │ ├── w10-02_str-funcs.c │ │ ├── w10-03_conversions.c │ │ ├── w10-04_arrays-of-strings.c │ │ ├── w10-05_cmdline.c │ │ ├── w11-01_2darrays.c │ │ ├── w11-02_argc-argv.c │ │ ├── w11-03_calc.c │ │ ├── w11-04_sort.c │ │ ├── w11-05_palindrom.c │ │ ├── w11-06_palindrome2.c │ │ ├── w11-07_struct.c │ │ ├── w11-09_files2.c │ │ ├── w12-01_files.c │ │ ├── w12-01_files_friends.txt │ │ ├── w12-02_anagrams.c │ │ ├── w12-03_billy-idol.c │ │ ├── w12-03_billy-idol_band.txt │ │ ├── w12-04_billy-idol-and-friends.c │ │ ├── w12-04_billy-idol-and-friends_band.txt │ │ ├── w12-05_padding.c │ │ ├── w13-01_ptr.c │ │ ├── w13-02_exam-20190621.c │ │ ├── w13-02_exam-20190621_28dec.txt │ │ ├── w13-02_exam-20190621_dat1.txt │ │ ├── w14-01_rolling.c │ │ ├── w14-02_exam20190216.c │ │ ├── w14-02_exam20190216_requests.txt │ │ ├── w14-02_exam20190216_warehouse.txt │ │ ├── w14-03_exam20190215.c │ │ ├── w14-03_exam20190215_catalog.txt │ │ └── w14-03_exam20190215_versions_sw.txt ├── Exams │ ├── 00-Cheatsheet.pdf │ ├── 20110701-A.pdf │ ├── 20110722-B.pdf │ ├── 20110919-A.pdf │ ├── 20120301.pdf │ ├── 20120627.pdf │ ├── 20120627_sol.c │ ├── 201209_sol.c │ ├── 20130204.pdf │ ├── 20130705-A+B.pdf │ ├── 20130705-A_sol.c │ ├── 20130705-B_sol.c │ ├── 20130719-A+B.pdf │ ├── 20130719-A.pdf │ ├── 20140109-A+C.pdf │ ├── 20140109-A.pdf │ ├── 20140120-A.pdf │ ├── 20140623-C.pdf │ ├── 20140707-A.pdf │ ├── 20140707-B.pdf │ ├── 20140719-B_sol.c │ ├── 20150224-B.pdf │ ├── 20150224-C+B.pdf │ ├── 20150622-A.pdf │ ├── 20150622-B.pdf │ ├── 20150622-B_sol.c │ ├── 20160218-C.pdf │ ├── 201606-A.dat │ ├── 201606-A_sol.c │ ├── 201606-B_calls.dat │ ├── 201606-B_rates.dat │ ├── 201606-B_sol.c │ ├── 201609-A_Image.dat │ ├── 201609-A_Kernel.dat │ ├── 201609-A_Kernel2.dat │ ├── 201609-A_sol.c │ ├── 201609-B_Results.txt │ ├── 201609-B_sol.c │ ├── 20170203-C.pdf │ ├── 20170203-C_limits.txt │ ├── 20170203-C_measures.txt │ ├── 20170203-C_sol.c │ ├── 20170217-B.pdf │ ├── 20180202-A.pdf │ ├── 20180202-B.pdf │ ├── 20180216-C.pdf │ ├── 20180216-D.pdf │ ├── 20180622-A.pdf │ ├── 20180622-A_burton.txt │ ├── 20180622-A_primo.txt │ ├── 20180622-A_secondo.txt │ ├── 20180622-A_sol.c │ ├── 20180914-B.pdf │ ├── 20180914-B_hotels.dat │ ├── 20180914-B_sol.c │ ├── 20190201-A.pdf │ ├── 20190201-B.pdf │ ├── 20190201-B_fares.txt │ ├── 20190201-B_sol.c │ ├── 20190215-C.pdf │ ├── 20190215-C_catalog.txt │ ├── 20190215-C_sol.c │ ├── 20190215_versions.txt │ ├── 20190216-D.pdf │ ├── 20190621-B.pdf │ ├── 20200131-C.c │ ├── 20200131-C.pdf │ ├── 20200131-C1.c │ ├── 20200131-C_map1.dat │ ├── 20200131-C_orders.dat │ ├── 20200214-A-pat.dat │ ├── 20200214-A-seq.dat │ ├── 20200214-A.pdf │ └── 20200214-A_sol.c └── IDE.md ├── LICENSE.md ├── Python ├── README.md ├── exams │ ├── _imported │ │ ├── README.md │ │ ├── astrologia_calciatori │ │ │ ├── README.md │ │ │ ├── sportivi.csv │ │ │ └── zodiaco.csv │ │ ├── bowling │ │ │ ├── README.md │ │ │ └── bowling.txt │ │ ├── discografia │ │ │ ├── README.md │ │ │ ├── acdc.txt │ │ │ ├── artists.txt │ │ │ ├── kiss.txt │ │ │ └── queen.txt │ │ ├── fantacalcio │ │ │ ├── README.md │ │ │ └── fantafoot.txt │ │ ├── ginnastica_artistica │ │ │ ├── README.md │ │ │ └── scores.txt │ │ ├── glucometer │ │ │ ├── README.md │ │ │ └── glucometers.txt │ │ ├── guess_who │ │ │ ├── README.md │ │ │ ├── characters.txt │ │ │ ├── question1.txt │ │ │ └── question2.txt │ │ ├── hacking │ │ │ ├── README.md │ │ │ ├── products.txt │ │ │ └── purchases.txt │ │ ├── murphy │ │ │ ├── Murphy_reads.txt │ │ │ ├── README.md │ │ │ └── arguments.txt │ │ ├── piramidi │ │ │ ├── README.md │ │ │ └── map.txt │ │ └── ricette │ │ │ ├── README.md │ │ │ ├── foods.txt │ │ │ ├── fusilli_alle_olive.txt │ │ │ └── polenta_concia.txt │ ├── armstrong │ │ ├── README.md │ │ ├── armstrong.py │ │ ├── evaluation-grid.md │ │ └── numbers.txt │ ├── ascii-stats │ │ ├── README.md │ │ ├── evaluation-grid.md │ │ ├── landscape.txt │ │ ├── landscape2.txt │ │ └── stats.py │ ├── battleship │ │ ├── README.md │ │ ├── grid.md │ │ ├── map1.dat │ │ ├── map2.dat │ │ └── moves.txt │ ├── cheat-sheet.pdf │ ├── chess │ │ ├── README.md │ │ ├── games.csv │ │ ├── games_short.csv │ │ ├── mr-t.py │ │ ├── players.csv │ │ └── players_short.csv │ ├── connect-four │ │ ├── README.md │ │ ├── connect-four.py │ │ ├── evaluation-grid.md │ │ └── moves.txt │ ├── consumption+production │ │ ├── README.md │ │ ├── consumption+production.py │ │ ├── consumptions.csv │ │ ├── evaluation-grid.md │ │ ├── systems.csv │ │ └── weather.csv │ ├── everwhen │ │ ├── README.md │ │ ├── everwhen.py │ │ ├── gemini.py │ │ └── grid.md │ ├── freedonia │ │ ├── README.md │ │ ├── dates-example1.dat │ │ ├── dates-example2.dat │ │ ├── dates.dat │ │ ├── freedonia.py │ │ ├── rules-example1.dat │ │ ├── rules-example2.dat │ │ └── rules.dat │ ├── magic-boxes │ │ ├── README.md │ │ ├── actions-fail_bob.txt │ │ ├── actions-fail_carl.txt │ │ ├── actions-simple.txt │ │ ├── actions.txt │ │ └── magic-boxes.py │ ├── misspell │ │ ├── README.md │ │ ├── mispell.py │ │ ├── names.txt │ │ └── parole_italiane.txt │ ├── munodi │ │ ├── README.md │ │ ├── munodi-chatbox_gpt.py │ │ ├── munodi.py │ │ ├── seq.dat │ │ └── seq_long.dat │ ├── shells │ │ ├── README.md │ │ ├── cart.dat │ │ ├── chatgpt.py │ │ ├── es1_cart.dat │ │ ├── es1_offers.dat │ │ ├── es1_prices.dat │ │ ├── evaluation-grid.md │ │ ├── offers.dat │ │ ├── prices.dat │ │ ├── shelley.py │ │ ├── t0_cart.dat │ │ ├── t0_offers.dat │ │ ├── t0_prices.dat │ │ ├── t1_cart.dat │ │ ├── t1_offers.dat │ │ ├── t1_prices.dat │ │ ├── t2_cart.dat │ │ ├── t2_offers.dat │ │ ├── t2_prices.dat │ │ ├── t3_cart.dat │ │ ├── t3_offers.dat │ │ └── t3_prices.dat │ ├── soccer │ │ ├── README.md │ │ ├── grid.md │ │ ├── player_stats-small.csv │ │ ├── player_stats.csv │ │ └── soccer.py │ ├── strawberry │ │ ├── README.md │ │ ├── strawberry-short.txt │ │ ├── strawberry.py │ │ └── strawberry.txt │ └── worms │ │ ├── README.md │ │ ├── evaluation-grid.md │ │ ├── seq-long.txt │ │ ├── seq.txt │ │ ├── worms-chatgpt.py │ │ └── worms.py ├── poetry.lock ├── pyproject.toml └── src │ ├── 2020-21 │ ├── 20201020-format.py │ ├── 20201021-01.py │ ├── 20201021-02.py │ ├── 20201021-03.py │ ├── 20201021-04.py │ ├── 20201021-05.py │ ├── 20201021-06.py │ ├── 20201026_richter_1.py │ ├── 20201026_richter_2.py │ ├── 20201026_tax_1.py │ ├── 20201026_tax_2.py │ ├── 20201026_tax_3.py │ ├── 20201026_tax_4.py │ ├── 20201028_for.py │ ├── 20201028_while_01.py │ ├── 20201028_while_02.py │ ├── 20201028_while_03.py │ ├── 20201028_while_04-nested.py │ ├── 20201028_while_05.py │ ├── 20201028_while_06.py │ ├── 20201028_while_07.py │ ├── 20201028_while_08.py │ ├── 20201028_while_09.py │ ├── 20201028_while_10.py │ ├── 20201102_functions.py │ ├── 20201104_main.py │ ├── 20201104_simple-functions.py │ ├── 20201109_lists_1.py │ ├── 20201109_lists_2.py │ ├── 20201109_lists_3.py │ ├── 20201109_lists_4.py │ ├── 20201111_my-index_1.py │ ├── 20201111_my-index_2.py │ ├── 20201111_print-list.py │ ├── 20201111_slices.py │ ├── 20201116_find.py │ ├── 20201116_join.py │ ├── 20201116_minmax.py │ ├── 20201116_remove_1.py │ ├── 20201116_remove_2.py │ ├── 20201118_list-input_1.py │ ├── 20201118_list-input_2.py │ ├── 20201118_list-input_3.py │ ├── 20201118_list-input_4.py │ ├── 20201118_scores.py │ ├── 20201123_dice_1.py │ ├── 20201123_dice_2.py │ ├── 20201123_dice_3.py │ ├── 20201125_convert-102B_1.py │ ├── 20201125_convert-102B_2.py │ ├── 20201125_convert-102B_3.py │ ├── 20201125_convert-B210_1.py │ ├── 20201125_convert-B2B_1 (partial).py │ ├── 20201125_convert-B2B_2 (partial).py │ ├── 20201125_convert-B2B_3.py │ ├── 20201130_1st-open.py │ ├── 20201130_format.py │ ├── 20201202_file+tuples.py │ ├── 20201202_file_1.py │ ├── 20201202_file_2.py │ ├── 20201202_file_3.py │ ├── 20201202_file_4.py │ ├── 20201202_file_5.py │ ├── 20201202_named-args.py │ ├── 20201202_try-execpt.py │ ├── 20201207_try-execpt_1.py │ ├── 20201207_try-execpt_2.py │ ├── 20201209_dict.py │ ├── 20201209_is_sublist.py │ ├── 20201209_sets_1.py │ ├── 20201209_sets_2.py │ ├── 20201216_functions-in-functions.py │ ├── 20201216_modules_gargle.py │ ├── 20201216_modules_main.py │ ├── 20201221_lab11-6_1.py │ ├── 20201221_lab11-6_2.py │ ├── 20201221_lab11-6_3.py │ ├── 20201221_lab11-7.py │ ├── 20210113_playfair.py │ ├── 20210113_words.py │ ├── 20210625_exam.py │ ├── 20210625_trolls.dat │ ├── 20210701_makeup-exam.py │ ├── 20210701_wines.dat │ ├── 20211103_pi.py │ └── 20211103_simulation.py │ ├── 2021-22 │ ├── 20210910_exam.py │ ├── 20211009_equation.py │ ├── 20211009_first-program.py │ ├── 20211013_tiles.py │ ├── 20211015_equations-1.py │ ├── 20211015_equations-2.py │ ├── 20211015_kb-sale.py │ ├── 20211022_average.py │ ├── 20211022_count.py │ ├── 20211022_interest.py │ ├── 20211022_match.py │ ├── 20211022_min-max_1.py │ ├── 20211022_min-max_2.py │ ├── 20211022_sum.py │ ├── 20211029_for-loops.py │ ├── 20211029_multiplication.py │ ├── 20211029_pirate-song.py │ ├── 20211029_pirate-song_2.py │ ├── 20211029_powtable.py │ ├── 20211029_primes.py │ ├── 20211029_strings.py │ ├── 20211029_vowels.py │ ├── 20211103_pi.py │ ├── 20211103_simulation.py │ ├── 20211105_eq1_take1.py │ ├── 20211105_eq1_take2.py │ ├── 20211105_eq2.py │ ├── 20211105_multi-line-strings.py │ ├── 20211105_namespace.py │ ├── 20211124_join.py │ ├── 20211124_maxmin.py │ ├── 20211124_reverse.py │ ├── 20211124_search.py │ ├── 20211124_swap.py │ ├── 20211126_list-comp.py │ ├── 20211126_open.py │ ├── 20211126_reading-files.py │ ├── 20211126_reading-files_2.py │ ├── 20211126_stairway.txt │ ├── 20211126_table.py │ ├── 20211126_tic-tac-toe.py │ ├── 20211126_words.py │ ├── 20211201_append.py │ ├── 20211201_files-recap.py │ ├── 20211201_input.txt │ ├── 20211201_song.txt │ ├── 20211201_sum-try.py │ ├── 20211201_sum.py │ ├── 20211203_battleship.py │ ├── 20211203_long-text.txt │ ├── 20211203_wordlist.py │ ├── 20211209_Lab10-Ex1.py │ ├── 20211209_Lab10-Ex2.py │ ├── 20211209_Lab10-Ex3.py │ ├── 20211209_input.gx │ ├── 20211210_CSC1.txt │ ├── 20211210_CSC2.txt │ ├── 20211210_courses.lst │ ├── 20211210_hotel.dat │ ├── 20211210_hotel.py │ ├── 20211210_mind.txt │ ├── 20211210_unique.py │ ├── 20211210_university.py │ ├── 20211210_walk.py │ ├── 20211217_births.py │ ├── 20211217_births.txt │ ├── 20211217_maze.py │ ├── 20211217_maze.txt │ ├── 20220112_hacking.py │ ├── 20220112_products.txt │ ├── 20220112_purchases.txt │ ├── 20220114_guess-who.py │ ├── 20220114_ingredients.txt │ ├── 20220114_map.txt │ ├── 20220114_piramids.py │ ├── 20220114_polenta_concia.txt │ ├── 20220114_questions-1.txt │ ├── 20220114_questions-2.txt │ └── 20220114_recipes.py │ ├── 2022-23 │ ├── 20221011_math.py │ ├── 20221011_tiles.py │ ├── 20221011_time.py │ ├── 20221014_equation.py │ ├── 20221014_if.py │ ├── 20221021_dna_1.py │ ├── 20221021_dna_2.py │ ├── 20221021_fibonacci.py │ ├── 20221021_sequence.py │ ├── 20221021_sum-nums.py │ ├── 20221025-substrings.py │ ├── 20221025_loops-1.py │ ├── 20221025_loops-2.py │ ├── 20221025_loops-diamonds-lab4-2.py │ ├── 20221028-nim_1-2.py │ ├── 20221028-nim_1..py │ ├── 20221104_list-for.py │ ├── 20221104_list-str.py │ ├── 20221104_lists-creation.py │ ├── 20221104_lists.py │ ├── 20221104_ranges.py │ ├── 20221111_list-numbers.py │ ├── 20221111_list-strings.py │ ├── 20221115_multret.py │ ├── 20221115_tables.py │ ├── 20221118_files-write.py │ ├── 20221118_files.py │ ├── 20221118_files2.py │ ├── 20221118_mult-table.py │ ├── 20221118_nums.py │ ├── 20221122_reverse.py │ ├── 20221122_slurp-files.py │ ├── 20221122_try1.py │ ├── 20221125_car-parking (take2).py │ ├── 20221125_car-parking.py │ ├── 20221125_cmp-lists.py │ ├── 20221125_maze.dat │ ├── 20221125_maze.py │ ├── 20221127_car_parking_recursion.py │ ├── 20221129_play-dice.py │ ├── 20221129_play-dice_take2.py │ ├── 20221206_bin2dec.py │ ├── 20221206_dec2bin.py │ ├── 20221215_sets.py │ ├── 20221216_dec2bin-2.py │ ├── 20221216_dict.py │ ├── 20221216_dups.py │ ├── 20221216_exams.py │ ├── 20221216_phonebook.xyz │ ├── 20221216_spiral.py │ ├── 20221220_csv.py │ ├── 20221220_zip-files.py │ ├── 20230110_wrapup.py │ ├── CSC1.txt │ ├── CSC2.txt │ ├── MTH121.txt │ ├── classes.txt │ ├── file-a.dat │ ├── file-b.dat │ ├── jingle.txt │ └── test.csv │ ├── 2023-24 │ ├── 20231013 div.py │ ├── 20231013 fibonacci.py │ ├── 20231013 for.py │ ├── 20231013 names.py │ ├── 20231013 seasons.py │ ├── 20231013 seasons2.py │ ├── 20231013 while.py │ ├── 20231013 while2.py │ ├── 20231017 f-strings.py │ ├── 20231017 if-else.py │ ├── 20231017 range.py │ ├── 20231020 interest-rate.py │ ├── 20231020 max-min.py │ ├── 20231020 sum-1.py │ ├── 20231020 sum-2.py │ ├── 20231020 user-avg-2.py │ ├── 20231020 user-avg.py │ ├── 20231024 functions.py │ ├── 20231024 happy-christmas - take2.py │ ├── 20231024 happy-christmas.py │ ├── 20231027 functions2.py │ ├── 20231027 list3.py │ ├── 20231027 lists.py │ ├── 20231027 lists2.py │ ├── 20231027 prime.py │ ├── 20231031 functions.py │ ├── 20231031 subst.py │ ├── 20231107 spell.py │ ├── 20231110 2-dim arrays.py │ ├── 20231110 dictionaries.py │ ├── 20231110 file.py │ ├── 20231110 loving.txt │ ├── 20231110 sets.py │ ├── 20231114 strawberry.py │ ├── 20231114 strawberry.txt │ ├── 20231117 armstrong.dat │ ├── 20231117 armstrong.py │ ├── 20231117 encoding+try.py │ ├── 20231117 numbers.dat │ ├── 20231117 tables.py │ ├── 20231117 test.txt │ ├── 20231117 try2.py │ ├── 20231124 longest-seq.py │ ├── 20231124 parking.py │ ├── 20231124 read.py │ ├── 20231128 converter.py │ ├── 20231201 super-convert.py │ ├── 20231212 Magic.py │ ├── 20231215 soccer.py │ ├── 20231219 actions.txt │ ├── 20231219 actions_bob.txt │ ├── 20231219 actions_carl.txt │ ├── 20231219 magic-boxes.py │ ├── 20231219 map.py │ ├── 20231219 sort.py │ ├── 20231219 sort2.py │ ├── 20231222 censored.txt │ ├── 20231222 dict-values.py │ ├── 20231222 scanner-darkly.md │ ├── 20231222 scanner-darkly.py │ ├── 20231222 the-theater.dat │ ├── 20231222 the-theater.py │ ├── 20231222 wiretap.txt │ ├── 20240109 lab11.py │ ├── 20240109 notes.dat │ ├── 20240109 notes.py │ ├── 20240109 sorting (again).py │ ├── 20240112 bowling.csv │ ├── 20240112 bowling.py │ ├── 20240112 freedonia.py │ ├── 20240112 rules.dat │ └── my_lib.py │ └── 2024-25 │ ├── 20141129 dicts2.py │ ├── 20241004 equation.py │ ├── 20241004 first.py │ ├── 20241004 second.py │ ├── 20241004 third.py │ ├── 20241008 format.py │ ├── 20241008 if.py │ ├── 20241008 strings.py │ ├── 20241011 strings again.py │ ├── 20241011 strings ops.py │ ├── 20241011 tiles.py │ ├── 20241015 list.py │ ├── 20241015 strings.py │ ├── 20241018 breaking.py │ ├── 20241018 defaults.py │ ├── 20241018 enumerate.py │ ├── 20241018 for.py │ ├── 20241018 ice-cream.py │ ├── 20241018 inifinity.py │ ├── 20241018 lists.py │ ├── 20241018 range.py │ ├── 20241018 seasons.py │ ├── 20241018 while.py │ ├── 20241018 while2.py │ ├── 20241022 enum.py │ ├── 20241022 lists.py │ ├── 20241025 camila.py │ ├── 20241025 input.py │ ├── 20241025 join.py │ ├── 20241025 loops.py │ ├── 20241025 money.py │ ├── 20241029 flags.py │ ├── 20241029 function-param.py │ ├── 20241029 functions.py │ ├── 20241029 scope.py │ ├── 20241105 functions-recap.py │ ├── 20241105 is-odd.py │ ├── 20241105 prime.py │ ├── 20241105 primes2.py │ ├── 20241105 return.py │ ├── 20241105 strings.py │ ├── 20241108 eqelem.py │ ├── 20241108 functions.py │ ├── 20241108 list-functions.py │ ├── 20241108 ret-lists.py │ ├── 20241108 return.py │ ├── 20241108 return2.py │ ├── 20241112 colltz.py │ ├── 20241112 conversion.py │ ├── 20241112 legb.py │ ├── 20241112 narcissistic.py │ ├── 20241115 convert.py │ ├── 20241115 exceptions.py │ ├── 20241115 files.py │ ├── 20241115 files2.py │ ├── 20241115 song.txt │ ├── 20241119 files.py │ ├── 20241119 in.gx │ ├── 20241119 out.gx │ ├── 20241119 tables.py │ ├── 20241122 1-line.zap │ ├── 20241122 movies.gx │ ├── 20241122 movies2.gx │ ├── 20241122 open.py │ ├── 20241122 open2.py │ ├── 20241122 repr.py │ ├── 20241126 chess.py │ ├── 20241126 dict.py │ ├── 20241126 players.csv │ ├── 20241129 capital.txt │ ├── 20241129 dicts.py │ ├── 20241129 sets.py │ ├── 20241129 words.py │ ├── 20241203 behavioral-param.py │ ├── 20241203 dict.py │ ├── 20241210 advent1.py │ ├── 20241210 map.py │ ├── 20241210 rules.dat │ ├── 20241210 swap2.py │ ├── 20241210 updates.dat │ ├── 20241210 xmas.dat │ ├── 20241213 chess.py │ ├── 20241213 games.csv │ ├── 20241213 monty.py │ ├── 20241213 players.csv │ ├── 20241217 friend.csv │ ├── 20241217 friends.py │ ├── 20241217 wow.py │ ├── 20241217 wow.txt │ ├── 20241220 2d-arrays.py │ ├── 20241220 bowling.py │ ├── 20241220 bowling.txt │ ├── 20241220 guess_who - characters.txt │ ├── 20241220 guess_who - questions1.txt │ ├── 20241220 guess_who - questions2.txt │ └── 20241220 guess_who.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-03-16.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | /* 9 | * Whoa! this IDE rocks! 10 | */ 11 | 12 | int main(void) 13 | { 14 | const long int zap = 42l; 15 | 16 | int jane, row; 17 | double zop; 18 | 19 | return EXIT_SUCCESS; // everything ok 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-03-31b.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int t; 11 | int digits; 12 | 13 | printf("Digits: "); 14 | scanf("%d", &digits); 15 | 16 | int val = 0; 17 | t = 0; 18 | while (t < digits) 19 | { 20 | int b; 21 | scanf("%d", &b); 22 | 23 | val = 2 * val + b; 24 | t = t + 1; 25 | } 26 | printf("\nVAL: %d\n", val); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-04-27b.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | char up(char c); 10 | 11 | int main() 12 | { 13 | char c; 14 | 15 | c = up('B'); 16 | printf("%c\n", c); 17 | c = up('g'); 18 | printf("%c\n", c); 19 | 20 | return 0; 21 | } 22 | 23 | char up(char c) 24 | { 25 | if (c >= 'a' && c <= 'z') 26 | { 27 | return c - 'a' + 'A'; 28 | } 29 | else 30 | { 31 | return c; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-04-28a.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define N 8 9 | 10 | int main() 11 | { 12 | int i; 13 | int v[N]; 14 | int w[N]; 15 | 16 | for (i = 0; i < N; ++i) 17 | { 18 | scanf("%d", &v[i]); 19 | } 20 | for (i = 0; i < N; ++i) 21 | { 22 | w[i] = v[i]; 23 | } 24 | 25 | printf("Hello world!\n"); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-05-28b.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define DIM 1024 9 | 10 | typedef struct _FOO 11 | { 12 | int x; 13 | int y; 14 | } FOO; 15 | 16 | void func(FOO x) 17 | { 18 | x.x = x.y = 23; 19 | } 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | FOO x; 24 | 25 | x.x = x.y = 42; 26 | printf("%d/%d\n", x.x, x.y); 27 | func(x); 28 | printf("%d/%d\n", x.x, x.y); 29 | 30 | return EXIT_FAILURE; 31 | } 32 | -------------------------------------------------------------------------------- /C/Class examples/2014-15/2015-06-08b.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define DIM 1024 9 | 10 | typedef struct _FOO 11 | { 12 | int x; 13 | int y; 14 | } FOO; 15 | 16 | void func(FOO x) 17 | { 18 | x.x = x.y = 23; 19 | } 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | FOO x; 24 | 25 | x.x = x.y = 42; 26 | printf("%d/%d\n", x.x, x.y); 27 | func(x); 28 | printf("%d/%d\n", x.x, x.y); 29 | 30 | return EXIT_FAILURE; 31 | } 32 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/README.md: -------------------------------------------------------------------------------- 1 | FLOW CHARTS 2 | =========== 3 | 4 | Get [Raptor](http://raptor.martincarlisle.com) (windows-only flowchart Interpreter) 5 | 6 | Import the file *"c-like loops.reg"* into windows registry to make *raptor* behave more c-like (i.e., iterate while the condition is true, exit on false). 7 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/c-like loops.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/c-like loops.reg -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/equations.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/equations.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/fibonacci.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/fibonacci.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/gcd.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/gcd.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/gcd_euclid.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/gcd_euclid.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/guess-a-number.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/guess-a-number.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/prime.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/prime.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/prime_v1.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/prime_v1.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/FlowCharts/prime_v2.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2015-16/FlowCharts/prime_v2.rap -------------------------------------------------------------------------------- /C/Class examples/2015-16/w04-Overflow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | signed char a, b, c; 11 | 12 | a = 120; 13 | b = 63; 14 | c = a + b; 15 | 16 | printf("Overflow: %d + %d = %d\n", a, b, c); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w05-bin2dec.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int t; 11 | int bit; 12 | int weight; 13 | int num; 14 | 15 | num = 0; 16 | weight = 128; 17 | t = 0; 18 | while (t < 8) 19 | { 20 | scanf("%d", &bit); 21 | num = num + weight * bit; 22 | 23 | weight = weight / 2; 24 | t = t + 1; 25 | } 26 | 27 | printf("Value: %d\n", num); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w05-dec2bin.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | unsigned int num; 11 | 12 | printf("Insert a number :"); 13 | scanf("%u", &num); 14 | 15 | while (num > 0) 16 | { 17 | printf("%d", num % 2); 18 | num = num / 2; 19 | } 20 | printf("\n\nNow read from right to left!\n"); 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w05-floats.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | int t; 12 | double d; 13 | int bit; 14 | int val; 15 | 16 | t = 0; 17 | val = 0; 18 | while (t < 8) 19 | { 20 | scanf("%d", &bit); 21 | val = 2 * val + bit; 22 | t = t + 1; 23 | } 24 | printf("Val: %d\n", val); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w05-pow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | double x; 12 | int t; 13 | 14 | t = 0; 15 | while (t < 30) 16 | { 17 | x = pow(2.0, (double)t); 18 | printf("%f\n", x); 19 | 20 | t = t + 1; 21 | } 22 | 23 | printf("Hello world!\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w07_switch.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int c; 11 | 12 | printf(": "); 13 | scanf("%c", &c); 14 | 15 | switch (c) 16 | { 17 | case 'y': 18 | case 'Y': // "ie. case 89:" 19 | printf("Cool\n"); 20 | break; 21 | default: 22 | printf("D'ho!\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/Class examples/2015-16/w10-commandline1.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2015-2016 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | int t; 11 | 12 | printf("argc: %d\n", argc); 13 | for (t = 0; t < argc; t += 1) 14 | { 15 | printf("ARG %d: %s\n", t, argv[t]); 16 | } 17 | 18 | return EXIT_SUCCESS; 19 | } 20 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/README.md: -------------------------------------------------------------------------------- 1 | FLOW CHARTS 2 | =========== 3 | 4 | Get [Raptor](http://raptor.martincarlisle.com) (windows-only flowchart Interpreter) 5 | 6 | Import the file *"c-like loops.reg"* into windows registry to make *raptor* behave more c-like (i.e., iterate while the condition is true, exit on false). 7 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/c-like loops.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/c-like loops.reg -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w01-Div7.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w01-Div7.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w01-Fibonacci.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w01-Fibonacci.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w01-Prime.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w01-Prime.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w01_AbbaZabba.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w01_AbbaZabba.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w02-GCD.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w02-GCD.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w02-GCD_smart.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w02-GCD_smart.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w02-multTable.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w02-multTable.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w02-triangle.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w02-triangle.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/FlowCharts/w03-mountains.rap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Class examples/2016-17/FlowCharts/w03-mountains.rap -------------------------------------------------------------------------------- /C/Class examples/2016-17/w03-hola_mundo.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | 7 | int main() 8 | { 9 | int a; 10 | printf("hola\t\tmundo!\n"); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w05-do_while.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("World hello!\n"); 11 | 12 | int n = 10; 13 | do 14 | { 15 | printf("%d\n", n); 16 | n = n - 1; 17 | } while (n >= 0); 18 | printf("BANG\n"); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w05-for.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int t; 11 | printf("LOOPS!\n"); 12 | 13 | t = 0; // INIT 14 | while (t < 10) 15 | { // TEST 16 | printf("Looping (%d)...\n", t); // BODY 17 | t = t + 1; // UPDATE 18 | } 19 | 20 | printf("goodbye cruel world!\n"); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w06-hack.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int array[8] = {0}; 11 | int foo = 42; 12 | 13 | printf("foo: %d\n", foo); 14 | for (int t = 0; t < 12; ++t) 15 | { 16 | array[t] = -1; 17 | printf("%d: foo: %d\n", t, foo); 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w06-ovrflow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | unsigned char a = 254; 11 | unsigned char b = 2; 12 | unsigned char c = a + b; 13 | 14 | printf("%d + %d = %d\n", a, b, c); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w06_b2d_2.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define BITS 8 9 | 10 | int main() 11 | { 12 | printf("Hello world!\n"); 13 | 14 | printf("Binary number (8 bit): "); 15 | int decimal = 0; 16 | for (int t = 0; t < BITS; ++t) 17 | { 18 | int bit; 19 | scanf("%d", &bit); 20 | decimal = decimal * 2 + bit; 21 | } 22 | printf("Decimal: %d\n", decimal); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w09-strcat.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define BUFFER_LEN 4 9 | 10 | int main() 11 | { 12 | char str[BUFFER_LEN]; 13 | 14 | //strcpy(str, "Hey"); // str = "Hey" 15 | strcat(str, " "); // str += " " 16 | strcat(str, "you"); 17 | strcat(str, ", "); 18 | strcat(str, "out"); 19 | 20 | printf("%s\n", str); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w09-strings_v2.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define MAX_LENGTH 256 10 | 11 | int main() 12 | { 13 | char name[MAX_LENGTH]; 14 | 15 | printf("Insert your name: "); 16 | scanf("%s", name); 17 | name[0] = toupper(name[0]); 18 | printf("\n\nHello %s!\n", name); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w09-strings_v3.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define MAX_LENGTH 256 10 | 11 | int main() 12 | { 13 | char name[MAX_LENGTH]; 14 | 15 | printf("Insert your name: "); 16 | gets(name); 17 | name[0] = toupper(name[0]); 18 | printf("\n\nHello %s!\n", name); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w10-Arrays_of_Strings-2.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | printf("ARGC: %d\n", argc); 12 | for (int t = 0; t < argc; ++t) 13 | { 14 | printf("ARGV %d: %s\n", t, argv[t]); 15 | } 16 | return EXIT_SUCCESS; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2016-17/w11-struct_rite.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2016-2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | FILE *output; 11 | 12 | output = fopen("file2.gx", "w"); 13 | if (output == NULL) 14 | { 15 | fprintf(stderr, "Yeuch, can't write to file...\n"); 16 | exit(EXIT_FAILURE); 17 | } 18 | 19 | fprintf(output, "It works!\n"); 20 | fclose(output); 21 | 22 | return EXIT_SUCCESS; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-10_my-first-program.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int foo; 11 | 12 | printf("Tell me a number: "); 13 | scanf("%d", &foo); 14 | printf("Hey, you told me %d!\n", foo); 15 | 16 | if (foo < 0) 17 | { 18 | printf("... and it is negative\n"); 19 | } 20 | else 21 | { 22 | printf("d'ho....\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-16_42.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define THE_ANSWER 42 9 | 10 | int main() 11 | { 12 | int a, b; 13 | 14 | a = 23; 15 | b = 10; 16 | 17 | printf("a=%d, b=%d\n", a, b); 18 | 19 | { 20 | int c = 17; 21 | int a = 42; 22 | printf("a=%d, b=%d, c=%d\n", a, b, c); 23 | } 24 | 25 | printf("a=%d, b=%d\n", a, b); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-23A_loops.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int t; 11 | 12 | t = 0; 13 | while (t < 1000) 14 | { 15 | printf("%d Whoa!\n", t); 16 | if (t == 3) 17 | { 18 | printf("I'm failing the exam :-)\n"); 19 | break; 20 | } 21 | t = t + 1; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-23C_loops.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int n; 11 | 12 | printf("Hello: "); 13 | scanf("%d", &n); 14 | 15 | printf("Sum(%d, %d) = ", 0, n); 16 | int sum = 0; 17 | while (n >= 0) 18 | { 19 | sum = sum + n; 20 | n = n - 1; 21 | } 22 | printf("%d\n", sum); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-23D_nested-loops.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define SIZE 10 9 | 10 | int main() 11 | { 12 | for (int r = 0; r < SIZE; r = r + 1) 13 | { 14 | for (int c = 0; c < r; c = c + 1) 15 | { 16 | printf(" "); 17 | } 18 | for (int c = 0; c < 10 - r; c = c + 1) 19 | { 20 | printf("#"); 21 | } 22 | printf("\n"); 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-24A_do-while.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int t = 999; 11 | do 12 | { 13 | printf("do "); 14 | t = t + 1; 15 | } while (t < 10); 16 | printf("while!\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-24B_continue.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | for (int t = 0; t < 20; t = t + 1) 11 | { 12 | if (t == 3) 13 | { 14 | continue; 15 | } 16 | printf("Hello world %d\n", t); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-30B_pi.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define STEPS 500000 9 | 10 | int main() 11 | { 12 | double pi = 0.0; 13 | 14 | double sign = 1.0; 15 | for (int s = 0; s < STEPS; s = s + 1) 16 | { 17 | pi = pi + sign * 4.0 / (1.0 + s * 2.0); 18 | 19 | printf("Pi: %.10f\n", pi); 20 | 21 | sign = sign * -1.0; 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-30_E_arrays.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define SIZE 1000 9 | 10 | int main() 11 | { 12 | int my_first_array[SIZE]; 13 | 14 | scanf("%d", &my_first_array[0]); 15 | for (int t = 1; t < SIZE; t = t + 1) 16 | { 17 | my_first_array[t] = my_first_array[0]; 18 | } 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-10-31D_slang.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Hello slang!\n"); 11 | 12 | int t = 0; 13 | 14 | t += 4; // t = t + 4; 15 | t *= 10; // t = t * 10; 16 | t -= 8; // t = t - 8; 17 | 18 | int foo; 19 | int bar; 20 | 21 | foo = 42; 22 | bar = foo-- * 10; 23 | 24 | foo = 42; 25 | bar = --foo * foo++; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-06_pre-post.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int foo = 42; 11 | 12 | printf("Increments:\n"); 13 | foo = foo + 1; // lame 14 | foo += 1; // slightly better 15 | foo++; // reasonable 16 | ++foo; // that's it! 17 | 18 | for (int t = 0; t < 10; ++t) 19 | { 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-07_randint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | srand(time(NULL)); 7 | int MAX = 5; 8 | int MIN = -5; 9 | for(int t = 0; t < 100; ++t) { 10 | int r = (rand() % (MAX-MIN+1)) + MIN; 11 | printf("\"Random\" number [-5, +5]: %d\n", r); 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-20_functions.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int lunch_time(int parameter) 9 | { 10 | int t; 11 | for (t = 0; t < 10; ++t) 12 | { 13 | printf("lunch time!!!!\n"); 14 | } 15 | return t * parameter; 16 | } 17 | 18 | int main() 19 | { 20 | int t = 42; 21 | int z = lunch_time(23); 22 | printf("%d\n", z); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-20_toupper.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | char c = '!'; 11 | 12 | printf("%c\n", c); 13 | printf("%c\n", toupper(c)); 14 | printf("%c\n", c - 'a' + 'A'); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-27_char-io.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Hello char-based i/o!\n"); 11 | 12 | char c; 13 | do 14 | { 15 | c = getchar(); 16 | printf("%c", c); 17 | } while (c != EOF); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-11-27_codepages.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | char c = '0'; 11 | int n = 48; 12 | 13 | printf("%d\n", n); 14 | printf("%c\n", n); 15 | 16 | printf("�����\n"); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-04_argc.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | printf("Hello argc/argv!\n"); 11 | 12 | printf("ARGC: %d\n", argc); 13 | for (int t = 0; t < argc; ++t) 14 | { 15 | printf("Argument %d: %s\n", t, argv[t]); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-05_more-args.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2017 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | // Hello World$ 9 | // the$-------- 10 | // answer$----- 11 | // is$--------- 12 | // 42$--------- 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | printf("I just got %d arguments\n", argc); 17 | for (int t = 0; t < argc; ++t) 18 | { 19 | printf("argv[%d] = ``%s''\n", t, argv[t]); 20 | } 21 | 22 | return EXIT_SUCCESS; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-17_file_in.gx: -------------------------------------------------------------------------------- 1 | 23 2 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-17_myfile.gx: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | 3 | 4 | dolor sit amet, 5 | consectetur adipisicing elit, sed do eiusmod 6 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 7 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 8 | consequat. Duis aute irure dolor in reprehenderit in 9 | voluptate velit esse 10 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 11 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 12 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-18_feof.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Hello world!\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-18_myfile.gx: -------------------------------------------------------------------------------- 1 | Lorem ipsum 2 | 3 | 4 | dolor sit amet, 5 | consectetur adipisicing elit, sed do eiusmod 6 | tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 7 | quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 8 | consequat. Duis aute irure dolor in reprehenderit in 9 | voluptate velit esse 10 | cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 11 | proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 12 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-19_feof_problems.gx: -------------------------------------------------------------------------------- 1 | 23 2 | 10 3 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-19_terribe_feof.gx: -------------------------------------------------------------------------------- 1 | 23 2 | 10 3 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-file_in.gx: -------------------------------------------------------------------------------- 1 | 23 2 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2017-12-file_out.gx: -------------------------------------------------------------------------------- 1 | Hello! 2 | This is my first file! 3 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2018-01-09_typedef.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | typedef unsigned long int bob; 9 | 10 | struct _POINT 11 | { 12 | double x, y; 13 | }; 14 | typedef struct _POINT POINT; 15 | 16 | int main() 17 | { 18 | bob foo; 19 | bob bar; 20 | 21 | POINT origin; 22 | 23 | printf("Hello world!\n"); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2018-01-10_es_typedef.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | typedef unsigned long int Bob; 9 | 10 | struct _COMPLEX 11 | { 12 | double re, im; 13 | }; 14 | typedef struct _COMPLEX COMPLEX; 15 | 16 | int main() 17 | { 18 | Bob foo; 19 | Bob bar; 20 | COMPLEX n1, n2; 21 | FILE *zop; 22 | 23 | printf("Size of Bob: %d\n", sizeof(Bob)); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2018-01-14_bus.dat: -------------------------------------------------------------------------------- 1 | -12 -2 34 2 | 34 56 -2 3 | 18 -32 18 4 | -2 56 -23 5 | -------------------------------------------------------------------------------- /C/Class examples/2017-18/2018-01-14_mat1.dat: -------------------------------------------------------------------------------- 1 | -12 -2 34 2 | 34 56 -2 3 | 18 -32 18 4 | -2 56 -23 5 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w03_ex01.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | double a; 11 | double b; 12 | 13 | scanf("%lg", &a); 14 | scanf("%lg", &b); 15 | 16 | double zap = a % b; 17 | 18 | if (a > b) 19 | { 20 | printf("Max is %g\n", a); 21 | } 22 | else 23 | { 24 | printf("Max is %g\n", b); 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w03_ex02-loops.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int i = 0; 11 | while (i < 3) 12 | { 13 | printf("Whoa!\n"); 14 | i = i + 1; 15 | } 16 | 17 | while (i < 2) 18 | { 19 | printf("d'ho!?\n"); 20 | i = i + 1; 21 | } 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w03_ex07-fibo.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | long long int a, b, c; 11 | 12 | printf("Fibonacci: 0 1"); 13 | b = 0; 14 | c = 1; 15 | 16 | int i = 0; 17 | while (i < 100) 18 | { 19 | a = b; 20 | b = c; 21 | c = a + b; 22 | printf(" %d", c); 23 | i = i + 1; 24 | } 25 | printf("\n"); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w04-0_printf.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | long long int i = 32ll; 11 | printf("%I64d\n", i); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w04_9-for2.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | for (int t = 0; t < 10; t = t + 1) 11 | { 12 | if (t % 2 == 1) 13 | continue; 14 | printf("%d) Loosing points at the exam!\n", t); 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w06-5_overflow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define NUM 100 9 | 10 | int main() 11 | { 12 | short int sum = 0; 13 | 14 | for (int t = 0; t < NUM; ++t) 15 | { 16 | int r = rand() % 1000; 17 | printf("%d + %d", sum, r); 18 | sum += r; 19 | printf(" = %d\n", sum); 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w06-6_pow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | long long int num = 1; 11 | 12 | int bits = 0; 13 | while (num != 0) 14 | { 15 | num *= 2; 16 | ++bits; 17 | } 18 | printf("bits: %d\n", bits); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w07-7_overflow.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | unsigned char c1, c2; 11 | unsigned char s; 12 | 13 | c1 = 99; 14 | c2 = 123; 15 | s = c1 - c2; 16 | 17 | printf("%d - %d = %d\n", c1, c2, s); 18 | 19 | // char test = 'a'; 20 | // char test = 70 + 9; 21 | // printf("%d %c\n", test, test); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w07-8_bitwise.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | unsigned char a = 15; 11 | unsigned char b = 240; 12 | unsigned char c = a ^ b; 13 | 14 | printf("%d %d -> %d\n", a, b, c); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w08-03_hex.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | signed char x = 0x7f; 11 | 12 | printf("x = 0x%02x\n", x); 13 | printf("%d\n", x); 14 | ++x; 15 | printf("x = 0x%02x\n", x); 16 | printf("%d\n", x); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w09-1_math.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | // proto (functions declaration) 10 | double log2(double x); 11 | double abba_zabba(double x, double y); // non existing function, ok... 12 | 13 | int main(void) 14 | { 15 | double x = 512.0; 16 | printf("log2(%g) = %g\n", x, log2(x)); 17 | } 18 | 19 | // function definition 20 | double log2(double x) 21 | { 22 | double res = log(x) / log(2.0); 23 | return res; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w09-2_chario.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Type 1 char: "); 11 | int c = getchar(); 12 | printf("Hey! You typed %d (%c)\n", c, c); 13 | c = getchar(); 14 | printf("and %d (%c)\n", c, c); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w09-3_eof.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int c; 11 | do 12 | { 13 | c = getchar(); 14 | printf("%c", c); 15 | } while (c != EOF); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w10-04_strcpies.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | char dst[5]; 11 | char src[] = "A Toyota is a Toyota"; 12 | 13 | strncpy(dst, src, 4); 14 | printf("dst: \"%s\" src: \"%s\"\n", dst, src); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2018-19/w10-05_pointers.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2018-2019 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | char line[256]; 12 | gets(line); 13 | 14 | for (int t = 0; line[t] != '\0'; ++t) 15 | { 16 | printf("%s (len: %d)\n", &line[t], strlen(&line[t])); 17 | } 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-00-Whoa.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Whoa!\n"); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-02_numbers.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int a = 7; 11 | 12 | printf("a / 2 = %d\n", a / 2); 13 | 14 | double tmp = a / 2; 15 | printf("a / 2 = %g\n", tmp); 16 | 17 | // old school 18 | double tmp2 = a / 2.0; 19 | printf("a / 2 = %g\n", tmp2); 20 | 21 | // newer 22 | double tmp3 = (double)a / 2.0; 23 | printf("a / 2 = %g\n", tmp3); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-03_scanf.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int i; 11 | printf("Enter a number: "); 12 | scanf("%d", &i); // keep scanf simple! 13 | printf("Cool, you typed \"%d\"\n", i); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-04_f2c.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | double fahrenheit; 11 | double celsius; 12 | 13 | printf("Fahrenheit to Celsius\n"); 14 | printf("Enter T in F: "); 15 | 16 | scanf("%lf", &fahrenheit); 17 | celsius = (fahrenheit - 32.0) * 5.0 / 9.0; 18 | printf("%gF = %gC\n", fahrenheit, celsius); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-05_scanf-problems.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | int yeuch; 12 | scanf("The answer is %d", &yeuch); 13 | printf("Yeuch = %d\n", yeuch); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-06_if.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Please, type 42: "); 11 | 12 | int dna; 13 | scanf("%d", &dna); 14 | 15 | if (dna == 42) 16 | { 17 | printf("Long life Douglas!\n"); 18 | } 19 | else 20 | { 21 | printf("D'ho!?\n"); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w03-10_loop.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int counter = 0; // INIT 11 | while (counter < 100) 12 | { // CONDITION 13 | printf("%d ", counter); // BODY 14 | counter = counter + 2; // UPDATE 15 | } 16 | printf("\n"); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w04-02_square.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int dim; 11 | printf("Dim: "); 12 | scanf("%d", &dim); 13 | 14 | for (int t = 0; t < dim; t = t + 1) 15 | { 16 | for (int u = 0; u < dim; u = u + 1) 17 | { 18 | printf("#"); 19 | } 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w04-03_triangle.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int dim; 11 | printf("Dim: "); 12 | scanf("%d", &dim); 13 | 14 | for (int t = 0; t < dim; t = t + 1) 15 | { 16 | for (int u = 0; u < t + 1; u = u + 1) 17 | { 18 | printf("#"); 19 | } 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w04-06_ptable.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | for (int t = 1; t < 13; t = t + 1) 11 | { 12 | // row 13 | for (int u = 1; u < 13; u = u + 1) 14 | { 15 | printf("%6d ", t * u); 16 | } 17 | 18 | printf("\n"); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w04-09_define.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define MAX_P_TABLE 10 9 | 10 | int main() 11 | { 12 | for (int t = 1; t <= MAX_P_TABLE; t = t + 1) 13 | { 14 | // row 15 | for (int u = 1; u <= MAX_P_TABLE; u = u + 1) 16 | { 17 | printf("%6d ", t * u); 18 | } 19 | 20 | printf("\n"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w05-02_arrays.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | #define ARRAY_SIZE 10 9 | 10 | int main() 11 | { 12 | int variable; 13 | int array[ARRAY_SIZE]; 14 | 15 | for (int t = 0; t < ARRAY_SIZE; ++t) 16 | { 17 | array[t] = t; 18 | } 19 | 20 | int t = 3; 21 | array[t * 2 - 1] = ++array[4] - --array[6]; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w08-04_multidim.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int Array2d[5][2] = {1, 2, 3, 4}; 9 | 10 | int main() 11 | { 12 | for (int t = 0; t < 5; ++t) 13 | { 14 | for (int u = 0; u < 2; ++u) 15 | { 16 | printf("%4d", Array2d[t][u]); 17 | } 18 | printf("\n"); 19 | } 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w09-01_codepages.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | printf("Voil�!?\n"); 11 | printf("����������\n"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w10-01_typedef.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | // int -> 16 bit -> 65,535 [ -32,768 +32,767 ] 6 | 7 | #include 8 | #include 9 | 10 | typedef unsigned long long int dkgjh_t; 11 | typedef int that_t; 12 | 13 | int main() 14 | { 15 | printf("%d\n", sizeof(dkgjh_t)); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w10-05_cmdline.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | int z = 42; 11 | for (int t = 0; t < argc; ++t) 12 | { 13 | printf("%d) \"%s\"\n", t, argv[t]); 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w11-07_struct.c: -------------------------------------------------------------------------------- 1 | // Copyright © 2019-2020 Giovanni Squillero 2 | // https://github.com/squillero/computer-sciences 3 | // Free under certain conditions — see the license for details. 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | int number; 11 | 12 | fprintf(stdout, "Tell me a number: "); 13 | fscanf(stdin, "%d", &number); 14 | fprintf(stdout, "You said %d\n", number); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w12-01_files_friends.txt: -------------------------------------------------------------------------------- 1 | Adam Levine Jesse Carmichael Mickey Madden James Valentine Matt Flynn PJ Morton Sam Farrar Chris Martin Jonny Buckland Guy Berryman Will Champion Phil Harvey 2 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w12-03_billy-idol_band.txt: -------------------------------------------------------------------------------- 1 | Billy Idol 2 | Billy Morrison 3 | Bonnie Hayes 4 | Brian Tichy 5 | Danny Sadownik 6 | Derek Sherinian 7 | Derwood Andrews 8 | Erik Eldenius 9 | Gregg Gerson 10 | James Stevenson 11 | Jennifer Blakeman 12 | Jeremy Colson 13 | John Towe 14 | Judi Dozier 15 | Julie Greaux 16 | Kenny Aaronson 17 | Larry Seymour 18 | Mark Laff 19 | Mark Schulman 20 | Mark Younger-Smith 21 | Paul Trudeau 22 | Phil Feit 23 | Phil Soussan 24 | Sasha Krivtsov 25 | Stephen McGrath 26 | Steve Missal 27 | Steve Stevens 28 | Steve Webster 29 | Susie Davis 30 | Tal Bergman 31 | Terry Chimes 32 | Thommy Price 33 | Tony James 34 | Zane Fix -------------------------------------------------------------------------------- /C/Class examples/2019-20/w12-04_billy-idol-and-friends_band.txt: -------------------------------------------------------------------------------- 1 | Billy Idol 2 | Slash 3 | Billy Morrison 4 | Bonnie Hayes 5 | Brian Tichy 6 | Zane Fix -------------------------------------------------------------------------------- /C/Class examples/2019-20/w13-02_exam-20190621_28dec.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 12:00 20.4 21.3 19.8 20.2 21.0 3 | 12:01 20.5 21.4 19.7 20.4 21.1 4 | 12:02 20.6 21.5 19.3 20.5 21.2 5 | 12:03 20.5 21.6 19.5 20.7 21.3 6 | 12:04 20.6 21.7 19.4 20.8 21.4 7 | 12:05 20.2 21.8 19.3 20.9 21.5 8 | 12:06 20.3 21.9 19.6 21.0 21.4 9 | 12:07 20.5 22.0 19.5 21.1 21.3 10 | 12:08 20.6 22.1 19.4 21.3 21.2 11 | 12:09 20.4 22.1 19.5 21.3 21.1 12 | 12:10 20.3 22.0 19.4 21.4 21.0 13 | 12:11 20.2 21.9 19.5 21.3 21.1 14 | 12:12 20.2 21.9 19.5 21.3 21.1 15 | 12:13 20.3 21.7 19.5 21.4 21.2 16 | 12:14 20.2 21.6 19.4 21.8 21.1 17 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w13-02_exam-20190621_dat1.txt: -------------------------------------------------------------------------------- 1 | 5 2 | 12:00 20.4 21.3 19.8 20.2 21.0 3 | 12:01 20.5 21.4 19.7 20.4 21.1 4 | 12:02 20.6 21.5 19.3 20.5 21.2 5 | 12:03 20.5 21.6 19.5 20.7 21.3 6 | 12:04 20.6 21.7 19.4 20.8 21.4 7 | 12:05 20.2 21.8 19.3 20.9 21.5 8 | 12:06 20.3 21.9 19.6 21.0 21.4 9 | 12:07 20.5 22.0 19.5 21.1 21.3 10 | 12:08 20.6 22.1 19.4 21.3 21.2 11 | 12:09 20.4 22.1 19.5 21.3 21.1 12 | 12:10 20.3 22.0 19.4 21.4 21.0 13 | 12:11 20.2 21.9 19.5 21.3 21.1 14 | 12:12 20.2 21.9 19.5 21.3 21.1 15 | 12:13 20.3 21.7 19.5 21.4 21.2 16 | 12:14 20.2 21.6 19.4 21.8 21.1 17 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w14-02_exam20190216_requests.txt: -------------------------------------------------------------------------------- 1 | Book 2 | Toy 3 | Bike 4 | Ball 5 | Guitar 6 | Ski 7 | Bike 8 | Ski 9 | Bike 10 | Book 11 | Bike 12 | Guitar 13 | Guitar 14 | Backsword 15 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w14-02_exam20190216_warehouse.txt: -------------------------------------------------------------------------------- 1 | Book 6 2 | Toy 18 3 | Bike 0 4 | Ball 98 5 | Tablet 20 6 | Guitar 0 7 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w14-03_exam20190215_catalog.txt: -------------------------------------------------------------------------------- 1 | HW111333 2 | door_opener remote_controller remote_control 3 | SW22222222 4 | HW111444 5 | door_opener local_control no_remote_controller 6 | SW22222222 7 | HW222444 8 | thermostat remote_controller remote_control 9 | SW12112121 10 | HW222555 11 | door_opener control_unit yes_remote_controller 12 | SW33335555 13 | -------------------------------------------------------------------------------- /C/Class examples/2019-20/w14-03_exam20190215_versions_sw.txt: -------------------------------------------------------------------------------- 1 | SW22222222 2 | base software operating system eCos 3 | SW12112121 4 | software version1 operating system VxWorks 5 | SW33334444 6 | software version2 operating system VxWorks 7 | SW44445555 8 | software version3 operating system eCos 9 | -------------------------------------------------------------------------------- /C/Exams/00-Cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/00-Cheatsheet.pdf -------------------------------------------------------------------------------- /C/Exams/20110701-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20110701-A.pdf -------------------------------------------------------------------------------- /C/Exams/20110722-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20110722-B.pdf -------------------------------------------------------------------------------- /C/Exams/20110919-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20110919-A.pdf -------------------------------------------------------------------------------- /C/Exams/20120301.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20120301.pdf -------------------------------------------------------------------------------- /C/Exams/20120627.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20120627.pdf -------------------------------------------------------------------------------- /C/Exams/20130204.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20130204.pdf -------------------------------------------------------------------------------- /C/Exams/20130705-A+B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20130705-A+B.pdf -------------------------------------------------------------------------------- /C/Exams/20130719-A+B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20130719-A+B.pdf -------------------------------------------------------------------------------- /C/Exams/20130719-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20130719-A.pdf -------------------------------------------------------------------------------- /C/Exams/20140109-A+C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140109-A+C.pdf -------------------------------------------------------------------------------- /C/Exams/20140109-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140109-A.pdf -------------------------------------------------------------------------------- /C/Exams/20140120-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140120-A.pdf -------------------------------------------------------------------------------- /C/Exams/20140623-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140623-C.pdf -------------------------------------------------------------------------------- /C/Exams/20140707-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140707-A.pdf -------------------------------------------------------------------------------- /C/Exams/20140707-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20140707-B.pdf -------------------------------------------------------------------------------- /C/Exams/20150224-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20150224-B.pdf -------------------------------------------------------------------------------- /C/Exams/20150224-C+B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20150224-C+B.pdf -------------------------------------------------------------------------------- /C/Exams/20150622-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20150622-A.pdf -------------------------------------------------------------------------------- /C/Exams/20150622-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20150622-B.pdf -------------------------------------------------------------------------------- /C/Exams/20160218-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20160218-C.pdf -------------------------------------------------------------------------------- /C/Exams/201606-A.dat: -------------------------------------------------------------------------------- 1 | o.... 2 | oooB. 3 | o.... 4 | oo... 5 | .oooB 6 | -------------------------------------------------------------------------------- /C/Exams/201606-B_calls.dat: -------------------------------------------------------------------------------- 1 | 3472222222 01/01/2011 10:10:12 10:11:10 S 2 | 3472222222 02/01/2011 15:10:12 16:11:20 N 3 | 3471111111 01/01/2011 11:10:12 11:21:10 N 4 | 3472222222 08/01/2011 21:20:12 22:13:09 N 5 | 3471111111 01/02/2011 11:15:00 11:15:10 N 6 | 3472222222 10/02/2011 21:20:12 22:11:10 N 7 | -------------------------------------------------------------------------------- /C/Exams/201606-B_rates.dat: -------------------------------------------------------------------------------- 1 | 0.23 2 | 0.51 3 | 0.65 4 | 0.12 5 | -------------------------------------------------------------------------------- /C/Exams/201609-A_Image.dat: -------------------------------------------------------------------------------- 1 | 10 2 20 30 0 0 1 10 20 10 2 | 1 40 -1 27 33 41 444 98 900 79 3 | 78 6 54 87 0 67 0 67 87 78 4 | 67 78 87 95 98 61 98 67 98 67 5 | 98 67 89 63 98 65 89 67 89 654 6 | 6 7 8 9 5 7 9 547 84 54 7 | 234 54 6 867 789 54 34 54 67 8 8 | -------------------------------------------------------------------------------- /C/Exams/201609-A_Kernel.dat: -------------------------------------------------------------------------------- 1 | 1 0 -1 2 | 0 0 0 3 | -1 0 1 4 | -------------------------------------------------------------------------------- /C/Exams/201609-A_Kernel2.dat: -------------------------------------------------------------------------------- 1 | 0 -1 0 2 | 0 1 0 3 | 0 0 0 4 | -------------------------------------------------------------------------------- /C/Exams/201609-B_Results.txt: -------------------------------------------------------------------------------- 1 | JUMPA A2323BB123 ITA 3 2 | SOCCE BB23234A12 BRA 1 3 | JUMPA AJKHGF65TY USA 1 4 | JUMPA JKI7HTYGRT FRA 2 5 | SOCCE 78JUYGHTY6 ITA 3 6 | SOCCE JKHTYFRGTY ESP 2 7 | JUMPA XCBFGHD67Y ESP 4 8 | BASKE XCBFGHD67Y USA 1 9 | SOCCE HJKIUOIUJH POR 4 10 | BASKE VBGFTREDJU GRE 3 11 | BASKE 8IK9765GHY CRO 2 12 | BASKE KJ8UKILKJH ESP 4 13 | -------------------------------------------------------------------------------- /C/Exams/20170203-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20170203-C.pdf -------------------------------------------------------------------------------- /C/Exams/20170203-C_limits.txt: -------------------------------------------------------------------------------- 1 | 4.00 5.00 2 | 2.00 3.00 3 | 5.01 7.02 4 | 3.10 7.03 5 | 2.00 6.00 6 | 5.00 5.50 7 | 3.00 4.00 8 | 6.00 6.20 9 | 4.00 6.00 10 | 3.50 6.90 11 | -------------------------------------------------------------------------------- /C/Exams/20170217-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20170217-B.pdf -------------------------------------------------------------------------------- /C/Exams/20180202-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180202-A.pdf -------------------------------------------------------------------------------- /C/Exams/20180202-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180202-B.pdf -------------------------------------------------------------------------------- /C/Exams/20180216-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180216-C.pdf -------------------------------------------------------------------------------- /C/Exams/20180216-D.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180216-D.pdf -------------------------------------------------------------------------------- /C/Exams/20180622-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180622-A.pdf -------------------------------------------------------------------------------- /C/Exams/20180622-A_burton.txt: -------------------------------------------------------------------------------- 1 | 08:05:12 1.100000 2 | 08:05:13 2.200000 3 | 08:05:15 3.300000 4 | 08:06:14 9.980000 5 | 08:09:14 99.000000 6 | -------------------------------------------------------------------------------- /C/Exams/20180622-A_primo.txt: -------------------------------------------------------------------------------- 1 | 08:05:13 2.2 2 | 08:06:14 9.99 3 | -------------------------------------------------------------------------------- /C/Exams/20180622-A_secondo.txt: -------------------------------------------------------------------------------- 1 | 08:05:12 1.1 2 | 08:05:15 3.3 3 | 08:06:14 9.97 4 | 08:09:14 99 5 | -------------------------------------------------------------------------------- /C/Exams/20180914-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20180914-B.pdf -------------------------------------------------------------------------------- /C/Exams/20180914-B_hotels.dat: -------------------------------------------------------------------------------- 1 | Dolomiti north 120.00 2 | Miramare south 80.00 3 | Gino east 60.00 4 | Fronti north 132.00 5 | Imperial east 200.00 6 | Locanda south 83.00 7 | Siberiano north 140.00 8 | -------------------------------------------------------------------------------- /C/Exams/20190201-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20190201-A.pdf -------------------------------------------------------------------------------- /C/Exams/20190201-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20190201-B.pdf -------------------------------------------------------------------------------- /C/Exams/20190201-B_fares.txt: -------------------------------------------------------------------------------- 1 | Torino Chivasso 3.50 2 | Santhia Vercelli 2.50 3 | Chivasso Santhia 3.25 4 | Magenta Rho 5.50 5 | Novara Magenta 3.00 6 | Rho Milano 4.35 7 | Vercelli Novara 1.20 8 | -------------------------------------------------------------------------------- /C/Exams/20190215-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20190215-C.pdf -------------------------------------------------------------------------------- /C/Exams/20190215-C_catalog.txt: -------------------------------------------------------------------------------- 1 | HW111333 2 | door_opener remote remote_access 3 | SW22222222 4 | HW111444 5 | door_opener local_access no_remote 6 | SW22222222 7 | HW222444 8 | thermo remote remote_access 9 | SW12112121 10 | HW222555 11 | door_opener cu si_remote 12 | SW33335555 13 | -------------------------------------------------------------------------------- /C/Exams/20190215_versions.txt: -------------------------------------------------------------------------------- 1 | SW22222222 2 | Base software for operating system eCos 3 | SW12112121 4 | Software version 1 for operativo system VxWorks 5 | SW33334444 6 | Software version 1.1 for operativo system VxWorks 7 | SW44445555 8 | Software version 3 for operativo system eCos 9 | -------------------------------------------------------------------------------- /C/Exams/20190216-D.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20190216-D.pdf -------------------------------------------------------------------------------- /C/Exams/20190621-B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20190621-B.pdf -------------------------------------------------------------------------------- /C/Exams/20200131-C.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20200131-C.pdf -------------------------------------------------------------------------------- /C/Exams/20200131-C_map1.dat: -------------------------------------------------------------------------------- 1 | 00000000 2 | 000aaa00 3 | 00b00000 4 | 00b00000 5 | 00b00000 6 | 00b00000 7 | 00000cc0 8 | 00000000 9 | -------------------------------------------------------------------------------- /C/Exams/20200131-C_orders.dat: -------------------------------------------------------------------------------- 1 | a E 2 2 | a S 1 3 | b N 2 4 | c S 2 5 | -------------------------------------------------------------------------------- /C/Exams/20200214-A-pat.dat: -------------------------------------------------------------------------------- 1 | AAA 2 | AABBAA 3 | XYZ 4 | -------------------------------------------------------------------------------- /C/Exams/20200214-A-seq.dat: -------------------------------------------------------------------------------- 1 | * 2 | X 3 | A 4 | A 5 | B 6 | B 7 | A 8 | A 9 | A 10 | A 11 | A 12 | A 13 | A 14 | A 15 | Y 16 | Z 17 | * 18 | -------------------------------------------------------------------------------- /C/Exams/20200214-A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/C/Exams/20200214-A.pdf -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## Computer Sciences 2 | 3 | 4 | 5 | #### Copyright © 2015-2024 by Giovanni Squillero 6 | 7 | Permission to make digital or hard copies of some or all of these files for 8 | personal or classroom use is granted without fee provided that copies are not 9 | made or distributed for profit or commercial advantage, and that copies bear 10 | both this copyright notice and the full reference to the source repository. 11 | To republish, to redistribute to lists, or to post on servers, contact the 12 | Author. Copyrights for third-party components must be honored. 13 | These files are offered as-is, without any warranty. 14 | -------------------------------------------------------------------------------- /Python/exams/_imported/README.md: -------------------------------------------------------------------------------- 1 | # IMPORTED 2 | 3 | :boom: An unchecked, uncontrolled, and possibly unreliable list of old exams translated from Italian ([original versions](https://github.com/polito-info-2021/Esempi-esame)). 4 | -------------------------------------------------------------------------------- /Python/exams/_imported/astrologia_calciatori/zodiaco.csv: -------------------------------------------------------------------------------- 1 | Aries,21/03,20/04 2 | Taurus,21/04,20/05 3 | Gemini,21/05,21/06 4 | Cancer,22/06,22/07 5 | Leone,23/07,23/08 6 | Virgo,24/08,22/09 7 | Libra,23/09,22/10 8 | Scorpio,23/10,22/11 9 | Sagittarius,23/11,21/12 10 | Capricorn,22/12,20/01 11 | Aquarius,21/01,19/02 12 | Pisces,20/02,20/03 13 | -------------------------------------------------------------------------------- /Python/exams/_imported/bowling/bowling.txt: -------------------------------------------------------------------------------- 1 | Rossi;Massimo;7;10;6;5;10;4;9;9;5;10;10 2 | Verdi;Giuseppe;10;10;6;6;7;9;9;8;9;9;10;10;10 3 | De Piscopo;Tullio;9;9;8;8;7;7;6;6;0;5 4 | Montalbano;Salvo;10;10;9;10;10;10;9;10;10;10 -------------------------------------------------------------------------------- /Python/exams/_imported/discografia/acdc.txt: -------------------------------------------------------------------------------- 1 | 1978;Kicked In The Teeth 2 | 1985;Playing with Girls 3 | 1985;Shake Your Foundations 4 | 1990;Thunderstruck -------------------------------------------------------------------------------- /Python/exams/_imported/discografia/artists.txt: -------------------------------------------------------------------------------- 1 | 01023;queen.txt 2 | 02346;kiss.txt 3 | 16750;acdc.txt -------------------------------------------------------------------------------- /Python/exams/_imported/discografia/kiss.txt: -------------------------------------------------------------------------------- 1 | 1980;Two Sides of the Coin 2 | 1985;King Of The Mountain 3 | 1979;I Was Made for Lovin' You -------------------------------------------------------------------------------- /Python/exams/_imported/discografia/queen.txt: -------------------------------------------------------------------------------- 1 | 1980;Crazy Little Thing Called Love 2 | 1985;It's a kind of magic 3 | 1978;Under pressure -------------------------------------------------------------------------------- /Python/exams/_imported/ginnastica_artistica/scores.txt: -------------------------------------------------------------------------------- 1 | Yuri Chechi M ITA 9.3 8.9 9.7 9.7 9.8 2 | Veronica Servente F ITA 9.0 9.0 9.0 9.2 9.5 3 | Sabrina Vega F USA 8.4 8.7 8.5 8.6 9.0 4 | Viktoria Komova F RUS 8.3 8.7 9.5 9.6 9.0 5 | Rebecca Downie F GRB 8.2 8.9 8.9 8.6 9.3 6 | Gabbie Douglas F USA 8.2 8.9 8.9 8.6 9.3 7 | Hannah Whelan F GRB 8.0 8.0 8.0 8.0 8.0 -------------------------------------------------------------------------------- /Python/exams/_imported/glucometer/glucometers.txt: -------------------------------------------------------------------------------- 1 | 1BF0 17:00 160 37.0 68 2 | 1BF0 17:05 168 37.0 68 3 | 1BF0 21:00 180 37.3 66 4 | 1BF0 21:05 210 37.1 67 5 | 0AE1 21:10 187 37.3 69 6 | 0AE1 21:15 192 37.3 70 7 | 0AE1 21:20 195 37.4 70 8 | 0AE1 21:25 201 37.4 75 9 | BBB3 22:30 108 37.5 73 10 | BBB3 22:35 200 37.5 73 11 | 0AE1 23:05 203 37.4 73 12 | 0AE1 23:10 210 37.5 71 13 | 1BF0 21:10 213 37.2 68 -------------------------------------------------------------------------------- /Python/exams/_imported/guess_who/question1.txt: -------------------------------------------------------------------------------- 1 | Hair color = Blond 2 | Hair length = Short 3 | Glasses = YES 4 | -------------------------------------------------------------------------------- /Python/exams/_imported/guess_who/question2.txt: -------------------------------------------------------------------------------- 1 | Gender = Male 2 | Hair length = Short 3 | Beard = YES 4 | -------------------------------------------------------------------------------- /Python/exams/_imported/hacking/products.txt: -------------------------------------------------------------------------------- 1 | P234HF22222 r1011 2 | P234HF22223 r1112 3 | P234HF22225 r1114 4 | P111TG11115 r1015 5 | P111TG11116 r1216 6 | P331LS00110 r1017 7 | P331LS00120 r1318 8 | P331LS00130 r1019 -------------------------------------------------------------------------------- /Python/exams/_imported/hacking/purchases.txt: -------------------------------------------------------------------------------- 1 | P234HF22223 r1112 2 | P111TG11115 r1015 3 | P111TG11115 r1216 4 | P234HF22222 r1011 5 | P331LS00110 r1014 6 | P331LS00120 r1318 7 | P331LS00130 r1019 8 | P234HF22225 r1114 9 | P234HF22223 r1114 -------------------------------------------------------------------------------- /Python/exams/_imported/murphy/arguments.txt: -------------------------------------------------------------------------------- 1 | male 2 | fretta 3 | lavoro 4 | -------------------------------------------------------------------------------- /Python/exams/_imported/piramidi/map.txt: -------------------------------------------------------------------------------- 1 | 3 4 4 4 3 2 1 0 0 0 2 | 3 4 5 4 3 2 1 1 1 1 3 | 3 4 4 4 3 2 2 2 2 1 4 | 3 3 3 3 3 3 3 3 2 1 5 | 2 2 2 2 2 3 4 3 2 1 6 | 1 1 1 1 2 3 3 3 2 1 7 | 0 0 0 1 2 2 2 2 2 1 8 | 0 0 0 1 1 1 1 1 1 1 9 | 0 1 0 0 0 0 0 0 0 0 10 | 0 0 0 0 0 0 1 0 0 0 -------------------------------------------------------------------------------- /Python/exams/_imported/ricette/foods.txt: -------------------------------------------------------------------------------- 1 | Corn flour; 2.21; 3620 2 | Toma; 19.8; 3710 3 | Fontina; 13.8; 3430 4 | Butter; 3.99; 7500 5 | Passed; 2.49; 180 6 | Olive; 11.65; 1420 7 | Capers; 18; 250 8 | Fusilli; 1.71; 3500 -------------------------------------------------------------------------------- /Python/exams/_imported/ricette/fusilli_alle_olive.txt: -------------------------------------------------------------------------------- 1 | Ingredients: 2 | Fusilli; 350 3 | Past; 500 4 | Olives; 80 5 | 6 | Method: 7 | Cook the tomato puree in a saucepan. Add the olives cut into rings. Boil the water and cook the fusilli. Drain al dente, add to the sauce and serve.al dente, unire al sugo e servire. -------------------------------------------------------------------------------- /Python/exams/_imported/ricette/polenta_concia.txt: -------------------------------------------------------------------------------- 1 | Ingrediants: 2 | Corn flour; 500 3 | Toma; 200 4 | Fontina; 200 5 | Butter; 200 6 | 7 | Method: 8 | Cut the fontina and toma cheese into cubes. Boil the water, add the cornmeal and mix. When the polenta has reached the desired consistency, add the butter, fontina and toma. -------------------------------------------------------------------------------- /Python/exams/armstrong/numbers.txt: -------------------------------------------------------------------------------- 1 | 42 2 | 7 3 | 1634 4 | 1743 5 | 2 6 | 45656 7 | 565 8 | 371 9 | 407 10 | 8208 11 | 153 12 | 6 13 | 4646 14 | 370 15 | 9474 16 | 9475 17 | -------------------------------------------------------------------------------- /Python/exams/battleship/map1.dat: -------------------------------------------------------------------------------- 1 | -#------#- 2 | -#-----##- 3 | -#-----##- 4 | --------#- 5 | --####---- 6 | ---------- 7 | -#--#----- 8 | -#------#- 9 | -#---##--- 10 | -#-------- 11 | -------------------------------------------------------------------------------- /Python/exams/battleship/map2.dat: -------------------------------------------------------------------------------- 1 | -#------#- 2 | -##-----#- 3 | -##-----#- 4 | -#-------- 5 | ---####--- 6 | ---------- 7 | ------#--# 8 | -#-------# 9 | -----##--# 10 | ---------# 11 | -------------------------------------------------------------------------------- /Python/exams/battleship/moves.txt: -------------------------------------------------------------------------------- 1 | A,1 2 | F,5 3 | A,4 4 | C,1 5 | A,5 6 | C,3 7 | A,6 8 | B,3 9 | -------------------------------------------------------------------------------- /Python/exams/cheat-sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/Python/exams/cheat-sheet.pdf -------------------------------------------------------------------------------- /Python/exams/chess/games_short.csv: -------------------------------------------------------------------------------- 1 | PLAYER A,PLAYER B,RESULT 2 | Magnus Carlsen,Mr. T,1-0 3 | Wesley So,Magnus Carlsen,0-1 4 | -------------------------------------------------------------------------------- /Python/exams/chess/players.csv: -------------------------------------------------------------------------------- 1 | PLAYER,SELO 2 | Alexander Grischuk,2764 3 | Alireza Firouzja,2804 4 | Anish Giri,2772 5 | Ding Liren,2799 6 | Fabiano Caruana,2792 7 | Ian Nepomniachtchi,2782 8 | Jan Krzysztof Duda,2760 9 | Leinier Dominguez Perez,2752 10 | Levon Aronian,2772 11 | Magnus Carlsen,2856 12 | Maxime Vachier Lagrave,2761 13 | Richard Rapport,2763 14 | Shakhriyar Mamedyarov,2767 15 | Teimour Radjabov,2753 16 | Wesley So,2772 17 | -------------------------------------------------------------------------------- /Python/exams/chess/players_short.csv: -------------------------------------------------------------------------------- 1 | PLAYER,SELO 2 | Magnus Carlsen,2856 3 | Wesley So,2772 -------------------------------------------------------------------------------- /Python/exams/connect-four/moves.txt: -------------------------------------------------------------------------------- 1 | G1 0 2 | G2 1 3 | G1 2 4 | G2 2 5 | G1 1 6 | G2 3 7 | G1 2 8 | G2 1 9 | G1 3 10 | G2 3 11 | G1 3 12 | -------------------------------------------------------------------------------- /Python/exams/consumption+production/systems.csv: -------------------------------------------------------------------------------- 1 | Household_ID;System_size;Efficiency 2 | ID1;63.51;0.19 3 | ID2;230.33;0.25 4 | ID3;41.99;0.2 5 | ID4;84.38;0.23 6 | ID5;330.67;0.18 7 | ID6;52.65;0.21 8 | ID7;46.84;0.23 9 | ID8;88.15;0.16 10 | ID9;81.43;0.22 11 | ID10;24.33;0.25 -------------------------------------------------------------------------------- /Python/exams/freedonia/dates-example1.dat: -------------------------------------------------------------------------------- 1 | 25-1-2021 2 | 1-1-1999 3 | 1-2-2022 4 | -------------------------------------------------------------------------------- /Python/exams/freedonia/dates-example2.dat: -------------------------------------------------------------------------------- 1 | 03-01-2000 2 | 23-06-2000 3 | 25-07-2000 4 | 16-12-2000 5 | 27-03-2001 6 | 07-05-2001 7 | 07-11-2001 8 | -------------------------------------------------------------------------------- /Python/exams/freedonia/dates.dat: -------------------------------------------------------------------------------- 1 | 08-01-2013 2 | 29-02-2000 3 | 08-12-2009 4 | 18-11-2019 5 | 08-08-2005 6 | 05-06-2006 7 | -------------------------------------------------------------------------------- /Python/exams/freedonia/rules-example1.dat: -------------------------------------------------------------------------------- 1 | 01-01-2021: +surgical_mask_outdoor +surgical_mask_indoor 2 | 05-01-2021: -surgical_mask_indoor +ffp2_mask_indoor 3 | 08-01-2021: +green_pass_workplace 4 | 01-02-2021: -ffp2_mask_indoor +surgical_mask_indoor -surgical_mask_outdoor 5 | 01-03-2021: +surgical_mask_outdoor 6 | 05-03-2021: +super_green_pass_workplace -green_pass_workplace 7 | -------------------------------------------------------------------------------- /Python/exams/freedonia/rules-example2.dat: -------------------------------------------------------------------------------- 1 | 17-01-2000: +rule_04 2 | 21-01-2000: -rule_04 3 | 22-01-2000: +rule_00 4 | 03-06-2000: +rule_03 5 | 07-06-2000: -rule_03 6 | 08-06-2000: -rule_00 7 | 03-07-2000: +rule_09 +rule_07 8 | 16-09-2000: -rule_07 -rule_09 9 | 02-10-2000: +rule_03 10 | 10-10-2000: -rule_03 11 | 13-12-2000: +rule_03 12 | 11-01-2001: +rule_04 13 | 07-02-2001: +rule_09 14 | 24-02-2001: +rule_07 +rule_02 15 | 18-03-2001: -rule_02 16 | 30-05-2001: +rule_02 17 | 22-06-2001: -rule_07 -rule_03 -rule_02 18 | 12-07-2001: -rule_09 19 | 26-09-2001: +rule_01 20 | 08-10-2001: -rule_01 +rule_00 21 | 22-10-2001: +rule_07 22 | 04-11-2001: -rule_00 -rule_07 23 | -------------------------------------------------------------------------------- /Python/exams/magic-boxes/actions-simple.txt: -------------------------------------------------------------------------------- 1 | Bob gives a APPLE 2 | Bob gives a BANANA 3 | Bob gives a APPLE 4 | Carl takes a BANANA 5 | Bob gives a CHERRY 6 | -------------------------------------------------------------------------------- /Python/exams/misspell/names.txt: -------------------------------------------------------------------------------- 1 | Martina 2 | Valentina 3 | Leonardo 4 | Gennaro 5 | Genoveffa -------------------------------------------------------------------------------- /Python/exams/munodi/seq.dat: -------------------------------------------------------------------------------- 1 | 12 6 3 10 5 16 8 4 2 1 2 | 12 6 3 10 4 16 8 4 2 1 3 | 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 4 | 1 5 | -------------------------------------------------------------------------------- /Python/exams/shells/cart.dat: -------------------------------------------------------------------------------- 1 | A 2 | A 3 | A 4 | A 5 | B 6 | B 7 | C 8 | D 9 | -------------------------------------------------------------------------------- /Python/exams/shells/es1_cart.dat: -------------------------------------------------------------------------------- 1 | Nautilus_Shell 2 | Nautilus_Shell 3 | Abalone 4 | Drupe 5 | Abalone 6 | Nautilus_Shell 7 | Venus_Comb 8 | Nautilus_Shell 9 | Nautilus_Shell 10 | Large_Strombus_Gigas 11 | Nautilus_Shell 12 | Nautilus_Shell 13 | Medium_Strombus_Gigas 14 | Nautilus_Shell 15 | Nautilus_Shell 16 | Nautilus_Shell 17 | Small_Strombus_Gigas 18 | Abalone 19 | Abalone 20 | -------------------------------------------------------------------------------- /Python/exams/shells/es1_offers.dat: -------------------------------------------------------------------------------- 1 | Abalone Abalone: Drupe 2 | Conus_Gloriamaris: Cowrie 3 | Large_Strombus_Gigas Medium_Strombus_Gigas Small_Strombus_Gigas: Venus_Comb 4 | Conch Conch: Melo_Melo 5 | Cypraea_Tigris: Miter_Shell 6 | Nautilus_Shell Nautilus_Shell Nautilus_Shell Nautilus_Shell: Nautilus_Shell 7 | Sand_Dollar Sand_Dollar Sand_Dollar Sand_Dollar: Sand_Dollar 8 | Murex Murex Murex: Oyster_Shell 9 | -------------------------------------------------------------------------------- /Python/exams/shells/es1_prices.dat: -------------------------------------------------------------------------------- 1 | Abalone: 19.99 2 | Clam_Shell: .1 3 | Conch: 50 4 | Conus_Gloriamaris: 20000 5 | Cowrie: 19.99 6 | Cypraea_Tigris: 5000 7 | Drupe: .99 8 | Large_Strombus_Gigas: 250 9 | Medium_Strombus_Gigas: 1000 10 | Melo_Melo: 4.99 11 | Melon_Shell: 1.5 12 | Miter_Shell: 3.5 13 | Murex: 2.5 14 | Nautilus_Shell: 2.99 15 | Oyster_Shell: .5 16 | Sand_Dollar: 2.5 17 | Small_Strombus_Gigas: 2500 18 | Venus_Comb: 75 19 | -------------------------------------------------------------------------------- /Python/exams/shells/offers.dat: -------------------------------------------------------------------------------- 1 | A A: A 2 | B B B: C 3 | C: D 4 | -------------------------------------------------------------------------------- /Python/exams/shells/prices.dat: -------------------------------------------------------------------------------- 1 | A: 1 2 | B: 10 3 | C: .1 4 | D: .01 5 | -------------------------------------------------------------------------------- /Python/exams/shells/t0_cart.dat: -------------------------------------------------------------------------------- 1 | Shell1 2 | Shell2 3 | Shell3 4 | -------------------------------------------------------------------------------- /Python/exams/shells/t0_offers.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/Python/exams/shells/t0_offers.dat -------------------------------------------------------------------------------- /Python/exams/shells/t0_prices.dat: -------------------------------------------------------------------------------- 1 | Shell1: 1 2 | Shell2: 2 3 | Shell3: 3 4 | -------------------------------------------------------------------------------- /Python/exams/shells/t1_cart.dat: -------------------------------------------------------------------------------- 1 | Shell1 2 | Shell1 3 | Shell1 4 | Shell2 -------------------------------------------------------------------------------- /Python/exams/shells/t1_offers.dat: -------------------------------------------------------------------------------- 1 | Shell1 Shell1 Shell1: Shell2 -------------------------------------------------------------------------------- /Python/exams/shells/t1_prices.dat: -------------------------------------------------------------------------------- 1 | Shell1: 1 2 | Shell2: 1000 3 | -------------------------------------------------------------------------------- /Python/exams/shells/t2_cart.dat: -------------------------------------------------------------------------------- 1 | Shell1 2 | Shell1 3 | Shell1 4 | Shell3 -------------------------------------------------------------------------------- /Python/exams/shells/t2_offers.dat: -------------------------------------------------------------------------------- 1 | Shell1 Shell1 Shell1: Shell2 -------------------------------------------------------------------------------- /Python/exams/shells/t2_prices.dat: -------------------------------------------------------------------------------- 1 | Shell1: .1 2 | Shell2: 1000 3 | Shell3: 1 4 | -------------------------------------------------------------------------------- /Python/exams/shells/t3_cart.dat: -------------------------------------------------------------------------------- 1 | Shell1 2 | Shell1 3 | Shell1 4 | Shell2 5 | Shell3 6 | -------------------------------------------------------------------------------- /Python/exams/shells/t3_offers.dat: -------------------------------------------------------------------------------- 1 | Shell1 Shell1 Shell1: Shell2 2 | Shell2 Shell2: Shell3 3 | -------------------------------------------------------------------------------- /Python/exams/shells/t3_prices.dat: -------------------------------------------------------------------------------- 1 | Shell1: .1 2 | Shell2: 1 3 | Shell3: 10000 4 | -------------------------------------------------------------------------------- /Python/exams/soccer/player_stats-small.csv: -------------------------------------------------------------------------------- 1 | player,position,team,birth_year,minutes,goals,assists,offsides,crosses,interceptions,tackles_won,pens_conceded,ball_recoveries,aerials_won,aerials_lost 2 | Aaron Mooy,MF,Australia,1990,360,0,0,0,10,3,6,0,35,2,3 3 | Aaron Ramsey,MF,Wales,1990,266,0,0,0,5,0,0,0,19,0,2 4 | Abdelhamid Sabiri,MF,Morocco,1996,181,0,1,0,1,5,1,0,7,2,2 5 | Abdelkarim Hassan,DF,Qatar,1993,270,0,0,1,6,1,3,0,11,3,1 6 | Abderrazak Hamdallah,FW,Morocco,1990,68,0,0,0,0,0,0,0,4,1,7 7 | Abdessamad Ezzalzouli,FW,Morocco,2001,93,0,0,0,1,0,2,0,4,1,2 8 | -------------------------------------------------------------------------------- /Python/exams/strawberry/strawberry-short.txt: -------------------------------------------------------------------------------- 1 | No one I think is in my tree 2 | I mean it must be high or low 3 | That is you cannot, you know, tune in, but it is all right 4 | That is I think it is not too bad... 5 | 6 | Let me take you down, because I am going to 7 | Strawberry Fields 8 | Nothing is real, and nothing to get hung about 9 | Strawberry Fields forever 10 | -------------------------------------------------------------------------------- /Python/exams/worms/seq.txt: -------------------------------------------------------------------------------- 1 | line word time line back number way water 2 | people boy water sound line day part sound work place 3 | year number line word boy back boy man thing time 4 | name sentence back man sound 5 | line boy sound word 6 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-01.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | foo = 4 6 | bar = 2 7 | 8 | print("The answer is \"{foo*10 + bar:10d}\"") 9 | print(f"The answer is \"{foo*10 + bar:10d}\"") 10 | print("The answer is", foo * 10 + bar) 11 | 12 | s1 = f"{foo*10 + bar}" 13 | s2 = f"{foo*10 + bar:e}" 14 | s3 = f"{foo*10 + bar:20.4f}" 15 | 16 | print(s1) 17 | print(s2) 18 | print(s3) 19 | 20 | print(f"{round(2/3):d}") 21 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-02.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | for n in range(0, 20): 6 | if n < 13: 7 | actual_floor = n 8 | else: 9 | actual_floor = n - 1 10 | if n != 13: 11 | print(f"User push {n} -> actual floor is {actual_floor}") 12 | 13 | print("That's all folks") 14 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-03.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | for n in range(0, 100): 6 | if n == 42: 7 | print(f"Whoa! n is exactly {n}!!!!!") 8 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-04.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = input("What is your name? ") 6 | 7 | if len(name) > 20: 8 | print(f'Oooooo, "{name}" is really a long name...') 9 | 10 | n = int(input(f"{name}, tell me a number: ")) 11 | print(n + 42) 12 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-05.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = input("What is your name? ") 6 | 7 | if name.upper() == "BOB": 8 | print(f"Hi {name}!") 9 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201021-06.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | str1 = input("First string : ") 6 | str2 = input("Second string: ") 7 | 8 | if str1 == str2: 9 | print("Hey, they are equal!") 10 | else: 11 | # Hey! Not the best optiom 12 | if str1 < str2: 13 | print(f'"{str1}" is first') 14 | print(f'"{str2}" is last') 15 | else: 16 | print(f'"{str2}" is first') 17 | print(f'"{str1}" is last') 18 | 19 | print("That's all folks...") 20 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201026_richter_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | value = float(input("Value: ")) 6 | 7 | if value >= 8: 8 | print("Most structures fall") 9 | elif value >= 7: 10 | print("Many buildings destroyed") 11 | elif value >= 6: 12 | print("Many buildings considerably damages, some collapse") 13 | elif value >= 4.5: 14 | print("Damage to poorly constructed buildings") 15 | else: 16 | print("No destruction of buildings") 17 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201026_richter_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | value = float(input("Value: ")) 6 | 7 | if value >= 8: 8 | print("Most structures fall") 9 | if 8 > value >= 7: 10 | print("Many buildings destroyed") 11 | if 7 > value >= 6: 12 | print("Many buildings considerably damages, some collapse") 13 | if 6 > value >= 4.5: 14 | print("Damage to poorly constructed buildings") 15 | if value < 4.5: 16 | print("No destruction of buildings") 17 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201026_tax_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | single = input("Are you single? [y/n] ") 6 | income = float(input("Income: ")) 7 | 8 | if single.lower() == "y": 9 | if income < 32000: 10 | net = income - income * .1 11 | else: 12 | net = income - 3200 - (income - 32000) * .25 13 | else: 14 | if income < 64000: 15 | net = income - income * .1 16 | else: 17 | net = income - 6400 - (income - 64000) * .25 18 | 19 | print(f"Net income: {net}") 20 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201026_tax_3.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | single = input("Are you single? [y/n] ") 6 | income = float(input("Income: ")) 7 | threshold = 32000 8 | 9 | if single.upper() != "Y": 10 | threshold = 64000 11 | 12 | if income < threshold: 13 | net = income * .1 14 | else: 15 | net = income - threshold * .1 - (income - threshold) * .25 16 | 17 | print(f"Net income: {net}") 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201026_tax_4.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | single = input("Are you single? [y/n] ") 6 | income = float(input("Income: ")) 7 | 8 | if single.lower() == "y" and income < 32000: 9 | net = income - income * .1 10 | elif single.lower() == "y" and income >= 32000: 11 | net = income - 3200 - (income - 32000) * .25 12 | elif single.lower() != "y" and income < 64000: 13 | net = income - income * .1 14 | else: 15 | net = income - 6400 - (income - 64000) * .25 16 | 17 | print(f"Net income: {net}") 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_for.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | DIM = 12 6 | 7 | for n1 in range(1, DIM + 1): 8 | for n2 in range(1, DIM + 1): 9 | print(f"{n1*n2:4d}", end='') 10 | print() 11 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_01.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | RATE = 2.5 # ie. 2.5% 6 | 7 | balance = 100 8 | target = 120 9 | year = 0 10 | 11 | print(f"Current balance in 2020 is {balance:.2f}$") 12 | while balance == target: 13 | year = year + 1 14 | interest = balance * RATE / 100 15 | balance = balance + interest 16 | print(f"Expected balance in year {2020+year} is {balance:.2f}$") 17 | else: 18 | print("Achievement accomplished!") 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_02.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | balance = 1000 6 | target = 2 * balance 7 | year = 0 8 | 9 | rate = float(input("Rate%: ")) 10 | 11 | print(f"Current balance in 2020 is {balance:.2f}$") 12 | while balance <= target: 13 | year = year + 1 14 | interest = balance * rate / 100 15 | balance = balance + interest 16 | print(f"Expected balance in year {2020+year} is {balance:.2f}$") 17 | else: 18 | print(f"Achievement accomplished (amount doubled after {year} years)!") 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_03.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | countdown = int(input("Start ")) 6 | 7 | while countdown > 0: 8 | print(f"{countdown}") 9 | countdown = countdown - 1 10 | 11 | print(f"{countdown}!!!!") 12 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_04-nested.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | max_num = int(input("Max num: ")) 6 | 7 | cnt1 = 1 8 | while cnt1 <= max_num: 9 | cnt2 = 1 10 | while cnt2 <= cnt1: 11 | print(f"{cnt1*cnt2:3d}", end=" | ") 12 | cnt2 = cnt2 + 1 13 | print() 14 | cnt1 = cnt1 + 1 15 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_05.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | max_num = int(input("Max num: ")) 6 | div = int(input("Num: ")) 7 | 8 | n = 0 9 | count = 0 10 | while n <= max_num: 11 | if n % div == 0: 12 | print(f"{n} can be divided by {div}") 13 | count = count + 1 14 | n = n + 1 15 | else: 16 | print(f"Found {count} numbers") 17 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_06.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | print("Whoa!") 6 | while str.upper(input("Another one? [y/n]")) == "Y": 7 | print("Whoa!") 8 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_07.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | print("Enter your votes, end with -1") 6 | 7 | sum_ = 0 # standard way for NOT shadowing a common name (or using a reserved keyword) 8 | num = 0 9 | 10 | vote = int(input(":")) 11 | while vote >= 0: 12 | sum_ = sum_ + vote 13 | num = num + 1 14 | vote = int(input(":")) # handling sentinel: duplicate code 15 | 16 | print(f"{num} votes, average is {sum_/num:.1f}") 17 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201028_while_08.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | print("Enter your votes, end with -1") 6 | 7 | sum_ = 0 # standard way for NOT shadowing a common name (or using a reserved keyword) 8 | num = 0 9 | 10 | vote = 9999 11 | while vote >= 0: 12 | vote = int(input(":")) 13 | if vote >= 0: # handling sentinel: duplicate condition 14 | sum_ = sum_ + vote 15 | num = num + 1 16 | 17 | print(f"{num} votes, average is {sum_/num:.1f}") 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201102_functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def factorial(num): 7 | fact = 1 8 | for n in range(1, num + 1): 9 | fact = fact * n 10 | num = "num is a local name!!!!!" 11 | print(f"num inside factorial: '{num}'") 12 | return fact 13 | 14 | 15 | num = int(input("number: ")) 16 | f = factorial(num) 17 | print(f"{num}! = {f}") 18 | print(f"num outside factorial: '{num}'") 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201104_main.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | for n in range(10): 8 | print(f"n IS NOW {n} (yes, I'm SHOUTING)") 9 | 10 | 11 | if __name__ == '__main__': # BLACK MAGIC! 12 | main() 13 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201104_simple-functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def draw_line(size): 7 | print("#" * size) 8 | 9 | 10 | def main(): 11 | foo = int(input("Square size: ")) 12 | draw_square(foo) 13 | 14 | 15 | def draw_square(size): 16 | for l in range(size): 17 | draw_line(size) 18 | 19 | 20 | main() 21 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201109_lists_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | beatles = ['John', 'Paul', 'George', 'Ringo'] 8 | for singer in beatles: 9 | print(f"I love {singer}!") 10 | 11 | 12 | if __name__ == '__main__': # BLACK MAGIC! 13 | main() 14 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201109_lists_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | beatles = ['John', 'Paul', 'George', 'Ringo'] 8 | print("The BEATLES:") 9 | for i in range(4): 10 | print(f"I love Beatles number {i+1}: {beatles[i]}!") 11 | 12 | 13 | if __name__ == '__main__': # BLACK MAGIC! 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201109_lists_3.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | beatles = ['John', 'Paul', 'George', 'Ringo', 'Stuart'] 8 | print("The BEATLES:") 9 | for i in range(len(beatles)): 10 | print(f"I love Beatles number {i+1}: {beatles[i]}!") 11 | 12 | 13 | if __name__ == '__main__': # BLACK MAGIC! 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201109_lists_4.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | beatles = ['John', 'Paul', 'George', 'Ringo', 'Stuart'] 8 | print("The BEATLES:") 9 | for i, b in enumerate(beatles): 10 | print(f"I love Beatles number {i+1}: {b}!") 11 | 12 | 13 | if __name__ == '__main__': # BLACK MAGIC! 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201111_slices.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | """Main entry point""" 8 | foo = list("ABCDEF") 9 | 10 | print(foo) 11 | 12 | # slice to substitute 13 | # foo[2:3] = ['XXX', 'YYY', 'ZZZ'] 14 | 15 | # slice to insert 16 | # foo[2:2] = ['XXX', 'YYY', 'ZZZ'] 17 | 18 | # slice to remove 19 | # foo[2:3] = [] 20 | 21 | print(foo) 22 | 23 | 24 | if __name__ == '__main__': # BLACK MAGIC! 25 | main() 26 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201116_join.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | """Main entry point""" 8 | friends = ['Alice', 'Bob', 'Carla', 'David'] 9 | 10 | result = "" 11 | for n in friends[:-1]: 12 | result = result + n + ", " 13 | result = result + friends[-1] 14 | 15 | print(f">>>> {result} <<<<") 16 | 17 | 18 | if __name__ == '__main__': # BLACK MAGIC! 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201116_remove_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | import random 6 | 7 | 8 | def main(): 9 | """Main entry point""" 10 | 11 | array = [1, 2, 5, 5, 3, 4] 12 | target = 5 13 | 14 | i = 0 15 | while i < len(array): 16 | if array[i] == target: 17 | array.pop(i) 18 | else: 19 | i = i + 1 20 | pass 21 | 22 | 23 | if __name__ == '__main__': # BLACK MAGIC! 24 | main() 25 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201116_remove_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | import random 6 | 7 | 8 | def main(): 9 | """Main entry point""" 10 | 11 | array = [5, 1, 2, 5, 5, 3, 4] 12 | target = 5 13 | 14 | for i in range(len(array) - 1, -1, -1): 15 | if array[i] == target: 16 | array.pop(i) 17 | pass 18 | 19 | 20 | if __name__ == '__main__': # BLACK MAGIC! 21 | main() 22 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201118_list-input_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | """Main entry point""" 8 | 9 | values = [] 10 | print("Enter values, Q to quit") 11 | 12 | user_input = input("") 13 | while user_input.upper() != "Q": 14 | values.append(float(user_input)) 15 | user_input = input("") 16 | 17 | print(values) 18 | print(f"Min is {min(values)}, max is {max(values)}") 19 | 20 | 21 | if __name__ == '__main__': # BLACK MAGIC! 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201125_convert-B210_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | """Main entry point""" 8 | number = input("Number: ") 9 | base = int(input("Base: ")) 10 | value = convert10(number, base) 11 | print(f"{number}|{base} = {value}|10") 12 | 13 | 14 | def convert10(number, base): 15 | value = 0 16 | for n, d in enumerate(reversed(number)): 17 | value = value + int(d) * base**n 18 | return value 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201130_1st-open.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | file = open("duck.txt", "r") 8 | line = file.readline() 9 | line = file.readline() 10 | while line != '': 11 | print(f"LINE: <<<{line[:-1]}>>>") 12 | line = file.readline() 13 | file = "" 14 | file.close() 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_file_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'snow.x' 6 | 7 | 8 | def main(): 9 | input_file = open(FILENAME, 'r') 10 | for line in input_file: 11 | print(f">>>{line.rstrip()}<<<") 12 | input_file.close() 13 | 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_file_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'snow.x' 6 | 7 | 8 | def main(): 9 | input_file = open(FILENAME, 'r') 10 | for line in input_file: 11 | for word in line.split(): 12 | trimmed_word = word.strip('.,!?\'"') 13 | print(f">>{trimmed_word}<<") 14 | input_file.close() 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_file_3.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'snow.x' 6 | CHUNK_SIZE = 7 7 | 8 | 9 | def main(): 10 | input_file = open(FILENAME, 'r') 11 | chunk = input_file.read(CHUNK_SIZE) 12 | while chunk != '': 13 | print(f"Chunk: >>{chunk}<<") 14 | chunk = input_file.read(CHUNK_SIZE) 15 | input_file.close() 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_file_4.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'snow.x' 6 | 7 | 8 | def main(): 9 | input_file = open(FILENAME, 'r') 10 | whole_file = input_file.read() 11 | input_file.close() 12 | 13 | for line in whole_file.splitlines(): 14 | print(f"Chunk: >>{line.rstrip()}<<") 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_file_5.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'heaven.txt' 6 | 7 | 8 | def main(): 9 | with open(FILENAME, 'r') as input_file: 10 | for line in input_file: 11 | for word in line.split(): 12 | trimmed_word = word.strip('.,!?\'"') 13 | print(f">>{trimmed_word}<<") 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_named-args.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(day, month): 7 | print(f"Hey, day={day} and month={month}") 8 | 9 | 10 | def main(): 11 | foo(23, 10) 12 | foo(day=23, month=10) 13 | foo(month=10, day=23) 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201202_try-execpt.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from random import randint 6 | 7 | 8 | def foo(x): 9 | if x == 42: 10 | raise ValueError("Can't handle 42!") 11 | print(f"x is {x}") 12 | 13 | 14 | def main(): 15 | try: 16 | for i in range(100): 17 | foo(randint(0, 100)) 18 | except ValueError as ve: 19 | print(f"Yeuch: {ve}") 20 | finally: 21 | print("That's all...") 22 | 23 | 24 | if __name__ == '__main__': 25 | main() 26 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201207_try-execpt_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def safe_int(whatever): 7 | try: 8 | value = int(whatever) 9 | except ValueError as exception: 10 | print(f"Yeuch: {str(exception)}") 11 | value = 0 12 | return value 13 | 14 | 15 | def main(): 16 | while True: 17 | user_input = input("> ") 18 | value = safe_int(user_input) 19 | print(f"Value is {value}") 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201207_try-execpt_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | while True: 8 | try: 9 | user_input = input("> ") 10 | value = int(user_input) 11 | print(f"Value is {value}") 12 | except ValueError: 13 | pass 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201209_is_sublist.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def is_sublist(l1, l2): 7 | for e in l2: 8 | if e not in l1: 9 | return False 10 | return True 11 | 12 | 13 | def main(): 14 | list1 = list("GIOVANNI") 15 | print(is_sublist(list1, "NIO")) 16 | print(is_sublist(list1, "XYZ")) 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201209_sets_1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILE_NAME = 'heaven.txt' 6 | 7 | 8 | def main(): 9 | words = set() 10 | with open(FILE_NAME, 'r') as song: 11 | for line in song: 12 | for w in line.split(): 13 | stripped_word = w.upper().strip('!?,.\'"') 14 | words.add(stripped_word) 15 | print(sorted(words)) 16 | print(f"Found {len(words):,} unique words") 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201216_functions-in-functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | """Entry point""" 8 | foo() 9 | bar() 10 | baz() # Error! 11 | 12 | 13 | def foo(): 14 | print("I'm Foo!") 15 | 16 | def baz(): 17 | print("I'm Baz...") 18 | 19 | baz() 20 | 21 | 22 | def bar(): 23 | print("I'm Bar!") 24 | 25 | 26 | if __name__ == '__main__': 27 | main() 28 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201216_modules_gargle.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def blaster(): 7 | print("PAN GALACTIC GARGLE BLASTER!") 8 | -------------------------------------------------------------------------------- /Python/src/2020-21/20201216_modules_main.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2020 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | import gargle 6 | from gargle import blaster as yoda 7 | 8 | 9 | def main(): 10 | """Entry point""" 11 | gargle.blaster() 12 | yoda() # same as before 13 | 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211009_equation.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from math import sqrt 6 | 7 | # 3 x**2 - 9 x + 2 8 | 9 | a = 3 10 | b = -9 11 | c = 2 12 | 13 | delta = b**2 - 4 * a * c 14 | x1 = (-b + sqrt(delta)) / (2 * a) 15 | x2 = (-b - sqrt(delta)) / (2 * a) 16 | 17 | print(f"x1={x1}; x2={x2}") 18 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211013_tiles.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | TILE_SIZE = 5 6 | 7 | # Change the following line and run 8 | total_width = 105 9 | 10 | usable_width = total_width - TILE_SIZE 11 | num_pairs = usable_width // (2 * TILE_SIZE) 12 | tile_width = TILE_SIZE + 2 * num_pairs * TILE_SIZE 13 | total_gap = total_width - tile_width 14 | gap = total_gap / 2 15 | 16 | print(f"With a wall of {total_width}cm we can use {1+2*num_pairs} tiles") 17 | print(f"corresponding to {tile_width}cm and we need a gap of {gap}cm each end") 18 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211022_average.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | sum_ = 0 6 | count = 0 7 | completed = False 8 | while not completed: 9 | user_input = input("Number: ") 10 | if user_input: 11 | sum_ += int(user_input) 12 | count += 1 13 | else: 14 | completed = True 15 | 16 | if count == 0: 17 | print(f"D'oh") 18 | else: 19 | print(f"Average of {count} values: {sum_/count:.2f}") 20 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211022_count.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | counter = 0 6 | completed = False 7 | while not completed: 8 | user_input = input() 9 | if not user_input: 10 | completed = True 11 | else: 12 | if int(user_input) == 42: 13 | counter += 1 14 | 15 | print(f"Whoa! You typed {counter:,} 42's") 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211022_interest.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | start_money = float(input("Initial money: ")) 6 | interest_rate = float(input("Interest rate: ")) 7 | 8 | current_money = start_money 9 | year = 0 10 | 11 | while current_money < 2 * start_money: 12 | year += 1 13 | current_money = current_money + current_money * interest_rate 14 | 15 | print(f"Whoa! After {year:,} years, I have ${current_money:.2f}!!!") 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211022_match.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | counter = 0 6 | completed = False 7 | found = False 8 | 9 | while not completed: 10 | user_input = input() 11 | if not user_input: 12 | completed = True 13 | else: 14 | if int(user_input) == 42: 15 | print("You got it!") 16 | completed = True 17 | found = True 18 | else: 19 | print("No") 20 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211022_min-max_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | min_ = max_ = None 6 | 7 | completed = False 8 | while not completed: 9 | user_input = input() 10 | if not user_input: 11 | completed = True 12 | else: 13 | val = int(user_input) 14 | if max_ is None or val > max_: 15 | max_ = val 16 | if min_ is None or val < min_: 17 | min_ = val 18 | 19 | print(f"max={max_}; min={min_}") 20 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_for-loops.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | for i in range(100): 6 | print(i) 7 | 8 | for i in range(100, -100, 10): 9 | print(f"Back: {i}") 10 | 11 | for i in "range": 12 | print(f"Letter \"{i}\"") 13 | 14 | del i 15 | print(f"And now 'i' is \"{i}\"") 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_multiplication.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | TABLE_SIZE = 10 6 | 7 | for r in range(1, TABLE_SIZE + 1): 8 | for c in range(1, TABLE_SIZE + 1): 9 | print(f"{r*c:8d}", end='') 10 | print() 11 | 12 | print("All done.") 13 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_pirate-song.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | # string = input() 6 | string = 'VanaTallinn' 7 | 8 | for num_chars in range(1, len(string) + 1): 9 | for i1 in range(len(string) - num_chars + 1): 10 | for i2 in range(num_chars): 11 | print(string[i1 + i2], end='') 12 | print() 13 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_pirate-song_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | string = input() 6 | 7 | # A 1-line solution using list comprehension (and a generator) 8 | print("\n".join(string[a:a + b + 1] for b in range(len(string)) for a in range(len(string) - b))) 9 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_powtable.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | NUM_ROWS = 10 6 | NUM_COLUMNS = 6 7 | 8 | for c in range(NUM_COLUMNS): 9 | header = f"x**{c+1}" 10 | print(f"{header:>10s}", end=' |') 11 | print() 12 | for r in range(NUM_ROWS): 13 | for c in range(NUM_COLUMNS): 14 | print(f"{(r+1)**(c+1):10,d}", end=' |') 15 | print() 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211029_primes.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | limit = int(input()) 6 | 7 | print(f"Prime number up to {limit}: ", end='') 8 | for number in range(2, limit + 1): 9 | prime = True 10 | for n in range(2, number // 2): 11 | if number % n == 0: 12 | prime = False 13 | if prime: 14 | print(f"{number:,}", end=' ') 15 | print() 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211105_eq1_take1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | a = int(input("a: ")) 6 | b = int(input("a: ")) 7 | 8 | 9 | def solve(a, b): 10 | x = -b / a 11 | return x 12 | 13 | 14 | foo = solve(b, a) 15 | print(f"x is {foo}") 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211105_eq1_take2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | THE_ANSWER = 42 6 | 7 | 8 | def solve(a, b): 9 | print(THE_ANSWER) 10 | x = -b / a 11 | return x 12 | 13 | 14 | def main(): 15 | a = int(input("a: ")) 16 | b = int(input("b: ")) 17 | 18 | foo = solve(a, b) 19 | print(f"x is {foo}") 20 | 21 | 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211105_eq2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from math import sqrt 6 | 7 | 8 | def solve2(a, b, c): 9 | """Solve equation ax**2 + bx + c == 0""" 10 | delta = b**2 - 4 * a * c 11 | x1 = (-b + sqrt(delta)) / (2 * a) 12 | x2 = (-b - sqrt(delta)) / (2 * a) 13 | return x1, x2 14 | 15 | 16 | def main(): 17 | a = float(input("a: ")) 18 | b = float(input("b: ")) 19 | c = float(input("c: ")) 20 | 21 | x1, x2 = solve2(a, b, c) 22 | print(f"x1={x1}; x2={x2}") 23 | 24 | 25 | main() 26 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211105_multi-line-strings.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | # Multi line string 6 | BEATLES = """John 7 | Paul 8 | George 9 | Ringo""" 10 | 11 | BEATLES_ALT = "John\nPaul\nGeorge\nRingo" 12 | 13 | 14 | def foo(): 15 | """Docstring 16 | May span over multiple 17 | lines""" 18 | 19 | print(BEATLES) 20 | print(BEATLES_ALT) 21 | 22 | print("""foo 23 | bar 24 | baz 25 | gargle 26 | """) 27 | 28 | 29 | foo() 30 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211105_namespace.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | def foo(x, y): 6 | x += 1 7 | y += 10 8 | 9 | 10 | def main(): 11 | x = 23 12 | y = 10 13 | foo(x, y) 14 | print(f"{x}-{y}") 15 | 16 | 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211124_join.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | the_beatles = ['John', 'Paul', 'George', 'Ringo'] 8 | 9 | string = the_beatles[0] 10 | for name in the_beatles[1:-1]: 11 | string += ', ' + name 12 | string += ', and ' + the_beatles[-1] # add Oxford comma! 13 | 14 | print(f">>>>{string}<<<<") 15 | print(f">>>>{', '.join(the_beatles)}<<<<") 16 | 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211124_swap.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | foo = list("GIOVANNI") 8 | bar = swap(foo) 9 | print(f"{foo} -> {bar}") 10 | 11 | 12 | def swap(original_list): 13 | new_list = original_list[:] 14 | new_list[0], new_list[-1] = new_list[-1], new_list[0] 15 | return new_list 16 | 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_list-comp.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | 8 | def main(): 9 | foo = [(x, x**2) for x in range(10)] 10 | print(foo) 11 | table = [(r + 1) * (c + 1) for r in range(10) for c in range(10)] 12 | print(table) 13 | table = [[(r + 1) * (c + 1) for r in range(10)] for c in range(10)] 14 | pprint(table) 15 | 16 | 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_open.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | input_file = open('stairway.txt') 8 | foo = input_file.readline() 9 | print(f"My FIRST line from a file: \"{foo}\"") 10 | foo = input_file.readline() 11 | print(f"My SECOND line from a file: \"{foo}\"") 12 | 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_reading-files.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILE_NAME_OLD = '20211126_stairway.txt' 6 | FILE_NAME = 'C:\\Users\\John Nefastis\\Documents\\C\\2018-19\\w04_12-for2\\w04_12-for2.c' 7 | 8 | 9 | def main(): 10 | with open(FILE_NAME) as song: 11 | for num, line in enumerate(song): 12 | print(f"{num+1:02d}: {line.rstrip()}") 13 | 14 | 15 | main() 16 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_reading-files_2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILE_NAME = '20211126_stairway.txt' 6 | 7 | 8 | def main(): 9 | with open(FILE_NAME) as song: 10 | for num, line in enumerate(reversed(song.readlines())): 11 | print(f"{num+1:02d}: {line.rstrip()}") 12 | 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_table.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | TABLE_SIZE = 10 8 | 9 | 10 | def main(): 11 | # create the "table" 12 | table = list() 13 | for i in range(TABLE_SIZE): 14 | table.append([None] * TABLE_SIZE) 15 | pprint(table) 16 | 17 | # fill in values 18 | for r in range(TABLE_SIZE): 19 | for c in range(TABLE_SIZE): 20 | table[r][c] = (r + 1) * (c + 1) 21 | pprint(table) 22 | 23 | 24 | main() 25 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211126_words.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILE_NAME = '20211126_stairway.txt' 6 | 7 | 8 | def main(): 9 | with open(FILE_NAME) as song: 10 | for num, line in enumerate(song): 11 | print(f"{num+1:02d}: {line.split()}") 12 | 13 | 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211201_append.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILE_A = '20211201_song.txt' 6 | FILE_B = '20211201_input.txt' 7 | FILE_C = '20211201_a+b.txt' 8 | 9 | 10 | def main(): 11 | with open(FILE_A) as file_a, open(FILE_B) as file_b, open(FILE_C, 'w') as file_c: 12 | a = file_a.read() 13 | b = file_b.read() 14 | file_c.write(a) 15 | file_c.write(b) 16 | 17 | 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211201_input.txt: -------------------------------------------------------------------------------- 1 | 32.00 2 | 54 3 | foo! 4 | 67.5 5 | 80.25 6 | 115 7 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211209_Lab10-Ex1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | INPUT_FILE = '20211209_input.gx' 6 | OUTPUT_FILE = '20211209_output.gx' 7 | 8 | 9 | def main(): 10 | try: 11 | with open(INPUT_FILE) as input_, open(OUTPUT_FILE, 'w') as output: 12 | for index, line in enumerate(input_): 13 | output.write(f"/*{index+1}*/ {line}") 14 | except OSError as error: 15 | print(f"Yeuch, we had a problem: {error}") 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211209_Lab10-Ex2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2021 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | INPUT_FILE = '20211209_input.gx' 6 | OUTPUT_FILE = '20211209_output.gx' 7 | 8 | 9 | def main(): 10 | try: 11 | with open(INPUT_FILE) as input_, open(OUTPUT_FILE, 'w') as output: 12 | for line in reversed(input_.readlines()): 13 | output.write(line) 14 | except OSError as error: 15 | print(f"Yeuch, we had a problem: {error}") 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211209_input.gx: -------------------------------------------------------------------------------- 1 | Society in every state is a blessing, but 2 | government, even in its best state, is but a 3 | necessary evil; in its worst state an intolerable 4 | one: for when we suffer, or are exposed to the 5 | same miseries by a government, which we might 6 | expect in a country without government, our 7 | calamity is heightened by reflecting that we 8 | furnish the means by which we suffer. 9 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211210_CSC1.txt: -------------------------------------------------------------------------------- 1 | 112233 A- 2 | 113322 B+ 3 | 221133 C 4 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211210_CSC2.txt: -------------------------------------------------------------------------------- 1 | 112233 A+ 2 | 448822 B+ 3 | 221133 C 4 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211210_courses.lst: -------------------------------------------------------------------------------- 1 | CSC1 2 | CSC2 3 | CSC46 4 | CSC151 5 | MTH121 6 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211210_hotel.dat: -------------------------------------------------------------------------------- 1 | Jake Blues; dinner; 23.5; Dec-12 2 | Elwood Blues; accommodation; 23.5; Dec-12 3 | Steve Cropper; dinner; 23.55; Dec-12 4 | Jake Blues; accommodation; 223.5; Dec-12 5 | Jake Blues; dinner; 213.5; Dec-12 6 | Elwood Blues; lunch; 24.5; Dec-12 7 | Steve Cropper; accommodation; 63.5; Dec-12 8 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211217_births.txt: -------------------------------------------------------------------------------- 1 | Mario Rossi Torino 02/03/2019 2 | Maria Verdi Torino 17/03/2021 3 | Ugo Bianchi Asti 12/05/1999 4 | -------------------------------------------------------------------------------- /Python/src/2021-22/20211217_maze.txt: -------------------------------------------------------------------------------- 1 | * ******* 2 | * * * * 3 | * ***** * 4 | * * * * 5 | * * *** * 6 | * * * 7 | ***** * * 8 | * * * 9 | ******* * 10 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220112_products.txt: -------------------------------------------------------------------------------- 1 | P234HF22222 r1011 2 | P234HF22223 r1112 3 | P234HF22225 r1114 4 | P111TG11115 r1015 5 | P111TG11116 r1216 6 | P331LS00110 r1017 7 | P331LS00120 r1318 8 | P331LS00130 r1019 9 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220112_purchases.txt: -------------------------------------------------------------------------------- 1 | P234HF22223 r1112 2 | P111TG11115 r1015 3 | P111TG11115 r1216 4 | P234HF22222 r1011 5 | P331LS00110 r1014 6 | P331LS00120 r1318 7 | P331LS00130 r1019 8 | P234HF22225 r1114 9 | P234HF22223 r1114 10 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220114_ingredients.txt: -------------------------------------------------------------------------------- 1 | Corn flour; 2.21; 3620 2 | Toma; 19.8; 3710 3 | Fontina; 13.8; 3430 4 | Butter; 3.99; 7500 5 | Passed; 2.49; 180 6 | Olive; 11.65; 1420 7 | Capers; 18; 250 8 | Fusilli; 1.71; 3500 9 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220114_map.txt: -------------------------------------------------------------------------------- 1 | 3 4 4 4 3 2 1 0 0 0 2 | 3 4 5 4 3 2 1 1 1 1 3 | 3 4 4 4 3 2 2 2 2 1 4 | 3 3 3 3 3 3 3 3 2 1 5 | 2 2 2 2 2 3 4 3 2 1 6 | 1 1 1 1 2 3 3 3 2 1 7 | 0 0 0 1 2 2 2 2 2 1 8 | 0 0 0 1 1 1 1 1 1 1 9 | 0 1 0 0 0 0 0 0 0 0 10 | 0 0 0 0 0 0 1 0 0 0 11 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220114_polenta_concia.txt: -------------------------------------------------------------------------------- 1 | Ingrediants: 2 | Corn flour; 500 3 | Toma; 200 4 | Fontina; 200 5 | Butter; 200 6 | 7 | Method: 8 | Cut the fontina and toma cheese into cubes. Boil the water, add the cornmeal and mix. When the polenta has reached the desired consistency, add the butter, fontina and toma. 9 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220114_questions-1.txt: -------------------------------------------------------------------------------- 1 | Hair Color = Blonde 2 | Hair Length = Short 3 | Glasses = YES 4 | -------------------------------------------------------------------------------- /Python/src/2021-22/20220114_questions-2.txt: -------------------------------------------------------------------------------- 1 | Gender = Man 2 | Hair Length = Short 3 | Beard = YES 4 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221011_math.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | #foo = math.sqrt(3.2) 6 | #print(foo) 7 | 8 | import math 9 | import cmath 10 | 11 | foo = math.sqrt(3.2) 12 | print(foo) 13 | 14 | foo = cmath.sqrt(-3.2) 15 | print(foo) 16 | 17 | foo = cmath.sqrt(3.2) 18 | print(foo) 19 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221011_tiles.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | TILE_SIZE = 12 6 | WALL_LENGTH = 500 7 | 8 | # Put a black tile 9 | length = WALL_LENGTH - TILE_SIZE 10 | num_pairs = length // (TILE_SIZE * 2) 11 | gap = length % (TILE_SIZE * 2) 12 | 13 | print(f"The gap at each side is: {gap/2}cm AND I need to use {1+num_pairs*2} tiles.") 14 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221014_if.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = input("What's your name? ") 6 | 7 | # name = input("What's your name? ").upper() 8 | #if name[-1] == 'a' or name[-1] == 'A': 9 | if name[-1].upper() == 'A': 10 | print("Hello girl") 11 | else: 12 | print("Hello boy") 13 | 14 | for a in name: 15 | print("foo") 16 | print("bar") 17 | print(a * 10, "!!!!") 18 | print("Yeuch") 19 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221021_fibonacci.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | i1 = 1 6 | i2 = 1 7 | 8 | print(1) 9 | print(1) 10 | for n in range(100): 11 | i0 = i1 12 | i1 = i2 13 | i2 = i1 + i0 14 | print(f"{i2:,}") 15 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221021_sequence.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | number = int(input("Start number: ")) 6 | 7 | while number > 1: 8 | if number % 2 == 0: 9 | number = number // 2 10 | else: 11 | number = number * 3 + 1 12 | print(number) 13 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221021_sum-nums.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | num = 0 6 | tot = 0 7 | while num >= 0: 8 | tot = tot + num 9 | num = int(input("Num: ")) 10 | print(f"Total: {tot:,}") 11 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221025-substrings.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | string = input('String: ') 6 | 7 | for len_ in range(1, len(string)+1): 8 | for i in range(len(string)-len_+1): 9 | print(string[i:i+len_]) 10 | 11 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221025_loops-2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | num = int(input('Num: ')) 6 | max_ = num 7 | min_ = num 8 | cnt = 0 9 | while num > 0: 10 | cnt += 1 11 | max_ = max(num, max_) 12 | min_ = min(num, min_) 13 | num = int(input('Num: ')) 14 | print(f"You eneterd {cnt:,} numbers between {min_:,} and {max_:,}") 15 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221025_loops-diamonds-lab4-2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | size = int(input("Size: ")) 6 | 7 | for n in range(1, size+1): 8 | print(" "*(size-n), "#"*n, "#"*(n-1), sep='') 9 | for n in range(1, size+1): 10 | print(" "*n, "#"*(size-n), "#"*(size-n-1), sep='') 11 | 12 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221104_list-str.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | x = "Giovanni" 8 | foo(x) 9 | # 'x' still bound to "Giovanni" 10 | print(x) 11 | 12 | 13 | def foo(y): 14 | # despite the +=, the object bound to 'y' can't change (strings are immutable) 15 | # thus, the += creates a new string and binds the local 'y' to it 16 | y += "Adolfo" 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221104_lists-creation.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | # creating lists... 8 | foo = list() 9 | foo = list('Giovanni') 10 | foo = [] 11 | foo = [18, 5, 'Paola'] 12 | print(foo[0]) 13 | print(foo[-1]) 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221104_lists.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | x = list() 8 | x.append(23) 9 | x.append(10) 10 | x.append('Giovanni') 11 | foo(x) 12 | # the object bound to 'x' has changed 13 | print(x) 14 | 15 | 16 | def foo(y): 17 | # the object bound to 'y' does change 18 | y.append(18) 19 | y.append(5) 20 | y.append('Paola') 21 | 22 | 23 | if __name__ == '__main__': 24 | main() 25 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221104_ranges.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | # use of ranges with strings and lists 8 | 9 | name = "Giovanni Adolfo Pietro Pio" 10 | print(name[2:10]) 11 | print(name[10:2:-1]) 12 | 13 | 14 | if __name__ == '__main__': 15 | main() 16 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221115_multret.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | _, x = foo() 8 | 9 | print(type(x), x) 10 | print(x[1]) 11 | 12 | paola, giovanni = foo() 13 | print(type(paola), paola) 14 | print(type(giovanni), giovanni) 15 | 16 | 17 | def foo(): 18 | return 18, 23 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221115_tables.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | DIMX = 20 8 | DIMY = 4 9 | 10 | 11 | def main(): 12 | table = list() 13 | for x in range(DIMY): 14 | table.append([0] * DIMX) 15 | table[2][3] = 6 16 | pprint(table) 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221118_files-write.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'test.dat' 6 | 7 | 8 | def main(): 9 | with open(FILENAME, "w") as my_file: 10 | my_file.write("Hello! This is my first file.\n") 11 | my_file.write("Hello! This is my first file.\n") 12 | 13 | 14 | if __name__ == '__main__': 15 | main() 16 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221118_files.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'song.txt' 6 | 7 | 8 | def main(): 9 | my_file = open(FILENAME) 10 | x = my_file.read() 11 | print(x) 12 | my_file.close() 13 | 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221118_files2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = 'song.txt' 6 | 7 | 8 | def main(): 9 | with open(FILENAME) as my_file: 10 | # whole_files = my_file.read() 11 | # whole_file_in_lines = list(my_file.readlines()) 12 | for line in my_file: 13 | print(line) 14 | #print(line[:-1]) 15 | 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221122_reverse.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME1 = 'file1.txt' 6 | FILENAME2 = 'file2.txt' 7 | 8 | 9 | def main(): 10 | with open(FILENAME1) as f1, open(FILENAME2, 'w') as f2: 11 | for line in reversed(f1.readlines()): 12 | f2.write(line) 13 | 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221122_try1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | x = input() 8 | try: 9 | num = int(x) 10 | dkgdkjfh 11 | except ValueError: 12 | num = None 13 | print(num) 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221125_maze.dat: -------------------------------------------------------------------------------- 1 | ..#......... 2 | ..#..####### 3 | ..#.....#... 4 | ###########. 5 | ...#........ 6 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221206_bin2dec.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def bin2dec(binary): 7 | num = 0 8 | for d in binary: 9 | num = num * 2 + int(d) 10 | return num 11 | 12 | 13 | def main(): 14 | binary = input() 15 | print(bin2dec(binary)) 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221216_dups.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2022 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | import random 6 | 7 | 8 | def main(): 9 | numbers = list() 10 | for _ in range(1_000_000): 11 | numbers.append(random.randint(1, 1_000_000)) 12 | 13 | # remove dups 14 | numbers2 = list(set(numbers)) 15 | print(f"{len(numbers):,} vs. {len(numbers2):,}") 16 | 17 | 18 | if __name__ == '__main__': 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2022-23/20221216_phonebook.xyz: -------------------------------------------------------------------------------- 1 | Alice 23-534535 2 | Bob Rock 23-53453543 3 | Carla 23-53451234 4 | David 23-534534 5 | Earl 23-5345354 6 | Frank Zap Zop Zip 23-534535646 7 | Gabriella 23-534534365 8 | Haley 23-534535436 9 | Bob Rock 666-666-666 10 | -------------------------------------------------------------------------------- /Python/src/2022-23/CSC1.txt: -------------------------------------------------------------------------------- 1 | 11234 A- 2 | 12547 B+ 3 | 21886 C- 4 | 31415 A+ 5 | -------------------------------------------------------------------------------- /Python/src/2022-23/CSC2.txt: -------------------------------------------------------------------------------- 1 | 11234 A- 2 | 12547 B 3 | 16753 B+ 4 | 21886 C 5 | -------------------------------------------------------------------------------- /Python/src/2022-23/MTH121.txt: -------------------------------------------------------------------------------- 1 | 11234 A- 2 | 12547 B 3 | 31415 A 4 | 27181 B 5 | -------------------------------------------------------------------------------- /Python/src/2022-23/classes.txt: -------------------------------------------------------------------------------- 1 | CSC1 2 | CSC2 3 | MTH121 4 | -------------------------------------------------------------------------------- /Python/src/2022-23/file-a.dat: -------------------------------------------------------------------------------- 1 | Italian 2 | English 3 | French 4 | Sanskrit 5 | -------------------------------------------------------------------------------- /Python/src/2022-23/file-b.dat: -------------------------------------------------------------------------------- 1 | Ciao, come stai? 2 | Hello, how do you do? 3 | Salut, comment vas-tu? 4 | नमस्कार, कथं करोषि ? 5 | -------------------------------------------------------------------------------- /Python/src/2022-23/test.csv: -------------------------------------------------------------------------------- 1 | LANGUAGE,GREET 2 | Italian,"Ciao, come stai?" 3 | English,"Hello, how do you do?" 4 | French,"Salut, comment vas-tu?" 5 | Sanskrit,"नमस्कार, कथं करोषि ?" 6 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 div.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | num = int(input("Number :")) 6 | 7 | n = 2 8 | while num > 1: 9 | if num % n == 0: 10 | print(f"Can be divided by {n}") 11 | num = num // n 12 | else: 13 | n = n + 1 14 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 fibonacci.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | f0 = 1 6 | f1 = 1 7 | print(f"{f0}\n{f1}") 8 | while f1 < 10_000_000_000_000_000_000: 9 | f2 = f0 + f1 10 | print(f"{f2:,}") 11 | f0 = f1 12 | f1 = f2 13 | 14 | print("\\") -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 for.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | for x in "Giovanni Adolfo Pietro Pio": 6 | print(f"Hello, the name 'x' is bound to: {x} <<>< >dfj gdrkjh g") 7 | 2 -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 names.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = input("Name: ") 6 | 7 | if len(name) > 20: 8 | print("Whoa! A LONG name...") 9 | 10 | length = len(name) 11 | print(name[length-1]) 12 | if name[length-1] == 'a': 13 | print("Ms.", name) 14 | else: 15 | print("Mr.", name) 16 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 while.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | x = '' 6 | while x != 'no': # not a == b -> a != b 7 | x = input('Continue?') 8 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231013 while2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | x = ord('a') 6 | while x <= 500: 7 | print(x, chr(x)) 8 | x = x + 1 9 | 10 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231017 f-strings.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | # numbers 6 | foo = 1 / 3 7 | print(f"{foo}") 8 | print(f"10-digit float: |{foo:10.2f}|") 9 | print(f"10-digit float: |{foo:<10.2f}|") 10 | print(f"{foo:.3}") 11 | 12 | # strings 13 | foo = "Giovanni" 14 | print(f"|{foo:60}|") 15 | print(f"|{foo:<60}|") 16 | print(f"|{foo:>60}|") 17 | print(f"|{foo:^60}|") 18 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231017 if-else.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | for num in range(20): 6 | print(num) 7 | if num == 4: 8 | print("China/Japan!") 9 | elif num == 7: 10 | print("East Asia") 11 | elif num == 9: 12 | print("Death!!!") 13 | elif num == 13: 14 | print("US!") 15 | elif num == 17: 16 | print("Italy!") 17 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231017 range.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | print("FIRST RANGE") 6 | for num in range(5): 7 | print(num) 8 | 9 | print("START-END") 10 | for num in range(3, 5): # ALL ranges are half-open ie. [3, 5) 11 | print(num) 12 | 13 | print("START-END-STEP") 14 | for num in range(3, 45, 7): 15 | print(num) 16 | 17 | print("BACKWARD") 18 | for num in range(10, 0, -1): 19 | print(num) 20 | print("BOOOOOOM!") 21 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 interest-rate.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | INITIAL_VALUE = 10_000 6 | INTEREST_RATE = 1 / 100 # ie. 1% 7 | 8 | money = INITIAL_VALUE 9 | num_years = 0 10 | 11 | while money < INITIAL_VALUE * 2: 12 | num_years = num_years + 1 13 | money = money + money * INTEREST_RATE 14 | 15 | print( 16 | f"With a {INTEREST_RATE*100:.0f}% interest, after {num_years} years, my money is duobled ({money:,.0f} EUR)" 17 | ) 18 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 max-min.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | max_ = None 6 | min_ = None 7 | user = input("Number (enter to exit): ") 8 | while user: 9 | number = int(user) 10 | if max_ is None or number > max_: 11 | max_ = number 12 | if min_ is None or number < min_: 13 | min_ = number 14 | user = input("Number (enter to exit): ") 15 | 16 | print(f"Minimum: {min_}, maximum: {max_}") 17 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 sum-1.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | NUMBER = 1732817328 6 | 7 | number = NUMBER 8 | total = 0 9 | while number > 0: 10 | # print(f"Number: {number}") 11 | digit = number % 10 12 | # print(f"Last digit: {digit}") 13 | number = number // 10 14 | total = total + digit 15 | 16 | print(f"The sum of all digits of {NUMBER} is {total}") -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 sum-2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | NUMBER = 1732817328 6 | 7 | number = str(NUMBER) 8 | total = 0 9 | for digit in number: 10 | total = total + int(digit) 11 | # alternative: total = total + ord(digit) - ord("0") 12 | 13 | print(f"The sum of all digits of {NUMBER} is {total}") 14 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 user-avg-2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | total = 0 6 | 7 | user = "" # Whatever, but not 'end' 8 | count = 0 9 | while user != "end": 10 | user = input("Number ('end' to exit): ") 11 | if user != "end": 12 | count = count + 1 13 | number = int(user) 14 | total = total + number 15 | 16 | if count > 0: 17 | print(f"Average is: {total/count:.2f}") 18 | else: 19 | print("D'ho!?") 20 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231020 user-avg.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | total = 0 6 | 7 | user = "*" # Whatever, but not '' 8 | count = 0 9 | while user: 10 | user = input("Number (enter to exit): ") 11 | if user: 12 | count = count + 1 13 | number = int(user) 14 | total = total + number 15 | 16 | if count > 0: 17 | print(f"Average is: {total/count:.2f}") 18 | else: 19 | print("D'ho!?") 20 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231024 functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def wanna_go_home(time): 7 | print(f"It's already {time}, please stop!") 8 | 9 | 10 | now = "17:21" 11 | wanna_go_home(now) 12 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231027 functions2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(): 7 | print("Useless function") 8 | 9 | 10 | def bar(): 11 | return 23, 10 12 | 13 | 14 | x = foo() 15 | print(x) 16 | 17 | x, y = bar() 18 | print(x, y) 19 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231027 list3.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(x): 7 | #x[1] = "X" 8 | x = "Paola" 9 | 10 | data = list("Giovanni") 11 | print(data) 12 | foo(data) 13 | print(data) 14 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231027 lists.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | birthdays = [23, 10, 18, 5] 6 | 7 | print(sorted(birthdays)) 8 | print(birthdays) 9 | birthdays.sort() 10 | print(birthdays) 11 | print(sorted(birthdays, reverse=True)) 12 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231027 lists2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | data = list("Giovanni Adolfo Pietro Pio") 6 | print(data) 7 | 8 | for index in range( 9 | 0, len(data), 2 10 | ): # Yeuch! Terrible but understandable 11 | print(index, data[index]) 12 | 13 | for index, element in enumerate(data): # YES! 14 | if index % 2 == 0: 15 | print(index, element) 16 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231031 functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(): 7 | print("Yeuch") 8 | 9 | 10 | def bar(): 11 | print("Wow") 12 | return 23, 10 13 | 14 | 15 | x = bar() 16 | print(x) 17 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231110 2-dim arrays.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | ROWS = 5 8 | COLUMNS = 10 9 | 10 | # create a list of size COLUMNS 11 | # row = [None] * COLUMNS 12 | # pprint(row) 13 | 14 | # Safe create an 2-dim array ROWS x COLUMNS 15 | data = list() 16 | for r in range(ROWS): 17 | data.append([0] * COLUMNS) 18 | data[1][2] = 1 19 | data[2][1] = 3 20 | pprint(data) 21 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231110 file.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | with open("20231110 loving.txt") as song: 8 | for line in song.readlines(): 9 | line = line.rstrip() 10 | print(line) 11 | 12 | with open("20231110 loving.txt") as song: 13 | lyrics_line_by_line = list(song.readlines()) 14 | 15 | with open("20231110 loving.txt") as song: 16 | raw_lyrics = song.read() 17 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231110 sets.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | data = set() 8 | data.add("giovanni") 9 | data.add("furkan") 10 | data.add("paola") 11 | data.add("giovanni") 12 | data.add("luca") 13 | data.add("alvi") 14 | data.add("iris") 15 | data.add("muhammadmahdi") 16 | 17 | pprint(data) 18 | print() 19 | data = data - {'giovanni'} 20 | pprint(data) 21 | print() 22 | data = data - {'giovanni'} 23 | pprint(data) 24 | print() 25 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231117 armstrong.dat: -------------------------------------------------------------------------------- 1 | 7 2 | 1634 3 | 2 4 | 371 5 | 407 6 | 8208 7 | 153 8 | 6 9 | 370 10 | 9474 11 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231117 numbers.dat: -------------------------------------------------------------------------------- 1 | 42 2 | 7 3 | 1634 4 | 1743 5 | 2 6 | 45656 7 | 565 8 | 371 9 | 407 10 | 8208 11 | 153 12 | 6 13 | 4646 14 | 370 15 | 9474 16 | 9475 -------------------------------------------------------------------------------- /Python/src/2023-24/20231117 tables.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | import warnings 6 | from pprint import pprint 7 | 8 | 9 | def make_table(rows, columns): 10 | warnings.warn('Yeuch, "tables" do not exist in Python!') 11 | table = list() 12 | for row in range(rows): 13 | table.append([None] * columns) 14 | return table 15 | 16 | 17 | def main(): 18 | table = make_table(10, 5) 19 | pprint(table) 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231117 try2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def safe_get_integer(): 7 | value = None 8 | while value is None: 9 | try: 10 | string = input("Number: ") 11 | value = int(string) 12 | except ValueError as problem: 13 | print(problem) 14 | value = None 15 | return value 16 | 17 | 18 | def main(): 19 | x = safe_get_integer() 20 | print(x) 21 | 22 | 23 | if __name__ == "__main__": 24 | main() 25 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231124 read.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def read_integer_sequence(): 7 | sequence = list() 8 | word = None 9 | while word != "": 10 | word = input() 11 | try: 12 | sequence.append(int(word)) 13 | except ValueError: 14 | pass 15 | return sequence 16 | 17 | 18 | def main(): 19 | print(read_integer_sequence()) 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231219 map.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | values = list(range(10, 20, 3)) 8 | print(values) 9 | return_value = list(map(lambda n: n**n, values)) 10 | print(f"RET: {return_value}") 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231219 sort2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from pprint import pprint 6 | 7 | 8 | def main(): 9 | birthdays = [ 10 | ["Mr. Blue", 1980], 11 | ["Mr. Pink", 1970], 12 | ["Mr. Green", 1990], 13 | ] 14 | birthdays_sorted = sorted(birthdays, key=lambda b: b[1]) 15 | pprint(birthdays_sorted) 16 | 17 | 18 | if __name__ == "__main__": 19 | main() 20 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231222 censored.txt: -------------------------------------------------------------------------------- 1 | è tutto okay 2 | si ma non trovo un pezzo non posso procedere finché non me lo procuro 3 | sarà un problema 4 | non credo potrei comprarlo al mercato nero ma ho paura della polizia 5 | procedi lo stesso la macchina mi serve 6 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231222 the-theater.dat: -------------------------------------------------------------------------------- 1 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 2 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 3 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 4 | 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 5 | 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 6 | 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 7 | 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 8 | 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 9 | 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 10 | -------------------------------------------------------------------------------- /Python/src/2023-24/20231222 wiretap.txt: -------------------------------------------------------------------------------- 1 | pronto 2 | salve signor arctor come sta 3 | molto bene ma chiamami bob 4 | okay ti chiamavo riguardo alla riparazione del auto 5 | è tutto okay 6 | si ma non trovo un pezzo non posso procedere finché non me lo procuro 7 | sarà un problema 8 | non credo potrei comprarlo al mercato nero ma ho paura della polizia 9 | procedi lo stesso la macchina mi serve 10 | -------------------------------------------------------------------------------- /Python/src/2023-24/20240109 notes.dat: -------------------------------------------------------------------------------- 1 | C;16.35 2 | C#;17.32 3 | D;18.35 4 | D#;19.45 5 | E;20.60 6 | F;21.83 7 | F#;23.12 8 | G;24.50 9 | G#;25.96 10 | A;27.50 11 | A#;29.14 12 | B;30.87 13 | -------------------------------------------------------------------------------- /Python/src/2023-24/20240109 sorting (again).py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | foo = {1, 2, 4, 6, 7, 8, 9, 23, 777, -2} 6 | print(sorted(foo)) 7 | print(sorted(foo, reverse=True)) 8 | 9 | foo = {"giovanni", "adolfo", "Pio", "Pietro"} 10 | print(sorted(foo)) 11 | print(sorted(foo, key=lambda e: e.casefold())) 12 | -------------------------------------------------------------------------------- /Python/src/2023-24/20240112 bowling.csv: -------------------------------------------------------------------------------- 1 | Rossi;Massimo;7;10;6;5;10;4;9;9;5;10;10 2 | Verdi;Giuseppe;10;10;6;6;7;9;9;8;9;9;10;10;10 3 | De Piscopo;Tullio;9;9;8;8;7;7;6;6;0;5 4 | Montalbano;Salvo;10;10;9;10;10;10;9;10;10;10 5 | -------------------------------------------------------------------------------- /Python/src/2023-24/20240112 rules.dat: -------------------------------------------------------------------------------- 1 | 01-01-2021: +surgical_mask_outdoor +surgical_mask_indoor 2 | 05-01-2021: -surgical_mask_indoor +ffp2_mask_indoor 3 | 08-01-2021: +green_pass_workplace 4 | 05-03-2021: +super_green_pass_workplace -green_pass_workplace 5 | 01-02-2021: -ffp2_mask_indoor +surgical_mask_indoor -surgical_mask_outdoor 6 | 01-03-2021: +surgical_mask_outdoor 7 | -------------------------------------------------------------------------------- /Python/src/2023-24/my_lib.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2023 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(): 7 | print(f"{__name__}:: I'm foo") 8 | 9 | 10 | def main(): 11 | foo() 12 | 13 | 14 | if __name__ == "__main__": 15 | main() 16 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241004 first.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | # This is a comment! 5 | 6 | 7 | # In Python a variable is an Object bound to a Name 8 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9 | 10 | A = "Pepsi" 11 | print(A) 12 | 13 | B = "Coke" 14 | print(A, B) 15 | 16 | A = B 17 | print(A, B) 18 | 19 | C = "Pepsi" 20 | D = "Pepsi" 21 | 22 | print(A, B, C, D) 23 | C = D 24 | print(A, B, C, D) 25 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241004 second.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = input("What's your name? ") 6 | 7 | surname = input("What's your surname? ") 8 | full_name = name + ' ' + surname 9 | print("Hello", full_name, "how are you?") 10 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241004 third.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | value_as_string = input("Number: ") 6 | value_as_int = int(value_as_string) 7 | 8 | if value_as_int > 10_000: 9 | print("Ooooooooohhh") 10 | print("Oooooooooooooooohhhhhhh") 11 | else: 12 | print("ahah") 13 | print("ahah") 14 | print("ahah") 15 | print("ahah") 16 | 17 | print("Goodbye") 18 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241011 strings ops.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | s = input() 6 | 7 | if s.isalpha(): 8 | print("All letters") 9 | if s.isalnum(): 10 | print("All letters or numbers") 11 | if s.isdecimal(): 12 | print("Decimal number") 13 | 14 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241011 tiles.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | TILE_WIDTH = 5 6 | 7 | total_width = int(input("Total width: ")) 8 | n_pairs = (total_width - TILE_WIDTH) // (2 * TILE_WIDTH) 9 | print(f"Total number of pairs: {n_pairs}") 10 | total_gap = total_width - TILE_WIDTH - n_pairs * 2 * TILE_WIDTH 11 | print(f"Gap: {total_gap}") 12 | 13 | print(f"Gap in each side: {total_gap/2:g}in") 14 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241015 strings.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = "Giovanni Adolfo Pietro Pio Squillero" 6 | print(type(name)) 7 | 8 | print(name[0]) 9 | first = name[0] 10 | print(type(first), len(first)) 11 | 12 | print(name[1]) 13 | print(name[2:5]) 14 | 15 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 defaults.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from icecream import ic 6 | 7 | ic(int()) 8 | ic(bool()) 9 | ic(float()) 10 | ic(str()) 11 | ic(complex()) 12 | ic(list()) 13 | 14 | # Conversion ANY -> bool 15 | ic(bool("Giovanni Squillero")) 16 | ic([1, 2, 3]) -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 ice-cream.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | # Install from the terminal 6 | # pip install -U icecream 7 | 8 | from icecream import ic 9 | 10 | foo = [1, 2, 3] 11 | bar = foo 12 | ic(foo, bar) 13 | ic(foo == bar) 14 | ic(foo is bar) 15 | 16 | baz = [1, 2, 3] 17 | ic(foo == baz) 18 | ic(foo is baz) 19 | 20 | variable = 32 21 | ic(variable) 22 | ic() 23 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 inifinity.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | n = 1 6 | while True: 7 | n = n * 2 8 | print(n) 9 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 lists.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | colors = list() 6 | colors.append("blue") 7 | colors.append("red") 8 | colors.append("magenta") 9 | 10 | foo = colors 11 | foo.append(42) 12 | 13 | print(colors == foo) 14 | print(colors is foo) 15 | 16 | print(list("Giovanni")) 17 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 while.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | name = "" 6 | while name != "Giovanni": 7 | name = input("Name: ") 8 | print(f"Hi, {name}!!!!!") 9 | 10 | # Alternative 11 | # name = input("Name: ") 12 | # while name != "Giovanni": 13 | # print(f"Hi, {name}!!!!!") 14 | # name = input("Name: ") 15 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241018 while2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | num = 3.14 6 | while num < 13.21: 7 | num = num * 1.2765 8 | print(num) 9 | # break/continue as with for 10 | else: # as in for 11 | print("Smooth...") 12 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241022 enum.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | foo = list("Giovanni Adolfo Pietro Pio Squillero") 6 | 7 | for c in foo: 8 | print(c) 9 | 10 | # BAD IDEA 11 | for i in range(len(foo)): 12 | print(i, foo[i]) 13 | 14 | # BETTER 15 | for i, c in enumerate(foo): 16 | print(i, c) 17 | 18 | for yes in enumerate(foo): 19 | print(yes) 20 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241025 input.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | print("Tell me 10 positive integer") 6 | numbers = list() 7 | 8 | while len(numbers) < 10: 9 | num = int(input('')) 10 | 11 | if num < 0: 12 | print("D'ho!") 13 | else: 14 | numbers.append(num) 15 | 16 | print(numbers) 17 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241025 money.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | money = 1 6 | rate = float(input("Interest rate: ")) 7 | goal = 2 * money 8 | 9 | years = 0 10 | while money < goal: 11 | years += 1 # years = years + 1 12 | money += money * rate # money = money + money * rate 13 | 14 | print(f"After {years} years, my money doubled!") 15 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241029 function-param.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def potato(number): 7 | print(f"Hello, my potato friend number {number}") 8 | 9 | 10 | foo = 42 11 | potato(foo) 12 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241029 functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def func(): 7 | print("Hello! This is my first function") 8 | 9 | 10 | print("This is the program") 11 | func() 12 | print("2") 13 | func() 14 | func() 15 | 16 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241029 scope.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def giovanni(): 7 | d = 23 8 | m = 10 9 | print(m, d) 10 | 11 | 12 | def paola(): 13 | d = 18 14 | m = 5 15 | print(m, d) 16 | 17 | 18 | giovanni() 19 | paola() 20 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241105 is-odd.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def is_odd(number): 7 | if number % 2 == 0: 8 | return False 9 | else: 10 | return True 11 | 12 | 13 | num = int(input("number: ")) 14 | if is_odd(num): 15 | print("Yeah!") 16 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241105 primes2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from math import sqrt, floor, ceil 6 | 7 | 8 | def prime(number): 9 | if number % 2 == 0 and number != 2: 10 | return False 11 | for n in range(3, ceil(sqrt(number)) + 1, 2): 12 | if number % n == 0: 13 | return False 14 | return True 15 | 16 | 17 | for n in range(10): 18 | print(f"{n} -> {prime(n)}") 19 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241105 return.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | def square(x): 6 | result = x ** 2 7 | return result 8 | 9 | result = 1 10 | print(square(result)) 11 | print(result) 12 | print(square(result+1)) 13 | 14 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241105 strings.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | beatles = """John 6 | Paul 7 | George 8 | Ringo""" 9 | 10 | print(beatles) 11 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241108 functions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def foo(bar): 7 | bar.extend([18, 5]) 8 | 9 | 10 | def gargle(bar): 11 | bar = [18, 5] 12 | 13 | 14 | x = [23, 10] 15 | foo(x) 16 | gargle(x) 17 | print(x) 18 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241108 ret-lists.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def make_list(a, b, c, d): 7 | return [a, b, c, d] 8 | 9 | 10 | def make_tuple(a, b, c, d): 11 | # implicit 12 | return a, b, c, d 13 | 14 | 15 | value = make_list(23, 10, 18, 5) 16 | print(value) 17 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241108 return.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def answer(): 7 | return 42 8 | 9 | 10 | def no_aswer(): 11 | print("D'ho!?") 12 | 13 | 14 | x = answer() 15 | answer() 16 | z = 2 * answer() 17 | 18 | no_aswer() 19 | value = no_aswer() 20 | print(value) 21 | 22 | if value is None: 23 | print("Whoa! Value is None!!!!") 24 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241108 return2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | from icecream import ic 7 | 8 | 9 | def swap(a, b): 10 | return b, a 11 | 12 | 13 | value = swap(23, 10) 14 | ic(value) 15 | ic(type(value)) 16 | 17 | foo = 23 18 | bar = 10 19 | bar, foo = swap(foo, bar) 20 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241112 conversion.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codetoanbug/computer-sciences/2a5d3f1453d764506729688502141ddc19bf0ba9/Python/src/2024-25/20241112 conversion.py -------------------------------------------------------------------------------- /Python/src/2024-25/20241115 exceptions.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | number = None 8 | while number is None: 9 | try: 10 | number = int(input("Number: ")) 11 | except ValueError: 12 | pass 13 | try: 14 | inverse = 1 / number 15 | except ZeroDivisionError: 16 | inverse = None 17 | print(f"Inverse of {number} is {inverse}") 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241115 files2.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | FILENAME = '20241115 song.txt' 6 | 7 | def sing(song): 8 | try: 9 | with open(song) as lyrics: 10 | for line in lyrics: 11 | print(line.rstrip()) 12 | except OSError as problem: 13 | exit(problem) 14 | print(None) 15 | 16 | 17 | def main(): 18 | sing(FILENAME) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241122 1-line.zap: -------------------------------------------------------------------------------- 1 | 1-line file 2 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241122 movies.gx: -------------------------------------------------------------------------------- 1 | Sharknado 2 | Plan 9 from outer space 3 | Battlefield Earth 4 | Interstellar 5 | Joker II 6 | Last Jedi 7 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241122 movies2.gx: -------------------------------------------------------------------------------- 1 | Sharknado 2 | Plan 9 from outer space 3 | Battlefield Earth 4 | Joker II 5 | Last Jedi 6 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241122 repr.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | WORKING_DAYS = 5 6 | 7 | 8 | def main(): 9 | a = 23 10 | b = "\t23\n\n" 11 | c = 23.0 12 | print(str(a), str(b), str(c)) 13 | print(repr(a), repr(b), repr(c)) 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241126 chess.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | PLAYERS_FILE = '20241126 players.csv' 6 | 7 | 8 | def open_csv(filename): 9 | try: 10 | with open(filename) as fin: 11 | lines = fin.readlines() 12 | except OSError: 13 | lines = list() 14 | return lines 15 | 16 | 17 | def main(): 18 | players = open_csv(PLAYERS_FILE) 19 | print(players) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241126 dict.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | from icecream import ic 6 | 7 | foo = dict() 8 | foo[2310] = 'Giovanni' 9 | foo[185] = 'Paola' 10 | ic(foo) 11 | 12 | bar = dict() 13 | bar['Giovanni'] = (23, 10) 14 | bar['Paola'] = (18, 5) 15 | bar[18] = 'Uuuuuu' 16 | bar[(1, 2, 3)] = [1, 2, 3, 4] 17 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241126 players.csv: -------------------------------------------------------------------------------- 1 | PLAYER,SELO 2 | Magnus Carlsen,2856 3 | Wesley So,2772 4 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241129 dicts.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | def main(): 6 | abook = dict() 7 | abook['giovanni'] = 'giovanni.squillero@polito.it' 8 | 9 | key = 'paola' 10 | if key not in abook: 11 | print("Yeuch") 12 | else: 13 | print(abook[key]) 14 | 15 | try: 16 | value = abook[key] 17 | except KeyError: 18 | value = 'Yeuch' 19 | print(value) 20 | 21 | 22 | if __name__ == '__main__': 23 | main() -------------------------------------------------------------------------------- /Python/src/2024-25/20241129 sets.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def main(): 7 | friends = set() 8 | friends.add('Giovanni') 9 | friends.add('Adolfo') 10 | friends.add('Pietro') 11 | friends.add('Pio') 12 | friends.add('Giovanni') 13 | 14 | print(friends) 15 | print(tuple(friends)) 16 | 17 | for x in enumerate(friends): 18 | print(x) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241210 map.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | 6 | def add_one(x): 7 | return x + 1 8 | 9 | 10 | def main(): 11 | data = [18, 5, 23, 10] 12 | print(list(range(10))) 13 | print(list(map(add_one, data))) 14 | 15 | 16 | if __name__ == '__main__': 17 | main() 18 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241210 rules.dat: -------------------------------------------------------------------------------- 1 | 47|53 2 | 97|13 3 | 97|61 4 | 97|47 5 | 75|29 6 | 61|13 7 | 75|53 8 | 29|13 9 | 97|29 10 | 53|29 11 | 61|53 12 | 97|53 13 | 61|29 14 | 47|13 15 | 75|47 16 | 97|75 17 | 47|61 18 | 75|61 19 | 47|29 20 | 75|13 21 | 53|13 22 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241210 updates.dat: -------------------------------------------------------------------------------- 1 | 75,47,61,53,29 2 | 97,61,53,29,13 3 | 75,29,13 4 | 75,97,47,61,53 5 | 61,13,29 6 | 97,13,75,29,47 7 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241210 xmas.dat: -------------------------------------------------------------------------------- 1 | MMMSXXMASM 2 | MSAMXMSMSA 3 | AMXSXMAAMM 4 | MSAMASMSMX 5 | XMASAMXAMM 6 | XXAMMXXAMA 7 | SMSMSASXSS 8 | SAXAMASAAA 9 | MAMMMXMMMM 10 | MXMXAXMASX 11 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241213 players.csv: -------------------------------------------------------------------------------- 1 | PLAYER;SELO 2 | Alexander Grischuk;2764 3 | Alireza Firouzja;2804 4 | Anish Giri; 2772 5 | Ding Liren;2799 6 | Fabiano Caruana;2792 7 | Ian Nepomniachtchi;2782 8 | Jan Krzysztof Duda;2760 9 | Leinier Dominguez Perez;2752 10 | Levon Aronian;2772 11 | Magnus Carlsen;2856 12 | Maxime Vachier Lagrave;2761 13 | Richard Rapport;2763 14 | Shakhriyar Mamedyarov;2767 15 | Teimour Radjabov;2753 16 | Wesley So;2772 17 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241217 friend.csv: -------------------------------------------------------------------------------- 1 | NAME,SURNAME,EMAIL,FOOD,MOVIE 2 | John,Doe,doe@polito.it,Pizza,Interstellar 3 | Jane,Row,row@stanford.edu,Pizza,Inception 4 | Giovanni,Squillero,squillero@polito.it,Ice cream,The Banshee of Inisherin 5 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241217 wow.txt: -------------------------------------------------------------------------------- 1 | line sound word time line back number way water 2 | people boy water sound line day part sound work place 3 | year number line word boy back boy man thing time 4 | name sentence back man sound 5 | line boy sound word 6 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241220 2d-arrays.py: -------------------------------------------------------------------------------- 1 | # Copyright © 2024 Giovanni Squillero 2 | # https://github.com/squillero/computer-sciences 3 | # Free under certain conditions — see the license for details. 4 | 5 | DIM_COLUMNS = 20 6 | DIM_ROWS = 5 7 | 8 | 9 | def print_array(array): 10 | for row in array: 11 | print('|'.join(row)) 12 | 13 | 14 | def main(): 15 | array2d = list() 16 | for _ in range(DIM_ROWS): 17 | array2d.append(['*'] * DIM_COLUMNS) 18 | print_array(array2d) 19 | print() 20 | array2d[0][1] = '!' 21 | array2d[1][2] = '+' 22 | print_array(array2d) 23 | 24 | 25 | if __name__ == '__main__': 26 | main() 27 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241220 bowling.txt: -------------------------------------------------------------------------------- 1 | Rossi;Massimo;7;10;6;5;10;4;9;9;5;10;10 2 | Verdi;Giuseppe;10;10;6;6;7;9;9;8;9;9;10;10;10;9;8;8;10;10;10 3 | De Piscopo;Tullio;9 4 | Montalbano;Salvo;10;10;9;10;10;10;9;10;10;10 5 | Bianchi;Luca;8;7;9;6;8;7 6 | Ferrari;Alessandro;6;8;4;6;3;7;9;8;7;6;7;8;9;8;7;8;9;7;8;9;8 7 | Esposito;Giulia;9;9;8;8;9;9;8;9;9;8;9;9 8 | Ricci;Francesca;7;8;7;8;7;8;7;8;7;8;7;8 9 | Romano;Marco;8;8;7;9;8;7;10;4;8;9;8;7;8;9;7;7;6;6;0;5 10 | Russo;Anna;9;9 11 | Gallo;Sofia;7;8;7;8;7;0;1;9;0;8;7;8;7;8;7;8 12 | Conti;Matteo;6;7;8;10;10;7;6;7;8;7;6;7;8;7;8;8;9;9;8;9;9;8;9;9 13 | Squillero;Giovanni;0;0 14 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241220 guess_who - questions1.txt: -------------------------------------------------------------------------------- 1 | Hair color = Blond 2 | Hair length = Short 3 | Glasses = YES 4 | -------------------------------------------------------------------------------- /Python/src/2024-25/20241220 guess_who - questions2.txt: -------------------------------------------------------------------------------- 1 | Gender = Male 2 | Hair length = Short 3 | Beard = YES 4 | --------------------------------------------------------------------------------