clpz

Find powers of 2 in a list Prolog

浪尽此生 提交于 2019-12-17 02:32:28
问题 I'm trying to create a list in Prolog (SWI Prolog) and check which numbers are powers of 2 and second find how many times a specific number is in the list (in this example I'm trying to find how many times the number 3 is in the list). For a example, if you ask ?- check([0,2,3,-5,-2,1,8,7,4], MULT2, THREE). you should see MULT2=[2,8,4] THREE=1 My first try to find a solution is to search the list with head and doing head mod 2 = 0 to find all numbers which are powers of 2, but something went

Find powers of 2 in a list Prolog

自闭症网瘾萝莉.ら 提交于 2019-11-26 12:33:20
I'm trying to create a list in Prolog (SWI Prolog) and check which numbers are powers of 2 and second find how many times a specific number is in the list (in this example I'm trying to find how many times the number 3 is in the list). For a example, if you ask ?- check([0,2,3,-5,-2,1,8,7,4], MULT2, THREE). you should see MULT2=[2,8,4] THREE=1 My first try to find a solution is to search the list with head and doing head mod 2 = 0 to find all numbers which are powers of 2, but something went wrong and I only get "false" as an answer. Here's how you can find the "powers of two" in logically