From 5c7d84e8f9cea68f4261404e51e30198460272bf Mon Sep 17 00:00:00 2001 From: FLotfiGit Date: Fri, 1 Mar 2024 14:56:29 -0500 Subject: [PATCH 1/5] update --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fc54ea7..7ca5cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ .pyc *.*~ _*_.* - +.ipynb From 9c7d6d24eb9b8c175fea5ff3268d8af1d529f08a Mon Sep 17 00:00:00 2001 From: FLotfiGit Date: Fri, 1 Mar 2024 14:57:41 -0500 Subject: [PATCH 2/5] update --- MyNoteBook.ipynb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 MyNoteBook.ipynb diff --git a/MyNoteBook.ipynb b/MyNoteBook.ipynb new file mode 100644 index 0000000..0abbfad --- /dev/null +++ b/MyNoteBook.ipynb @@ -0,0 +1,21 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# test codes\n" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} From ee78e9edd769081ea54fc60660f51f77ef5d2ad5 Mon Sep 17 00:00:00 2001 From: FLotfiGit Date: Sat, 2 Mar 2024 10:42:58 -0500 Subject: [PATCH 3/5] update --- 3sum_closest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/3sum_closest.py b/3sum_closest.py index 777f7ac..210c9c1 100644 --- a/3sum_closest.py +++ b/3sum_closest.py @@ -21,7 +21,7 @@ def sum_closest(L, num_k, target): prev = {} max_t = sum([x for x in L if x > 0]) min_t = sum([x for x in L if x <= 0]) - print 'target range: [%d, %d]' %(min_t, max_t) + print('target range: [%d, %d]' %(min_t, max_t)) # Initialization: # S(0,any,any) = False @@ -57,7 +57,7 @@ def sum_closest(L, num_k, target): next_i,next_k,next_t = prev[(i,k,t)] if next_k == k-1: output.append(L[next_i]) i,k,t = next_i,next_k,next_t - print 'output:', output, 'sum(output):', sum(output) + print('output:', output, 'sum(output):', sum(output)) return output From 5cc48cb8763871d3f329c6bd557a823f3e4fc7ea Mon Sep 17 00:00:00 2001 From: FLotfiGit Date: Sat, 2 Mar 2024 10:57:24 -0500 Subject: [PATCH 4/5] my_update --- 3sum_closest.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/3sum_closest.py b/3sum_closest.py index 210c9c1..301a5df 100644 --- a/3sum_closest.py +++ b/3sum_closest.py @@ -10,12 +10,12 @@ ''' from __future__ import division import random +import math ### DP? Given a list L # S(i, k, target) = True if we can find k elements among L[:i] to sum up to target # S(i, k, target) = S(i-1, k-1, target-L[i-1]) or S(i-1, k, target) def sum_closest(L, num_k, target): - import math n = len(L) S = {} prev = {} @@ -62,6 +62,17 @@ def sum_closest(L, num_k, target): if __name__ == '__main__': - sum_closest([-1, 2, 1, -3, 6], 2, 2) - + sum_closest([-1, 2, 1, -3, 6], 3, 2) +####---------- my test codes ------------#### +# this is for 3 number in order! +def my_sum(L,num_k,target): + for i in range(len(L)): + sum_L = 0 + output = [] + for j in range(num_k): + sum_L += L[i+j] + output.append(L[i+j]) + if sum_L == target: + break + return output \ No newline at end of file From bc617d6c18686a3ff34adcd5cf745cfa3f8b10ee Mon Sep 17 00:00:00 2001 From: FLotfiGit Date: Sun, 3 Mar 2024 19:55:53 -0500 Subject: [PATCH 5/5] update --- MyNoteBook.ipynb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MyNoteBook.ipynb b/MyNoteBook.ipynb index 0abbfad..d20924e 100644 --- a/MyNoteBook.ipynb +++ b/MyNoteBook.ipynb @@ -11,10 +11,21 @@ } ], "metadata": { + "kernelspec": { + "display_name": "Python 3.8.13 ('pytorch_m1')", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "name": "python", + "version": "3.8.13" }, - "orig_nbformat": 4 + "orig_nbformat": 4, + "vscode": { + "interpreter": { + "hash": "7847b48317249e3ca26d69faac65a9677ad7ca85de2bc94a91f5d8868713ce5f" + } + } }, "nbformat": 4, "nbformat_minor": 2